Add database backend (SQLite) (#26)

Add database with background information for each pkgbase, for possible future use.
A static status page is generated from the db.

Currently includes:

* sub-packages
* build-time
* build-duration
* status (failed, latest, skipped, queued, building, build)
* version (both from PKGBUILD and repo)
* last checked

Database is currently only used for informational purposes. Goal is to refactor many (expensive) methods to use the db instead of searching/parsing files.

Reviewed-on: https://git.harting.dev/anonfunc/ALHP.GO/pulls/26
Co-authored-by: Giovanni Harting <539@idlegandalf.com>
Co-committed-by: Giovanni Harting <539@idlegandalf.com>
This commit is contained in:
2021-07-13 18:07:29 +02:00
parent 9c8366372f
commit b0cfe7b205
27 changed files with 6949 additions and 47 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
}
if ps := dpq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (dpq *DbPackageQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(dpq.driver.Dialect())
t1 := builder.Table(dbpackage.Table)
selector := builder.Select(t1.Columns(dbpackage.Columns...)...).From(t1)
if dpq.sql != nil {
selector = dpq.sql
selector.Select(selector.Columns(dbpackage.Columns...)...)
}
for _, p := range dpq.predicates {
p(selector)
}
for _, p := range dpq.order {
p(selector)
}
if offset := dpq.offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := dpq.limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// DbPackageGroupBy is the group-by builder for DbPackage entities.
type DbPackageGroupBy struct {
config
fields []string
fns []AggregateFunc
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Aggregate adds the given aggregation functions to the group-by query.
func (dpgb *DbPackageGroupBy) Aggregate(fns ...AggregateFunc) *DbPackageGroupBy {
dpgb.fns = append(dpgb.fns, fns...)
return dpgb
}
// Scan applies the group-by query and scans the result into the given value.
func (dpgb *DbPackageGroupBy) Scan(ctx context.Context, v interface{}) error {
query, err := dpgb.path(ctx)
if err != nil {
return err
}
dpgb.sql = query
return dpgb.sqlScan(ctx, v)
}
// ScanX is like Scan, but panics if an error occurs.
func (dpgb *DbPackageGroupBy) ScanX(ctx context.Context, v interface{}) {
if err := dpgb.Scan(ctx, v); err != nil {
panic(err)
}
}
// Strings returns list of strings from group-by.
// It is only allowed when executing a group-by query with one field.
func (dpgb *DbPackageGroupBy) Strings(ctx context.Context) ([]string, error) {
if len(dpgb.fields) > 1 {
return nil, errors.New("ent: DbPackageGroupBy.Strings is not achievable when grouping more than 1 field")
}
var v []string
if err := dpgb.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// StringsX is like Strings, but panics if an error occurs.
func (dpgb *DbPackageGroupBy) StringsX(ctx context.Context) []string {
v, err := dpgb.Strings(ctx)
if err != nil {
panic(err)
}
return v
}
// String returns a single string from a group-by query.
// It is only allowed when executing a group-by query with one field.
func (dpgb *DbPackageGroupBy) String(ctx context.Context) (_ string, err error) {
var v []string
if v, err = dpgb.Strings(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{dbpackage.Label}
default:
err = fmt.Errorf("ent: DbPackageGroupBy.Strings returned %d results when one was expected", len(v))
}
return
}
// StringX is like String, but panics if an error occurs.
func (dpgb *DbPackageGroupBy) StringX(ctx context.Context) string {
v, err := dpgb.String(ctx)
if err != nil {
panic(err)
}
return v
}
// Ints returns list of ints from group-by.
// It is only allowed when executing a group-by query with one field.
func (dpgb *DbPackageGroupBy) Ints(ctx context.Context) ([]int, error) {
if len(dpgb.fields) > 1 {
return nil, errors.New("ent: DbPackageGroupBy.Ints is not achievable when grouping more than 1 field")
}
var v []int
if err := dpgb.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// IntsX is like Ints, but panics if an error occurs.
func (dpgb *DbPackageGroupBy) IntsX(ctx context.Context) []int {
v, err := dpgb.Ints(ctx)
if err != nil {
panic(err)
}
return v
}
// Int returns a single int from a group-by query.
// It is only allowed when executing a group-by query with one field.
func (dpgb *DbPackageGroupBy) Int(ctx context.Context) (_ int, err error) {
var v []int
if v, err = dpgb.Ints(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{dbpackage.Label}
default:
err = fmt.Errorf("ent: DbPackageGroupBy.Ints returned %d results when one was expected", len(v))
}
return
}
// IntX is like Int, but panics if an error occurs.
func (dpgb *DbPackageGroupBy) IntX(ctx context.Context) int {
v, err := dpgb.Int(ctx)
if err != nil {
panic(err)
}
return v
}
// Float64s returns list of float64s from group-by.
// It is only allowed when executing a group-by query with one field.
func (dpgb *DbPackageGroupBy) Float64s(ctx context.Context) ([]float64, error) {
if len(dpgb.fields) > 1 {
return nil, errors.New("ent: DbPackageGroupBy.Float64s is not achievable when grouping more than 1 field")
}
var v []float64
if err := dpgb.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// Float64sX is like Float64s, but panics if an error occurs.
func (dpgb *DbPackageGroupBy) Float64sX(ctx context.Context) []float64 {
v, err := dpgb.Float64s(ctx)
if err != nil {
panic(err)
}
return v
}
// Float64 returns a single float64 from a group-by query.
// It is only allowed when executing a group-by query with one field.
func (dpgb *DbPackageGroupBy) Float64(ctx context.Context) (_ float64, err error) {
var v []float64
if v, err = dpgb.Float64s(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{dbpackage.Label}
default:
err = fmt.Errorf("ent: DbPackageGroupBy.Float64s returned %d results when one was expected", len(v))
}
return
}
// Float64X is like Float64, but panics if an error occurs.
func (dpgb *DbPackageGroupBy) Float64X(ctx context.Context) float64 {
v, err := dpgb.Float64(ctx)
if err != nil {
panic(err)
}
return v
}
// Bools returns list of bools from group-by.
// It is only allowed when executing a group-by query with one field.
func (dpgb *DbPackageGroupBy) Bools(ctx context.Context) ([]bool, error) {
if len(dpgb.fields) > 1 {
return nil, errors.New("ent: DbPackageGroupBy.Bools is not achievable when grouping more than 1 field")
}
var v []bool
if err := dpgb.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// BoolsX is like Bools, but panics if an error occurs.
func (dpgb *DbPackageGroupBy) BoolsX(ctx context.Context) []bool {
v, err := dpgb.Bools(ctx)
if err != nil {
panic(err)
}
return v
}
// Bool returns a single bool from a group-by query.
// It is only allowed when executing a group-by query with one field.
func (dpgb *DbPackageGroupBy) Bool(ctx context.Context) (_ bool, err error) {
var v []bool
if v, err = dpgb.Bools(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{dbpackage.Label}
default:
err = fmt.Errorf("ent: DbPackageGroupBy.Bools returned %d results when one was expected", len(v))
}
return
}
// BoolX is like Bool, but panics if an error occurs.
func (dpgb *DbPackageGroupBy) BoolX(ctx context.Context) bool {
v, err := dpgb.Bool(ctx)
if err != nil {
panic(err)
}
return v
}
func (dpgb *DbPackageGroupBy) sqlScan(ctx context.Context, v interface{}) error {
for _, f := range dpgb.fields {
if !dbpackage.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
}
}
selector := dpgb.sqlQuery()
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := dpgb.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
func (dpgb *DbPackageGroupBy) sqlQuery() *sql.Selector {
selector := dpgb.sql
columns := make([]string, 0, len(dpgb.fields)+len(dpgb.fns))
columns = append(columns, dpgb.fields...)
for _, fn := range dpgb.fns {
columns = append(columns, fn(selector))
}
return selector.Select(columns...).GroupBy(dpgb.fields...)
}
// DbPackageSelect is the builder for selecting fields of DbPackage entities.
type DbPackageSelect struct {
*DbPackageQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
}
// Scan applies the selector query and scans the result into the given value.
func (dps *DbPackageSelect) Scan(ctx context.Context, v interface{}) error {
if err := dps.prepareQuery(ctx); err != nil {
return err
}
dps.sql = dps.DbPackageQuery.sqlQuery(ctx)
return dps.sqlScan(ctx, v)
}
// ScanX is like Scan, but panics if an error occurs.
func (dps *DbPackageSelect) ScanX(ctx context.Context, v interface{}) {
if err := dps.Scan(ctx, v); err != nil {
panic(err)
}
}
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
func (dps *DbPackageSelect) Strings(ctx context.Context) ([]string, error) {
if len(dps.fields) > 1 {
return nil, errors.New("ent: DbPackageSelect.Strings is not achievable when selecting more than 1 field")
}
var v []string
if err := dps.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// StringsX is like Strings, but panics if an error occurs.
func (dps *DbPackageSelect) StringsX(ctx context.Context) []string {
v, err := dps.Strings(ctx)
if err != nil {
panic(err)
}
return v
}
// String returns a single string from a selector. It is only allowed when selecting one field.
func (dps *DbPackageSelect) String(ctx context.Context) (_ string, err error) {
var v []string
if v, err = dps.Strings(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{dbpackage.Label}
default:
err = fmt.Errorf("ent: DbPackageSelect.Strings returned %d results when one was expected", len(v))
}
return
}
// StringX is like String, but panics if an error occurs.
func (dps *DbPackageSelect) StringX(ctx context.Context) string {
v, err := dps.String(ctx)
if err != nil {
panic(err)
}
return v
}
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
func (dps *DbPackageSelect) Ints(ctx context.Context) ([]int, error) {
if len(dps.fields) > 1 {
return nil, errors.New("ent: DbPackageSelect.Ints is not achievable when selecting more than 1 field")
}
var v []int
if err := dps.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// IntsX is like Ints, but panics if an error occurs.
func (dps *DbPackageSelect) IntsX(ctx context.Context) []int {
v, err := dps.Ints(ctx)
if err != nil {
panic(err)
}
return v
}
// Int returns a single int from a selector. It is only allowed when selecting one field.
func (dps *DbPackageSelect) Int(ctx context.Context) (_ int, err error) {
var v []int
if v, err = dps.Ints(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{dbpackage.Label}
default:
err = fmt.Errorf("ent: DbPackageSelect.Ints returned %d results when one was expected", len(v))
}
return
}
// IntX is like Int, but panics if an error occurs.
func (dps *DbPackageSelect) IntX(ctx context.Context) int {
v, err := dps.Int(ctx)
if err != nil {
panic(err)
}
return v
}
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
func (dps *DbPackageSelect) Float64s(ctx context.Context) ([]float64, error) {
if len(dps.fields) > 1 {
return nil, errors.New("ent: DbPackageSelect.Float64s is not achievable when selecting more than 1 field")
}
var v []float64
if err := dps.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// Float64sX is like Float64s, but panics if an error occurs.
func (dps *DbPackageSelect) Float64sX(ctx context.Context) []float64 {
v, err := dps.Float64s(ctx)
if err != nil {
panic(err)
}
return v
}
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
func (dps *DbPackageSelect) Float64(ctx context.Context) (_ float64, err error) {
var v []float64
if v, err = dps.Float64s(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{dbpackage.Label}
default:
err = fmt.Errorf("ent: DbPackageSelect.Float64s returned %d results when one was expected", len(v))
}
return
}
// Float64X is like Float64, but panics if an error occurs.
func (dps *DbPackageSelect) Float64X(ctx context.Context) float64 {
v, err := dps.Float64(ctx)
if err != nil {
panic(err)
}
return v
}
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
func (dps *DbPackageSelect) Bools(ctx context.Context) ([]bool, error) {
if len(dps.fields) > 1 {
return nil, errors.New("ent: DbPackageSelect.Bools is not achievable when selecting more than 1 field")
}
var v []bool
if err := dps.Scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// BoolsX is like Bools, but panics if an error occurs.
func (dps *DbPackageSelect) BoolsX(ctx context.Context) []bool {
v, err := dps.Bools(ctx)
if err != nil {
panic(err)
}
return v
}
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
func (dps *DbPackageSelect) Bool(ctx context.Context) (_ bool, err error) {
var v []bool
if v, err = dps.Bools(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{dbpackage.Label}
default:
err = fmt.Errorf("ent: DbPackageSelect.Bools returned %d results when one was expected", len(v))
}
return
}
// BoolX is like Bool, but panics if an error occurs.
func (dps *DbPackageSelect) BoolX(ctx context.Context) bool {
v, err := dps.Bool(ctx)
if err != nil {
panic(err)
}
return v
}
func (dps *DbPackageSelect) sqlScan(ctx context.Context, v interface{}) error {
rows := &sql.Rows{}
query, args := dps.sqlQuery().Query()
if err := dps.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
func (dps *DbPackageSelect) sqlQuery() sql.Querier {
selector := dps.sql
selector.Select(selector.Columns(dps.fields...)...)
return selector
}

915
ent/dbpackage_update.go Normal file
View File

@@ -0,0 +1,915 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"time"
"ALHP.go/ent/dbpackage"
"ALHP.go/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// DbPackageUpdate is the builder for updating DbPackage entities.
type DbPackageUpdate struct {
config
hooks []Hook
mutation *DbPackageMutation
}
// Where adds a new predicate for the DbPackageUpdate builder.
func (dpu *DbPackageUpdate) Where(ps ...predicate.DbPackage) *DbPackageUpdate {
dpu.mutation.predicates = append(dpu.mutation.predicates, ps...)
return dpu
}
// SetPackages sets the "packages" field.
func (dpu *DbPackageUpdate) SetPackages(s []string) *DbPackageUpdate {
dpu.mutation.SetPackages(s)
return dpu
}
// ClearPackages clears the value of the "packages" field.
func (dpu *DbPackageUpdate) ClearPackages() *DbPackageUpdate {
dpu.mutation.ClearPackages()
return dpu
}
// SetStatus sets the "status" field.
func (dpu *DbPackageUpdate) SetStatus(i int) *DbPackageUpdate {
dpu.mutation.ResetStatus()
dpu.mutation.SetStatus(i)
return dpu
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (dpu *DbPackageUpdate) SetNillableStatus(i *int) *DbPackageUpdate {
if i != nil {
dpu.SetStatus(*i)
}
return dpu
}
// AddStatus adds i to the "status" field.
func (dpu *DbPackageUpdate) AddStatus(i int) *DbPackageUpdate {
dpu.mutation.AddStatus(i)
return dpu
}
// ClearStatus clears the value of the "status" field.
func (dpu *DbPackageUpdate) ClearStatus() *DbPackageUpdate {
dpu.mutation.ClearStatus()
return dpu
}
// SetSkipReason sets the "skip_reason" field.
func (dpu *DbPackageUpdate) SetSkipReason(s string) *DbPackageUpdate {
dpu.mutation.SetSkipReason(s)
return dpu
}
// SetNillableSkipReason sets the "skip_reason" field if the given value is not nil.
func (dpu *DbPackageUpdate) SetNillableSkipReason(s *string) *DbPackageUpdate {
if s != nil {
dpu.SetSkipReason(*s)
}
return dpu
}
// ClearSkipReason clears the value of the "skip_reason" field.
func (dpu *DbPackageUpdate) ClearSkipReason() *DbPackageUpdate {
dpu.mutation.ClearSkipReason()
return dpu
}
// SetRepository sets the "repository" field.
func (dpu *DbPackageUpdate) SetRepository(s string) *DbPackageUpdate {
dpu.mutation.SetRepository(s)
return dpu
}
// SetMarch sets the "march" field.
func (dpu *DbPackageUpdate) SetMarch(s string) *DbPackageUpdate {
dpu.mutation.SetMarch(s)
return dpu
}
// SetVersion sets the "version" field.
func (dpu *DbPackageUpdate) SetVersion(s string) *DbPackageUpdate {
dpu.mutation.SetVersion(s)
return dpu
}
// SetNillableVersion sets the "version" field if the given value is not nil.
func (dpu *DbPackageUpdate) SetNillableVersion(s *string) *DbPackageUpdate {
if s != nil {
dpu.SetVersion(*s)
}
return dpu
}
// ClearVersion clears the value of the "version" field.
func (dpu *DbPackageUpdate) ClearVersion() *DbPackageUpdate {
dpu.mutation.ClearVersion()
return dpu
}
// SetRepoVersion sets the "repo_version" field.
func (dpu *DbPackageUpdate) SetRepoVersion(s string) *DbPackageUpdate {
dpu.mutation.SetRepoVersion(s)
return dpu
}
// SetNillableRepoVersion sets the "repo_version" field if the given value is not nil.
func (dpu *DbPackageUpdate) SetNillableRepoVersion(s *string) *DbPackageUpdate {
if s != nil {
dpu.SetRepoVersion(*s)
}
return dpu
}
// ClearRepoVersion clears the value of the "repo_version" field.
func (dpu *DbPackageUpdate) ClearRepoVersion() *DbPackageUpdate {
dpu.mutation.ClearRepoVersion()
return dpu
}
// SetBuildTime sets the "build_time" field.
func (dpu *DbPackageUpdate) SetBuildTime(t time.Time) *DbPackageUpdate {
dpu.mutation.SetBuildTime(t)
return dpu
}
// SetNillableBuildTime sets the "build_time" field if the given value is not nil.
func (dpu *DbPackageUpdate) SetNillableBuildTime(t *time.Time) *DbPackageUpdate {
if t != nil {
dpu.SetBuildTime(*t)
}
return dpu
}
// ClearBuildTime clears the value of the "build_time" field.
func (dpu *DbPackageUpdate) ClearBuildTime() *DbPackageUpdate {
dpu.mutation.ClearBuildTime()
return dpu
}
// SetBuildDuration sets the "build_duration" field.
func (dpu *DbPackageUpdate) SetBuildDuration(u uint64) *DbPackageUpdate {
dpu.mutation.ResetBuildDuration()
dpu.mutation.SetBuildDuration(u)
return dpu
}
// SetNillableBuildDuration sets the "build_duration" field if the given value is not nil.
func (dpu *DbPackageUpdate) SetNillableBuildDuration(u *uint64) *DbPackageUpdate {
if u != nil {
dpu.SetBuildDuration(*u)
}
return dpu
}
// AddBuildDuration adds u to the "build_duration" field.
func (dpu *DbPackageUpdate) AddBuildDuration(u uint64) *DbPackageUpdate {
dpu.mutation.AddBuildDuration(u)
return dpu
}
// ClearBuildDuration clears the value of the "build_duration" field.
func (dpu *DbPackageUpdate) ClearBuildDuration() *DbPackageUpdate {
dpu.mutation.ClearBuildDuration()
return dpu
}
// SetUpdated sets the "updated" field.
func (dpu *DbPackageUpdate) SetUpdated(t time.Time) *DbPackageUpdate {
dpu.mutation.SetUpdated(t)
return dpu
}
// SetNillableUpdated sets the "updated" field if the given value is not nil.
func (dpu *DbPackageUpdate) SetNillableUpdated(t *time.Time) *DbPackageUpdate {
if t != nil {
dpu.SetUpdated(*t)
}
return dpu
}
// ClearUpdated clears the value of the "updated" field.
func (dpu *DbPackageUpdate) ClearUpdated() *DbPackageUpdate {
dpu.mutation.ClearUpdated()
return dpu
}
// Mutation returns the DbPackageMutation object of the builder.
func (dpu *DbPackageUpdate) Mutation() *DbPackageMutation {
return dpu.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (dpu *DbPackageUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(dpu.hooks) == 0 {
if err = dpu.check(); err != nil {
return 0, err
}
affected, err = dpu.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 = dpu.check(); err != nil {
return 0, err
}
dpu.mutation = mutation
affected, err = dpu.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(dpu.hooks) - 1; i >= 0; i-- {
mut = dpu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, dpu.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (dpu *DbPackageUpdate) SaveX(ctx context.Context) int {
affected, err := dpu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (dpu *DbPackageUpdate) Exec(ctx context.Context) error {
_, err := dpu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dpu *DbPackageUpdate) ExecX(ctx context.Context) {
if err := dpu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (dpu *DbPackageUpdate) check() error {
if v, ok := dpu.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 v, ok := dpu.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 v, ok := dpu.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 := dpu.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 (dpu *DbPackageUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: dbpackage.Table,
Columns: dbpackage.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbpackage.FieldID,
},
},
}
if ps := dpu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dpu.mutation.Packages(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Value: value,
Column: dbpackage.FieldPackages,
})
}
if dpu.mutation.PackagesCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Column: dbpackage.FieldPackages,
})
}
if value, ok := dpu.mutation.Status(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: dbpackage.FieldStatus,
})
}
if value, ok := dpu.mutation.AddedStatus(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: dbpackage.FieldStatus,
})
}
if dpu.mutation.StatusCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbpackage.FieldStatus,
})
}
if value, ok := dpu.mutation.SkipReason(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldSkipReason,
})
}
if dpu.mutation.SkipReasonCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbpackage.FieldSkipReason,
})
}
if value, ok := dpu.mutation.Repository(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldRepository,
})
}
if value, ok := dpu.mutation.March(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldMarch,
})
}
if value, ok := dpu.mutation.Version(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldVersion,
})
}
if dpu.mutation.VersionCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbpackage.FieldVersion,
})
}
if value, ok := dpu.mutation.RepoVersion(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldRepoVersion,
})
}
if dpu.mutation.RepoVersionCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbpackage.FieldRepoVersion,
})
}
if value, ok := dpu.mutation.BuildTime(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: dbpackage.FieldBuildTime,
})
}
if dpu.mutation.BuildTimeCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Column: dbpackage.FieldBuildTime,
})
}
if value, ok := dpu.mutation.BuildDuration(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: dbpackage.FieldBuildDuration,
})
}
if value, ok := dpu.mutation.AddedBuildDuration(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: dbpackage.FieldBuildDuration,
})
}
if dpu.mutation.BuildDurationCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Column: dbpackage.FieldBuildDuration,
})
}
if value, ok := dpu.mutation.Updated(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: dbpackage.FieldUpdated,
})
}
if dpu.mutation.UpdatedCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Column: dbpackage.FieldUpdated,
})
}
if n, err = sqlgraph.UpdateNodes(ctx, dpu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{dbpackage.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
}
return n, nil
}
// DbPackageUpdateOne is the builder for updating a single DbPackage entity.
type DbPackageUpdateOne struct {
config
fields []string
hooks []Hook
mutation *DbPackageMutation
}
// SetPackages sets the "packages" field.
func (dpuo *DbPackageUpdateOne) SetPackages(s []string) *DbPackageUpdateOne {
dpuo.mutation.SetPackages(s)
return dpuo
}
// ClearPackages clears the value of the "packages" field.
func (dpuo *DbPackageUpdateOne) ClearPackages() *DbPackageUpdateOne {
dpuo.mutation.ClearPackages()
return dpuo
}
// SetStatus sets the "status" field.
func (dpuo *DbPackageUpdateOne) SetStatus(i int) *DbPackageUpdateOne {
dpuo.mutation.ResetStatus()
dpuo.mutation.SetStatus(i)
return dpuo
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (dpuo *DbPackageUpdateOne) SetNillableStatus(i *int) *DbPackageUpdateOne {
if i != nil {
dpuo.SetStatus(*i)
}
return dpuo
}
// AddStatus adds i to the "status" field.
func (dpuo *DbPackageUpdateOne) AddStatus(i int) *DbPackageUpdateOne {
dpuo.mutation.AddStatus(i)
return dpuo
}
// ClearStatus clears the value of the "status" field.
func (dpuo *DbPackageUpdateOne) ClearStatus() *DbPackageUpdateOne {
dpuo.mutation.ClearStatus()
return dpuo
}
// SetSkipReason sets the "skip_reason" field.
func (dpuo *DbPackageUpdateOne) SetSkipReason(s string) *DbPackageUpdateOne {
dpuo.mutation.SetSkipReason(s)
return dpuo
}
// SetNillableSkipReason sets the "skip_reason" field if the given value is not nil.
func (dpuo *DbPackageUpdateOne) SetNillableSkipReason(s *string) *DbPackageUpdateOne {
if s != nil {
dpuo.SetSkipReason(*s)
}
return dpuo
}
// ClearSkipReason clears the value of the "skip_reason" field.
func (dpuo *DbPackageUpdateOne) ClearSkipReason() *DbPackageUpdateOne {
dpuo.mutation.ClearSkipReason()
return dpuo
}
// SetRepository sets the "repository" field.
func (dpuo *DbPackageUpdateOne) SetRepository(s string) *DbPackageUpdateOne {
dpuo.mutation.SetRepository(s)
return dpuo
}
// SetMarch sets the "march" field.
func (dpuo *DbPackageUpdateOne) SetMarch(s string) *DbPackageUpdateOne {
dpuo.mutation.SetMarch(s)
return dpuo
}
// SetVersion sets the "version" field.
func (dpuo *DbPackageUpdateOne) SetVersion(s string) *DbPackageUpdateOne {
dpuo.mutation.SetVersion(s)
return dpuo
}
// SetNillableVersion sets the "version" field if the given value is not nil.
func (dpuo *DbPackageUpdateOne) SetNillableVersion(s *string) *DbPackageUpdateOne {
if s != nil {
dpuo.SetVersion(*s)
}
return dpuo
}
// ClearVersion clears the value of the "version" field.
func (dpuo *DbPackageUpdateOne) ClearVersion() *DbPackageUpdateOne {
dpuo.mutation.ClearVersion()
return dpuo
}
// SetRepoVersion sets the "repo_version" field.
func (dpuo *DbPackageUpdateOne) SetRepoVersion(s string) *DbPackageUpdateOne {
dpuo.mutation.SetRepoVersion(s)
return dpuo
}
// SetNillableRepoVersion sets the "repo_version" field if the given value is not nil.
func (dpuo *DbPackageUpdateOne) SetNillableRepoVersion(s *string) *DbPackageUpdateOne {
if s != nil {
dpuo.SetRepoVersion(*s)
}
return dpuo
}
// ClearRepoVersion clears the value of the "repo_version" field.
func (dpuo *DbPackageUpdateOne) ClearRepoVersion() *DbPackageUpdateOne {
dpuo.mutation.ClearRepoVersion()
return dpuo
}
// SetBuildTime sets the "build_time" field.
func (dpuo *DbPackageUpdateOne) SetBuildTime(t time.Time) *DbPackageUpdateOne {
dpuo.mutation.SetBuildTime(t)
return dpuo
}
// SetNillableBuildTime sets the "build_time" field if the given value is not nil.
func (dpuo *DbPackageUpdateOne) SetNillableBuildTime(t *time.Time) *DbPackageUpdateOne {
if t != nil {
dpuo.SetBuildTime(*t)
}
return dpuo
}
// ClearBuildTime clears the value of the "build_time" field.
func (dpuo *DbPackageUpdateOne) ClearBuildTime() *DbPackageUpdateOne {
dpuo.mutation.ClearBuildTime()
return dpuo
}
// SetBuildDuration sets the "build_duration" field.
func (dpuo *DbPackageUpdateOne) SetBuildDuration(u uint64) *DbPackageUpdateOne {
dpuo.mutation.ResetBuildDuration()
dpuo.mutation.SetBuildDuration(u)
return dpuo
}
// SetNillableBuildDuration sets the "build_duration" field if the given value is not nil.
func (dpuo *DbPackageUpdateOne) SetNillableBuildDuration(u *uint64) *DbPackageUpdateOne {
if u != nil {
dpuo.SetBuildDuration(*u)
}
return dpuo
}
// AddBuildDuration adds u to the "build_duration" field.
func (dpuo *DbPackageUpdateOne) AddBuildDuration(u uint64) *DbPackageUpdateOne {
dpuo.mutation.AddBuildDuration(u)
return dpuo
}
// ClearBuildDuration clears the value of the "build_duration" field.
func (dpuo *DbPackageUpdateOne) ClearBuildDuration() *DbPackageUpdateOne {
dpuo.mutation.ClearBuildDuration()
return dpuo
}
// SetUpdated sets the "updated" field.
func (dpuo *DbPackageUpdateOne) SetUpdated(t time.Time) *DbPackageUpdateOne {
dpuo.mutation.SetUpdated(t)
return dpuo
}
// SetNillableUpdated sets the "updated" field if the given value is not nil.
func (dpuo *DbPackageUpdateOne) SetNillableUpdated(t *time.Time) *DbPackageUpdateOne {
if t != nil {
dpuo.SetUpdated(*t)
}
return dpuo
}
// ClearUpdated clears the value of the "updated" field.
func (dpuo *DbPackageUpdateOne) ClearUpdated() *DbPackageUpdateOne {
dpuo.mutation.ClearUpdated()
return dpuo
}
// Mutation returns the DbPackageMutation object of the builder.
func (dpuo *DbPackageUpdateOne) Mutation() *DbPackageMutation {
return dpuo.mutation
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (dpuo *DbPackageUpdateOne) Select(field string, fields ...string) *DbPackageUpdateOne {
dpuo.fields = append([]string{field}, fields...)
return dpuo
}
// Save executes the query and returns the updated DbPackage entity.
func (dpuo *DbPackageUpdateOne) Save(ctx context.Context) (*DbPackage, error) {
var (
err error
node *DbPackage
)
if len(dpuo.hooks) == 0 {
if err = dpuo.check(); err != nil {
return nil, err
}
node, err = dpuo.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 = dpuo.check(); err != nil {
return nil, err
}
dpuo.mutation = mutation
node, err = dpuo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(dpuo.hooks) - 1; i >= 0; i-- {
mut = dpuo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, dpuo.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (dpuo *DbPackageUpdateOne) SaveX(ctx context.Context) *DbPackage {
node, err := dpuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (dpuo *DbPackageUpdateOne) Exec(ctx context.Context) error {
_, err := dpuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dpuo *DbPackageUpdateOne) ExecX(ctx context.Context) {
if err := dpuo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (dpuo *DbPackageUpdateOne) check() error {
if v, ok := dpuo.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 v, ok := dpuo.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 v, ok := dpuo.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 := dpuo.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 (dpuo *DbPackageUpdateOne) sqlSave(ctx context.Context) (_node *DbPackage, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: dbpackage.Table,
Columns: dbpackage.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbpackage.FieldID,
},
},
}
id, ok := dpuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing DbPackage.ID for update")}
}
_spec.Node.ID.Value = id
if fields := dpuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, dbpackage.FieldID)
for _, f := range fields {
if !dbpackage.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != dbpackage.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := dpuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dpuo.mutation.Packages(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Value: value,
Column: dbpackage.FieldPackages,
})
}
if dpuo.mutation.PackagesCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeJSON,
Column: dbpackage.FieldPackages,
})
}
if value, ok := dpuo.mutation.Status(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: dbpackage.FieldStatus,
})
}
if value, ok := dpuo.mutation.AddedStatus(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: dbpackage.FieldStatus,
})
}
if dpuo.mutation.StatusCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: dbpackage.FieldStatus,
})
}
if value, ok := dpuo.mutation.SkipReason(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldSkipReason,
})
}
if dpuo.mutation.SkipReasonCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbpackage.FieldSkipReason,
})
}
if value, ok := dpuo.mutation.Repository(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldRepository,
})
}
if value, ok := dpuo.mutation.March(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldMarch,
})
}
if value, ok := dpuo.mutation.Version(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldVersion,
})
}
if dpuo.mutation.VersionCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbpackage.FieldVersion,
})
}
if value, ok := dpuo.mutation.RepoVersion(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: dbpackage.FieldRepoVersion,
})
}
if dpuo.mutation.RepoVersionCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: dbpackage.FieldRepoVersion,
})
}
if value, ok := dpuo.mutation.BuildTime(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: dbpackage.FieldBuildTime,
})
}
if dpuo.mutation.BuildTimeCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Column: dbpackage.FieldBuildTime,
})
}
if value, ok := dpuo.mutation.BuildDuration(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: dbpackage.FieldBuildDuration,
})
}
if value, ok := dpuo.mutation.AddedBuildDuration(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Value: value,
Column: dbpackage.FieldBuildDuration,
})
}
if dpuo.mutation.BuildDurationCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeUint64,
Column: dbpackage.FieldBuildDuration,
})
}
if value, ok := dpuo.mutation.Updated(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Value: value,
Column: dbpackage.FieldUpdated,
})
}
if dpuo.mutation.UpdatedCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeTime,
Column: dbpackage.FieldUpdated,
})
}
_node = &DbPackage{config: dpuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, dpuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{dbpackage.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err
}
return _node, nil
}

279
ent/ent.go Normal file
View File

@@ -0,0 +1,279 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"errors"
"fmt"
"ALHP.go/ent/dbpackage"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
// ent aliases to avoid import conflicts in user's code.
type (
Op = ent.Op
Hook = ent.Hook
Value = ent.Value
Query = ent.Query
Policy = ent.Policy
Mutator = ent.Mutator
Mutation = ent.Mutation
MutateFunc = ent.MutateFunc
)
// OrderFunc applies an ordering on the sql selector.
type OrderFunc func(*sql.Selector)
// columnChecker returns a function indicates if the column exists in the given column.
func columnChecker(table string) func(string) error {
checks := map[string]func(string) bool{
dbpackage.Table: dbpackage.ValidColumn,
}
check, ok := checks[table]
if !ok {
return func(string) error {
return fmt.Errorf("unknown table %q", table)
}
}
return func(column string) error {
if !check(column) {
return fmt.Errorf("unknown column %q for table %q", column, table)
}
return nil
}
}
// Asc applies the given fields in ASC order.
func Asc(fields ...string) OrderFunc {
return func(s *sql.Selector) {
check := columnChecker(s.TableName())
for _, f := range fields {
if err := check(f); err != nil {
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
}
s.OrderBy(sql.Asc(s.C(f)))
}
}
}
// Desc applies the given fields in DESC order.
func Desc(fields ...string) OrderFunc {
return func(s *sql.Selector) {
check := columnChecker(s.TableName())
for _, f := range fields {
if err := check(f); err != nil {
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
}
s.OrderBy(sql.Desc(s.C(f)))
}
}
}
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
type AggregateFunc func(*sql.Selector) string
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
//
// GroupBy(field1, field2).
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
// Scan(ctx, &v)
//
func As(fn AggregateFunc, end string) AggregateFunc {
return func(s *sql.Selector) string {
return sql.As(fn(s), end)
}
}
// Count applies the "count" aggregation function on each group.
func Count() AggregateFunc {
return func(s *sql.Selector) string {
return sql.Count("*")
}
}
// Max applies the "max" aggregation function on the given field of each group.
func Max(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Max(s.C(field))
}
}
// Mean applies the "mean" aggregation function on the given field of each group.
func Mean(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Avg(s.C(field))
}
}
// Min applies the "min" aggregation function on the given field of each group.
func Min(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Min(s.C(field))
}
}
// Sum applies the "sum" aggregation function on the given field of each group.
func Sum(field string) AggregateFunc {
return func(s *sql.Selector) string {
check := columnChecker(s.TableName())
if err := check(field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
return ""
}
return sql.Sum(s.C(field))
}
}
// ValidationError returns when validating a field fails.
type ValidationError struct {
Name string // Field or edge name.
err error
}
// Error implements the error interface.
func (e *ValidationError) Error() string {
return e.err.Error()
}
// Unwrap implements the errors.Wrapper interface.
func (e *ValidationError) Unwrap() error {
return e.err
}
// IsValidationError returns a boolean indicating whether the error is a validaton error.
func IsValidationError(err error) bool {
if err == nil {
return false
}
var e *ValidationError
return errors.As(err, &e)
}
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
type NotFoundError struct {
label string
}
// Error implements the error interface.
func (e *NotFoundError) Error() string {
return "ent: " + e.label + " not found"
}
// IsNotFound returns a boolean indicating whether the error is a not found error.
func IsNotFound(err error) bool {
if err == nil {
return false
}
var e *NotFoundError
return errors.As(err, &e)
}
// MaskNotFound masks not found error.
func MaskNotFound(err error) error {
if IsNotFound(err) {
return nil
}
return err
}
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
type NotSingularError struct {
label string
}
// Error implements the error interface.
func (e *NotSingularError) Error() string {
return "ent: " + e.label + " not singular"
}
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
func IsNotSingular(err error) bool {
if err == nil {
return false
}
var e *NotSingularError
return errors.As(err, &e)
}
// NotLoadedError returns when trying to get a node that was not loaded by the query.
type NotLoadedError struct {
edge string
}
// Error implements the error interface.
func (e *NotLoadedError) Error() string {
return "ent: " + e.edge + " edge was not loaded"
}
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
func IsNotLoaded(err error) bool {
if err == nil {
return false
}
var e *NotLoadedError
return errors.As(err, &e)
}
// ConstraintError returns when trying to create/update one or more entities and
// one or more of their constraints failed. For example, violation of edge or
// field uniqueness.
type ConstraintError struct {
msg string
wrap error
}
// Error implements the error interface.
func (e ConstraintError) Error() string {
return "ent: constraint failed: " + e.msg
}
// Unwrap implements the errors.Wrapper interface.
func (e *ConstraintError) Unwrap() error {
return e.wrap
}
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
func IsConstraintError(err error) bool {
if err == nil {
return false
}
var e *ConstraintError
return errors.As(err, &e)
}
func isSQLConstraintError(err error) (*ConstraintError, bool) {
if sqlgraph.IsConstraintError(err) {
return &ConstraintError{err.Error(), err}, true
}
return nil, false
}
// rollback calls tx.Rollback and wraps the given error with the rollback error if present.
func rollback(tx dialect.Tx, err error) error {
if rerr := tx.Rollback(); rerr != nil {
err = fmt.Errorf("%w: %v", err, rerr)
}
if err, ok := isSQLConstraintError(err); ok {
return err
}
return err
}

78
ent/enttest/enttest.go Normal file
View File

@@ -0,0 +1,78 @@
// Code generated by entc, DO NOT EDIT.
package enttest
import (
"context"
"ALHP.go/ent"
// required by schema hooks.
_ "ALHP.go/ent/runtime"
"entgo.io/ent/dialect/sql/schema"
)
type (
// TestingT is the interface that is shared between
// testing.T and testing.B and used by enttest.
TestingT interface {
FailNow()
Error(...interface{})
}
// Option configures client creation.
Option func(*options)
options struct {
opts []ent.Option
migrateOpts []schema.MigrateOption
}
)
// WithOptions forwards options to client creation.
func WithOptions(opts ...ent.Option) Option {
return func(o *options) {
o.opts = append(o.opts, opts...)
}
}
// WithMigrateOptions forwards options to auto migration.
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
return func(o *options) {
o.migrateOpts = append(o.migrateOpts, opts...)
}
}
func newOptions(opts []Option) *options {
o := &options{}
for _, opt := range opts {
opt(o)
}
return o
}
// Open calls ent.Open and auto-run migration.
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
o := newOptions(opts)
c, err := ent.Open(driverName, dataSourceName, o.opts...)
if err != nil {
t.Error(err)
t.FailNow()
}
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
t.Error(err)
t.FailNow()
}
return c
}
// NewClient calls ent.NewClient and auto-run migration.
func NewClient(t TestingT, opts ...Option) *ent.Client {
o := newOptions(opts)
c := ent.NewClient(o.opts...)
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
t.Error(err)
t.FailNow()
}
return c
}

3
ent/generate.go Normal file
View File

@@ -0,0 +1,3 @@
package ent
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema

204
ent/hook/hook.go Normal file
View File

@@ -0,0 +1,204 @@
// Code generated by entc, DO NOT EDIT.
package hook
import (
"context"
"fmt"
"ALHP.go/ent"
)
// The DbPackageFunc type is an adapter to allow the use of ordinary
// function as DbPackage mutator.
type DbPackageFunc func(context.Context, *ent.DbPackageMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f DbPackageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
mv, ok := m.(*ent.DbPackageMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DbPackageMutation", m)
}
return f(ctx, mv)
}
// Condition is a hook condition function.
type Condition func(context.Context, ent.Mutation) bool
// And groups conditions with the AND operator.
func And(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
if !first(ctx, m) || !second(ctx, m) {
return false
}
for _, cond := range rest {
if !cond(ctx, m) {
return false
}
}
return true
}
}
// Or groups conditions with the OR operator.
func Or(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
if first(ctx, m) || second(ctx, m) {
return true
}
for _, cond := range rest {
if cond(ctx, m) {
return true
}
}
return false
}
}
// Not negates a given condition.
func Not(cond Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
return !cond(ctx, m)
}
}
// HasOp is a condition testing mutation operation.
func HasOp(op ent.Op) Condition {
return func(_ context.Context, m ent.Mutation) bool {
return m.Op().Is(op)
}
}
// HasAddedFields is a condition validating `.AddedField` on fields.
func HasAddedFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.AddedField(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.AddedField(field); !exists {
return false
}
}
return true
}
}
// HasClearedFields is a condition validating `.FieldCleared` on fields.
func HasClearedFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if exists := m.FieldCleared(field); !exists {
return false
}
for _, field := range fields {
if exists := m.FieldCleared(field); !exists {
return false
}
}
return true
}
}
// HasFields is a condition validating `.Field` on fields.
func HasFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.Field(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.Field(field); !exists {
return false
}
}
return true
}
}
// If executes the given hook under condition.
//
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
//
func If(hk ent.Hook, cond Condition) ent.Hook {
return func(next ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if cond(ctx, m) {
return hk(next).Mutate(ctx, m)
}
return next.Mutate(ctx, m)
})
}
}
// On executes the given hook only for the given operation.
//
// hook.On(Log, ent.Delete|ent.Create)
//
func On(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, HasOp(op))
}
// Unless skips the given hook only for the given operation.
//
// hook.Unless(Log, ent.Update|ent.UpdateOne)
//
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, Not(HasOp(op)))
}
// FixedError is a hook returning a fixed error.
func FixedError(err error) ent.Hook {
return func(ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
return nil, err
})
}
}
// Reject returns a hook that rejects all operations that match op.
//
// func (T) Hooks() []ent.Hook {
// return []ent.Hook{
// Reject(ent.Delete|ent.Update),
// }
// }
//
func Reject(op ent.Op) ent.Hook {
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
return On(hk, op)
}
// Chain acts as a list of hooks and is effectively immutable.
// Once created, it will always hold the same set of hooks in the same order.
type Chain struct {
hooks []ent.Hook
}
// NewChain creates a new chain of hooks.
func NewChain(hooks ...ent.Hook) Chain {
return Chain{append([]ent.Hook(nil), hooks...)}
}
// Hook chains the list of hooks and returns the final hook.
func (c Chain) Hook() ent.Hook {
return func(mutator ent.Mutator) ent.Mutator {
for i := len(c.hooks) - 1; i >= 0; i-- {
mutator = c.hooks[i](mutator)
}
return mutator
}
}
// Append extends a chain, adding the specified hook
// as the last ones in the mutation flow.
func (c Chain) Append(hooks ...ent.Hook) Chain {
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
newHooks = append(newHooks, c.hooks...)
newHooks = append(newHooks, hooks...)
return Chain{newHooks}
}
// Extend extends a chain, adding the specified chain
// as the last ones in the mutation flow.
func (c Chain) Extend(chain Chain) Chain {
return c.Append(chain.hooks...)
}

72
ent/migrate/migrate.go Normal file
View File

@@ -0,0 +1,72 @@
// Code generated by entc, DO NOT EDIT.
package migrate
import (
"context"
"fmt"
"io"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql/schema"
)
var (
// WithGlobalUniqueID sets the universal ids options to the migration.
// If this option is enabled, ent migration will allocate a 1<<32 range
// for the ids of each entity (table).
// Note that this option cannot be applied on tables that already exist.
WithGlobalUniqueID = schema.WithGlobalUniqueID
// WithDropColumn sets the drop column option to the migration.
// If this option is enabled, ent migration will drop old columns
// that were used for both fields and edges. This defaults to false.
WithDropColumn = schema.WithDropColumn
// WithDropIndex sets the drop index option to the migration.
// If this option is enabled, ent migration will drop old indexes
// that were defined in the schema. This defaults to false.
// Note that unique constraints are defined using `UNIQUE INDEX`,
// and therefore, it's recommended to enable this option to get more
// flexibility in the schema changes.
WithDropIndex = schema.WithDropIndex
// WithFixture sets the foreign-key renaming option to the migration when upgrading
// ent from v0.1.0 (issue-#285). Defaults to false.
WithFixture = schema.WithFixture
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
WithForeignKeys = schema.WithForeignKeys
)
// Schema is the API for creating, migrating and dropping a schema.
type Schema struct {
drv dialect.Driver
universalID bool
}
// NewSchema creates a new schema client.
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
// Create creates all schema resources.
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
migrate, err := schema.NewMigrate(s.drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.Create(ctx, Tables...)
}
// WriteTo writes the schema changes to w instead of running them against the database.
//
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
// log.Fatal(err)
// }
//
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
drv := &schema.WriteDriver{
Writer: w,
Driver: s.drv,
}
migrate, err := schema.NewMigrate(drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.Create(ctx, Tables...)
}

40
ent/migrate/schema.go Normal file
View File

@@ -0,0 +1,40 @@
// Code generated by entc, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// DbPackagesColumns holds the columns for the "db_packages" table.
DbPackagesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "pkgbase", Type: field.TypeString, Unique: true},
{Name: "packages", Type: field.TypeJSON, Nullable: true},
{Name: "status", Type: field.TypeInt, Nullable: true},
{Name: "skip_reason", Type: field.TypeString, Nullable: true},
{Name: "repository", Type: field.TypeString},
{Name: "march", Type: field.TypeString},
{Name: "version", Type: field.TypeString, Nullable: true},
{Name: "repo_version", Type: field.TypeString, Nullable: true},
{Name: "build_time", Type: field.TypeTime, Nullable: true},
{Name: "build_duration", Type: field.TypeUint64, Nullable: true},
{Name: "updated", Type: field.TypeTime, Nullable: true},
}
// DbPackagesTable holds the schema information for the "db_packages" table.
DbPackagesTable = &schema.Table{
Name: "db_packages",
Columns: DbPackagesColumns,
PrimaryKey: []*schema.Column{DbPackagesColumns[0]},
ForeignKeys: []*schema.ForeignKey{},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
DbPackagesTable,
}
)
func init() {
}

1080
ent/mutation.go Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
// Code generated by entc, DO NOT EDIT.
package predicate
import (
"entgo.io/ent/dialect/sql"
)
// DbPackage is the predicate function for dbpackage builders.
type DbPackage func(*sql.Selector)

36
ent/runtime.go Normal file
View File

@@ -0,0 +1,36 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"ALHP.go/ent/dbpackage"
"ALHP.go/ent/schema"
)
// The init function reads all schema descriptors with runtime code
// (default values, validators, hooks and policies) and stitches it
// to their package variables.
func init() {
dbpackageFields := schema.DbPackage{}.Fields()
_ = dbpackageFields
// dbpackageDescPkgbase is the schema descriptor for pkgbase field.
dbpackageDescPkgbase := dbpackageFields[0].Descriptor()
// dbpackage.PkgbaseValidator is a validator for the "pkgbase" field. It is called by the builders before save.
dbpackage.PkgbaseValidator = dbpackageDescPkgbase.Validators[0].(func(string) error)
// dbpackageDescStatus is the schema descriptor for status field.
dbpackageDescStatus := dbpackageFields[2].Descriptor()
// dbpackage.StatusValidator is a validator for the "status" field. It is called by the builders before save.
dbpackage.StatusValidator = dbpackageDescStatus.Validators[0].(func(int) error)
// dbpackageDescRepository is the schema descriptor for repository field.
dbpackageDescRepository := dbpackageFields[4].Descriptor()
// dbpackage.RepositoryValidator is a validator for the "repository" field. It is called by the builders before save.
dbpackage.RepositoryValidator = dbpackageDescRepository.Validators[0].(func(string) error)
// dbpackageDescMarch is the schema descriptor for march field.
dbpackageDescMarch := dbpackageFields[5].Descriptor()
// dbpackage.MarchValidator is a validator for the "march" field. It is called by the builders before save.
dbpackage.MarchValidator = dbpackageDescMarch.Validators[0].(func(string) error)
// dbpackageDescBuildDuration is the schema descriptor for build_duration field.
dbpackageDescBuildDuration := dbpackageFields[9].Descriptor()
// dbpackage.BuildDurationValidator is a validator for the "build_duration" field. It is called by the builders before save.
dbpackage.BuildDurationValidator = dbpackageDescBuildDuration.Validators[0].(func(uint64) error)
}

10
ent/runtime/runtime.go Normal file
View File

@@ -0,0 +1,10 @@
// Code generated by entc, DO NOT EDIT.
package runtime
// The schema-stitching logic is generated in ALHP.go/ent/runtime.go
const (
Version = "v0.8.0" // Version of ent codegen.
Sum = "h1:xirrW//1oda7pp0bz+XssSOv4/C3nmgYQOxjIfljFt8=" // Sum of ent codegen.
)

33
ent/schema/dbpackage.go Normal file
View File

@@ -0,0 +1,33 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
// DbPackage holds the schema definition for the DbPackage entity.
type DbPackage struct {
ent.Schema
}
// Fields of the DbPackage.
func (DbPackage) Fields() []ent.Field {
return []ent.Field{
field.String("pkgbase").NotEmpty().Immutable().Unique(),
field.Strings("packages").Optional(),
field.Int("status").Optional().Min(0),
field.String("skip_reason").Optional(),
field.String("repository").NotEmpty(),
field.String("march").NotEmpty(),
field.String("version").Optional(),
field.String("repo_version").Optional(),
field.Time("build_time").Optional(),
field.Uint64("build_duration").Positive().Optional(),
field.Time("updated").Optional(),
}
}
// Edges of the DbPackage.
func (DbPackage) Edges() []ent.Edge {
return nil
}

210
ent/tx.go Normal file
View File

@@ -0,0 +1,210 @@
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"sync"
"entgo.io/ent/dialect"
)
// Tx is a transactional client that is created by calling Client.Tx().
type Tx struct {
config
// DbPackage is the client for interacting with the DbPackage builders.
DbPackage *DbPackageClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []CommitHook
onRollback []RollbackHook
// ctx lives for the life of the transaction. It is
// the same context used by the underlying connection.
ctx context.Context
}
type (
// Committer is the interface that wraps the Committer method.
Committer interface {
Commit(context.Context, *Tx) error
}
// The CommitFunc type is an adapter to allow the use of ordinary
// function as a Committer. If f is a function with the appropriate
// signature, CommitFunc(f) is a Committer that calls f.
CommitFunc func(context.Context, *Tx) error
// CommitHook defines the "commit middleware". A function that gets a Committer
// and returns a Committer. For example:
//
// hook := func(next ent.Committer) ent.Committer {
// return ent.CommitFunc(func(context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Commit(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
CommitHook func(Committer) Committer
)
// Commit calls f(ctx, m).
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Commit commits the transaction.
func (tx *Tx) Commit() error {
txDriver := tx.config.driver.(*txDriver)
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
return txDriver.tx.Commit()
})
tx.mu.Lock()
hooks := append([]CommitHook(nil), tx.onCommit...)
tx.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Commit(tx.ctx, tx)
}
// OnCommit adds a hook to call on commit.
func (tx *Tx) OnCommit(f CommitHook) {
tx.mu.Lock()
defer tx.mu.Unlock()
tx.onCommit = append(tx.onCommit, f)
}
type (
// Rollbacker is the interface that wraps the Rollbacker method.
Rollbacker interface {
Rollback(context.Context, *Tx) error
}
// The RollbackFunc type is an adapter to allow the use of ordinary
// function as a Rollbacker. If f is a function with the appropriate
// signature, RollbackFunc(f) is a Rollbacker that calls f.
RollbackFunc func(context.Context, *Tx) error
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
// and returns a Rollbacker. For example:
//
// hook := func(next ent.Rollbacker) ent.Rollbacker {
// return ent.RollbackFunc(func(context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Rollback(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
RollbackHook func(Rollbacker) Rollbacker
)
// Rollback calls f(ctx, m).
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Rollback rollbacks the transaction.
func (tx *Tx) Rollback() error {
txDriver := tx.config.driver.(*txDriver)
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
return txDriver.tx.Rollback()
})
tx.mu.Lock()
hooks := append([]RollbackHook(nil), tx.onRollback...)
tx.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Rollback(tx.ctx, tx)
}
// OnRollback adds a hook to call on rollback.
func (tx *Tx) OnRollback(f RollbackHook) {
tx.mu.Lock()
defer tx.mu.Unlock()
tx.onRollback = append(tx.onRollback, f)
}
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {
tx.DbPackage = NewDbPackageClient(tx.config)
}
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
// The idea is to support transactions without adding any extra code to the builders.
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
// Commit and Rollback are nop for the internal builders and the user must call one
// of them in order to commit or rollback the transaction.
//
// If a closed transaction is embedded in one of the generated entities, and the entity
// applies a query, for example: DbPackage.QueryXXX(), the query will be executed
// through the driver which created this transaction.
//
// Note that txDriver is not goroutine safe.
type txDriver struct {
// the driver we started the transaction from.
drv dialect.Driver
// tx is the underlying transaction.
tx dialect.Tx
}
// newTx creates a new transactional driver.
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
tx, err := drv.Tx(ctx)
if err != nil {
return nil, err
}
return &txDriver{tx: tx, drv: drv}, nil
}
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
// from the internal builders. Should be called only by the internal builders.
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
// Dialect returns the dialect of the driver we started the transaction from.
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
// Close is a nop close.
func (*txDriver) Close() error { return nil }
// Commit is a nop commit for the internal builders.
// User must call `Tx.Commit` in order to commit the transaction.
func (*txDriver) Commit() error { return nil }
// Rollback is a nop rollback for the internal builders.
// User must call `Tx.Rollback` in order to rollback the transaction.
func (*txDriver) Rollback() error { return nil }
// Exec calls tx.Exec.
func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error {
return tx.tx.Exec(ctx, query, args, v)
}
// Query calls tx.Query.
func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error {
return tx.tx.Query(ctx, query, args, v)
}
var _ dialect.Driver = (*txDriver)(nil)