switched to ent

This commit is contained in:
Giovanni Harting 2021-07-12 00:50:40 +02:00
parent d1df9f6943
commit f124a95e4c
25 changed files with 6697 additions and 95 deletions

212
ent/client.go Normal file
View File

@ -0,0 +1,212 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"log"
"ALHP.go/ent/migrate"
"ALHP.go/ent/dbpackage"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
)
// Client is the client that holds all ent builders.
type Client struct {
config
// Schema is the client for creating, migrating and dropping schema.
Schema *migrate.Schema
// DbPackage is the client for interacting with the DbPackage builders.
DbPackage *DbPackageClient
}
// NewClient creates a new client configured with the given options.
func NewClient(opts ...Option) *Client {
cfg := config{log: log.Println, hooks: &hooks{}}
cfg.options(opts...)
client := &Client{config: cfg}
client.init()
return client
}
func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.DbPackage = NewDbPackageClient(c.config)
}
// Open opens a database/sql.DB specified by the driver name and
// the data source name, and returns a new client attached to it.
// Optional parameters can be added for configuring the client.
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
switch driverName {
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
drv, err := sql.Open(driverName, dataSourceName)
if err != nil {
return nil, err
}
return NewClient(append(options, Driver(drv))...), nil
default:
return nil, fmt.Errorf("unsupported driver: %q", driverName)
}
}
// Tx returns a new transactional client. The provided context
// is used until the transaction is committed or rolled back.
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
if _, ok := c.driver.(*txDriver); ok {
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
}
tx, err := newTx(ctx, c.driver)
if err != nil {
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
}
cfg := c.config
cfg.driver = tx
return &Tx{
ctx: ctx,
config: cfg,
DbPackage: NewDbPackageClient(cfg),
}, nil
}
// BeginTx returns a transactional client with specified options.
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
if _, ok := c.driver.(*txDriver); ok {
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
}
tx, err := c.driver.(interface {
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
}).BeginTx(ctx, opts)
if err != nil {
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
}
cfg := c.config
cfg.driver = &txDriver{tx: tx, drv: c.driver}
return &Tx{
config: cfg,
DbPackage: NewDbPackageClient(cfg),
}, nil
}
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// DbPackage.
// Query().
// Count(ctx)
//
func (c *Client) Debug() *Client {
if c.debug {
return c
}
cfg := c.config
cfg.driver = dialect.Debug(c.driver, c.log)
client := &Client{config: cfg}
client.init()
return client
}
// Close closes the database connection and prevents new queries from starting.
func (c *Client) Close() error {
return c.driver.Close()
}
// Use adds the mutation hooks to all the entity clients.
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
c.DbPackage.Use(hooks...)
}
// DbPackageClient is a client for the DbPackage schema.
type DbPackageClient struct {
config
}
// NewDbPackageClient returns a client for the DbPackage from the given config.
func NewDbPackageClient(c config) *DbPackageClient {
return &DbPackageClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `dbpackage.Hooks(f(g(h())))`.
func (c *DbPackageClient) Use(hooks ...Hook) {
c.hooks.DbPackage = append(c.hooks.DbPackage, hooks...)
}
// Create returns a create builder for DbPackage.
func (c *DbPackageClient) Create() *DbPackageCreate {
mutation := newDbPackageMutation(c.config, OpCreate)
return &DbPackageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of DbPackage entities.
func (c *DbPackageClient) CreateBulk(builders ...*DbPackageCreate) *DbPackageCreateBulk {
return &DbPackageCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for DbPackage.
func (c *DbPackageClient) Update() *DbPackageUpdate {
mutation := newDbPackageMutation(c.config, OpUpdate)
return &DbPackageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *DbPackageClient) UpdateOne(dp *DbPackage) *DbPackageUpdateOne {
mutation := newDbPackageMutation(c.config, OpUpdateOne, withDbPackage(dp))
return &DbPackageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *DbPackageClient) UpdateOneID(id int) *DbPackageUpdateOne {
mutation := newDbPackageMutation(c.config, OpUpdateOne, withDbPackageID(id))
return &DbPackageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for DbPackage.
func (c *DbPackageClient) Delete() *DbPackageDelete {
mutation := newDbPackageMutation(c.config, OpDelete)
return &DbPackageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a delete builder for the given entity.
func (c *DbPackageClient) DeleteOne(dp *DbPackage) *DbPackageDeleteOne {
return c.DeleteOneID(dp.ID)
}
// DeleteOneID returns a delete builder for the given id.
func (c *DbPackageClient) DeleteOneID(id int) *DbPackageDeleteOne {
builder := c.Delete().Where(dbpackage.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &DbPackageDeleteOne{builder}
}
// Query returns a query builder for DbPackage.
func (c *DbPackageClient) Query() *DbPackageQuery {
return &DbPackageQuery{
config: c.config,
}
}
// Get returns a DbPackage entity by its id.
func (c *DbPackageClient) Get(ctx context.Context, id int) (*DbPackage, error) {
return c.Query().Where(dbpackage.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *DbPackageClient) GetX(ctx context.Context, id int) *DbPackage {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *DbPackageClient) Hooks() []Hook {
return c.hooks.DbPackage
}

59
ent/config.go Normal file
View File

@ -0,0 +1,59 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"entgo.io/ent"
"entgo.io/ent/dialect"
)
// Option function to configure the client.
type Option func(*config)
// Config is the configuration for the client and its builder.
type config struct {
// driver used for executing database requests.
driver dialect.Driver
// debug enable a debug logging.
debug bool
// log used for logging on debug mode.
log func(...interface{})
// hooks to execute on mutations.
hooks *hooks
}
// hooks per client, for fast access.
type hooks struct {
DbPackage []ent.Hook
}
// Options applies the options on the config object.
func (c *config) options(opts ...Option) {
for _, opt := range opts {
opt(c)
}
if c.debug {
c.driver = dialect.Debug(c.driver, c.log)
}
}
// Debug enables debug logging on the ent.Driver.
func Debug() Option {
return func(c *config) {
c.debug = true
}
}
// Log sets the logging function for debug mode.
func Log(fn func(...interface{})) Option {
return func(c *config) {
c.log = fn
}
}
// Driver configures the client driver.
func Driver(driver dialect.Driver) Option {
return func(c *config) {
c.driver = driver
}
}

33
ent/context.go Normal file
View File

@ -0,0 +1,33 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
)
type clientCtxKey struct{}
// FromContext returns a Client stored inside a context, or nil if there isn't one.
func FromContext(ctx context.Context) *Client {
c, _ := ctx.Value(clientCtxKey{}).(*Client)
return c
}
// NewContext returns a new context with the given Client attached.
func NewContext(parent context.Context, c *Client) context.Context {
return context.WithValue(parent, clientCtxKey{}, c)
}
type txCtxKey struct{}
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
func TxFromContext(ctx context.Context) *Tx {
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
return tx
}
// NewTxContext returns a new context with the given Tx attached.
func NewTxContext(parent context.Context, tx *Tx) context.Context {
return context.WithValue(parent, txCtxKey{}, tx)
}

208
ent/dbpackage.go Normal file
View File

@ -0,0 +1,208 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"ALHP.go/ent/dbpackage"
"entgo.io/ent/dialect/sql"
)
// DbPackage is the model entity for the DbPackage schema.
type DbPackage struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Pkgbase holds the value of the "pkgbase" field.
Pkgbase string `json:"pkgbase,omitempty"`
// Packages holds the value of the "packages" field.
Packages []string `json:"packages,omitempty"`
// Status holds the value of the "status" field.
Status int `json:"status,omitempty"`
// SkipReason holds the value of the "skip_reason" field.
SkipReason string `json:"skip_reason,omitempty"`
// Repository holds the value of the "repository" field.
Repository string `json:"repository,omitempty"`
// March holds the value of the "march" field.
March string `json:"march,omitempty"`
// Version holds the value of the "version" field.
Version string `json:"version,omitempty"`
// RepoVersion holds the value of the "repo_version" field.
RepoVersion string `json:"repo_version,omitempty"`
// BuildTime holds the value of the "build_time" field.
BuildTime time.Time `json:"build_time,omitempty"`
// BuildDuration holds the value of the "build_duration" field.
BuildDuration uint64 `json:"build_duration,omitempty"`
// Updated holds the value of the "updated" field.
Updated time.Time `json:"updated,omitempty"`
}
// scanValues returns the types for scanning values from sql.Rows.
func (*DbPackage) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
case dbpackage.FieldPackages:
values[i] = new([]byte)
case dbpackage.FieldID, dbpackage.FieldStatus, dbpackage.FieldBuildDuration:
values[i] = new(sql.NullInt64)
case dbpackage.FieldPkgbase, dbpackage.FieldSkipReason, dbpackage.FieldRepository, dbpackage.FieldMarch, dbpackage.FieldVersion, dbpackage.FieldRepoVersion:
values[i] = new(sql.NullString)
case dbpackage.FieldBuildTime, dbpackage.FieldUpdated:
values[i] = new(sql.NullTime)
default:
return nil, fmt.Errorf("unexpected column %q for type DbPackage", columns[i])
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the DbPackage fields.
func (dp *DbPackage) assignValues(columns []string, values []interface{}) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case dbpackage.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
dp.ID = int(value.Int64)
case dbpackage.FieldPkgbase:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field pkgbase", values[i])
} else if value.Valid {
dp.Pkgbase = value.String
}
case dbpackage.FieldPackages:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field packages", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &dp.Packages); err != nil {
return fmt.Errorf("unmarshal field packages: %w", err)
}
}
case dbpackage.FieldStatus:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
dp.Status = int(value.Int64)
}
case dbpackage.FieldSkipReason:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field skip_reason", values[i])
} else if value.Valid {
dp.SkipReason = value.String
}
case dbpackage.FieldRepository:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field repository", values[i])
} else if value.Valid {
dp.Repository = value.String
}
case dbpackage.FieldMarch:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field march", values[i])
} else if value.Valid {
dp.March = value.String
}
case dbpackage.FieldVersion:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field version", values[i])
} else if value.Valid {
dp.Version = value.String
}
case dbpackage.FieldRepoVersion:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field repo_version", values[i])
} else if value.Valid {
dp.RepoVersion = value.String
}
case dbpackage.FieldBuildTime:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field build_time", values[i])
} else if value.Valid {
dp.BuildTime = value.Time
}
case dbpackage.FieldBuildDuration:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field build_duration", values[i])
} else if value.Valid {
dp.BuildDuration = uint64(value.Int64)
}
case dbpackage.FieldUpdated:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated", values[i])
} else if value.Valid {
dp.Updated = value.Time
}
}
}
return nil
}
// Update returns a builder for updating this DbPackage.
// Note that you need to call DbPackage.Unwrap() before calling this method if this DbPackage
// was returned from a transaction, and the transaction was committed or rolled back.
func (dp *DbPackage) Update() *DbPackageUpdateOne {
return (&DbPackageClient{config: dp.config}).UpdateOne(dp)
}
// Unwrap unwraps the DbPackage entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (dp *DbPackage) Unwrap() *DbPackage {
tx, ok := dp.config.driver.(*txDriver)
if !ok {
panic("ent: DbPackage is not a transactional entity")
}
dp.config.driver = tx.drv
return dp
}
// String implements the fmt.Stringer.
func (dp *DbPackage) String() string {
var builder strings.Builder
builder.WriteString("DbPackage(")
builder.WriteString(fmt.Sprintf("id=%v", dp.ID))
builder.WriteString(", pkgbase=")
builder.WriteString(dp.Pkgbase)
builder.WriteString(", packages=")
builder.WriteString(fmt.Sprintf("%v", dp.Packages))
builder.WriteString(", status=")
builder.WriteString(fmt.Sprintf("%v", dp.Status))
builder.WriteString(", skip_reason=")
builder.WriteString(dp.SkipReason)
builder.WriteString(", repository=")
builder.WriteString(dp.Repository)
builder.WriteString(", march=")
builder.WriteString(dp.March)
builder.WriteString(", version=")
builder.WriteString(dp.Version)
builder.WriteString(", repo_version=")
builder.WriteString(dp.RepoVersion)
builder.WriteString(", build_time=")
builder.WriteString(dp.BuildTime.Format(time.ANSIC))
builder.WriteString(", build_duration=")
builder.WriteString(fmt.Sprintf("%v", dp.BuildDuration))
builder.WriteString(", updated=")
builder.WriteString(dp.Updated.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// DbPackages is a parsable slice of DbPackage.
type DbPackages []*DbPackage
func (dp DbPackages) config(cfg config) {
for _i := range dp {
dp[_i].config = cfg
}
}

View File

@ -0,0 +1,73 @@
// Code generated by entc, DO NOT EDIT.
package dbpackage
const (
// Label holds the string label denoting the dbpackage type in the database.
Label = "db_package"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldPkgbase holds the string denoting the pkgbase field in the database.
FieldPkgbase = "pkgbase"
// FieldPackages holds the string denoting the packages field in the database.
FieldPackages = "packages"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldSkipReason holds the string denoting the skip_reason field in the database.
FieldSkipReason = "skip_reason"
// FieldRepository holds the string denoting the repository field in the database.
FieldRepository = "repository"
// FieldMarch holds the string denoting the march field in the database.
FieldMarch = "march"
// FieldVersion holds the string denoting the version field in the database.
FieldVersion = "version"
// FieldRepoVersion holds the string denoting the repo_version field in the database.
FieldRepoVersion = "repo_version"
// FieldBuildTime holds the string denoting the build_time field in the database.
FieldBuildTime = "build_time"
// FieldBuildDuration holds the string denoting the build_duration field in the database.
FieldBuildDuration = "build_duration"
// FieldUpdated holds the string denoting the updated field in the database.
FieldUpdated = "updated"
// Table holds the table name of the dbpackage in the database.
Table = "db_packages"
)
// Columns holds all SQL columns for dbpackage fields.
var Columns = []string{
FieldID,
FieldPkgbase,
FieldPackages,
FieldStatus,
FieldSkipReason,
FieldRepository,
FieldMarch,
FieldVersion,
FieldRepoVersion,
FieldBuildTime,
FieldBuildDuration,
FieldUpdated,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// PkgbaseValidator is a validator for the "pkgbase" field. It is called by the builders before save.
PkgbaseValidator func(string) error
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator func(int) error
// RepositoryValidator is a validator for the "repository" field. It is called by the builders before save.
RepositoryValidator func(string) error
// MarchValidator is a validator for the "march" field. It is called by the builders before save.
MarchValidator func(string) error
// BuildDurationValidator is a validator for the "build_duration" field. It is called by the builders before save.
BuildDurationValidator func(uint64) error
)

1277
ent/dbpackage/where.go Normal file

File diff suppressed because it is too large Load Diff

412
ent/dbpackage_create.go Normal file
View File

@ -0,0 +1,412 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"ALHP.go/ent/dbpackage"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// DbPackageCreate is the builder for creating a DbPackage entity.
type DbPackageCreate struct {
config
mutation *DbPackageMutation
hooks []Hook
}
// SetPkgbase sets the "pkgbase" field.
func (dpc *DbPackageCreate) SetPkgbase(s string) *DbPackageCreate {
dpc.mutation.SetPkgbase(s)
return dpc
}
// SetPackages sets the "packages" field.
func (dpc *DbPackageCreate) SetPackages(s []string) *DbPackageCreate {
dpc.mutation.SetPackages(s)
return dpc
}
// SetStatus sets the "status" field.
func (dpc *DbPackageCreate) SetStatus(i int) *DbPackageCreate {
dpc.mutation.SetStatus(i)
return dpc
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (dpc *DbPackageCreate) SetNillableStatus(i *int) *DbPackageCreate {
if i != nil {
dpc.SetStatus(*i)
}
return dpc
}
// SetSkipReason sets the "skip_reason" field.
func (dpc *DbPackageCreate) SetSkipReason(s string) *DbPackageCreate {
dpc.mutation.SetSkipReason(s)
return dpc
}
// SetNillableSkipReason sets the "skip_reason" field if the given value is not nil.
func (dpc *DbPackageCreate) SetNillableSkipReason(s *string) *DbPackageCreate {
if s != nil {
dpc.SetSkipReason(*s)
}
return dpc
}
// SetRepository sets the "repository" field.
func (dpc *DbPackageCreate) SetRepository(s string) *DbPackageCreate {
dpc.mutation.SetRepository(s)
return dpc
}
// SetMarch sets the "march" field.
func (dpc *DbPackageCreate) SetMarch(s string) *DbPackageCreate {
dpc.mutation.SetMarch(s)
return dpc
}
// SetVersion sets the "version" field.
func (dpc *DbPackageCreate) SetVersion(s string) *DbPackageCreate {
dpc.mutation.SetVersion(s)
return dpc
}
// SetNillableVersion sets the "version" field if the given value is not nil.
func (dpc *DbPackageCreate) SetNillableVersion(s *string) *DbPackageCreate {
if s != nil {
dpc.SetVersion(*s)
}
return dpc
}
// SetRepoVersion sets the "repo_version" field.
func (dpc *DbPackageCreate) SetRepoVersion(s string) *DbPackageCreate {
dpc.mutation.SetRepoVersion(s)
return dpc
}
// SetNillableRepoVersion sets the "repo_version" field if the given value is not nil.
func (dpc *DbPackageCreate) SetNillableRepoVersion(s *string) *DbPackageCreate {
if s != nil {
dpc.SetRepoVersion(*s)
}
return dpc
}
// SetBuildTime sets the "build_time" field.
func (dpc *DbPackageCreate) SetBuildTime(t time.Time) *DbPackageCreate {
dpc.mutation.SetBuildTime(t)
return dpc
}
// SetNillableBuildTime sets the "build_time" field if the given value is not nil.
func (dpc *DbPackageCreate) SetNillableBuildTime(t *time.Time) *DbPackageCreate {
if t != nil {
dpc.SetBuildTime(*t)
}
return dpc
}
// SetBuildDuration sets the "build_duration" field.
func (dpc *DbPackageCreate) SetBuildDuration(u uint64) *DbPackageCreate {
dpc.mutation.SetBuildDuration(u)
return dpc
}
// SetNillableBuildDuration sets the "build_duration" field if the given value is not nil.
func (dpc *DbPackageCreate) SetNillableBuildDuration(u *uint64) *DbPackageCreate {
if u != nil {
dpc.SetBuildDuration(*u)
}
return dpc
}
// SetUpdated sets the "updated" field.
func (dpc *DbPackageCreate) SetUpdated(t time.Time) *DbPackageCreate {
dpc.mutation.SetUpdated(t)
return dpc
}
// SetNillableUpdated sets the "updated" field if the given value is not nil.
func (dpc *DbPackageCreate) SetNillableUpdated(t *time.Time) *DbPackageCreate {
if t != nil {
dpc.SetUpdated(*t)
}
return dpc
}
// Mutation returns the DbPackageMutation object of the builder.
func (dpc *DbPackageCreate) Mutation() *DbPackageMutation {
return dpc.mutation
}
// Save creates the DbPackage in the database.
func (dpc *DbPackageCreate) Save(ctx context.Context) (*DbPackage, error) {
var (
err error
node *DbPackage
)
if len(dpc.hooks) == 0 {
if err = dpc.check(); err != nil {
return nil, err
}
node, err = dpc.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DbPackageMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err = dpc.check(); err != nil {
return nil, err
}
dpc.mutation = mutation
node, err = dpc.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(dpc.hooks) - 1; i >= 0; i-- {
mut = dpc.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, dpc.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX calls Save and panics if Save returns an error.
func (dpc *DbPackageCreate) SaveX(ctx context.Context) *DbPackage {
v, err := dpc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// check runs all checks and user-defined validators on the builder.
func (dpc *DbPackageCreate) check() error {
if _, ok := dpc.mutation.Pkgbase(); !ok {
return &ValidationError{Name: "pkgbase", err: errors.New("ent: missing required field \"pkgbase\"")}
}
if v, ok := dpc.mutation.Pkgbase(); ok {
if err := dbpackage.PkgbaseValidator(v); err != nil {
return &ValidationError{Name: "pkgbase", err: fmt.Errorf("ent: validator failed for field \"pkgbase\": %w", err)}
}
}
if v, ok := dpc.mutation.Status(); ok {
if err := dbpackage.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf("ent: validator failed for field \"status\": %w", err)}
}
}
if _, ok := dpc.mutation.Repository(); !ok {
return &ValidationError{Name: "repository", err: errors.New("ent: missing required field \"repository\"")}
}
if v, ok := dpc.mutation.Repository(); ok {
if err := dbpackage.RepositoryValidator(v); err != nil {
return &ValidationError{Name: "repository", err: fmt.Errorf("ent: validator failed for field \"repository\": %w", err)}
}
}
if _, ok := dpc.mutation.March(); !ok {
return &ValidationError{Name: "march", err: errors.New("ent: missing required field \"march\"")}
}
if v, ok := dpc.mutation.March(); ok {
if err := dbpackage.MarchValidator(v); err != nil {
return &ValidationError{Name: "march", err: fmt.Errorf("ent: validator failed for field \"march\": %w", err)}
}
}
if v, ok := dpc.mutation.BuildDuration(); ok {
if err := dbpackage.BuildDurationValidator(v); err != nil {
return &ValidationError{Name: "build_duration", err: fmt.Errorf("ent: validator failed for field \"build_duration\": %w", err)}
}
}
return nil
}
func (dpc *DbPackageCreate) sqlSave(ctx context.Context) (*DbPackage, error) {
_node, _spec := dpc.createSpec()
if err := sqlgraph.CreateNode(ctx, dpc.driver, _spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
return _node, nil
}
func (dpc *DbPackageCreate) createSpec() (*DbPackage, *sqlgraph.CreateSpec) {
var (
_node = &DbPackage{config: dpc.config}
_spec = &sqlgraph.CreateSpec{
Table: dbpackage.Table,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbpackage.FieldID,
},
}
)
if value, ok := dpc.mutation.Pkgbase(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldPkgbase,
})
_node.Pkgbase = value
}
if value, ok := dpc.mutation.Packages(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Value: value,
Column: dbpackage.FieldPackages,
})
_node.Packages = value
}
if value, ok := dpc.mutation.Status(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: dbpackage.FieldStatus,
})
_node.Status = value
}
if value, ok := dpc.mutation.SkipReason(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldSkipReason,
})
_node.SkipReason = value
}
if value, ok := dpc.mutation.Repository(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldRepository,
})
_node.Repository = value
}
if value, ok := dpc.mutation.March(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldMarch,
})
_node.March = value
}
if value, ok := dpc.mutation.Version(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldVersion,
})
_node.Version = value
}
if value, ok := dpc.mutation.RepoVersion(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldRepoVersion,
})
_node.RepoVersion = value
}
if value, ok := dpc.mutation.BuildTime(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: dbpackage.FieldBuildTime,
})
_node.BuildTime = value
}
if value, ok := dpc.mutation.BuildDuration(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: dbpackage.FieldBuildDuration,
})
_node.BuildDuration = value
}
if value, ok := dpc.mutation.Updated(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: dbpackage.FieldUpdated,
})
_node.Updated = value
}
return _node, _spec
}
// DbPackageCreateBulk is the builder for creating many DbPackage entities in bulk.
type DbPackageCreateBulk struct {
config
builders []*DbPackageCreate
}
// Save creates the DbPackage entities in the database.
func (dpcb *DbPackageCreateBulk) Save(ctx context.Context) ([]*DbPackage, error) {
specs := make([]*sqlgraph.CreateSpec, len(dpcb.builders))
nodes := make([]*DbPackage, len(dpcb.builders))
mutators := make([]Mutator, len(dpcb.builders))
for i := range dpcb.builders {
func(i int, root context.Context) {
builder := dpcb.builders[i]
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DbPackageMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
nodes[i], specs[i] = builder.createSpec()
var err error
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, dpcb.builders[i+1].mutation)
} else {
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, dpcb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
}
}
mutation.done = true
if err != nil {
return nil, err
}
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, dpcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (dpcb *DbPackageCreateBulk) SaveX(ctx context.Context) []*DbPackage {
v, err := dpcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}

108
ent/dbpackage_delete.go Normal file
View File

@ -0,0 +1,108 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"ALHP.go/ent/dbpackage"
"ALHP.go/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// DbPackageDelete is the builder for deleting a DbPackage entity.
type DbPackageDelete struct {
config
hooks []Hook
mutation *DbPackageMutation
}
// Where adds a new predicate to the DbPackageDelete builder.
func (dpd *DbPackageDelete) Where(ps ...predicate.DbPackage) *DbPackageDelete {
dpd.mutation.predicates = append(dpd.mutation.predicates, ps...)
return dpd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (dpd *DbPackageDelete) Exec(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(dpd.hooks) == 0 {
affected, err = dpd.sqlExec(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DbPackageMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
dpd.mutation = mutation
affected, err = dpd.sqlExec(ctx)
mutation.done = true
return affected, err
})
for i := len(dpd.hooks) - 1; i >= 0; i-- {
mut = dpd.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, dpd.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// ExecX is like Exec, but panics if an error occurs.
func (dpd *DbPackageDelete) ExecX(ctx context.Context) int {
n, err := dpd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (dpd *DbPackageDelete) sqlExec(ctx context.Context) (int, error) {
_spec := &sqlgraph.DeleteSpec{
Node: &sqlgraph.NodeSpec{
Table: dbpackage.Table,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbpackage.FieldID,
},
},
}
if ps := dpd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return sqlgraph.DeleteNodes(ctx, dpd.driver, _spec)
}
// DbPackageDeleteOne is the builder for deleting a single DbPackage entity.
type DbPackageDeleteOne struct {
dpd *DbPackageDelete
}
// Exec executes the deletion query.
func (dpdo *DbPackageDeleteOne) Exec(ctx context.Context) error {
n, err := dpdo.dpd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{dbpackage.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (dpdo *DbPackageDeleteOne) ExecX(ctx context.Context) {
dpdo.dpd.ExecX(ctx)
}

906
ent/dbpackage_query.go Normal file
View File

@ -0,0 +1,906 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"math"
"ALHP.go/ent/dbpackage"
"ALHP.go/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// DbPackageQuery is the builder for querying DbPackage entities.
type DbPackageQuery struct {
config
limit *int
offset *int
unique *bool
order []OrderFunc
fields []string
predicates []predicate.DbPackage
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the DbPackageQuery builder.
func (dpq *DbPackageQuery) Where(ps ...predicate.DbPackage) *DbPackageQuery {
dpq.predicates = append(dpq.predicates, ps...)
return dpq
}
// Limit adds a limit step to the query.
func (dpq *DbPackageQuery) Limit(limit int) *DbPackageQuery {
dpq.limit = &limit
return dpq
}
// Offset adds an offset step to the query.
func (dpq *DbPackageQuery) Offset(offset int) *DbPackageQuery {
dpq.offset = &offset
return dpq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (dpq *DbPackageQuery) Unique(unique bool) *DbPackageQuery {
dpq.unique = &unique
return dpq
}
// Order adds an order step to the query.
func (dpq *DbPackageQuery) Order(o ...OrderFunc) *DbPackageQuery {
dpq.order = append(dpq.order, o...)
return dpq
}
// First returns the first DbPackage entity from the query.
// Returns a *NotFoundError when no DbPackage was found.
func (dpq *DbPackageQuery) First(ctx context.Context) (*DbPackage, error) {
nodes, err := dpq.Limit(1).All(ctx)
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{dbpackage.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (dpq *DbPackageQuery) FirstX(ctx context.Context) *DbPackage {
node, err := dpq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first DbPackage ID from the query.
// Returns a *NotFoundError when no DbPackage ID was found.
func (dpq *DbPackageQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = dpq.Limit(1).IDs(ctx); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{dbpackage.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (dpq *DbPackageQuery) FirstIDX(ctx context.Context) int {
id, err := dpq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single DbPackage entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when exactly one DbPackage entity is not found.
// Returns a *NotFoundError when no DbPackage entities are found.
func (dpq *DbPackageQuery) Only(ctx context.Context) (*DbPackage, error) {
nodes, err := dpq.Limit(2).All(ctx)
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{dbpackage.Label}
default:
return nil, &NotSingularError{dbpackage.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (dpq *DbPackageQuery) OnlyX(ctx context.Context) *DbPackage {
node, err := dpq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only DbPackage ID in the query.
// Returns a *NotSingularError when exactly one DbPackage ID is not found.
// Returns a *NotFoundError when no entities are found.
func (dpq *DbPackageQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = dpq.Limit(2).IDs(ctx); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{dbpackage.Label}
default:
err = &NotSingularError{dbpackage.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (dpq *DbPackageQuery) OnlyIDX(ctx context.Context) int {
id, err := dpq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of DbPackages.
func (dpq *DbPackageQuery) All(ctx context.Context) ([]*DbPackage, error) {
if err := dpq.prepareQuery(ctx); err != nil {
return nil, err
}
return dpq.sqlAll(ctx)
}
// AllX is like All, but panics if an error occurs.
func (dpq *DbPackageQuery) AllX(ctx context.Context) []*DbPackage {
nodes, err := dpq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of DbPackage IDs.
func (dpq *DbPackageQuery) IDs(ctx context.Context) ([]int, error) {
var ids []int
if err := dpq.Select(dbpackage.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (dpq *DbPackageQuery) IDsX(ctx context.Context) []int {
ids, err := dpq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (dpq *DbPackageQuery) Count(ctx context.Context) (int, error) {
if err := dpq.prepareQuery(ctx); err != nil {
return 0, err
}
return dpq.sqlCount(ctx)
}
// CountX is like Count, but panics if an error occurs.
func (dpq *DbPackageQuery) CountX(ctx context.Context) int {
count, err := dpq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (dpq *DbPackageQuery) Exist(ctx context.Context) (bool, error) {
if err := dpq.prepareQuery(ctx); err != nil {
return false, err
}
return dpq.sqlExist(ctx)
}
// ExistX is like Exist, but panics if an error occurs.
func (dpq *DbPackageQuery) ExistX(ctx context.Context) bool {
exist, err := dpq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the DbPackageQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (dpq *DbPackageQuery) Clone() *DbPackageQuery {
if dpq == nil {
return nil
}
return &DbPackageQuery{
config: dpq.config,
limit: dpq.limit,
offset: dpq.offset,
order: append([]OrderFunc{}, dpq.order...),
predicates: append([]predicate.DbPackage{}, dpq.predicates...),
// clone intermediate query.
sql: dpq.sql.Clone(),
path: dpq.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Pkgbase string `json:"pkgbase,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.DbPackage.Query().
// GroupBy(dbpackage.FieldPkgbase).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
//
func (dpq *DbPackageQuery) GroupBy(field string, fields ...string) *DbPackageGroupBy {
group := &DbPackageGroupBy{config: dpq.config}
group.fields = append([]string{field}, fields...)
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
if err := dpq.prepareQuery(ctx); err != nil {
return nil, err
}
return dpq.sqlQuery(ctx), nil
}
return group
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Pkgbase string `json:"pkgbase,omitempty"`
// }
//
// client.DbPackage.Query().
// Select(dbpackage.FieldPkgbase).
// Scan(ctx, &v)
//
func (dpq *DbPackageQuery) Select(field string, fields ...string) *DbPackageSelect {
dpq.fields = append([]string{field}, fields...)
return &DbPackageSelect{DbPackageQuery: dpq}
}
func (dpq *DbPackageQuery) prepareQuery(ctx context.Context) error {
for _, f := range dpq.fields {
if !dbpackage.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if dpq.path != nil {
prev, err := dpq.path(ctx)
if err != nil {
return err
}
dpq.sql = prev
}
return nil
}
func (dpq *DbPackageQuery) sqlAll(ctx context.Context) ([]*DbPackage, error) {
var (
nodes = []*DbPackage{}
_spec = dpq.querySpec()
)
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
node := &DbPackage{config: dpq.config}
nodes = append(nodes, node)
return node.scanValues(columns)
}
_spec.Assign = func(columns []string, values []interface{}) error {
if len(nodes) == 0 {
return fmt.Errorf("ent: Assign called without calling ScanValues")
}
node := nodes[len(nodes)-1]
return node.assignValues(columns, values)
}
if err := sqlgraph.QueryNodes(ctx, dpq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (dpq *DbPackageQuery) sqlCount(ctx context.Context) (int, error) {
_spec := dpq.querySpec()
return sqlgraph.CountNodes(ctx, dpq.driver, _spec)
}
func (dpq *DbPackageQuery) sqlExist(ctx context.Context) (bool, error) {
n, err := dpq.sqlCount(ctx)
if err != nil {
return false, fmt.Errorf("ent: check existence: %w", err)
}
return n > 0, nil
}
func (dpq *DbPackageQuery) querySpec() *sqlgraph.QuerySpec {
_spec := &sqlgraph.QuerySpec{
Node: &sqlgraph.NodeSpec{
Table: dbpackage.Table,
Columns: dbpackage.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbpackage.FieldID,
},
},
From: dpq.sql,
Unique: true,
}
if unique := dpq.unique; unique != nil {
_spec.Unique = *unique
}
if fields := dpq.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, dbpackage.FieldID)
for i := range fields {
if fields[i] != dbpackage.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := dpq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := dpq.limit; limit != nil {
_spec.Limit = *limit
}
if offset := dpq.offset; offset != nil {
_spec.Offset = *offset
}