Add general queue
This commit is contained in:
@@ -0,0 +1,483 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"git.gorlug.de/code/ersteller/schema/ent/migrate"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueue"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueuestate"
|
||||
)
|
||||
|
||||
// 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
|
||||
// GeneralQueue is the client for interacting with the GeneralQueue builders.
|
||||
GeneralQueue *GeneralQueueClient
|
||||
// GeneralQueueState is the client for interacting with the GeneralQueueState builders.
|
||||
GeneralQueueState *GeneralQueueStateClient
|
||||
}
|
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
func NewClient(opts ...Option) *Client {
|
||||
client := &Client{config: newConfig(opts...)}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.GeneralQueue = NewGeneralQueueClient(c.config)
|
||||
c.GeneralQueueState = NewGeneralQueueStateClient(c.config)
|
||||
}
|
||||
|
||||
type (
|
||||
// config is the configuration for the client and its builder.
|
||||
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(...any)
|
||||
// hooks to execute on mutations.
|
||||
hooks *hooks
|
||||
// interceptors to execute on queries.
|
||||
inters *inters
|
||||
}
|
||||
// Option function to configure the client.
|
||||
Option func(*config)
|
||||
)
|
||||
|
||||
// newConfig creates a new config for the client.
|
||||
func newConfig(opts ...Option) config {
|
||||
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||
cfg.options(opts...)
|
||||
return cfg
|
||||
}
|
||||
|
||||
// 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(...any)) 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
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
|
||||
|
||||
// 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, ErrTxStarted
|
||||
}
|
||||
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,
|
||||
GeneralQueue: NewGeneralQueueClient(cfg),
|
||||
GeneralQueueState: NewGeneralQueueStateClient(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, errors.New("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{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
GeneralQueue: NewGeneralQueueClient(cfg),
|
||||
GeneralQueueState: NewGeneralQueueStateClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// GeneralQueue.
|
||||
// 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.GeneralQueue.Use(hooks...)
|
||||
c.GeneralQueueState.Use(hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds the query interceptors to all the entity clients.
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
c.GeneralQueue.Intercept(interceptors...)
|
||||
c.GeneralQueueState.Intercept(interceptors...)
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *GeneralQueueMutation:
|
||||
return c.GeneralQueue.mutate(ctx, m)
|
||||
case *GeneralQueueStateMutation:
|
||||
return c.GeneralQueueState.mutate(ctx, m)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
||||
}
|
||||
}
|
||||
|
||||
// GeneralQueueClient is a client for the GeneralQueue schema.
|
||||
type GeneralQueueClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewGeneralQueueClient returns a client for the GeneralQueue from the given config.
|
||||
func NewGeneralQueueClient(c config) *GeneralQueueClient {
|
||||
return &GeneralQueueClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `generalqueue.Hooks(f(g(h())))`.
|
||||
func (c *GeneralQueueClient) Use(hooks ...Hook) {
|
||||
c.hooks.GeneralQueue = append(c.hooks.GeneralQueue, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `generalqueue.Intercept(f(g(h())))`.
|
||||
func (c *GeneralQueueClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.GeneralQueue = append(c.inters.GeneralQueue, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a GeneralQueue entity.
|
||||
func (c *GeneralQueueClient) Create() *GeneralQueueCreate {
|
||||
mutation := newGeneralQueueMutation(c.config, OpCreate)
|
||||
return &GeneralQueueCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of GeneralQueue entities.
|
||||
func (c *GeneralQueueClient) CreateBulk(builders ...*GeneralQueueCreate) *GeneralQueueCreateBulk {
|
||||
return &GeneralQueueCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *GeneralQueueClient) MapCreateBulk(slice any, setFunc func(*GeneralQueueCreate, int)) *GeneralQueueCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &GeneralQueueCreateBulk{err: fmt.Errorf("calling to GeneralQueueClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*GeneralQueueCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &GeneralQueueCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for GeneralQueue.
|
||||
func (c *GeneralQueueClient) Update() *GeneralQueueUpdate {
|
||||
mutation := newGeneralQueueMutation(c.config, OpUpdate)
|
||||
return &GeneralQueueUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *GeneralQueueClient) UpdateOne(_m *GeneralQueue) *GeneralQueueUpdateOne {
|
||||
mutation := newGeneralQueueMutation(c.config, OpUpdateOne, withGeneralQueue(_m))
|
||||
return &GeneralQueueUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *GeneralQueueClient) UpdateOneID(id int) *GeneralQueueUpdateOne {
|
||||
mutation := newGeneralQueueMutation(c.config, OpUpdateOne, withGeneralQueueID(id))
|
||||
return &GeneralQueueUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for GeneralQueue.
|
||||
func (c *GeneralQueueClient) Delete() *GeneralQueueDelete {
|
||||
mutation := newGeneralQueueMutation(c.config, OpDelete)
|
||||
return &GeneralQueueDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *GeneralQueueClient) DeleteOne(_m *GeneralQueue) *GeneralQueueDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *GeneralQueueClient) DeleteOneID(id int) *GeneralQueueDeleteOne {
|
||||
builder := c.Delete().Where(generalqueue.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &GeneralQueueDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for GeneralQueue.
|
||||
func (c *GeneralQueueClient) Query() *GeneralQueueQuery {
|
||||
return &GeneralQueueQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeGeneralQueue},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a GeneralQueue entity by its id.
|
||||
func (c *GeneralQueueClient) Get(ctx context.Context, id int) (*GeneralQueue, error) {
|
||||
return c.Query().Where(generalqueue.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *GeneralQueueClient) GetX(ctx context.Context, id int) *GeneralQueue {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *GeneralQueueClient) Hooks() []Hook {
|
||||
return c.hooks.GeneralQueue
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *GeneralQueueClient) Interceptors() []Interceptor {
|
||||
return c.inters.GeneralQueue
|
||||
}
|
||||
|
||||
func (c *GeneralQueueClient) mutate(ctx context.Context, m *GeneralQueueMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&GeneralQueueCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&GeneralQueueUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&GeneralQueueUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&GeneralQueueDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown GeneralQueue mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// GeneralQueueStateClient is a client for the GeneralQueueState schema.
|
||||
type GeneralQueueStateClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewGeneralQueueStateClient returns a client for the GeneralQueueState from the given config.
|
||||
func NewGeneralQueueStateClient(c config) *GeneralQueueStateClient {
|
||||
return &GeneralQueueStateClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `generalqueuestate.Hooks(f(g(h())))`.
|
||||
func (c *GeneralQueueStateClient) Use(hooks ...Hook) {
|
||||
c.hooks.GeneralQueueState = append(c.hooks.GeneralQueueState, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `generalqueuestate.Intercept(f(g(h())))`.
|
||||
func (c *GeneralQueueStateClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.GeneralQueueState = append(c.inters.GeneralQueueState, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a GeneralQueueState entity.
|
||||
func (c *GeneralQueueStateClient) Create() *GeneralQueueStateCreate {
|
||||
mutation := newGeneralQueueStateMutation(c.config, OpCreate)
|
||||
return &GeneralQueueStateCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of GeneralQueueState entities.
|
||||
func (c *GeneralQueueStateClient) CreateBulk(builders ...*GeneralQueueStateCreate) *GeneralQueueStateCreateBulk {
|
||||
return &GeneralQueueStateCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *GeneralQueueStateClient) MapCreateBulk(slice any, setFunc func(*GeneralQueueStateCreate, int)) *GeneralQueueStateCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &GeneralQueueStateCreateBulk{err: fmt.Errorf("calling to GeneralQueueStateClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*GeneralQueueStateCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &GeneralQueueStateCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for GeneralQueueState.
|
||||
func (c *GeneralQueueStateClient) Update() *GeneralQueueStateUpdate {
|
||||
mutation := newGeneralQueueStateMutation(c.config, OpUpdate)
|
||||
return &GeneralQueueStateUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *GeneralQueueStateClient) UpdateOne(_m *GeneralQueueState) *GeneralQueueStateUpdateOne {
|
||||
mutation := newGeneralQueueStateMutation(c.config, OpUpdateOne, withGeneralQueueState(_m))
|
||||
return &GeneralQueueStateUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *GeneralQueueStateClient) UpdateOneID(id int) *GeneralQueueStateUpdateOne {
|
||||
mutation := newGeneralQueueStateMutation(c.config, OpUpdateOne, withGeneralQueueStateID(id))
|
||||
return &GeneralQueueStateUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for GeneralQueueState.
|
||||
func (c *GeneralQueueStateClient) Delete() *GeneralQueueStateDelete {
|
||||
mutation := newGeneralQueueStateMutation(c.config, OpDelete)
|
||||
return &GeneralQueueStateDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *GeneralQueueStateClient) DeleteOne(_m *GeneralQueueState) *GeneralQueueStateDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *GeneralQueueStateClient) DeleteOneID(id int) *GeneralQueueStateDeleteOne {
|
||||
builder := c.Delete().Where(generalqueuestate.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &GeneralQueueStateDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for GeneralQueueState.
|
||||
func (c *GeneralQueueStateClient) Query() *GeneralQueueStateQuery {
|
||||
return &GeneralQueueStateQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeGeneralQueueState},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a GeneralQueueState entity by its id.
|
||||
func (c *GeneralQueueStateClient) Get(ctx context.Context, id int) (*GeneralQueueState, error) {
|
||||
return c.Query().Where(generalqueuestate.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *GeneralQueueStateClient) GetX(ctx context.Context, id int) *GeneralQueueState {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *GeneralQueueStateClient) Hooks() []Hook {
|
||||
return c.hooks.GeneralQueueState
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *GeneralQueueStateClient) Interceptors() []Interceptor {
|
||||
return c.inters.GeneralQueueState
|
||||
}
|
||||
|
||||
func (c *GeneralQueueStateClient) mutate(ctx context.Context, m *GeneralQueueStateMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&GeneralQueueStateCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&GeneralQueueStateUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&GeneralQueueStateUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&GeneralQueueStateDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown GeneralQueueState mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
GeneralQueue, GeneralQueueState []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
GeneralQueue, GeneralQueueState []ent.Interceptor
|
||||
}
|
||||
)
|
||||
@@ -6,15 +6,14 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueue"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueuestate"
|
||||
)
|
||||
|
||||
// ent aliases to avoid import conflicts in user's code.
|
||||
@@ -75,9 +74,8 @@ var (
|
||||
func checkColumn(t, c string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
group.Table: group.ValidColumn,
|
||||
todo.Table: todo.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
generalqueue.Table: generalqueue.ValidColumn,
|
||||
generalqueuestate.Table: generalqueuestate.ValidColumn,
|
||||
})
|
||||
})
|
||||
return columnCheck(t, c)
|
||||
@@ -5,13 +5,12 @@ package enttest
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent"
|
||||
"git.gorlug.de/code/ersteller/schema/ent"
|
||||
// required by schema hooks.
|
||||
_ "git.gorlug.de/code/ersteller/schema/ent/example/ent/runtime"
|
||||
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/migrate"
|
||||
_ "git.gorlug.de/code/ersteller/schema/ent/runtime"
|
||||
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/migrate"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -1,692 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/migrate"
|
||||
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// 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
|
||||
// Group is the client for interacting with the Group builders.
|
||||
Group *GroupClient
|
||||
// Todo is the client for interacting with the Todo builders.
|
||||
Todo *TodoClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
}
|
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
func NewClient(opts ...Option) *Client {
|
||||
client := &Client{config: newConfig(opts...)}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Group = NewGroupClient(c.config)
|
||||
c.Todo = NewTodoClient(c.config)
|
||||
c.User = NewUserClient(c.config)
|
||||
}
|
||||
|
||||
type (
|
||||
// config is the configuration for the client and its builder.
|
||||
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(...any)
|
||||
// hooks to execute on mutations.
|
||||
hooks *hooks
|
||||
// interceptors to execute on queries.
|
||||
inters *inters
|
||||
}
|
||||
// Option function to configure the client.
|
||||
Option func(*config)
|
||||
)
|
||||
|
||||
// newConfig creates a new config for the client.
|
||||
func newConfig(opts ...Option) config {
|
||||
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||
cfg.options(opts...)
|
||||
return cfg
|
||||
}
|
||||
|
||||
// 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(...any)) 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
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
|
||||
|
||||
// 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, ErrTxStarted
|
||||
}
|
||||
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,
|
||||
Group: NewGroupClient(cfg),
|
||||
Todo: NewTodoClient(cfg),
|
||||
User: NewUserClient(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, errors.New("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{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Group: NewGroupClient(cfg),
|
||||
Todo: NewTodoClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// Group.
|
||||
// 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.Group.Use(hooks...)
|
||||
c.Todo.Use(hooks...)
|
||||
c.User.Use(hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds the query interceptors to all the entity clients.
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
c.Group.Intercept(interceptors...)
|
||||
c.Todo.Intercept(interceptors...)
|
||||
c.User.Intercept(interceptors...)
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *GroupMutation:
|
||||
return c.Group.mutate(ctx, m)
|
||||
case *TodoMutation:
|
||||
return c.Todo.mutate(ctx, m)
|
||||
case *UserMutation:
|
||||
return c.User.mutate(ctx, m)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
||||
}
|
||||
}
|
||||
|
||||
// GroupClient is a client for the Group schema.
|
||||
type GroupClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewGroupClient returns a client for the Group from the given config.
|
||||
func NewGroupClient(c config) *GroupClient {
|
||||
return &GroupClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `group.Hooks(f(g(h())))`.
|
||||
func (c *GroupClient) Use(hooks ...Hook) {
|
||||
c.hooks.Group = append(c.hooks.Group, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `group.Intercept(f(g(h())))`.
|
||||
func (c *GroupClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Group = append(c.inters.Group, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Group entity.
|
||||
func (c *GroupClient) Create() *GroupCreate {
|
||||
mutation := newGroupMutation(c.config, OpCreate)
|
||||
return &GroupCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Group entities.
|
||||
func (c *GroupClient) CreateBulk(builders ...*GroupCreate) *GroupCreateBulk {
|
||||
return &GroupCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *GroupClient) MapCreateBulk(slice any, setFunc func(*GroupCreate, int)) *GroupCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &GroupCreateBulk{err: fmt.Errorf("calling to GroupClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*GroupCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &GroupCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Group.
|
||||
func (c *GroupClient) Update() *GroupUpdate {
|
||||
mutation := newGroupMutation(c.config, OpUpdate)
|
||||
return &GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *GroupClient) UpdateOne(_m *Group) *GroupUpdateOne {
|
||||
mutation := newGroupMutation(c.config, OpUpdateOne, withGroup(_m))
|
||||
return &GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *GroupClient) UpdateOneID(id int) *GroupUpdateOne {
|
||||
mutation := newGroupMutation(c.config, OpUpdateOne, withGroupID(id))
|
||||
return &GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Group.
|
||||
func (c *GroupClient) Delete() *GroupDelete {
|
||||
mutation := newGroupMutation(c.config, OpDelete)
|
||||
return &GroupDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *GroupClient) DeleteOne(_m *Group) *GroupDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *GroupClient) DeleteOneID(id int) *GroupDeleteOne {
|
||||
builder := c.Delete().Where(group.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &GroupDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Group.
|
||||
func (c *GroupClient) Query() *GroupQuery {
|
||||
return &GroupQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeGroup},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Group entity by its id.
|
||||
func (c *GroupClient) Get(ctx context.Context, id int) (*Group, error) {
|
||||
return c.Query().Where(group.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *GroupClient) GetX(ctx context.Context, id int) *Group {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryUsers queries the users edge of a Group.
|
||||
func (c *GroupClient) QueryUsers(_m *Group) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, group.UsersTable, group.UsersPrimaryKey...),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryTodos queries the todos edge of a Group.
|
||||
func (c *GroupClient) QueryTodos(_m *Group) *TodoQuery {
|
||||
query := (&TodoClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
sqlgraph.To(todo.Table, todo.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, group.TodosTable, group.TodosColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *GroupClient) Hooks() []Hook {
|
||||
return c.hooks.Group
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *GroupClient) Interceptors() []Interceptor {
|
||||
return c.inters.Group
|
||||
}
|
||||
|
||||
func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// TodoClient is a client for the Todo schema.
|
||||
type TodoClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewTodoClient returns a client for the Todo from the given config.
|
||||
func NewTodoClient(c config) *TodoClient {
|
||||
return &TodoClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `todo.Hooks(f(g(h())))`.
|
||||
func (c *TodoClient) Use(hooks ...Hook) {
|
||||
c.hooks.Todo = append(c.hooks.Todo, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `todo.Intercept(f(g(h())))`.
|
||||
func (c *TodoClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Todo = append(c.inters.Todo, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Todo entity.
|
||||
func (c *TodoClient) Create() *TodoCreate {
|
||||
mutation := newTodoMutation(c.config, OpCreate)
|
||||
return &TodoCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Todo entities.
|
||||
func (c *TodoClient) CreateBulk(builders ...*TodoCreate) *TodoCreateBulk {
|
||||
return &TodoCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *TodoClient) MapCreateBulk(slice any, setFunc func(*TodoCreate, int)) *TodoCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &TodoCreateBulk{err: fmt.Errorf("calling to TodoClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*TodoCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &TodoCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Todo.
|
||||
func (c *TodoClient) Update() *TodoUpdate {
|
||||
mutation := newTodoMutation(c.config, OpUpdate)
|
||||
return &TodoUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *TodoClient) UpdateOne(_m *Todo) *TodoUpdateOne {
|
||||
mutation := newTodoMutation(c.config, OpUpdateOne, withTodo(_m))
|
||||
return &TodoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *TodoClient) UpdateOneID(id int) *TodoUpdateOne {
|
||||
mutation := newTodoMutation(c.config, OpUpdateOne, withTodoID(id))
|
||||
return &TodoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Todo.
|
||||
func (c *TodoClient) Delete() *TodoDelete {
|
||||
mutation := newTodoMutation(c.config, OpDelete)
|
||||
return &TodoDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *TodoClient) DeleteOne(_m *Todo) *TodoDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *TodoClient) DeleteOneID(id int) *TodoDeleteOne {
|
||||
builder := c.Delete().Where(todo.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &TodoDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Todo.
|
||||
func (c *TodoClient) Query() *TodoQuery {
|
||||
return &TodoQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeTodo},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Todo entity by its id.
|
||||
func (c *TodoClient) Get(ctx context.Context, id int) (*Todo, error) {
|
||||
return c.Query().Where(todo.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *TodoClient) GetX(ctx context.Context, id int) *Todo {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryGroup queries the group edge of a Todo.
|
||||
func (c *TodoClient) QueryGroup(_m *Todo) *GroupQuery {
|
||||
query := (&GroupClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(todo.Table, todo.FieldID, id),
|
||||
sqlgraph.To(group.Table, group.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, todo.GroupTable, todo.GroupColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *TodoClient) Hooks() []Hook {
|
||||
return c.hooks.Todo
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *TodoClient) Interceptors() []Interceptor {
|
||||
return c.inters.Todo
|
||||
}
|
||||
|
||||
func (c *TodoClient) mutate(ctx context.Context, m *TodoMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&TodoCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&TodoUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&TodoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&TodoDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Todo mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// UserClient is a client for the User schema.
|
||||
type UserClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewUserClient returns a client for the User from the given config.
|
||||
func NewUserClient(c config) *UserClient {
|
||||
return &UserClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`.
|
||||
func (c *UserClient) Use(hooks ...Hook) {
|
||||
c.hooks.User = append(c.hooks.User, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`.
|
||||
func (c *UserClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.User = append(c.inters.User, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a User entity.
|
||||
func (c *UserClient) Create() *UserCreate {
|
||||
mutation := newUserMutation(c.config, OpCreate)
|
||||
return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of User entities.
|
||||
func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk {
|
||||
return &UserCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*UserCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &UserCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for User.
|
||||
func (c *UserClient) Update() *UserUpdate {
|
||||
mutation := newUserMutation(c.config, OpUpdate)
|
||||
return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *UserClient) UpdateOne(_m *User) *UserUpdateOne {
|
||||
mutation := newUserMutation(c.config, OpUpdateOne, withUser(_m))
|
||||
return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *UserClient) UpdateOneID(id int) *UserUpdateOne {
|
||||
mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id))
|
||||
return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for User.
|
||||
func (c *UserClient) Delete() *UserDelete {
|
||||
mutation := newUserMutation(c.config, OpDelete)
|
||||
return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *UserClient) DeleteOne(_m *User) *UserDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *UserClient) DeleteOneID(id int) *UserDeleteOne {
|
||||
builder := c.Delete().Where(user.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &UserDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for User.
|
||||
func (c *UserClient) Query() *UserQuery {
|
||||
return &UserQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeUser},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a User entity by its id.
|
||||
func (c *UserClient) Get(ctx context.Context, id int) (*User, error) {
|
||||
return c.Query().Where(user.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *UserClient) GetX(ctx context.Context, id int) *User {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryGroup queries the group edge of a User.
|
||||
func (c *UserClient) QueryGroup(_m *User) *GroupQuery {
|
||||
query := (&GroupClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(group.Table, group.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, user.GroupTable, user.GroupPrimaryKey...),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *UserClient) Hooks() []Hook {
|
||||
return c.hooks.User
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *UserClient) Interceptors() []Interceptor {
|
||||
return c.inters.User
|
||||
}
|
||||
|
||||
func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
Group, Todo, User []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
Group, Todo, User []ent.Interceptor
|
||||
}
|
||||
)
|
||||
@@ -1,170 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Group is the model entity for the Group schema.
|
||||
type Group struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the GroupQuery when eager-loading is set.
|
||||
Edges GroupEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// GroupEdges holds the relations/edges for other nodes in the graph.
|
||||
type GroupEdges struct {
|
||||
// Users holds the value of the users edge.
|
||||
Users []*User `json:"users,omitempty"`
|
||||
// Todos holds the value of the todos edge.
|
||||
Todos []*Todo `json:"todos,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// UsersOrErr returns the Users value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e GroupEdges) UsersOrErr() ([]*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.Users, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "users"}
|
||||
}
|
||||
|
||||
// TodosOrErr returns the Todos value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e GroupEdges) TodosOrErr() ([]*Todo, error) {
|
||||
if e.loadedTypes[1] {
|
||||
return e.Todos, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "todos"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Group) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case group.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case group.FieldName:
|
||||
values[i] = new(sql.NullString)
|
||||
case group.FieldCreatedAt, group.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Group fields.
|
||||
func (_m *Group) assignValues(columns []string, values []any) 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 group.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case group.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CreatedAt = value.Time
|
||||
}
|
||||
case group.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UpdatedAt = value.Time
|
||||
}
|
||||
case group.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Name = value.String
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Group.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Group) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUsers queries the "users" edge of the Group entity.
|
||||
func (_m *Group) QueryUsers() *UserQuery {
|
||||
return NewGroupClient(_m.config).QueryUsers(_m)
|
||||
}
|
||||
|
||||
// QueryTodos queries the "todos" edge of the Group entity.
|
||||
func (_m *Group) QueryTodos() *TodoQuery {
|
||||
return NewGroupClient(_m.config).QueryTodos(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Group.
|
||||
// Note that you need to call Group.Unwrap() before calling this method if this Group
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Group) Update() *GroupUpdateOne {
|
||||
return NewGroupClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Group 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 (_m *Group) Unwrap() *Group {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Group is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Group) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Group(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Groups is a parsable slice of Group.
|
||||
type Groups []*Group
|
||||
@@ -1,141 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the group type in the database.
|
||||
Label = "group"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// EdgeUsers holds the string denoting the users edge name in mutations.
|
||||
EdgeUsers = "users"
|
||||
// EdgeTodos holds the string denoting the todos edge name in mutations.
|
||||
EdgeTodos = "todos"
|
||||
// Table holds the table name of the group in the database.
|
||||
Table = "groups"
|
||||
// UsersTable is the table that holds the users relation/edge. The primary key declared below.
|
||||
UsersTable = "user_group"
|
||||
// UsersInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UsersInverseTable = "users"
|
||||
// TodosTable is the table that holds the todos relation/edge.
|
||||
TodosTable = "todos"
|
||||
// TodosInverseTable is the table name for the Todo entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "todo" package.
|
||||
TodosInverseTable = "todos"
|
||||
// TodosColumn is the table column denoting the todos relation/edge.
|
||||
TodosColumn = "todo_group"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for group fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldName,
|
||||
}
|
||||
|
||||
var (
|
||||
// UsersPrimaryKey and UsersColumn2 are the table columns denoting the
|
||||
// primary key for the users relation (M2M).
|
||||
UsersPrimaryKey = []string{"user_id", "group_id"}
|
||||
)
|
||||
|
||||
// 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 (
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// DefaultName holds the default value on creation for the "name" field.
|
||||
DefaultName string
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the Group queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUsersCount orders the results by users count.
|
||||
func ByUsersCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newUsersStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByUsers orders the results by users terms.
|
||||
func ByUsers(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUsersStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByTodosCount orders the results by todos count.
|
||||
func ByTodosCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newTodosStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByTodos orders the results by todos terms.
|
||||
func ByTodos(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newTodosStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newUsersStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UsersInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, UsersTable, UsersPrimaryKey...),
|
||||
)
|
||||
}
|
||||
func newTodosStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(TodosInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, TodosTable, TodosColumn),
|
||||
)
|
||||
}
|
||||
@@ -1,277 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Group {
|
||||
return predicate.Group(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Group {
|
||||
return predicate.Group(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.Group {
|
||||
return predicate.Group(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.Group {
|
||||
return predicate.Group(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.Group {
|
||||
return predicate.Group(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.Group {
|
||||
return predicate.Group(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// HasUsers applies the HasEdge predicate on the "users" edge.
|
||||
func HasUsers() predicate.Group {
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, UsersTable, UsersPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUsersWith applies the HasEdge predicate on the "users" edge with a given conditions (other predicates).
|
||||
func HasUsersWith(preds ...predicate.User) predicate.Group {
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
step := newUsersStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasTodos applies the HasEdge predicate on the "todos" edge.
|
||||
func HasTodos() predicate.Group {
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, TodosTable, TodosColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasTodosWith applies the HasEdge predicate on the "todos" edge with a given conditions (other predicates).
|
||||
func HasTodosWith(preds ...predicate.Todo) predicate.Group {
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
step := newTodosStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Group) predicate.Group {
|
||||
return predicate.Group(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Group) predicate.Group {
|
||||
return predicate.Group(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Group) predicate.Group {
|
||||
return predicate.Group(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -1,316 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// GroupCreate is the builder for creating a Group entity.
|
||||
type GroupCreate struct {
|
||||
config
|
||||
mutation *GroupMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *GroupCreate) SetCreatedAt(v time.Time) *GroupCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *GroupCreate) SetNillableCreatedAt(v *time.Time) *GroupCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_c *GroupCreate) SetUpdatedAt(v time.Time) *GroupCreate {
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_c *GroupCreate) SetNillableUpdatedAt(v *time.Time) *GroupCreate {
|
||||
if v != nil {
|
||||
_c.SetUpdatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *GroupCreate) SetName(v string) *GroupCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_c *GroupCreate) SetNillableName(v *string) *GroupCreate {
|
||||
if v != nil {
|
||||
_c.SetName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddUserIDs adds the "users" edge to the User entity by IDs.
|
||||
func (_c *GroupCreate) AddUserIDs(ids ...int) *GroupCreate {
|
||||
_c.mutation.AddUserIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddUsers adds the "users" edges to the User entity.
|
||||
func (_c *GroupCreate) AddUsers(v ...*User) *GroupCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddUserIDs(ids...)
|
||||
}
|
||||
|
||||
// AddTodoIDs adds the "todos" edge to the Todo entity by IDs.
|
||||
func (_c *GroupCreate) AddTodoIDs(ids ...int) *GroupCreate {
|
||||
_c.mutation.AddTodoIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddTodos adds the "todos" edges to the Todo entity.
|
||||
func (_c *GroupCreate) AddTodos(v ...*Todo) *GroupCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddTodoIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the GroupMutation object of the builder.
|
||||
func (_c *GroupCreate) Mutation() *GroupMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Group in the database.
|
||||
func (_c *GroupCreate) Save(ctx context.Context) (*Group, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *GroupCreate) SaveX(ctx context.Context) *Group {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *GroupCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *GroupCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *GroupCreate) defaults() {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := group.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
v := group.DefaultUpdatedAt()
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
v := group.DefaultName
|
||||
_c.mutation.SetName(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *GroupCreate) check() error {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Group.created_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Group.updated_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Group.name"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *GroupCreate) sqlSave(ctx context.Context) (*Group, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Group{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(group.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(group.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if nodes := _c.mutation.UsersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: group.UsersTable,
|
||||
Columns: group.UsersPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.TodosIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: group.TodosTable,
|
||||
Columns: []string{group.TodosColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// GroupCreateBulk is the builder for creating many Group entities in bulk.
|
||||
type GroupCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*GroupCreate
|
||||
}
|
||||
|
||||
// Save creates the Group entities in the database.
|
||||
func (_c *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Group, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*GroupMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
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, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *GroupCreateBulk) SaveX(ctx context.Context) []*Group {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *GroupCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *GroupCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// GroupDelete is the builder for deleting a Group entity.
|
||||
type GroupDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GroupMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupDelete builder.
|
||||
func (_d *GroupDelete) Where(ps ...predicate.Group) *GroupDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *GroupDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *GroupDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *GroupDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// GroupDeleteOne is the builder for deleting a single Group entity.
|
||||
type GroupDeleteOne struct {
|
||||
_d *GroupDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupDelete builder.
|
||||
func (_d *GroupDeleteOne) Where(ps ...predicate.Group) *GroupDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *GroupDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{group.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *GroupDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,712 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// GroupQuery is the builder for querying Group entities.
|
||||
type GroupQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []group.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Group
|
||||
withUsers *UserQuery
|
||||
withTodos *TodoQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the GroupQuery builder.
|
||||
func (_q *GroupQuery) Where(ps ...predicate.Group) *GroupQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *GroupQuery) Limit(limit int) *GroupQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *GroupQuery) Offset(offset int) *GroupQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// 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 (_q *GroupQuery) Unique(unique bool) *GroupQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *GroupQuery) Order(o ...group.OrderOption) *GroupQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryUsers chains the current query on the "users" edge.
|
||||
func (_q *GroupQuery) QueryUsers() *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, group.UsersTable, group.UsersPrimaryKey...),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryTodos chains the current query on the "todos" edge.
|
||||
func (_q *GroupQuery) QueryTodos() *TodoQuery {
|
||||
query := (&TodoClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, selector),
|
||||
sqlgraph.To(todo.Table, todo.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, group.TodosTable, group.TodosColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Group entity from the query.
|
||||
// Returns a *NotFoundError when no Group was found.
|
||||
func (_q *GroupQuery) First(ctx context.Context) (*Group, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{group.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *GroupQuery) FirstX(ctx context.Context) *Group {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Group ID from the query.
|
||||
// Returns a *NotFoundError when no Group ID was found.
|
||||
func (_q *GroupQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{group.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *GroupQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Group entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Group entity is found.
|
||||
// Returns a *NotFoundError when no Group entities are found.
|
||||
func (_q *GroupQuery) Only(ctx context.Context) (*Group, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{group.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{group.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *GroupQuery) OnlyX(ctx context.Context) *Group {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Group ID in the query.
|
||||
// Returns a *NotSingularError when more than one Group ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *GroupQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{group.Label}
|
||||
default:
|
||||
err = &NotSingularError{group.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *GroupQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Groups.
|
||||
func (_q *GroupQuery) All(ctx context.Context) ([]*Group, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Group, *GroupQuery]()
|
||||
return withInterceptors[[]*Group](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *GroupQuery) AllX(ctx context.Context) []*Group {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Group IDs.
|
||||
func (_q *GroupQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(group.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *GroupQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *GroupQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*GroupQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *GroupQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *GroupQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *GroupQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the GroupQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *GroupQuery) Clone() *GroupQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &GroupQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]group.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Group{}, _q.predicates...),
|
||||
withUsers: _q.withUsers.Clone(),
|
||||
withTodos: _q.withTodos.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithUsers tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "users" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *GroupQuery) WithUsers(opts ...func(*UserQuery)) *GroupQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withUsers = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithTodos tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "todos" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *GroupQuery) WithTodos(opts ...func(*TodoQuery)) *GroupQuery {
|
||||
query := (&TodoClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withTodos = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Group.Query().
|
||||
// GroupBy(group.FieldCreatedAt).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &GroupGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = group.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Group.Query().
|
||||
// Select(group.FieldCreatedAt).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *GroupQuery) Select(fields ...string) *GroupSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &GroupSelect{GroupQuery: _q}
|
||||
sbuild.label = group.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a GroupSelect configured with the given aggregations.
|
||||
func (_q *GroupQuery) Aggregate(fns ...AggregateFunc) *GroupSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *GroupQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !group.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group, error) {
|
||||
var (
|
||||
nodes = []*Group{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [2]bool{
|
||||
_q.withUsers != nil,
|
||||
_q.withTodos != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Group).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Group{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withUsers; query != nil {
|
||||
if err := _q.loadUsers(ctx, query, nodes,
|
||||
func(n *Group) { n.Edges.Users = []*User{} },
|
||||
func(n *Group, e *User) { n.Edges.Users = append(n.Edges.Users, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withTodos; query != nil {
|
||||
if err := _q.loadTodos(ctx, query, nodes,
|
||||
func(n *Group) { n.Edges.Todos = []*Todo{} },
|
||||
func(n *Group, e *Todo) { n.Edges.Todos = append(n.Edges.Todos, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *GroupQuery) loadUsers(ctx context.Context, query *UserQuery, nodes []*Group, init func(*Group), assign func(*Group, *User)) error {
|
||||
edgeIDs := make([]driver.Value, len(nodes))
|
||||
byID := make(map[int]*Group)
|
||||
nids := make(map[int]map[*Group]struct{})
|
||||
for i, node := range nodes {
|
||||
edgeIDs[i] = node.ID
|
||||
byID[node.ID] = node
|
||||
if init != nil {
|
||||
init(node)
|
||||
}
|
||||
}
|
||||
query.Where(func(s *sql.Selector) {
|
||||
joinT := sql.Table(group.UsersTable)
|
||||
s.Join(joinT).On(s.C(user.FieldID), joinT.C(group.UsersPrimaryKey[0]))
|
||||
s.Where(sql.InValues(joinT.C(group.UsersPrimaryKey[1]), edgeIDs...))
|
||||
columns := s.SelectedColumns()
|
||||
s.Select(joinT.C(group.UsersPrimaryKey[1]))
|
||||
s.AppendSelect(columns...)
|
||||
s.SetDistinct(false)
|
||||
})
|
||||
if err := query.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append([]any{new(sql.NullInt64)}, values...), nil
|
||||
}
|
||||
spec.Assign = func(columns []string, values []any) error {
|
||||
outValue := int(values[0].(*sql.NullInt64).Int64)
|
||||
inValue := int(values[1].(*sql.NullInt64).Int64)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*Group]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
})
|
||||
neighbors, err := withInterceptors[[]*User](ctx, query, qr, query.inters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected "users" node returned %v`, n.ID)
|
||||
}
|
||||
for kn := range nodes {
|
||||
assign(kn, n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *GroupQuery) loadTodos(ctx context.Context, query *TodoQuery, nodes []*Group, init func(*Group), assign func(*Group, *Todo)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*Group)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Todo(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(group.TodosColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.todo_group
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "todo_group" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "todo_group" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *GroupQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *GroupQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, group.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != group.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(group.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = group.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := _q.ctx.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 := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// GroupGroupBy is the group-by builder for Group entities.
|
||||
type GroupGroupBy struct {
|
||||
selector
|
||||
build *GroupQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *GroupGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*GroupQuery, *GroupGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *GroupGroupBy) sqlScan(ctx context.Context, root *GroupQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// GroupSelect is the builder for selecting fields of Group entities.
|
||||
type GroupSelect struct {
|
||||
*GroupQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *GroupSelect) Aggregate(fns ...AggregateFunc) *GroupSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *GroupSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*GroupQuery, *GroupSelect](ctx, _s.GroupQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *GroupSelect) sqlScan(ctx context.Context, root *GroupQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
@@ -1,572 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// GroupUpdate is the builder for updating Group entities.
|
||||
type GroupUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GroupMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupUpdate builder.
|
||||
func (_u *GroupUpdate) Where(ps ...predicate.Group) *GroupUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *GroupUpdate) SetUpdatedAt(v time.Time) *GroupUpdate {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *GroupUpdate) SetName(v string) *GroupUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *GroupUpdate) SetNillableName(v *string) *GroupUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUserIDs adds the "users" edge to the User entity by IDs.
|
||||
func (_u *GroupUpdate) AddUserIDs(ids ...int) *GroupUpdate {
|
||||
_u.mutation.AddUserIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUsers adds the "users" edges to the User entity.
|
||||
func (_u *GroupUpdate) AddUsers(v ...*User) *GroupUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddUserIDs(ids...)
|
||||
}
|
||||
|
||||
// AddTodoIDs adds the "todos" edge to the Todo entity by IDs.
|
||||
func (_u *GroupUpdate) AddTodoIDs(ids ...int) *GroupUpdate {
|
||||
_u.mutation.AddTodoIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddTodos adds the "todos" edges to the Todo entity.
|
||||
func (_u *GroupUpdate) AddTodos(v ...*Todo) *GroupUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddTodoIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the GroupMutation object of the builder.
|
||||
func (_u *GroupUpdate) Mutation() *GroupMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUsers clears all "users" edges to the User entity.
|
||||
func (_u *GroupUpdate) ClearUsers() *GroupUpdate {
|
||||
_u.mutation.ClearUsers()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveUserIDs removes the "users" edge to User entities by IDs.
|
||||
func (_u *GroupUpdate) RemoveUserIDs(ids ...int) *GroupUpdate {
|
||||
_u.mutation.RemoveUserIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveUsers removes "users" edges to User entities.
|
||||
func (_u *GroupUpdate) RemoveUsers(v ...*User) *GroupUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveUserIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearTodos clears all "todos" edges to the Todo entity.
|
||||
func (_u *GroupUpdate) ClearTodos() *GroupUpdate {
|
||||
_u.mutation.ClearTodos()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveTodoIDs removes the "todos" edge to Todo entities by IDs.
|
||||
func (_u *GroupUpdate) RemoveTodoIDs(ids ...int) *GroupUpdate {
|
||||
_u.mutation.RemoveTodoIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveTodos removes "todos" edges to Todo entities.
|
||||
func (_u *GroupUpdate) RemoveTodos(v ...*Todo) *GroupUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveTodoIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *GroupUpdate) Save(ctx context.Context) (int, error) {
|
||||
_u.defaults()
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *GroupUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *GroupUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GroupUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_u *GroupUpdate) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := group.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(group.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UsersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: group.UsersTable,
|
||||
Columns: group.UsersPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedUsersIDs(); len(nodes) > 0 && !_u.mutation.UsersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: group.UsersTable,
|
||||
Columns: group.UsersPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UsersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: group.UsersTable,
|
||||
Columns: group.UsersPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.TodosCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: group.TodosTable,
|
||||
Columns: []string{group.TodosColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedTodosIDs(); len(nodes) > 0 && !_u.mutation.TodosCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: group.TodosTable,
|
||||
Columns: []string{group.TodosColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.TodosIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: group.TodosTable,
|
||||
Columns: []string{group.TodosColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{group.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// GroupUpdateOne is the builder for updating a single Group entity.
|
||||
type GroupUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *GroupMutation
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *GroupUpdateOne) SetUpdatedAt(v time.Time) *GroupUpdateOne {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *GroupUpdateOne) SetName(v string) *GroupUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *GroupUpdateOne) SetNillableName(v *string) *GroupUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUserIDs adds the "users" edge to the User entity by IDs.
|
||||
func (_u *GroupUpdateOne) AddUserIDs(ids ...int) *GroupUpdateOne {
|
||||
_u.mutation.AddUserIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUsers adds the "users" edges to the User entity.
|
||||
func (_u *GroupUpdateOne) AddUsers(v ...*User) *GroupUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddUserIDs(ids...)
|
||||
}
|
||||
|
||||
// AddTodoIDs adds the "todos" edge to the Todo entity by IDs.
|
||||
func (_u *GroupUpdateOne) AddTodoIDs(ids ...int) *GroupUpdateOne {
|
||||
_u.mutation.AddTodoIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddTodos adds the "todos" edges to the Todo entity.
|
||||
func (_u *GroupUpdateOne) AddTodos(v ...*Todo) *GroupUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddTodoIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the GroupMutation object of the builder.
|
||||
func (_u *GroupUpdateOne) Mutation() *GroupMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUsers clears all "users" edges to the User entity.
|
||||
func (_u *GroupUpdateOne) ClearUsers() *GroupUpdateOne {
|
||||
_u.mutation.ClearUsers()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveUserIDs removes the "users" edge to User entities by IDs.
|
||||
func (_u *GroupUpdateOne) RemoveUserIDs(ids ...int) *GroupUpdateOne {
|
||||
_u.mutation.RemoveUserIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveUsers removes "users" edges to User entities.
|
||||
func (_u *GroupUpdateOne) RemoveUsers(v ...*User) *GroupUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveUserIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearTodos clears all "todos" edges to the Todo entity.
|
||||
func (_u *GroupUpdateOne) ClearTodos() *GroupUpdateOne {
|
||||
_u.mutation.ClearTodos()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveTodoIDs removes the "todos" edge to Todo entities by IDs.
|
||||
func (_u *GroupUpdateOne) RemoveTodoIDs(ids ...int) *GroupUpdateOne {
|
||||
_u.mutation.RemoveTodoIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveTodos removes "todos" edges to Todo entities.
|
||||
func (_u *GroupUpdateOne) RemoveTodos(v ...*Todo) *GroupUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveTodoIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupUpdate builder.
|
||||
func (_u *GroupUpdateOne) Where(ps ...predicate.Group) *GroupUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Group entity.
|
||||
func (_u *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
|
||||
_u.defaults()
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *GroupUpdateOne) SaveX(ctx context.Context) *Group {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *GroupUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GroupUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_u *GroupUpdateOne) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := group.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Group.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, group.FieldID)
|
||||
for _, f := range fields {
|
||||
if !group.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != group.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(group.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UsersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: group.UsersTable,
|
||||
Columns: group.UsersPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedUsersIDs(); len(nodes) > 0 && !_u.mutation.UsersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: group.UsersTable,
|
||||
Columns: group.UsersPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UsersIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: group.UsersTable,
|
||||
Columns: group.UsersPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.TodosCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: group.TodosTable,
|
||||
Columns: []string{group.TodosColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedTodosIDs(); len(nodes) > 0 && !_u.mutation.TodosCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: group.TodosTable,
|
||||
Columns: []string{group.TodosColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.TodosIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: group.TodosTable,
|
||||
Columns: []string{group.TodosColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Group{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{group.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// GroupsColumns holds the columns for the "groups" table.
|
||||
GroupsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "name", Type: field.TypeString, Default: ""},
|
||||
}
|
||||
// GroupsTable holds the schema information for the "groups" table.
|
||||
GroupsTable = &schema.Table{
|
||||
Name: "groups",
|
||||
Columns: GroupsColumns,
|
||||
PrimaryKey: []*schema.Column{GroupsColumns[0]},
|
||||
}
|
||||
// TodosColumns holds the columns for the "todos" table.
|
||||
TodosColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "title", Type: field.TypeString, Default: ""},
|
||||
{Name: "completed", Type: field.TypeBool, Default: false},
|
||||
{Name: "todo_group", Type: field.TypeInt, Nullable: true},
|
||||
}
|
||||
// TodosTable holds the schema information for the "todos" table.
|
||||
TodosTable = &schema.Table{
|
||||
Name: "todos",
|
||||
Columns: TodosColumns,
|
||||
PrimaryKey: []*schema.Column{TodosColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "todos_groups_group",
|
||||
Columns: []*schema.Column{TodosColumns[5]},
|
||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// UsersColumns holds the columns for the "users" table.
|
||||
UsersColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "email", Type: field.TypeString, Default: "unknown@localhost"},
|
||||
{Name: "password", Type: field.TypeString, Default: ""},
|
||||
}
|
||||
// UsersTable holds the schema information for the "users" table.
|
||||
UsersTable = &schema.Table{
|
||||
Name: "users",
|
||||
Columns: UsersColumns,
|
||||
PrimaryKey: []*schema.Column{UsersColumns[0]},
|
||||
}
|
||||
// UserGroupColumns holds the columns for the "user_group" table.
|
||||
UserGroupColumns = []*schema.Column{
|
||||
{Name: "user_id", Type: field.TypeInt},
|
||||
{Name: "group_id", Type: field.TypeInt},
|
||||
}
|
||||
// UserGroupTable holds the schema information for the "user_group" table.
|
||||
UserGroupTable = &schema.Table{
|
||||
Name: "user_group",
|
||||
Columns: UserGroupColumns,
|
||||
PrimaryKey: []*schema.Column{UserGroupColumns[0], UserGroupColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "user_group_user_id",
|
||||
Columns: []*schema.Column{UserGroupColumns[0]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "user_group_group_id",
|
||||
Columns: []*schema.Column{UserGroupColumns[1]},
|
||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
GroupsTable,
|
||||
TodosTable,
|
||||
UsersTable,
|
||||
UserGroupTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
TodosTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
UserGroupTable.ForeignKeys[0].RefTable = UsersTable
|
||||
UserGroupTable.ForeignKeys[1].RefTable = GroupsTable
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,16 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package predicate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Group is the predicate function for group builders.
|
||||
type Group func(*sql.Selector)
|
||||
|
||||
// Todo is the predicate function for todo builders.
|
||||
type Todo func(*sql.Selector)
|
||||
|
||||
// User is the predicate function for user builders.
|
||||
type User func(*sql.Selector)
|
||||
@@ -1,82 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/schema"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 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() {
|
||||
groupMixin := schema.Group{}.Mixin()
|
||||
groupMixinFields0 := groupMixin[0].Fields()
|
||||
_ = groupMixinFields0
|
||||
groupFields := schema.Group{}.Fields()
|
||||
_ = groupFields
|
||||
// groupDescCreatedAt is the schema descriptor for created_at field.
|
||||
groupDescCreatedAt := groupMixinFields0[0].Descriptor()
|
||||
// group.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
group.DefaultCreatedAt = groupDescCreatedAt.Default.(func() time.Time)
|
||||
// groupDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
groupDescUpdatedAt := groupMixinFields0[1].Descriptor()
|
||||
// group.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
group.DefaultUpdatedAt = groupDescUpdatedAt.Default.(func() time.Time)
|
||||
// group.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
group.UpdateDefaultUpdatedAt = groupDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// groupDescName is the schema descriptor for name field.
|
||||
groupDescName := groupFields[0].Descriptor()
|
||||
// group.DefaultName holds the default value on creation for the name field.
|
||||
group.DefaultName = groupDescName.Default.(string)
|
||||
todoMixin := schema.Todo{}.Mixin()
|
||||
todoMixinFields0 := todoMixin[0].Fields()
|
||||
_ = todoMixinFields0
|
||||
todoFields := schema.Todo{}.Fields()
|
||||
_ = todoFields
|
||||
// todoDescCreatedAt is the schema descriptor for created_at field.
|
||||
todoDescCreatedAt := todoMixinFields0[0].Descriptor()
|
||||
// todo.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
todo.DefaultCreatedAt = todoDescCreatedAt.Default.(func() time.Time)
|
||||
// todoDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
todoDescUpdatedAt := todoMixinFields0[1].Descriptor()
|
||||
// todo.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
todo.DefaultUpdatedAt = todoDescUpdatedAt.Default.(func() time.Time)
|
||||
// todo.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
todo.UpdateDefaultUpdatedAt = todoDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// todoDescTitle is the schema descriptor for title field.
|
||||
todoDescTitle := todoFields[0].Descriptor()
|
||||
// todo.DefaultTitle holds the default value on creation for the title field.
|
||||
todo.DefaultTitle = todoDescTitle.Default.(string)
|
||||
// todoDescCompleted is the schema descriptor for completed field.
|
||||
todoDescCompleted := todoFields[1].Descriptor()
|
||||
// todo.DefaultCompleted holds the default value on creation for the completed field.
|
||||
todo.DefaultCompleted = todoDescCompleted.Default.(bool)
|
||||
userMixin := schema.User{}.Mixin()
|
||||
userMixinFields0 := userMixin[0].Fields()
|
||||
_ = userMixinFields0
|
||||
userFields := schema.User{}.Fields()
|
||||
_ = userFields
|
||||
// userDescCreatedAt is the schema descriptor for created_at field.
|
||||
userDescCreatedAt := userMixinFields0[0].Descriptor()
|
||||
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
|
||||
// userDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
userDescUpdatedAt := userMixinFields0[1].Descriptor()
|
||||
// user.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time)
|
||||
// user.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
user.UpdateDefaultUpdatedAt = userDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// userDescEmail is the schema descriptor for email field.
|
||||
userDescEmail := userFields[0].Descriptor()
|
||||
// user.DefaultEmail holds the default value on creation for the email field.
|
||||
user.DefaultEmail = userDescEmail.Default.(string)
|
||||
// userDescPassword is the schema descriptor for password field.
|
||||
userDescPassword := userFields[1].Descriptor()
|
||||
// user.DefaultPassword holds the default value on creation for the password field.
|
||||
user.DefaultPassword = userDescPassword.Default.(string)
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"git.gorlug.de/code/ersteller/schema/ent"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
type Group struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Group) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
ersteller_ent.TimeMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
func (Group) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").Default(""),
|
||||
}
|
||||
}
|
||||
|
||||
func (Group) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
// Back-reference to users that belong to this group
|
||||
edge.From("users", User.Type).Ref("group"),
|
||||
// Back-reference to todos that belong to this group
|
||||
edge.From("todos", Todo.Type).Ref("group"),
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"git.gorlug.de/code/ersteller/schema/ent"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
type Todo struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Todo) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
ersteller_ent.TimeMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
func (Todo) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("title").Default(""),
|
||||
field.Bool("completed").Default(false),
|
||||
}
|
||||
}
|
||||
|
||||
func (Todo) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("group", Group.Type).Unique(),
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"git.gorlug.de/code/ersteller/schema/ent"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// User holds the schema definition for the User entity.
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (User) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
ersteller_ent.TimeMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("email").
|
||||
Default("unknown@localhost"),
|
||||
field.String("password").Default(""),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("group", Group.Type),
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Todo is the model entity for the Todo schema.
|
||||
type Todo struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Title holds the value of the "title" field.
|
||||
Title string `json:"title,omitempty"`
|
||||
// Completed holds the value of the "completed" field.
|
||||
Completed bool `json:"completed,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the TodoQuery when eager-loading is set.
|
||||
Edges TodoEdges `json:"edges"`
|
||||
todo_group *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// TodoEdges holds the relations/edges for other nodes in the graph.
|
||||
type TodoEdges struct {
|
||||
// Group holds the value of the group edge.
|
||||
Group *Group `json:"group,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// GroupOrErr returns the Group value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e TodoEdges) GroupOrErr() (*Group, error) {
|
||||
if e.Group != nil {
|
||||
return e.Group, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: group.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "group"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Todo) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case todo.FieldCompleted:
|
||||
values[i] = new(sql.NullBool)
|
||||
case todo.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case todo.FieldTitle:
|
||||
values[i] = new(sql.NullString)
|
||||
case todo.FieldCreatedAt, todo.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case todo.ForeignKeys[0]: // todo_group
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Todo fields.
|
||||
func (_m *Todo) assignValues(columns []string, values []any) 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 todo.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case todo.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CreatedAt = value.Time
|
||||
}
|
||||
case todo.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UpdatedAt = value.Time
|
||||
}
|
||||
case todo.FieldTitle:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field title", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Title = value.String
|
||||
}
|
||||
case todo.FieldCompleted:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field completed", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Completed = value.Bool
|
||||
}
|
||||
case todo.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field todo_group", value)
|
||||
} else if value.Valid {
|
||||
_m.todo_group = new(int)
|
||||
*_m.todo_group = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Todo.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Todo) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryGroup queries the "group" edge of the Todo entity.
|
||||
func (_m *Todo) QueryGroup() *GroupQuery {
|
||||
return NewTodoClient(_m.config).QueryGroup(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Todo.
|
||||
// Note that you need to call Todo.Unwrap() before calling this method if this Todo
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Todo) Update() *TodoUpdateOne {
|
||||
return NewTodoClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Todo 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 (_m *Todo) Unwrap() *Todo {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Todo is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Todo) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Todo(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("title=")
|
||||
builder.WriteString(_m.Title)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("completed=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Completed))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Todos is a parsable slice of Todo.
|
||||
type Todos []*Todo
|
||||
@@ -1,121 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package todo
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the todo type in the database.
|
||||
Label = "todo"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldTitle holds the string denoting the title field in the database.
|
||||
FieldTitle = "title"
|
||||
// FieldCompleted holds the string denoting the completed field in the database.
|
||||
FieldCompleted = "completed"
|
||||
// EdgeGroup holds the string denoting the group edge name in mutations.
|
||||
EdgeGroup = "group"
|
||||
// Table holds the table name of the todo in the database.
|
||||
Table = "todos"
|
||||
// GroupTable is the table that holds the group relation/edge.
|
||||
GroupTable = "todos"
|
||||
// GroupInverseTable is the table name for the Group entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "group" package.
|
||||
GroupInverseTable = "groups"
|
||||
// GroupColumn is the table column denoting the group relation/edge.
|
||||
GroupColumn = "todo_group"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for todo fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldTitle,
|
||||
FieldCompleted,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "todos"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"todo_group",
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// DefaultTitle holds the default value on creation for the "title" field.
|
||||
DefaultTitle string
|
||||
// DefaultCompleted holds the default value on creation for the "completed" field.
|
||||
DefaultCompleted bool
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the Todo queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTitle orders the results by the title field.
|
||||
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTitle, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCompleted orders the results by the completed field.
|
||||
func ByCompleted(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCompleted, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByGroupField orders the results by group field.
|
||||
func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newGroupStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(GroupInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn),
|
||||
)
|
||||
}
|
||||
@@ -1,269 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package todo
|
||||
|
||||
import (
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
|
||||
func Title(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldTitle, v))
|
||||
}
|
||||
|
||||
// Completed applies equality check predicate on the "completed" field. It's identical to CompletedEQ.
|
||||
func Completed(v bool) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldCompleted, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// TitleEQ applies the EQ predicate on the "title" field.
|
||||
func TitleEQ(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleNEQ applies the NEQ predicate on the "title" field.
|
||||
func TitleNEQ(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldNEQ(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleIn applies the In predicate on the "title" field.
|
||||
func TitleIn(vs ...string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldIn(FieldTitle, vs...))
|
||||
}
|
||||
|
||||
// TitleNotIn applies the NotIn predicate on the "title" field.
|
||||
func TitleNotIn(vs ...string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldNotIn(FieldTitle, vs...))
|
||||
}
|
||||
|
||||
// TitleGT applies the GT predicate on the "title" field.
|
||||
func TitleGT(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldGT(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleGTE applies the GTE predicate on the "title" field.
|
||||
func TitleGTE(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldGTE(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleLT applies the LT predicate on the "title" field.
|
||||
func TitleLT(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldLT(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleLTE applies the LTE predicate on the "title" field.
|
||||
func TitleLTE(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldLTE(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleContains applies the Contains predicate on the "title" field.
|
||||
func TitleContains(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldContains(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
|
||||
func TitleHasPrefix(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldHasPrefix(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
|
||||
func TitleHasSuffix(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldHasSuffix(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleEqualFold applies the EqualFold predicate on the "title" field.
|
||||
func TitleEqualFold(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEqualFold(FieldTitle, v))
|
||||
}
|
||||
|
||||
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
|
||||
func TitleContainsFold(v string) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldContainsFold(FieldTitle, v))
|
||||
}
|
||||
|
||||
// CompletedEQ applies the EQ predicate on the "completed" field.
|
||||
func CompletedEQ(v bool) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldEQ(FieldCompleted, v))
|
||||
}
|
||||
|
||||
// CompletedNEQ applies the NEQ predicate on the "completed" field.
|
||||
func CompletedNEQ(v bool) predicate.Todo {
|
||||
return predicate.Todo(sql.FieldNEQ(FieldCompleted, v))
|
||||
}
|
||||
|
||||
// HasGroup applies the HasEdge predicate on the "group" edge.
|
||||
func HasGroup() predicate.Todo {
|
||||
return predicate.Todo(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates).
|
||||
func HasGroupWith(preds ...predicate.Group) predicate.Todo {
|
||||
return predicate.Todo(func(s *sql.Selector) {
|
||||
step := newGroupStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Todo) predicate.Todo {
|
||||
return predicate.Todo(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Todo) predicate.Todo {
|
||||
return predicate.Todo(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Todo) predicate.Todo {
|
||||
return predicate.Todo(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -1,314 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// TodoCreate is the builder for creating a Todo entity.
|
||||
type TodoCreate struct {
|
||||
config
|
||||
mutation *TodoMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *TodoCreate) SetCreatedAt(v time.Time) *TodoCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *TodoCreate) SetNillableCreatedAt(v *time.Time) *TodoCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_c *TodoCreate) SetUpdatedAt(v time.Time) *TodoCreate {
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_c *TodoCreate) SetNillableUpdatedAt(v *time.Time) *TodoCreate {
|
||||
if v != nil {
|
||||
_c.SetUpdatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (_c *TodoCreate) SetTitle(v string) *TodoCreate {
|
||||
_c.mutation.SetTitle(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||
func (_c *TodoCreate) SetNillableTitle(v *string) *TodoCreate {
|
||||
if v != nil {
|
||||
_c.SetTitle(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCompleted sets the "completed" field.
|
||||
func (_c *TodoCreate) SetCompleted(v bool) *TodoCreate {
|
||||
_c.mutation.SetCompleted(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCompleted sets the "completed" field if the given value is not nil.
|
||||
func (_c *TodoCreate) SetNillableCompleted(v *bool) *TodoCreate {
|
||||
if v != nil {
|
||||
_c.SetCompleted(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group" edge to the Group entity by ID.
|
||||
func (_c *TodoCreate) SetGroupID(id int) *TodoCreate {
|
||||
_c.mutation.SetGroupID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableGroupID sets the "group" edge to the Group entity by ID if the given value is not nil.
|
||||
func (_c *TodoCreate) SetNillableGroupID(id *int) *TodoCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetGroupID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (_c *TodoCreate) SetGroup(v *Group) *TodoCreate {
|
||||
return _c.SetGroupID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the TodoMutation object of the builder.
|
||||
func (_c *TodoCreate) Mutation() *TodoMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Todo in the database.
|
||||
func (_c *TodoCreate) Save(ctx context.Context) (*Todo, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *TodoCreate) SaveX(ctx context.Context) *Todo {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *TodoCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *TodoCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *TodoCreate) defaults() {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := todo.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
v := todo.DefaultUpdatedAt()
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Title(); !ok {
|
||||
v := todo.DefaultTitle
|
||||
_c.mutation.SetTitle(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Completed(); !ok {
|
||||
v := todo.DefaultCompleted
|
||||
_c.mutation.SetCompleted(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *TodoCreate) check() error {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Todo.created_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Todo.updated_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Title(); !ok {
|
||||
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Todo.title"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Completed(); !ok {
|
||||
return &ValidationError{Name: "completed", err: errors.New(`ent: missing required field "Todo.completed"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *TodoCreate) sqlSave(ctx context.Context) (*Todo, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Todo{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(todo.Table, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(todo.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(todo.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.Title(); ok {
|
||||
_spec.SetField(todo.FieldTitle, field.TypeString, value)
|
||||
_node.Title = value
|
||||
}
|
||||
if value, ok := _c.mutation.Completed(); ok {
|
||||
_spec.SetField(todo.FieldCompleted, field.TypeBool, value)
|
||||
_node.Completed = value
|
||||
}
|
||||
if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: todo.GroupTable,
|
||||
Columns: []string{todo.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.todo_group = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// TodoCreateBulk is the builder for creating many Todo entities in bulk.
|
||||
type TodoCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*TodoCreate
|
||||
}
|
||||
|
||||
// Save creates the Todo entities in the database.
|
||||
func (_c *TodoCreateBulk) Save(ctx context.Context) ([]*Todo, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Todo, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*TodoMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
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, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *TodoCreateBulk) SaveX(ctx context.Context) []*Todo {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *TodoCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *TodoCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// TodoDelete is the builder for deleting a Todo entity.
|
||||
type TodoDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *TodoMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TodoDelete builder.
|
||||
func (_d *TodoDelete) Where(ps ...predicate.Todo) *TodoDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *TodoDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *TodoDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *TodoDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(todo.Table, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt))
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// TodoDeleteOne is the builder for deleting a single Todo entity.
|
||||
type TodoDeleteOne struct {
|
||||
_d *TodoDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TodoDelete builder.
|
||||
func (_d *TodoDeleteOne) Where(ps ...predicate.Todo) *TodoDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *TodoDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{todo.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *TodoDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,389 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// TodoUpdate is the builder for updating Todo entities.
|
||||
type TodoUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *TodoMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TodoUpdate builder.
|
||||
func (_u *TodoUpdate) Where(ps ...predicate.Todo) *TodoUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *TodoUpdate) SetUpdatedAt(v time.Time) *TodoUpdate {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (_u *TodoUpdate) SetTitle(v string) *TodoUpdate {
|
||||
_u.mutation.SetTitle(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||
func (_u *TodoUpdate) SetNillableTitle(v *string) *TodoUpdate {
|
||||
if v != nil {
|
||||
_u.SetTitle(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCompleted sets the "completed" field.
|
||||
func (_u *TodoUpdate) SetCompleted(v bool) *TodoUpdate {
|
||||
_u.mutation.SetCompleted(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCompleted sets the "completed" field if the given value is not nil.
|
||||
func (_u *TodoUpdate) SetNillableCompleted(v *bool) *TodoUpdate {
|
||||
if v != nil {
|
||||
_u.SetCompleted(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group" edge to the Group entity by ID.
|
||||
func (_u *TodoUpdate) SetGroupID(id int) *TodoUpdate {
|
||||
_u.mutation.SetGroupID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableGroupID sets the "group" edge to the Group entity by ID if the given value is not nil.
|
||||
func (_u *TodoUpdate) SetNillableGroupID(id *int) *TodoUpdate {
|
||||
if id != nil {
|
||||
_u = _u.SetGroupID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (_u *TodoUpdate) SetGroup(v *Group) *TodoUpdate {
|
||||
return _u.SetGroupID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the TodoMutation object of the builder.
|
||||
func (_u *TodoUpdate) Mutation() *TodoMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (_u *TodoUpdate) ClearGroup() *TodoUpdate {
|
||||
_u.mutation.ClearGroup()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *TodoUpdate) Save(ctx context.Context) (int, error) {
|
||||
_u.defaults()
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *TodoUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *TodoUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *TodoUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_u *TodoUpdate) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := todo.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *TodoUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(todo.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Title(); ok {
|
||||
_spec.SetField(todo.FieldTitle, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Completed(); ok {
|
||||
_spec.SetField(todo.FieldCompleted, field.TypeBool, value)
|
||||
}
|
||||
if _u.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: todo.GroupTable,
|
||||
Columns: []string{todo.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: todo.GroupTable,
|
||||
Columns: []string{todo.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{todo.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// TodoUpdateOne is the builder for updating a single Todo entity.
|
||||
type TodoUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *TodoMutation
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *TodoUpdateOne) SetUpdatedAt(v time.Time) *TodoUpdateOne {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (_u *TodoUpdateOne) SetTitle(v string) *TodoUpdateOne {
|
||||
_u.mutation.SetTitle(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||
func (_u *TodoUpdateOne) SetNillableTitle(v *string) *TodoUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetTitle(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCompleted sets the "completed" field.
|
||||
func (_u *TodoUpdateOne) SetCompleted(v bool) *TodoUpdateOne {
|
||||
_u.mutation.SetCompleted(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCompleted sets the "completed" field if the given value is not nil.
|
||||
func (_u *TodoUpdateOne) SetNillableCompleted(v *bool) *TodoUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCompleted(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group" edge to the Group entity by ID.
|
||||
func (_u *TodoUpdateOne) SetGroupID(id int) *TodoUpdateOne {
|
||||
_u.mutation.SetGroupID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableGroupID sets the "group" edge to the Group entity by ID if the given value is not nil.
|
||||
func (_u *TodoUpdateOne) SetNillableGroupID(id *int) *TodoUpdateOne {
|
||||
if id != nil {
|
||||
_u = _u.SetGroupID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (_u *TodoUpdateOne) SetGroup(v *Group) *TodoUpdateOne {
|
||||
return _u.SetGroupID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the TodoMutation object of the builder.
|
||||
func (_u *TodoUpdateOne) Mutation() *TodoMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (_u *TodoUpdateOne) ClearGroup() *TodoUpdateOne {
|
||||
_u.mutation.ClearGroup()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TodoUpdate builder.
|
||||
func (_u *TodoUpdateOne) Where(ps ...predicate.Todo) *TodoUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Todo entity.
|
||||
func (_u *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) {
|
||||
_u.defaults()
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *TodoUpdateOne) SaveX(ctx context.Context) *Todo {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *TodoUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *TodoUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_u *TodoUpdateOne) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := todo.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Todo.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, todo.FieldID)
|
||||
for _, f := range fields {
|
||||
if !todo.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != todo.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(todo.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Title(); ok {
|
||||
_spec.SetField(todo.FieldTitle, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Completed(); ok {
|
||||
_spec.SetField(todo.FieldCompleted, field.TypeBool, value)
|
||||
}
|
||||
if _u.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: todo.GroupTable,
|
||||
Columns: []string{todo.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: todo.GroupTable,
|
||||
Columns: []string{todo.GroupColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Todo{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{todo.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// User is the model entity for the User schema.
|
||||
type User struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Email holds the value of the "email" field.
|
||||
Email string `json:"email,omitempty"`
|
||||
// Password holds the value of the "password" field.
|
||||
Password string `json:"password,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the UserQuery when eager-loading is set.
|
||||
Edges UserEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// UserEdges holds the relations/edges for other nodes in the graph.
|
||||
type UserEdges struct {
|
||||
// Group holds the value of the group edge.
|
||||
Group []*Group `json:"group,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// GroupOrErr returns the Group value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) GroupOrErr() ([]*Group, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.Group, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "group"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*User) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case user.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case user.FieldEmail, user.FieldPassword:
|
||||
values[i] = new(sql.NullString)
|
||||
case user.FieldCreatedAt, user.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the User fields.
|
||||
func (_m *User) assignValues(columns []string, values []any) 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 user.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case user.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CreatedAt = value.Time
|
||||
}
|
||||
case user.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UpdatedAt = value.Time
|
||||
}
|
||||
case user.FieldEmail:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field email", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Email = value.String
|
||||
}
|
||||
case user.FieldPassword:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field password", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Password = value.String
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the User.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *User) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryGroup queries the "group" edge of the User entity.
|
||||
func (_m *User) QueryGroup() *GroupQuery {
|
||||
return NewUserClient(_m.config).QueryGroup(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this User.
|
||||
// Note that you need to call User.Unwrap() before calling this method if this User
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *User) Update() *UserUpdateOne {
|
||||
return NewUserClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the User 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 (_m *User) Unwrap() *User {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: User is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *User) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("User(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("email=")
|
||||
builder.WriteString(_m.Email)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("password=")
|
||||
builder.WriteString(_m.Password)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Users is a parsable slice of User.
|
||||
type Users []*User
|
||||
@@ -1,121 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the user type in the database.
|
||||
Label = "user"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldEmail holds the string denoting the email field in the database.
|
||||
FieldEmail = "email"
|
||||
// FieldPassword holds the string denoting the password field in the database.
|
||||
FieldPassword = "password"
|
||||
// EdgeGroup holds the string denoting the group edge name in mutations.
|
||||
EdgeGroup = "group"
|
||||
// Table holds the table name of the user in the database.
|
||||
Table = "users"
|
||||
// GroupTable is the table that holds the group relation/edge. The primary key declared below.
|
||||
GroupTable = "user_group"
|
||||
// GroupInverseTable is the table name for the Group entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "group" package.
|
||||
GroupInverseTable = "groups"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for user fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldEmail,
|
||||
FieldPassword,
|
||||
}
|
||||
|
||||
var (
|
||||
// GroupPrimaryKey and GroupColumn2 are the table columns denoting the
|
||||
// primary key for the group relation (M2M).
|
||||
GroupPrimaryKey = []string{"user_id", "group_id"}
|
||||
)
|
||||
|
||||
// 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 (
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// DefaultEmail holds the default value on creation for the "email" field.
|
||||
DefaultEmail string
|
||||
// DefaultPassword holds the default value on creation for the "password" field.
|
||||
DefaultPassword string
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the User queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByEmail orders the results by the email field.
|
||||
func ByEmail(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldEmail, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPassword orders the results by the password field.
|
||||
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPassword, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByGroupCount orders the results by group count.
|
||||
func ByGroupCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newGroupStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByGroup orders the results by group terms.
|
||||
func ByGroup(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newGroupStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newGroupStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(GroupInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, GroupTable, GroupPrimaryKey...),
|
||||
)
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// Email applies equality check predicate on the "email" field. It's identical to EmailEQ.
|
||||
func Email(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldEmail, v))
|
||||
}
|
||||
|
||||
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
|
||||
func Password(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// EmailEQ applies the EQ predicate on the "email" field.
|
||||
func EmailEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailNEQ applies the NEQ predicate on the "email" field.
|
||||
func EmailNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailIn applies the In predicate on the "email" field.
|
||||
func EmailIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldEmail, vs...))
|
||||
}
|
||||
|
||||
// EmailNotIn applies the NotIn predicate on the "email" field.
|
||||
func EmailNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldEmail, vs...))
|
||||
}
|
||||
|
||||
// EmailGT applies the GT predicate on the "email" field.
|
||||
func EmailGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailGTE applies the GTE predicate on the "email" field.
|
||||
func EmailGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailLT applies the LT predicate on the "email" field.
|
||||
func EmailLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailLTE applies the LTE predicate on the "email" field.
|
||||
func EmailLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailContains applies the Contains predicate on the "email" field.
|
||||
func EmailContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailHasPrefix applies the HasPrefix predicate on the "email" field.
|
||||
func EmailHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailHasSuffix applies the HasSuffix predicate on the "email" field.
|
||||
func EmailHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailEqualFold applies the EqualFold predicate on the "email" field.
|
||||
func EmailEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailContainsFold applies the ContainsFold predicate on the "email" field.
|
||||
func EmailContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldEmail, v))
|
||||
}
|
||||
|
||||
// PasswordEQ applies the EQ predicate on the "password" field.
|
||||
func PasswordEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordNEQ applies the NEQ predicate on the "password" field.
|
||||
func PasswordNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordIn applies the In predicate on the "password" field.
|
||||
func PasswordIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldPassword, vs...))
|
||||
}
|
||||
|
||||
// PasswordNotIn applies the NotIn predicate on the "password" field.
|
||||
func PasswordNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldPassword, vs...))
|
||||
}
|
||||
|
||||
// PasswordGT applies the GT predicate on the "password" field.
|
||||
func PasswordGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordGTE applies the GTE predicate on the "password" field.
|
||||
func PasswordGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordLT applies the LT predicate on the "password" field.
|
||||
func PasswordLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordLTE applies the LTE predicate on the "password" field.
|
||||
func PasswordLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordContains applies the Contains predicate on the "password" field.
|
||||
func PasswordContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
|
||||
func PasswordHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
|
||||
func PasswordHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
|
||||
func PasswordEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
|
||||
func PasswordContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldPassword, v))
|
||||
}
|
||||
|
||||
// HasGroup applies the HasEdge predicate on the "group" edge.
|
||||
func HasGroup() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, GroupTable, GroupPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates).
|
||||
func HasGroupWith(preds ...predicate.Group) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newGroupStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.User) predicate.User {
|
||||
return predicate.User(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -1,309 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserCreate is the builder for creating a User entity.
|
||||
type UserCreate struct {
|
||||
config
|
||||
mutation *UserMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *UserCreate) SetCreatedAt(v time.Time) *UserCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableCreatedAt(v *time.Time) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_c *UserCreate) SetUpdatedAt(v time.Time) *UserCreate {
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableUpdatedAt(v *time.Time) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetUpdatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (_c *UserCreate) SetEmail(v string) *UserCreate {
|
||||
_c.mutation.SetEmail(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableEmail(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetEmail(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (_c *UserCreate) SetPassword(v string) *UserCreate {
|
||||
_c.mutation.SetPassword(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillablePassword(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetPassword(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddGroupIDs adds the "group" edge to the Group entity by IDs.
|
||||
func (_c *UserCreate) AddGroupIDs(ids ...int) *UserCreate {
|
||||
_c.mutation.AddGroupIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddGroup adds the "group" edges to the Group entity.
|
||||
func (_c *UserCreate) AddGroup(v ...*Group) *UserCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddGroupIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (_c *UserCreate) Mutation() *UserMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the User in the database.
|
||||
func (_c *UserCreate) Save(ctx context.Context) (*User, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *UserCreate) SaveX(ctx context.Context) *User {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *UserCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *UserCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *UserCreate) defaults() {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := user.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
v := user.DefaultUpdatedAt()
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Email(); !ok {
|
||||
v := user.DefaultEmail
|
||||
_c.mutation.SetEmail(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Password(); !ok {
|
||||
v := user.DefaultPassword
|
||||
_c.mutation.SetPassword(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *UserCreate) check() error {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "User.created_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "User.updated_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Email(); !ok {
|
||||
return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "User.email"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Password(); !ok {
|
||||
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "User.password"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &User{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.Email(); ok {
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
_node.Email = value
|
||||
}
|
||||
if value, ok := _c.mutation.Password(); ok {
|
||||
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
||||
_node.Password = value
|
||||
}
|
||||
if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.GroupTable,
|
||||
Columns: user.GroupPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// UserCreateBulk is the builder for creating many User entities in bulk.
|
||||
type UserCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*UserCreate
|
||||
}
|
||||
|
||||
// Save creates the User entities in the database.
|
||||
func (_c *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*User, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*UserMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
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, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *UserCreateBulk) SaveX(ctx context.Context) []*User {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *UserCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *UserCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserDelete is the builder for deleting a User entity.
|
||||
type UserDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserDelete builder.
|
||||
func (_d *UserDelete) Where(ps ...predicate.User) *UserDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *UserDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *UserDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *UserDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// UserDeleteOne is the builder for deleting a single User entity.
|
||||
type UserDeleteOne struct {
|
||||
_d *UserDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserDelete builder.
|
||||
func (_d *UserDeleteOne) Where(ps ...predicate.User) *UserDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *UserDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{user.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *UserDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -1,443 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserUpdate is the builder for updating User entities.
|
||||
type UserUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserUpdate builder.
|
||||
func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *UserUpdate) SetUpdatedAt(v time.Time) *UserUpdate {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (_u *UserUpdate) SetEmail(v string) *UserUpdate {
|
||||
_u.mutation.SetEmail(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (_u *UserUpdate) SetNillableEmail(v *string) *UserUpdate {
|
||||
if v != nil {
|
||||
_u.SetEmail(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (_u *UserUpdate) SetPassword(v string) *UserUpdate {
|
||||
_u.mutation.SetPassword(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_u *UserUpdate) SetNillablePassword(v *string) *UserUpdate {
|
||||
if v != nil {
|
||||
_u.SetPassword(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddGroupIDs adds the "group" edge to the Group entity by IDs.
|
||||
func (_u *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate {
|
||||
_u.mutation.AddGroupIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddGroup adds the "group" edges to the Group entity.
|
||||
func (_u *UserUpdate) AddGroup(v ...*Group) *UserUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddGroupIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (_u *UserUpdate) Mutation() *UserMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearGroup clears all "group" edges to the Group entity.
|
||||
func (_u *UserUpdate) ClearGroup() *UserUpdate {
|
||||
_u.mutation.ClearGroup()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveGroupIDs removes the "group" edge to Group entities by IDs.
|
||||
func (_u *UserUpdate) RemoveGroupIDs(ids ...int) *UserUpdate {
|
||||
_u.mutation.RemoveGroupIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveGroup removes "group" edges to Group entities.
|
||||
func (_u *UserUpdate) RemoveGroup(v ...*Group) *UserUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveGroupIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *UserUpdate) Save(ctx context.Context) (int, error) {
|
||||
_u.defaults()
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *UserUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *UserUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *UserUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_u *UserUpdate) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := user.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Email(); ok {
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.GroupTable,
|
||||
Columns: user.GroupPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedGroupIDs(); len(nodes) > 0 && !_u.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.GroupTable,
|
||||
Columns: user.GroupPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.GroupTable,
|
||||
Columns: user.GroupPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// UserUpdateOne is the builder for updating a single User entity.
|
||||
type UserUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *UserUpdateOne) SetUpdatedAt(v time.Time) *UserUpdateOne {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (_u *UserUpdateOne) SetEmail(v string) *UserUpdateOne {
|
||||
_u.mutation.SetEmail(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (_u *UserUpdateOne) SetNillableEmail(v *string) *UserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetEmail(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (_u *UserUpdateOne) SetPassword(v string) *UserUpdateOne {
|
||||
_u.mutation.SetPassword(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_u *UserUpdateOne) SetNillablePassword(v *string) *UserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetPassword(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddGroupIDs adds the "group" edge to the Group entity by IDs.
|
||||
func (_u *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne {
|
||||
_u.mutation.AddGroupIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddGroup adds the "group" edges to the Group entity.
|
||||
func (_u *UserUpdateOne) AddGroup(v ...*Group) *UserUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddGroupIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (_u *UserUpdateOne) Mutation() *UserMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearGroup clears all "group" edges to the Group entity.
|
||||
func (_u *UserUpdateOne) ClearGroup() *UserUpdateOne {
|
||||
_u.mutation.ClearGroup()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveGroupIDs removes the "group" edge to Group entities by IDs.
|
||||
func (_u *UserUpdateOne) RemoveGroupIDs(ids ...int) *UserUpdateOne {
|
||||
_u.mutation.RemoveGroupIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveGroup removes "group" edges to Group entities.
|
||||
func (_u *UserUpdateOne) RemoveGroup(v ...*Group) *UserUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveGroupIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserUpdate builder.
|
||||
func (_u *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated User entity.
|
||||
func (_u *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
||||
_u.defaults()
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *UserUpdateOne) SaveX(ctx context.Context) *User {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *UserUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *UserUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_u *UserUpdateOne) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := user.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
|
||||
for _, f := range fields {
|
||||
if !user.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != user.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Email(); ok {
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.GroupTable,
|
||||
Columns: user.GroupPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedGroupIDs(); len(nodes) > 0 && !_u.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.GroupTable,
|
||||
Columns: user.GroupPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.GroupTable,
|
||||
Columns: user.GroupPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &User{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"entgo.io/ent/entc"
|
||||
"entgo.io/ent/entc/gen"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Println("ersteller start")
|
||||
// Parse our custom pagination template (per-entity Query methods).
|
||||
paginationPath := "schema/ent/pagination_query.tmpl"
|
||||
//paginationTmpl := gen.MustParse(gen.NewTemplate("pagination_query").
|
||||
// ParseFiles(paginationPath))
|
||||
|
||||
must(entc.Generate(
|
||||
"./schema/ent/example/ent/schema",
|
||||
&gen.Config{},
|
||||
entc.TemplateFiles(paginationPath),
|
||||
))
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
|
||||
client, err := ent.Open("sqlite3", "/tmp/ersteller_ent_example.db?_fk=1",
|
||||
ent.Log(log.Println), ent.Debug())
|
||||
if err != nil {
|
||||
log.Fatalf("failed opening connection to sqlite: %v", err)
|
||||
}
|
||||
log.Println("client", client)
|
||||
defer client.Close()
|
||||
|
||||
// Add authorization interceptor for Todo queries
|
||||
client.Todo.Intercept(TodoAuthorizationInterceptor())
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
|
||||
defer cancel()
|
||||
|
||||
if err := client.Schema.Create(ctx); err != nil {
|
||||
log.Fatalf("failed creating schema resources: %v", err)
|
||||
}
|
||||
|
||||
testGroup, err := client.Group.Create().SetName("Test").Save(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("failed creating group: %w", err)
|
||||
}
|
||||
u, err := client.User.
|
||||
Create().
|
||||
SetEmail("something@gorlug.de").
|
||||
SetPassword("uhoh").
|
||||
AddGroup(testGroup).
|
||||
Save(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("failed creating user: %w", err)
|
||||
}
|
||||
log.Println("user was created: ", u)
|
||||
|
||||
//time.Sleep(time.Second * 1)
|
||||
//u, err = client.User.UpdateOneID(u.ID).SetPassword("wtf").Save(ctx)
|
||||
//if err != nil {
|
||||
// log.Fatalf("failed updating user: %w", err)
|
||||
//}j
|
||||
//log.Println("user was updated", u)
|
||||
query := client.User.Query()
|
||||
users, nextId, hasNext, err := query.PaginateAfterID(ctx, 0, 2)
|
||||
if err != nil {
|
||||
log.Fatalf("failed listing users: %w", err)
|
||||
}
|
||||
if hasNext {
|
||||
log.Println("next id", nextId)
|
||||
for _, u := range users {
|
||||
log.Println("user", u.ID, u.Email, u.Password)
|
||||
}
|
||||
}
|
||||
users, nextId, hasNext, err = query.PaginateAfterID(ctx, nextId, 2)
|
||||
if err != nil {
|
||||
log.Fatalf("failed listing users: %w", err)
|
||||
}
|
||||
if hasNext {
|
||||
log.Println("2 next id", nextId)
|
||||
for _, u := range users {
|
||||
log.Println("2 user", u.ID, u.Email, u.Password)
|
||||
}
|
||||
}
|
||||
|
||||
todoItem, err := client.Todo.Create().SetTitle("test").
|
||||
SetGroup(testGroup).Save(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create todo", err)
|
||||
}
|
||||
|
||||
// Add user ID to context for authorization
|
||||
authorizedCtx := context.WithValue(ctx, UserIDKey, u.ID)
|
||||
|
||||
// This should work - user is in the group
|
||||
retrievedTodo, err := client.Todo.Get(authorizedCtx, todoItem.ID)
|
||||
if err != nil {
|
||||
log.Fatalf("failed getting todo with authorization: %v", err)
|
||||
}
|
||||
log.Println("retrieved todo:", retrievedTodo)
|
||||
|
||||
// This should fail - no user ID in context
|
||||
_, err = client.Todo.Get(ctx, todoItem.ID)
|
||||
if err != nil {
|
||||
log.Println("expected authorization error:", err)
|
||||
}
|
||||
|
||||
secondGroup, err := client.Group.Create().SetName("second").Save(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("failed creating group: %w", err)
|
||||
}
|
||||
secondUser, err := client.User.Create().SetEmail("abc@def.de").AddGroup(secondGroup).Save(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("failed creating user: %w", err)
|
||||
}
|
||||
|
||||
// Add user ID to context for authorization
|
||||
secondUserAuthorizedCtx := context.WithValue(ctx, UserIDKey, secondUser.ID)
|
||||
_, err = client.Todo.Get(secondUserAuthorizedCtx, todoItem.ID)
|
||||
if err != nil {
|
||||
log.Println("expected authorization error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// UserIDKey is used to store user ID in context
|
||||
type contextKey string
|
||||
|
||||
const UserIDKey = contextKey("userID")
|
||||
|
||||
// TodoAuthorizationInterceptor returns an interceptor that enforces user authorization for todos
|
||||
func TodoAuthorizationInterceptor() ent.Interceptor {
|
||||
return ent.InterceptFunc(func(next ent.Querier) ent.Querier {
|
||||
return ent.QuerierFunc(func(ctx context.Context, query ent.Query) (ent.Value, error) {
|
||||
// Get user ID from context
|
||||
userID, ok := ctx.Value(UserIDKey).(int)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("user ID is required in context for todo operations")
|
||||
}
|
||||
|
||||
// Cast to TodoQuery to add authorization filter
|
||||
if tq, ok := query.(*ent.TodoQuery); ok {
|
||||
// Add predicate to ensure user is in the same group as the todo
|
||||
tq = tq.Where(todo.HasGroupWith(group.HasUsersWith(user.ID(userID))))
|
||||
return next.Query(ctx, tq)
|
||||
}
|
||||
|
||||
return next.Query(ctx, query)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueue"
|
||||
)
|
||||
|
||||
// GeneralQueue is the model entity for the GeneralQueue schema.
|
||||
type GeneralQueue struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Payload holds the value of the "payload" field.
|
||||
Payload map[string]interface{} `json:"payload,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status generalqueue.Status `json:"status,omitempty"`
|
||||
// NumberOfTries holds the value of the "number_of_tries" field.
|
||||
NumberOfTries int `json:"number_of_tries,omitempty"`
|
||||
// MaxRetries holds the value of the "max_retries" field.
|
||||
MaxRetries int `json:"max_retries,omitempty"`
|
||||
// ErrorMessage holds the value of the "error_message" field.
|
||||
ErrorMessage string `json:"error_message,omitempty"`
|
||||
// FailurePayload holds the value of the "failure_payload" field.
|
||||
FailurePayload map[string]interface{} `json:"failure_payload,omitempty"`
|
||||
// ResultPayload holds the value of the "result_payload" field.
|
||||
ResultPayload map[string]interface{} `json:"result_payload,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// ProcessedAt holds the value of the "processed_at" field.
|
||||
ProcessedAt time.Time `json:"processed_at,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*GeneralQueue) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case generalqueue.FieldPayload, generalqueue.FieldFailurePayload, generalqueue.FieldResultPayload:
|
||||
values[i] = new([]byte)
|
||||
case generalqueue.FieldID, generalqueue.FieldNumberOfTries, generalqueue.FieldMaxRetries:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case generalqueue.FieldName, generalqueue.FieldStatus, generalqueue.FieldErrorMessage:
|
||||
values[i] = new(sql.NullString)
|
||||
case generalqueue.FieldCreatedAt, generalqueue.FieldUpdatedAt, generalqueue.FieldProcessedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the GeneralQueue fields.
|
||||
func (_m *GeneralQueue) assignValues(columns []string, values []any) 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 generalqueue.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case generalqueue.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Name = value.String
|
||||
}
|
||||
case generalqueue.FieldPayload:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field payload", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &_m.Payload); err != nil {
|
||||
return fmt.Errorf("unmarshal field payload: %w", err)
|
||||
}
|
||||
}
|
||||
case generalqueue.FieldStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Status = generalqueue.Status(value.String)
|
||||
}
|
||||
case generalqueue.FieldNumberOfTries:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field number_of_tries", values[i])
|
||||
} else if value.Valid {
|
||||
_m.NumberOfTries = int(value.Int64)
|
||||
}
|
||||
case generalqueue.FieldMaxRetries:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field max_retries", values[i])
|
||||
} else if value.Valid {
|
||||
_m.MaxRetries = int(value.Int64)
|
||||
}
|
||||
case generalqueue.FieldErrorMessage:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field error_message", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ErrorMessage = value.String
|
||||
}
|
||||
case generalqueue.FieldFailurePayload:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field failure_payload", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &_m.FailurePayload); err != nil {
|
||||
return fmt.Errorf("unmarshal field failure_payload: %w", err)
|
||||
}
|
||||
}
|
||||
case generalqueue.FieldResultPayload:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field result_payload", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &_m.ResultPayload); err != nil {
|
||||
return fmt.Errorf("unmarshal field result_payload: %w", err)
|
||||
}
|
||||
}
|
||||
case generalqueue.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CreatedAt = value.Time
|
||||
}
|
||||
case generalqueue.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UpdatedAt = value.Time
|
||||
}
|
||||
case generalqueue.FieldProcessedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field processed_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ProcessedAt = value.Time
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the GeneralQueue.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *GeneralQueue) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this GeneralQueue.
|
||||
// Note that you need to call GeneralQueue.Unwrap() before calling this method if this GeneralQueue
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *GeneralQueue) Update() *GeneralQueueUpdateOne {
|
||||
return NewGeneralQueueClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the GeneralQueue 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 (_m *GeneralQueue) Unwrap() *GeneralQueue {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: GeneralQueue is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *GeneralQueue) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("GeneralQueue(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("payload=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Payload))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Status))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("number_of_tries=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.NumberOfTries))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("max_retries=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.MaxRetries))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("error_message=")
|
||||
builder.WriteString(_m.ErrorMessage)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("failure_payload=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.FailurePayload))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("result_payload=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.ResultPayload))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("processed_at=")
|
||||
builder.WriteString(_m.ProcessedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// GeneralQueues is a parsable slice of GeneralQueue.
|
||||
type GeneralQueues []*GeneralQueue
|
||||
@@ -0,0 +1,146 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package generalqueue
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the generalqueue type in the database.
|
||||
Label = "general_queue"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldPayload holds the string denoting the payload field in the database.
|
||||
FieldPayload = "payload"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldNumberOfTries holds the string denoting the number_of_tries field in the database.
|
||||
FieldNumberOfTries = "number_of_tries"
|
||||
// FieldMaxRetries holds the string denoting the max_retries field in the database.
|
||||
FieldMaxRetries = "max_retries"
|
||||
// FieldErrorMessage holds the string denoting the error_message field in the database.
|
||||
FieldErrorMessage = "error_message"
|
||||
// FieldFailurePayload holds the string denoting the failure_payload field in the database.
|
||||
FieldFailurePayload = "failure_payload"
|
||||
// FieldResultPayload holds the string denoting the result_payload field in the database.
|
||||
FieldResultPayload = "result_payload"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldProcessedAt holds the string denoting the processed_at field in the database.
|
||||
FieldProcessedAt = "processed_at"
|
||||
// Table holds the table name of the generalqueue in the database.
|
||||
Table = "generalQueue"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for generalqueue fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
FieldPayload,
|
||||
FieldStatus,
|
||||
FieldNumberOfTries,
|
||||
FieldMaxRetries,
|
||||
FieldErrorMessage,
|
||||
FieldFailurePayload,
|
||||
FieldResultPayload,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldProcessedAt,
|
||||
}
|
||||
|
||||
// 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 (
|
||||
// DefaultNumberOfTries holds the default value on creation for the "number_of_tries" field.
|
||||
DefaultNumberOfTries int
|
||||
// DefaultMaxRetries holds the default value on creation for the "max_retries" field.
|
||||
DefaultMaxRetries int
|
||||
)
|
||||
|
||||
// Status defines the type for the "status" enum field.
|
||||
type Status string
|
||||
|
||||
// Status values.
|
||||
const (
|
||||
StatusPending Status = "pending"
|
||||
StatusInProgress Status = "in_progress"
|
||||
StatusCompleted Status = "completed"
|
||||
StatusFailed Status = "failed"
|
||||
)
|
||||
|
||||
func (s Status) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
|
||||
func StatusValidator(s Status) error {
|
||||
switch s {
|
||||
case StatusPending, StatusInProgress, StatusCompleted, StatusFailed:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("generalqueue: invalid enum value for status field: %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the GeneralQueue queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNumberOfTries orders the results by the number_of_tries field.
|
||||
func ByNumberOfTries(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNumberOfTries, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMaxRetries orders the results by the max_retries field.
|
||||
func ByMaxRetries(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMaxRetries, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByErrorMessage orders the results by the error_message field.
|
||||
func ByErrorMessage(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldErrorMessage, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByProcessedAt orders the results by the processed_at field.
|
||||
func ByProcessedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldProcessedAt, opts...).ToFunc()
|
||||
}
|
||||
@@ -0,0 +1,495 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package generalqueue
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NumberOfTries applies equality check predicate on the "number_of_tries" field. It's identical to NumberOfTriesEQ.
|
||||
func NumberOfTries(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldNumberOfTries, v))
|
||||
}
|
||||
|
||||
// MaxRetries applies equality check predicate on the "max_retries" field. It's identical to MaxRetriesEQ.
|
||||
func MaxRetries(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldMaxRetries, v))
|
||||
}
|
||||
|
||||
// ErrorMessage applies equality check predicate on the "error_message" field. It's identical to ErrorMessageEQ.
|
||||
func ErrorMessage(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// ProcessedAt applies equality check predicate on the "processed_at" field. It's identical to ProcessedAtEQ.
|
||||
func ProcessedAt(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldProcessedAt, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// StatusEQ applies the EQ predicate on the "status" field.
|
||||
func StatusEQ(v Status) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||
func StatusNEQ(v Status) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusIn applies the In predicate on the "status" field.
|
||||
func StatusIn(vs ...Status) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// StatusNotIn applies the NotIn predicate on the "status" field.
|
||||
func StatusNotIn(vs ...Status) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// NumberOfTriesEQ applies the EQ predicate on the "number_of_tries" field.
|
||||
func NumberOfTriesEQ(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldNumberOfTries, v))
|
||||
}
|
||||
|
||||
// NumberOfTriesNEQ applies the NEQ predicate on the "number_of_tries" field.
|
||||
func NumberOfTriesNEQ(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNEQ(FieldNumberOfTries, v))
|
||||
}
|
||||
|
||||
// NumberOfTriesIn applies the In predicate on the "number_of_tries" field.
|
||||
func NumberOfTriesIn(vs ...int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIn(FieldNumberOfTries, vs...))
|
||||
}
|
||||
|
||||
// NumberOfTriesNotIn applies the NotIn predicate on the "number_of_tries" field.
|
||||
func NumberOfTriesNotIn(vs ...int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotIn(FieldNumberOfTries, vs...))
|
||||
}
|
||||
|
||||
// NumberOfTriesGT applies the GT predicate on the "number_of_tries" field.
|
||||
func NumberOfTriesGT(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGT(FieldNumberOfTries, v))
|
||||
}
|
||||
|
||||
// NumberOfTriesGTE applies the GTE predicate on the "number_of_tries" field.
|
||||
func NumberOfTriesGTE(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGTE(FieldNumberOfTries, v))
|
||||
}
|
||||
|
||||
// NumberOfTriesLT applies the LT predicate on the "number_of_tries" field.
|
||||
func NumberOfTriesLT(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLT(FieldNumberOfTries, v))
|
||||
}
|
||||
|
||||
// NumberOfTriesLTE applies the LTE predicate on the "number_of_tries" field.
|
||||
func NumberOfTriesLTE(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLTE(FieldNumberOfTries, v))
|
||||
}
|
||||
|
||||
// MaxRetriesEQ applies the EQ predicate on the "max_retries" field.
|
||||
func MaxRetriesEQ(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldMaxRetries, v))
|
||||
}
|
||||
|
||||
// MaxRetriesNEQ applies the NEQ predicate on the "max_retries" field.
|
||||
func MaxRetriesNEQ(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNEQ(FieldMaxRetries, v))
|
||||
}
|
||||
|
||||
// MaxRetriesIn applies the In predicate on the "max_retries" field.
|
||||
func MaxRetriesIn(vs ...int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIn(FieldMaxRetries, vs...))
|
||||
}
|
||||
|
||||
// MaxRetriesNotIn applies the NotIn predicate on the "max_retries" field.
|
||||
func MaxRetriesNotIn(vs ...int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotIn(FieldMaxRetries, vs...))
|
||||
}
|
||||
|
||||
// MaxRetriesGT applies the GT predicate on the "max_retries" field.
|
||||
func MaxRetriesGT(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGT(FieldMaxRetries, v))
|
||||
}
|
||||
|
||||
// MaxRetriesGTE applies the GTE predicate on the "max_retries" field.
|
||||
func MaxRetriesGTE(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGTE(FieldMaxRetries, v))
|
||||
}
|
||||
|
||||
// MaxRetriesLT applies the LT predicate on the "max_retries" field.
|
||||
func MaxRetriesLT(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLT(FieldMaxRetries, v))
|
||||
}
|
||||
|
||||
// MaxRetriesLTE applies the LTE predicate on the "max_retries" field.
|
||||
func MaxRetriesLTE(v int) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLTE(FieldMaxRetries, v))
|
||||
}
|
||||
|
||||
// ErrorMessageEQ applies the EQ predicate on the "error_message" field.
|
||||
func ErrorMessageEQ(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageNEQ applies the NEQ predicate on the "error_message" field.
|
||||
func ErrorMessageNEQ(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNEQ(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageIn applies the In predicate on the "error_message" field.
|
||||
func ErrorMessageIn(vs ...string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIn(FieldErrorMessage, vs...))
|
||||
}
|
||||
|
||||
// ErrorMessageNotIn applies the NotIn predicate on the "error_message" field.
|
||||
func ErrorMessageNotIn(vs ...string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotIn(FieldErrorMessage, vs...))
|
||||
}
|
||||
|
||||
// ErrorMessageGT applies the GT predicate on the "error_message" field.
|
||||
func ErrorMessageGT(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGT(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageGTE applies the GTE predicate on the "error_message" field.
|
||||
func ErrorMessageGTE(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGTE(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageLT applies the LT predicate on the "error_message" field.
|
||||
func ErrorMessageLT(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLT(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageLTE applies the LTE predicate on the "error_message" field.
|
||||
func ErrorMessageLTE(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLTE(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageContains applies the Contains predicate on the "error_message" field.
|
||||
func ErrorMessageContains(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldContains(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageHasPrefix applies the HasPrefix predicate on the "error_message" field.
|
||||
func ErrorMessageHasPrefix(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldHasPrefix(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageHasSuffix applies the HasSuffix predicate on the "error_message" field.
|
||||
func ErrorMessageHasSuffix(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldHasSuffix(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageIsNil applies the IsNil predicate on the "error_message" field.
|
||||
func ErrorMessageIsNil() predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIsNull(FieldErrorMessage))
|
||||
}
|
||||
|
||||
// ErrorMessageNotNil applies the NotNil predicate on the "error_message" field.
|
||||
func ErrorMessageNotNil() predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotNull(FieldErrorMessage))
|
||||
}
|
||||
|
||||
// ErrorMessageEqualFold applies the EqualFold predicate on the "error_message" field.
|
||||
func ErrorMessageEqualFold(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEqualFold(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// ErrorMessageContainsFold applies the ContainsFold predicate on the "error_message" field.
|
||||
func ErrorMessageContainsFold(v string) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldContainsFold(FieldErrorMessage, v))
|
||||
}
|
||||
|
||||
// FailurePayloadIsNil applies the IsNil predicate on the "failure_payload" field.
|
||||
func FailurePayloadIsNil() predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIsNull(FieldFailurePayload))
|
||||
}
|
||||
|
||||
// FailurePayloadNotNil applies the NotNil predicate on the "failure_payload" field.
|
||||
func FailurePayloadNotNil() predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotNull(FieldFailurePayload))
|
||||
}
|
||||
|
||||
// ResultPayloadIsNil applies the IsNil predicate on the "result_payload" field.
|
||||
func ResultPayloadIsNil() predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIsNull(FieldResultPayload))
|
||||
}
|
||||
|
||||
// ResultPayloadNotNil applies the NotNil predicate on the "result_payload" field.
|
||||
func ResultPayloadNotNil() predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotNull(FieldResultPayload))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// ProcessedAtEQ applies the EQ predicate on the "processed_at" field.
|
||||
func ProcessedAtEQ(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldEQ(FieldProcessedAt, v))
|
||||
}
|
||||
|
||||
// ProcessedAtNEQ applies the NEQ predicate on the "processed_at" field.
|
||||
func ProcessedAtNEQ(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNEQ(FieldProcessedAt, v))
|
||||
}
|
||||
|
||||
// ProcessedAtIn applies the In predicate on the "processed_at" field.
|
||||
func ProcessedAtIn(vs ...time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIn(FieldProcessedAt, vs...))
|
||||
}
|
||||
|
||||
// ProcessedAtNotIn applies the NotIn predicate on the "processed_at" field.
|
||||
func ProcessedAtNotIn(vs ...time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotIn(FieldProcessedAt, vs...))
|
||||
}
|
||||
|
||||
// ProcessedAtGT applies the GT predicate on the "processed_at" field.
|
||||
func ProcessedAtGT(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGT(FieldProcessedAt, v))
|
||||
}
|
||||
|
||||
// ProcessedAtGTE applies the GTE predicate on the "processed_at" field.
|
||||
func ProcessedAtGTE(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldGTE(FieldProcessedAt, v))
|
||||
}
|
||||
|
||||
// ProcessedAtLT applies the LT predicate on the "processed_at" field.
|
||||
func ProcessedAtLT(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLT(FieldProcessedAt, v))
|
||||
}
|
||||
|
||||
// ProcessedAtLTE applies the LTE predicate on the "processed_at" field.
|
||||
func ProcessedAtLTE(v time.Time) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldLTE(FieldProcessedAt, v))
|
||||
}
|
||||
|
||||
// ProcessedAtIsNil applies the IsNil predicate on the "processed_at" field.
|
||||
func ProcessedAtIsNil() predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldIsNull(FieldProcessedAt))
|
||||
}
|
||||
|
||||
// ProcessedAtNotNil applies the NotNil predicate on the "processed_at" field.
|
||||
func ProcessedAtNotNil() predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.FieldNotNull(FieldProcessedAt))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.GeneralQueue) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.GeneralQueue) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.GeneralQueue) predicate.GeneralQueue {
|
||||
return predicate.GeneralQueue(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueue"
|
||||
)
|
||||
|
||||
// GeneralQueueCreate is the builder for creating a GeneralQueue entity.
|
||||
type GeneralQueueCreate struct {
|
||||
config
|
||||
mutation *GeneralQueueMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *GeneralQueueCreate) SetName(v string) *GeneralQueueCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPayload sets the "payload" field.
|
||||
func (_c *GeneralQueueCreate) SetPayload(v map[string]interface{}) *GeneralQueueCreate {
|
||||
_c.mutation.SetPayload(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_c *GeneralQueueCreate) SetStatus(v generalqueue.Status) *GeneralQueueCreate {
|
||||
_c.mutation.SetStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNumberOfTries sets the "number_of_tries" field.
|
||||
func (_c *GeneralQueueCreate) SetNumberOfTries(v int) *GeneralQueueCreate {
|
||||
_c.mutation.SetNumberOfTries(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableNumberOfTries sets the "number_of_tries" field if the given value is not nil.
|
||||
func (_c *GeneralQueueCreate) SetNillableNumberOfTries(v *int) *GeneralQueueCreate {
|
||||
if v != nil {
|
||||
_c.SetNumberOfTries(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetMaxRetries sets the "max_retries" field.
|
||||
func (_c *GeneralQueueCreate) SetMaxRetries(v int) *GeneralQueueCreate {
|
||||
_c.mutation.SetMaxRetries(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableMaxRetries sets the "max_retries" field if the given value is not nil.
|
||||
func (_c *GeneralQueueCreate) SetNillableMaxRetries(v *int) *GeneralQueueCreate {
|
||||
if v != nil {
|
||||
_c.SetMaxRetries(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetErrorMessage sets the "error_message" field.
|
||||
func (_c *GeneralQueueCreate) SetErrorMessage(v string) *GeneralQueueCreate {
|
||||
_c.mutation.SetErrorMessage(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
|
||||
func (_c *GeneralQueueCreate) SetNillableErrorMessage(v *string) *GeneralQueueCreate {
|
||||
if v != nil {
|
||||
_c.SetErrorMessage(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetFailurePayload sets the "failure_payload" field.
|
||||
func (_c *GeneralQueueCreate) SetFailurePayload(v map[string]interface{}) *GeneralQueueCreate {
|
||||
_c.mutation.SetFailurePayload(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetResultPayload sets the "result_payload" field.
|
||||
func (_c *GeneralQueueCreate) SetResultPayload(v map[string]interface{}) *GeneralQueueCreate {
|
||||
_c.mutation.SetResultPayload(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *GeneralQueueCreate) SetCreatedAt(v time.Time) *GeneralQueueCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_c *GeneralQueueCreate) SetUpdatedAt(v time.Time) *GeneralQueueCreate {
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetProcessedAt sets the "processed_at" field.
|
||||
func (_c *GeneralQueueCreate) SetProcessedAt(v time.Time) *GeneralQueueCreate {
|
||||
_c.mutation.SetProcessedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableProcessedAt sets the "processed_at" field if the given value is not nil.
|
||||
func (_c *GeneralQueueCreate) SetNillableProcessedAt(v *time.Time) *GeneralQueueCreate {
|
||||
if v != nil {
|
||||
_c.SetProcessedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the GeneralQueueMutation object of the builder.
|
||||
func (_c *GeneralQueueCreate) Mutation() *GeneralQueueMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the GeneralQueue in the database.
|
||||
func (_c *GeneralQueueCreate) Save(ctx context.Context) (*GeneralQueue, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *GeneralQueueCreate) SaveX(ctx context.Context) *GeneralQueue {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *GeneralQueueCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *GeneralQueueCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *GeneralQueueCreate) defaults() {
|
||||
if _, ok := _c.mutation.NumberOfTries(); !ok {
|
||||
v := generalqueue.DefaultNumberOfTries
|
||||
_c.mutation.SetNumberOfTries(v)
|
||||
}
|
||||
if _, ok := _c.mutation.MaxRetries(); !ok {
|
||||
v := generalqueue.DefaultMaxRetries
|
||||
_c.mutation.SetMaxRetries(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *GeneralQueueCreate) check() error {
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "GeneralQueue.name"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Payload(); !ok {
|
||||
return &ValidationError{Name: "payload", err: errors.New(`ent: missing required field "GeneralQueue.payload"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "GeneralQueue.status"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Status(); ok {
|
||||
if err := generalqueue.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "GeneralQueue.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.NumberOfTries(); !ok {
|
||||
return &ValidationError{Name: "number_of_tries", err: errors.New(`ent: missing required field "GeneralQueue.number_of_tries"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.MaxRetries(); !ok {
|
||||
return &ValidationError{Name: "max_retries", err: errors.New(`ent: missing required field "GeneralQueue.max_retries"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "GeneralQueue.created_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "GeneralQueue.updated_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *GeneralQueueCreate) sqlSave(ctx context.Context) (*GeneralQueue, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *GeneralQueueCreate) createSpec() (*GeneralQueue, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &GeneralQueue{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(generalqueue.Table, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(generalqueue.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.Payload(); ok {
|
||||
_spec.SetField(generalqueue.FieldPayload, field.TypeJSON, value)
|
||||
_node.Payload = value
|
||||
}
|
||||
if value, ok := _c.mutation.Status(); ok {
|
||||
_spec.SetField(generalqueue.FieldStatus, field.TypeEnum, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := _c.mutation.NumberOfTries(); ok {
|
||||
_spec.SetField(generalqueue.FieldNumberOfTries, field.TypeInt, value)
|
||||
_node.NumberOfTries = value
|
||||
}
|
||||
if value, ok := _c.mutation.MaxRetries(); ok {
|
||||
_spec.SetField(generalqueue.FieldMaxRetries, field.TypeInt, value)
|
||||
_node.MaxRetries = value
|
||||
}
|
||||
if value, ok := _c.mutation.ErrorMessage(); ok {
|
||||
_spec.SetField(generalqueue.FieldErrorMessage, field.TypeString, value)
|
||||
_node.ErrorMessage = value
|
||||
}
|
||||
if value, ok := _c.mutation.FailurePayload(); ok {
|
||||
_spec.SetField(generalqueue.FieldFailurePayload, field.TypeJSON, value)
|
||||
_node.FailurePayload = value
|
||||
}
|
||||
if value, ok := _c.mutation.ResultPayload(); ok {
|
||||
_spec.SetField(generalqueue.FieldResultPayload, field.TypeJSON, value)
|
||||
_node.ResultPayload = value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(generalqueue.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(generalqueue.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.ProcessedAt(); ok {
|
||||
_spec.SetField(generalqueue.FieldProcessedAt, field.TypeTime, value)
|
||||
_node.ProcessedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// GeneralQueueCreateBulk is the builder for creating many GeneralQueue entities in bulk.
|
||||
type GeneralQueueCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*GeneralQueueCreate
|
||||
}
|
||||
|
||||
// Save creates the GeneralQueue entities in the database.
|
||||
func (_c *GeneralQueueCreateBulk) Save(ctx context.Context) ([]*GeneralQueue, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*GeneralQueue, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*GeneralQueueMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
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, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *GeneralQueueCreateBulk) SaveX(ctx context.Context) []*GeneralQueue {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *GeneralQueueCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *GeneralQueueCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueue"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/predicate"
|
||||
)
|
||||
|
||||
// GeneralQueueDelete is the builder for deleting a GeneralQueue entity.
|
||||
type GeneralQueueDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GeneralQueueMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GeneralQueueDelete builder.
|
||||
func (_d *GeneralQueueDelete) Where(ps ...predicate.GeneralQueue) *GeneralQueueDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *GeneralQueueDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *GeneralQueueDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *GeneralQueueDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(generalqueue.Table, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt))
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// GeneralQueueDeleteOne is the builder for deleting a single GeneralQueue entity.
|
||||
type GeneralQueueDeleteOne struct {
|
||||
_d *GeneralQueueDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GeneralQueueDelete builder.
|
||||
func (_d *GeneralQueueDeleteOne) Where(ps ...predicate.GeneralQueue) *GeneralQueueDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *GeneralQueueDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{generalqueue.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *GeneralQueueDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -5,99 +5,74 @@ package ent
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/todo"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueue"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/predicate"
|
||||
)
|
||||
|
||||
// TodoQuery is the builder for querying Todo entities.
|
||||
type TodoQuery struct {
|
||||
// GeneralQueueQuery is the builder for querying GeneralQueue entities.
|
||||
type GeneralQueueQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []todo.OrderOption
|
||||
order []generalqueue.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Todo
|
||||
withGroup *GroupQuery
|
||||
withFKs bool
|
||||
predicates []predicate.GeneralQueue
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the TodoQuery builder.
|
||||
func (_q *TodoQuery) Where(ps ...predicate.Todo) *TodoQuery {
|
||||
// Where adds a new predicate for the GeneralQueueQuery builder.
|
||||
func (_q *GeneralQueueQuery) Where(ps ...predicate.GeneralQueue) *GeneralQueueQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *TodoQuery) Limit(limit int) *TodoQuery {
|
||||
func (_q *GeneralQueueQuery) Limit(limit int) *GeneralQueueQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *TodoQuery) Offset(offset int) *TodoQuery {
|
||||
func (_q *GeneralQueueQuery) Offset(offset int) *GeneralQueueQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// 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 (_q *TodoQuery) Unique(unique bool) *TodoQuery {
|
||||
func (_q *GeneralQueueQuery) Unique(unique bool) *GeneralQueueQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *TodoQuery) Order(o ...todo.OrderOption) *TodoQuery {
|
||||
func (_q *GeneralQueueQuery) Order(o ...generalqueue.OrderOption) *GeneralQueueQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryGroup chains the current query on the "group" edge.
|
||||
func (_q *TodoQuery) QueryGroup() *GroupQuery {
|
||||
query := (&GroupClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(todo.Table, todo.FieldID, selector),
|
||||
sqlgraph.To(group.Table, group.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, todo.GroupTable, todo.GroupColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Todo entity from the query.
|
||||
// Returns a *NotFoundError when no Todo was found.
|
||||
func (_q *TodoQuery) First(ctx context.Context) (*Todo, error) {
|
||||
// First returns the first GeneralQueue entity from the query.
|
||||
// Returns a *NotFoundError when no GeneralQueue was found.
|
||||
func (_q *GeneralQueueQuery) First(ctx context.Context) (*GeneralQueue, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{todo.Label}
|
||||
return nil, &NotFoundError{generalqueue.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *TodoQuery) FirstX(ctx context.Context) *Todo {
|
||||
func (_q *GeneralQueueQuery) FirstX(ctx context.Context) *GeneralQueue {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
@@ -105,22 +80,22 @@ func (_q *TodoQuery) FirstX(ctx context.Context) *Todo {
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Todo ID from the query.
|
||||
// Returns a *NotFoundError when no Todo ID was found.
|
||||
func (_q *TodoQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
// FirstID returns the first GeneralQueue ID from the query.
|
||||
// Returns a *NotFoundError when no GeneralQueue ID was found.
|
||||
func (_q *GeneralQueueQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{todo.Label}
|
||||
err = &NotFoundError{generalqueue.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *TodoQuery) FirstIDX(ctx context.Context) int {
|
||||
func (_q *GeneralQueueQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
@@ -128,10 +103,10 @@ func (_q *TodoQuery) FirstIDX(ctx context.Context) int {
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Todo entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Todo entity is found.
|
||||
// Returns a *NotFoundError when no Todo entities are found.
|
||||
func (_q *TodoQuery) Only(ctx context.Context) (*Todo, error) {
|
||||
// Only returns a single GeneralQueue entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one GeneralQueue entity is found.
|
||||
// Returns a *NotFoundError when no GeneralQueue entities are found.
|
||||
func (_q *GeneralQueueQuery) Only(ctx context.Context) (*GeneralQueue, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -140,14 +115,14 @@ func (_q *TodoQuery) Only(ctx context.Context) (*Todo, error) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{todo.Label}
|
||||
return nil, &NotFoundError{generalqueue.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{todo.Label}
|
||||
return nil, &NotSingularError{generalqueue.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *TodoQuery) OnlyX(ctx context.Context) *Todo {
|
||||
func (_q *GeneralQueueQuery) OnlyX(ctx context.Context) *GeneralQueue {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -155,10 +130,10 @@ func (_q *TodoQuery) OnlyX(ctx context.Context) *Todo {
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Todo ID in the query.
|
||||
// Returns a *NotSingularError when more than one Todo ID is found.
|
||||
// OnlyID is like Only, but returns the only GeneralQueue ID in the query.
|
||||
// Returns a *NotSingularError when more than one GeneralQueue ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *TodoQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
func (_q *GeneralQueueQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
@@ -167,15 +142,15 @@ func (_q *TodoQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{todo.Label}
|
||||
err = &NotFoundError{generalqueue.Label}
|
||||
default:
|
||||
err = &NotSingularError{todo.Label}
|
||||
err = &NotSingularError{generalqueue.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *TodoQuery) OnlyIDX(ctx context.Context) int {
|
||||
func (_q *GeneralQueueQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -183,18 +158,18 @@ func (_q *TodoQuery) OnlyIDX(ctx context.Context) int {
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Todos.
|
||||
func (_q *TodoQuery) All(ctx context.Context) ([]*Todo, error) {
|
||||
// All executes the query and returns a list of GeneralQueues.
|
||||
func (_q *GeneralQueueQuery) All(ctx context.Context) ([]*GeneralQueue, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Todo, *TodoQuery]()
|
||||
return withInterceptors[[]*Todo](ctx, _q, qr, _q.inters)
|
||||
qr := querierAll[[]*GeneralQueue, *GeneralQueueQuery]()
|
||||
return withInterceptors[[]*GeneralQueue](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *TodoQuery) AllX(ctx context.Context) []*Todo {
|
||||
func (_q *GeneralQueueQuery) AllX(ctx context.Context) []*GeneralQueue {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -202,20 +177,20 @@ func (_q *TodoQuery) AllX(ctx context.Context) []*Todo {
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Todo IDs.
|
||||
func (_q *TodoQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
// IDs executes the query and returns a list of GeneralQueue IDs.
|
||||
func (_q *GeneralQueueQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(todo.FieldID).Scan(ctx, &ids); err != nil {
|
||||
if err = _q.Select(generalqueue.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *TodoQuery) IDsX(ctx context.Context) []int {
|
||||
func (_q *GeneralQueueQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -224,16 +199,16 @@ func (_q *TodoQuery) IDsX(ctx context.Context) []int {
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *TodoQuery) Count(ctx context.Context) (int, error) {
|
||||
func (_q *GeneralQueueQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*TodoQuery](), _q.inters)
|
||||
return withInterceptors[int](ctx, _q, querierCount[*GeneralQueueQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *TodoQuery) CountX(ctx context.Context) int {
|
||||
func (_q *GeneralQueueQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -242,7 +217,7 @@ func (_q *TodoQuery) CountX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *TodoQuery) Exist(ctx context.Context) (bool, error) {
|
||||
func (_q *GeneralQueueQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
@@ -255,7 +230,7 @@ func (_q *TodoQuery) Exist(ctx context.Context) (bool, error) {
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *TodoQuery) ExistX(ctx context.Context) bool {
|
||||
func (_q *GeneralQueueQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -263,55 +238,43 @@ func (_q *TodoQuery) ExistX(ctx context.Context) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the TodoQuery builder, including all associated steps. It can be
|
||||
// Clone returns a duplicate of the GeneralQueueQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *TodoQuery) Clone() *TodoQuery {
|
||||
func (_q *GeneralQueueQuery) Clone() *GeneralQueueQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &TodoQuery{
|
||||
return &GeneralQueueQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]todo.OrderOption{}, _q.order...),
|
||||
order: append([]generalqueue.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Todo{}, _q.predicates...),
|
||||
withGroup: _q.withGroup.Clone(),
|
||||
predicates: append([]predicate.GeneralQueue{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithGroup tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *TodoQuery) WithGroup(opts ...func(*GroupQuery)) *TodoQuery {
|
||||
query := (&GroupClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withGroup = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Todo.Query().
|
||||
// GroupBy(todo.FieldCreatedAt).
|
||||
// client.GeneralQueue.Query().
|
||||
// GroupBy(generalqueue.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *TodoQuery) GroupBy(field string, fields ...string) *TodoGroupBy {
|
||||
func (_q *GeneralQueueQuery) GroupBy(field string, fields ...string) *GeneralQueueGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &TodoGroupBy{build: _q}
|
||||
grbuild := &GeneralQueueGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = todo.Label
|
||||
grbuild.label = generalqueue.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
@@ -322,26 +285,26 @@ func (_q *TodoQuery) GroupBy(field string, fields ...string) *TodoGroupBy {
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Todo.Query().
|
||||
// Select(todo.FieldCreatedAt).
|
||||
// client.GeneralQueue.Query().
|
||||
// Select(generalqueue.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *TodoQuery) Select(fields ...string) *TodoSelect {
|
||||
func (_q *GeneralQueueQuery) Select(fields ...string) *GeneralQueueSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &TodoSelect{TodoQuery: _q}
|
||||
sbuild.label = todo.Label
|
||||
sbuild := &GeneralQueueSelect{GeneralQueueQuery: _q}
|
||||
sbuild.label = generalqueue.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a TodoSelect configured with the given aggregations.
|
||||
func (_q *TodoQuery) Aggregate(fns ...AggregateFunc) *TodoSelect {
|
||||
// Aggregate returns a GeneralQueueSelect configured with the given aggregations.
|
||||
func (_q *GeneralQueueQuery) Aggregate(fns ...AggregateFunc) *GeneralQueueSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *TodoQuery) prepareQuery(ctx context.Context) error {
|
||||
func (_q *GeneralQueueQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
@@ -353,7 +316,7 @@ func (_q *TodoQuery) prepareQuery(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !todo.ValidColumn(f) {
|
||||
if !generalqueue.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
@@ -367,28 +330,17 @@ func (_q *TodoQuery) prepareQuery(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *TodoQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Todo, error) {
|
||||
func (_q *GeneralQueueQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*GeneralQueue, error) {
|
||||
var (
|
||||
nodes = []*Todo{}
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withGroup != nil,
|
||||
}
|
||||
nodes = []*GeneralQueue{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
if _q.withGroup != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, todo.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Todo).scanValues(nil, columns)
|
||||
return (*GeneralQueue).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Todo{config: _q.config}
|
||||
node := &GeneralQueue{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
@@ -400,49 +352,10 @@ func (_q *TodoQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Todo, e
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withGroup; query != nil {
|
||||
if err := _q.loadGroup(ctx, query, nodes, nil,
|
||||
func(n *Todo, e *Group) { n.Edges.Group = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *TodoQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*Todo, init func(*Todo), assign func(*Todo, *Group)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Todo)
|
||||
for i := range nodes {
|
||||
if nodes[i].todo_group == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].todo_group
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(group.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "todo_group" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *TodoQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
func (_q *GeneralQueueQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
@@ -451,8 +364,8 @@ func (_q *TodoQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *TodoQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt))
|
||||
func (_q *GeneralQueueQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(generalqueue.Table, generalqueue.Columns, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
@@ -461,9 +374,9 @@ func (_q *TodoQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, todo.FieldID)
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, generalqueue.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != todo.FieldID {
|
||||
if fields[i] != generalqueue.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
@@ -491,12 +404,12 @@ func (_q *TodoQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *TodoQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
func (_q *GeneralQueueQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(todo.Table)
|
||||
t1 := builder.Table(generalqueue.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = todo.Columns
|
||||
columns = generalqueue.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
@@ -523,28 +436,28 @@ func (_q *TodoQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
return selector
|
||||
}
|
||||
|
||||
// TodoGroupBy is the group-by builder for Todo entities.
|
||||
type TodoGroupBy struct {
|
||||
// GeneralQueueGroupBy is the group-by builder for GeneralQueue entities.
|
||||
type GeneralQueueGroupBy struct {
|
||||
selector
|
||||
build *TodoQuery
|
||||
build *GeneralQueueQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *TodoGroupBy) Aggregate(fns ...AggregateFunc) *TodoGroupBy {
|
||||
func (_g *GeneralQueueGroupBy) Aggregate(fns ...AggregateFunc) *GeneralQueueGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *TodoGroupBy) Scan(ctx context.Context, v any) error {
|
||||
func (_g *GeneralQueueGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*TodoQuery, *TodoGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
return scanWithInterceptors[*GeneralQueueQuery, *GeneralQueueGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *TodoGroupBy) sqlScan(ctx context.Context, root *TodoQuery, v any) error {
|
||||
func (_g *GeneralQueueGroupBy) sqlScan(ctx context.Context, root *GeneralQueueQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
@@ -571,28 +484,28 @@ func (_g *TodoGroupBy) sqlScan(ctx context.Context, root *TodoQuery, v any) erro
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// TodoSelect is the builder for selecting fields of Todo entities.
|
||||
type TodoSelect struct {
|
||||
*TodoQuery
|
||||
// GeneralQueueSelect is the builder for selecting fields of GeneralQueue entities.
|
||||
type GeneralQueueSelect struct {
|
||||
*GeneralQueueQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *TodoSelect) Aggregate(fns ...AggregateFunc) *TodoSelect {
|
||||
func (_s *GeneralQueueSelect) Aggregate(fns ...AggregateFunc) *GeneralQueueSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *TodoSelect) Scan(ctx context.Context, v any) error {
|
||||
func (_s *GeneralQueueSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*TodoQuery, *TodoSelect](ctx, _s.TodoQuery, _s, _s.inters, v)
|
||||
return scanWithInterceptors[*GeneralQueueQuery, *GeneralQueueSelect](ctx, _s.GeneralQueueQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *TodoSelect) sqlScan(ctx context.Context, root *TodoQuery, v any) error {
|
||||
func (_s *GeneralQueueSelect) sqlScan(ctx context.Context, root *GeneralQueueQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
@@ -0,0 +1,640 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueue"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/predicate"
|
||||
)
|
||||
|
||||
// GeneralQueueUpdate is the builder for updating GeneralQueue entities.
|
||||
type GeneralQueueUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GeneralQueueMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GeneralQueueUpdate builder.
|
||||
func (_u *GeneralQueueUpdate) Where(ps ...predicate.GeneralQueue) *GeneralQueueUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *GeneralQueueUpdate) SetName(v string) *GeneralQueueUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdate) SetNillableName(v *string) *GeneralQueueUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPayload sets the "payload" field.
|
||||
func (_u *GeneralQueueUpdate) SetPayload(v map[string]interface{}) *GeneralQueueUpdate {
|
||||
_u.mutation.SetPayload(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *GeneralQueueUpdate) SetStatus(v generalqueue.Status) *GeneralQueueUpdate {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdate) SetNillableStatus(v *generalqueue.Status) *GeneralQueueUpdate {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNumberOfTries sets the "number_of_tries" field.
|
||||
func (_u *GeneralQueueUpdate) SetNumberOfTries(v int) *GeneralQueueUpdate {
|
||||
_u.mutation.ResetNumberOfTries()
|
||||
_u.mutation.SetNumberOfTries(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNumberOfTries sets the "number_of_tries" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdate) SetNillableNumberOfTries(v *int) *GeneralQueueUpdate {
|
||||
if v != nil {
|
||||
_u.SetNumberOfTries(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddNumberOfTries adds value to the "number_of_tries" field.
|
||||
func (_u *GeneralQueueUpdate) AddNumberOfTries(v int) *GeneralQueueUpdate {
|
||||
_u.mutation.AddNumberOfTries(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetMaxRetries sets the "max_retries" field.
|
||||
func (_u *GeneralQueueUpdate) SetMaxRetries(v int) *GeneralQueueUpdate {
|
||||
_u.mutation.ResetMaxRetries()
|
||||
_u.mutation.SetMaxRetries(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableMaxRetries sets the "max_retries" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdate) SetNillableMaxRetries(v *int) *GeneralQueueUpdate {
|
||||
if v != nil {
|
||||
_u.SetMaxRetries(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddMaxRetries adds value to the "max_retries" field.
|
||||
func (_u *GeneralQueueUpdate) AddMaxRetries(v int) *GeneralQueueUpdate {
|
||||
_u.mutation.AddMaxRetries(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetErrorMessage sets the "error_message" field.
|
||||
func (_u *GeneralQueueUpdate) SetErrorMessage(v string) *GeneralQueueUpdate {
|
||||
_u.mutation.SetErrorMessage(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdate) SetNillableErrorMessage(v *string) *GeneralQueueUpdate {
|
||||
if v != nil {
|
||||
_u.SetErrorMessage(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearErrorMessage clears the value of the "error_message" field.
|
||||
func (_u *GeneralQueueUpdate) ClearErrorMessage() *GeneralQueueUpdate {
|
||||
_u.mutation.ClearErrorMessage()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetFailurePayload sets the "failure_payload" field.
|
||||
func (_u *GeneralQueueUpdate) SetFailurePayload(v map[string]interface{}) *GeneralQueueUpdate {
|
||||
_u.mutation.SetFailurePayload(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearFailurePayload clears the value of the "failure_payload" field.
|
||||
func (_u *GeneralQueueUpdate) ClearFailurePayload() *GeneralQueueUpdate {
|
||||
_u.mutation.ClearFailurePayload()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetResultPayload sets the "result_payload" field.
|
||||
func (_u *GeneralQueueUpdate) SetResultPayload(v map[string]interface{}) *GeneralQueueUpdate {
|
||||
_u.mutation.SetResultPayload(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearResultPayload clears the value of the "result_payload" field.
|
||||
func (_u *GeneralQueueUpdate) ClearResultPayload() *GeneralQueueUpdate {
|
||||
_u.mutation.ClearResultPayload()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_u *GeneralQueueUpdate) SetCreatedAt(v time.Time) *GeneralQueueUpdate {
|
||||
_u.mutation.SetCreatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdate) SetNillableCreatedAt(v *time.Time) *GeneralQueueUpdate {
|
||||
if v != nil {
|
||||
_u.SetCreatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *GeneralQueueUpdate) SetUpdatedAt(v time.Time) *GeneralQueueUpdate {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdate) SetNillableUpdatedAt(v *time.Time) *GeneralQueueUpdate {
|
||||
if v != nil {
|
||||
_u.SetUpdatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProcessedAt sets the "processed_at" field.
|
||||
func (_u *GeneralQueueUpdate) SetProcessedAt(v time.Time) *GeneralQueueUpdate {
|
||||
_u.mutation.SetProcessedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProcessedAt sets the "processed_at" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdate) SetNillableProcessedAt(v *time.Time) *GeneralQueueUpdate {
|
||||
if v != nil {
|
||||
_u.SetProcessedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearProcessedAt clears the value of the "processed_at" field.
|
||||
func (_u *GeneralQueueUpdate) ClearProcessedAt() *GeneralQueueUpdate {
|
||||
_u.mutation.ClearProcessedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the GeneralQueueMutation object of the builder.
|
||||
func (_u *GeneralQueueUpdate) Mutation() *GeneralQueueMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *GeneralQueueUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *GeneralQueueUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *GeneralQueueUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GeneralQueueUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *GeneralQueueUpdate) check() error {
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := generalqueue.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "GeneralQueue.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *GeneralQueueUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(generalqueue.Table, generalqueue.Columns, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(generalqueue.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Payload(); ok {
|
||||
_spec.SetField(generalqueue.FieldPayload, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(generalqueue.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.NumberOfTries(); ok {
|
||||
_spec.SetField(generalqueue.FieldNumberOfTries, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedNumberOfTries(); ok {
|
||||
_spec.AddField(generalqueue.FieldNumberOfTries, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.MaxRetries(); ok {
|
||||
_spec.SetField(generalqueue.FieldMaxRetries, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedMaxRetries(); ok {
|
||||
_spec.AddField(generalqueue.FieldMaxRetries, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ErrorMessage(); ok {
|
||||
_spec.SetField(generalqueue.FieldErrorMessage, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ErrorMessageCleared() {
|
||||
_spec.ClearField(generalqueue.FieldErrorMessage, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.FailurePayload(); ok {
|
||||
_spec.SetField(generalqueue.FieldFailurePayload, field.TypeJSON, value)
|
||||
}
|
||||
if _u.mutation.FailurePayloadCleared() {
|
||||
_spec.ClearField(generalqueue.FieldFailurePayload, field.TypeJSON)
|
||||
}
|
||||
if value, ok := _u.mutation.ResultPayload(); ok {
|
||||
_spec.SetField(generalqueue.FieldResultPayload, field.TypeJSON, value)
|
||||
}
|
||||
if _u.mutation.ResultPayloadCleared() {
|
||||
_spec.ClearField(generalqueue.FieldResultPayload, field.TypeJSON)
|
||||
}
|
||||
if value, ok := _u.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(generalqueue.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(generalqueue.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ProcessedAt(); ok {
|
||||
_spec.SetField(generalqueue.FieldProcessedAt, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.ProcessedAtCleared() {
|
||||
_spec.ClearField(generalqueue.FieldProcessedAt, field.TypeTime)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{generalqueue.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// GeneralQueueUpdateOne is the builder for updating a single GeneralQueue entity.
|
||||
type GeneralQueueUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *GeneralQueueMutation
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetName(v string) *GeneralQueueUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdateOne) SetNillableName(v *string) *GeneralQueueUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPayload sets the "payload" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetPayload(v map[string]interface{}) *GeneralQueueUpdateOne {
|
||||
_u.mutation.SetPayload(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetStatus(v generalqueue.Status) *GeneralQueueUpdateOne {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdateOne) SetNillableStatus(v *generalqueue.Status) *GeneralQueueUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNumberOfTries sets the "number_of_tries" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetNumberOfTries(v int) *GeneralQueueUpdateOne {
|
||||
_u.mutation.ResetNumberOfTries()
|
||||
_u.mutation.SetNumberOfTries(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNumberOfTries sets the "number_of_tries" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdateOne) SetNillableNumberOfTries(v *int) *GeneralQueueUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetNumberOfTries(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddNumberOfTries adds value to the "number_of_tries" field.
|
||||
func (_u *GeneralQueueUpdateOne) AddNumberOfTries(v int) *GeneralQueueUpdateOne {
|
||||
_u.mutation.AddNumberOfTries(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetMaxRetries sets the "max_retries" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetMaxRetries(v int) *GeneralQueueUpdateOne {
|
||||
_u.mutation.ResetMaxRetries()
|
||||
_u.mutation.SetMaxRetries(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableMaxRetries sets the "max_retries" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdateOne) SetNillableMaxRetries(v *int) *GeneralQueueUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetMaxRetries(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddMaxRetries adds value to the "max_retries" field.
|
||||
func (_u *GeneralQueueUpdateOne) AddMaxRetries(v int) *GeneralQueueUpdateOne {
|
||||
_u.mutation.AddMaxRetries(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetErrorMessage sets the "error_message" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetErrorMessage(v string) *GeneralQueueUpdateOne {
|
||||
_u.mutation.SetErrorMessage(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdateOne) SetNillableErrorMessage(v *string) *GeneralQueueUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetErrorMessage(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearErrorMessage clears the value of the "error_message" field.
|
||||
func (_u *GeneralQueueUpdateOne) ClearErrorMessage() *GeneralQueueUpdateOne {
|
||||
_u.mutation.ClearErrorMessage()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetFailurePayload sets the "failure_payload" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetFailurePayload(v map[string]interface{}) *GeneralQueueUpdateOne {
|
||||
_u.mutation.SetFailurePayload(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearFailurePayload clears the value of the "failure_payload" field.
|
||||
func (_u *GeneralQueueUpdateOne) ClearFailurePayload() *GeneralQueueUpdateOne {
|
||||
_u.mutation.ClearFailurePayload()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetResultPayload sets the "result_payload" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetResultPayload(v map[string]interface{}) *GeneralQueueUpdateOne {
|
||||
_u.mutation.SetResultPayload(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearResultPayload clears the value of the "result_payload" field.
|
||||
func (_u *GeneralQueueUpdateOne) ClearResultPayload() *GeneralQueueUpdateOne {
|
||||
_u.mutation.ClearResultPayload()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetCreatedAt(v time.Time) *GeneralQueueUpdateOne {
|
||||
_u.mutation.SetCreatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdateOne) SetNillableCreatedAt(v *time.Time) *GeneralQueueUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCreatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetUpdatedAt(v time.Time) *GeneralQueueUpdateOne {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdateOne) SetNillableUpdatedAt(v *time.Time) *GeneralQueueUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUpdatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProcessedAt sets the "processed_at" field.
|
||||
func (_u *GeneralQueueUpdateOne) SetProcessedAt(v time.Time) *GeneralQueueUpdateOne {
|
||||
_u.mutation.SetProcessedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProcessedAt sets the "processed_at" field if the given value is not nil.
|
||||
func (_u *GeneralQueueUpdateOne) SetNillableProcessedAt(v *time.Time) *GeneralQueueUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetProcessedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearProcessedAt clears the value of the "processed_at" field.
|
||||
func (_u *GeneralQueueUpdateOne) ClearProcessedAt() *GeneralQueueUpdateOne {
|
||||
_u.mutation.ClearProcessedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the GeneralQueueMutation object of the builder.
|
||||
func (_u *GeneralQueueUpdateOne) Mutation() *GeneralQueueMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GeneralQueueUpdate builder.
|
||||
func (_u *GeneralQueueUpdateOne) Where(ps ...predicate.GeneralQueue) *GeneralQueueUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *GeneralQueueUpdateOne) Select(field string, fields ...string) *GeneralQueueUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated GeneralQueue entity.
|
||||
func (_u *GeneralQueueUpdateOne) Save(ctx context.Context) (*GeneralQueue, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *GeneralQueueUpdateOne) SaveX(ctx context.Context) *GeneralQueue {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *GeneralQueueUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GeneralQueueUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *GeneralQueueUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := generalqueue.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "GeneralQueue.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *GeneralQueueUpdateOne) sqlSave(ctx context.Context) (_node *GeneralQueue, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(generalqueue.Table, generalqueue.Columns, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "GeneralQueue.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, generalqueue.FieldID)
|
||||
for _, f := range fields {
|
||||
if !generalqueue.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != generalqueue.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(generalqueue.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Payload(); ok {
|
||||
_spec.SetField(generalqueue.FieldPayload, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(generalqueue.FieldStatus, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := _u.mutation.NumberOfTries(); ok {
|
||||
_spec.SetField(generalqueue.FieldNumberOfTries, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedNumberOfTries(); ok {
|
||||
_spec.AddField(generalqueue.FieldNumberOfTries, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.MaxRetries(); ok {
|
||||
_spec.SetField(generalqueue.FieldMaxRetries, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedMaxRetries(); ok {
|
||||
_spec.AddField(generalqueue.FieldMaxRetries, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ErrorMessage(); ok {
|
||||
_spec.SetField(generalqueue.FieldErrorMessage, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ErrorMessageCleared() {
|
||||
_spec.ClearField(generalqueue.FieldErrorMessage, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.FailurePayload(); ok {
|
||||
_spec.SetField(generalqueue.FieldFailurePayload, field.TypeJSON, value)
|
||||
}
|
||||
if _u.mutation.FailurePayloadCleared() {
|
||||
_spec.ClearField(generalqueue.FieldFailurePayload, field.TypeJSON)
|
||||
}
|
||||
if value, ok := _u.mutation.ResultPayload(); ok {
|
||||
_spec.SetField(generalqueue.FieldResultPayload, field.TypeJSON, value)
|
||||
}
|
||||
if _u.mutation.ResultPayloadCleared() {
|
||||
_spec.ClearField(generalqueue.FieldResultPayload, field.TypeJSON)
|
||||
}
|
||||
if value, ok := _u.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(generalqueue.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(generalqueue.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ProcessedAt(); ok {
|
||||
_spec.SetField(generalqueue.FieldProcessedAt, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.ProcessedAtCleared() {
|
||||
_spec.ClearField(generalqueue.FieldProcessedAt, field.TypeTime)
|
||||
}
|
||||
_node = &GeneralQueue{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{generalqueue.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueuestate"
|
||||
)
|
||||
|
||||
// GeneralQueueState is the model entity for the GeneralQueueState schema.
|
||||
type GeneralQueueState struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name of the queue (e.g., 'email', 'notifications')
|
||||
Name string `json:"name,omitempty"`
|
||||
// Whether the queue is currently running
|
||||
Running bool `json:"running,omitempty"`
|
||||
// Last time the state was updated
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*GeneralQueueState) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case generalqueuestate.FieldRunning:
|
||||
values[i] = new(sql.NullBool)
|
||||
case generalqueuestate.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case generalqueuestate.FieldName:
|
||||
values[i] = new(sql.NullString)
|
||||
case generalqueuestate.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the GeneralQueueState fields.
|
||||
func (_m *GeneralQueueState) assignValues(columns []string, values []any) 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 generalqueuestate.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case generalqueuestate.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Name = value.String
|
||||
}
|
||||
case generalqueuestate.FieldRunning:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field running", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Running = value.Bool
|
||||
}
|
||||
case generalqueuestate.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UpdatedAt = value.Time
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the GeneralQueueState.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *GeneralQueueState) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this GeneralQueueState.
|
||||
// Note that you need to call GeneralQueueState.Unwrap() before calling this method if this GeneralQueueState
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *GeneralQueueState) Update() *GeneralQueueStateUpdateOne {
|
||||
return NewGeneralQueueStateClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the GeneralQueueState 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 (_m *GeneralQueueState) Unwrap() *GeneralQueueState {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: GeneralQueueState is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *GeneralQueueState) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("GeneralQueueState(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("running=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Running))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// GeneralQueueStates is a parsable slice of GeneralQueueState.
|
||||
type GeneralQueueStates []*GeneralQueueState
|
||||
@@ -0,0 +1,68 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package generalqueuestate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the generalqueuestate type in the database.
|
||||
Label = "general_queue_state"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldRunning holds the string denoting the running field in the database.
|
||||
FieldRunning = "running"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// Table holds the table name of the generalqueuestate in the database.
|
||||
Table = "generalQueueState"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for generalqueuestate fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
FieldRunning,
|
||||
FieldUpdatedAt,
|
||||
}
|
||||
|
||||
// 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 (
|
||||
// DefaultRunning holds the default value on creation for the "running" field.
|
||||
DefaultRunning bool
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the GeneralQueueState queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByRunning orders the results by the running field.
|
||||
func ByRunning(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldRunning, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package generalqueuestate
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// Running applies equality check predicate on the "running" field. It's identical to RunningEQ.
|
||||
func Running(v bool) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldEQ(FieldRunning, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// RunningEQ applies the EQ predicate on the "running" field.
|
||||
func RunningEQ(v bool) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldEQ(FieldRunning, v))
|
||||
}
|
||||
|
||||
// RunningNEQ applies the NEQ predicate on the "running" field.
|
||||
func RunningNEQ(v bool) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldNEQ(FieldRunning, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.GeneralQueueState) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.GeneralQueueState) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.GeneralQueueState) predicate.GeneralQueueState {
|
||||
return predicate.GeneralQueueState(sql.NotPredicates(p))
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueuestate"
|
||||
)
|
||||
|
||||
// GeneralQueueStateCreate is the builder for creating a GeneralQueueState entity.
|
||||
type GeneralQueueStateCreate struct {
|
||||
config
|
||||
mutation *GeneralQueueStateMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *GeneralQueueStateCreate) SetName(v string) *GeneralQueueStateCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetRunning sets the "running" field.
|
||||
func (_c *GeneralQueueStateCreate) SetRunning(v bool) *GeneralQueueStateCreate {
|
||||
_c.mutation.SetRunning(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableRunning sets the "running" field if the given value is not nil.
|
||||
func (_c *GeneralQueueStateCreate) SetNillableRunning(v *bool) *GeneralQueueStateCreate {
|
||||
if v != nil {
|
||||
_c.SetRunning(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_c *GeneralQueueStateCreate) SetUpdatedAt(v time.Time) *GeneralQueueStateCreate {
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the GeneralQueueStateMutation object of the builder.
|
||||
func (_c *GeneralQueueStateCreate) Mutation() *GeneralQueueStateMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the GeneralQueueState in the database.
|
||||
func (_c *GeneralQueueStateCreate) Save(ctx context.Context) (*GeneralQueueState, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *GeneralQueueStateCreate) SaveX(ctx context.Context) *GeneralQueueState {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *GeneralQueueStateCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *GeneralQueueStateCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *GeneralQueueStateCreate) defaults() {
|
||||
if _, ok := _c.mutation.Running(); !ok {
|
||||
v := generalqueuestate.DefaultRunning
|
||||
_c.mutation.SetRunning(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *GeneralQueueStateCreate) check() error {
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "GeneralQueueState.name"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Running(); !ok {
|
||||
return &ValidationError{Name: "running", err: errors.New(`ent: missing required field "GeneralQueueState.running"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "GeneralQueueState.updated_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *GeneralQueueStateCreate) sqlSave(ctx context.Context) (*GeneralQueueState, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *GeneralQueueStateCreate) createSpec() (*GeneralQueueState, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &GeneralQueueState{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(generalqueuestate.Table, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(generalqueuestate.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.Running(); ok {
|
||||
_spec.SetField(generalqueuestate.FieldRunning, field.TypeBool, value)
|
||||
_node.Running = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(generalqueuestate.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// GeneralQueueStateCreateBulk is the builder for creating many GeneralQueueState entities in bulk.
|
||||
type GeneralQueueStateCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*GeneralQueueStateCreate
|
||||
}
|
||||
|
||||
// Save creates the GeneralQueueState entities in the database.
|
||||
func (_c *GeneralQueueStateCreateBulk) Save(ctx context.Context) ([]*GeneralQueueState, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*GeneralQueueState, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*GeneralQueueStateMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
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, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *GeneralQueueStateCreateBulk) SaveX(ctx context.Context) []*GeneralQueueState {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *GeneralQueueStateCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *GeneralQueueStateCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueuestate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/predicate"
|
||||
)
|
||||
|
||||
// GeneralQueueStateDelete is the builder for deleting a GeneralQueueState entity.
|
||||
type GeneralQueueStateDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GeneralQueueStateMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GeneralQueueStateDelete builder.
|
||||
func (_d *GeneralQueueStateDelete) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *GeneralQueueStateDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *GeneralQueueStateDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *GeneralQueueStateDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(generalqueuestate.Table, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt))
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// GeneralQueueStateDeleteOne is the builder for deleting a single GeneralQueueState entity.
|
||||
type GeneralQueueStateDeleteOne struct {
|
||||
_d *GeneralQueueStateDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GeneralQueueStateDelete builder.
|
||||
func (_d *GeneralQueueStateDeleteOne) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *GeneralQueueStateDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{generalqueuestate.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *GeneralQueueStateDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -4,100 +4,75 @@ package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/group"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent/user"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueuestate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/predicate"
|
||||
)
|
||||
|
||||
// UserQuery is the builder for querying User entities.
|
||||
type UserQuery struct {
|
||||
// GeneralQueueStateQuery is the builder for querying GeneralQueueState entities.
|
||||
type GeneralQueueStateQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []user.OrderOption
|
||||
order []generalqueuestate.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.User
|
||||
withGroup *GroupQuery
|
||||
predicates []predicate.GeneralQueueState
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the UserQuery builder.
|
||||
func (_q *UserQuery) Where(ps ...predicate.User) *UserQuery {
|
||||
// Where adds a new predicate for the GeneralQueueStateQuery builder.
|
||||
func (_q *GeneralQueueStateQuery) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *UserQuery) Limit(limit int) *UserQuery {
|
||||
func (_q *GeneralQueueStateQuery) Limit(limit int) *GeneralQueueStateQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *UserQuery) Offset(offset int) *UserQuery {
|
||||
func (_q *GeneralQueueStateQuery) Offset(offset int) *GeneralQueueStateQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// 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 (_q *UserQuery) Unique(unique bool) *UserQuery {
|
||||
func (_q *GeneralQueueStateQuery) Unique(unique bool) *GeneralQueueStateQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *UserQuery) Order(o ...user.OrderOption) *UserQuery {
|
||||
func (_q *GeneralQueueStateQuery) Order(o ...generalqueuestate.OrderOption) *GeneralQueueStateQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryGroup chains the current query on the "group" edge.
|
||||
func (_q *UserQuery) QueryGroup() *GroupQuery {
|
||||
query := (&GroupClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(group.Table, group.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, user.GroupTable, user.GroupPrimaryKey...),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first User entity from the query.
|
||||
// Returns a *NotFoundError when no User was found.
|
||||
func (_q *UserQuery) First(ctx context.Context) (*User, error) {
|
||||
// First returns the first GeneralQueueState entity from the query.
|
||||
// Returns a *NotFoundError when no GeneralQueueState was found.
|
||||
func (_q *GeneralQueueStateQuery) First(ctx context.Context) (*GeneralQueueState, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{user.Label}
|
||||
return nil, &NotFoundError{generalqueuestate.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *UserQuery) FirstX(ctx context.Context) *User {
|
||||
func (_q *GeneralQueueStateQuery) FirstX(ctx context.Context) *GeneralQueueState {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
@@ -105,22 +80,22 @@ func (_q *UserQuery) FirstX(ctx context.Context) *User {
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first User ID from the query.
|
||||
// Returns a *NotFoundError when no User ID was found.
|
||||
func (_q *UserQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
// FirstID returns the first GeneralQueueState ID from the query.
|
||||
// Returns a *NotFoundError when no GeneralQueueState ID was found.
|
||||
func (_q *GeneralQueueStateQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{user.Label}
|
||||
err = &NotFoundError{generalqueuestate.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *UserQuery) FirstIDX(ctx context.Context) int {
|
||||
func (_q *GeneralQueueStateQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
@@ -128,10 +103,10 @@ func (_q *UserQuery) FirstIDX(ctx context.Context) int {
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single User entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one User entity is found.
|
||||
// Returns a *NotFoundError when no User entities are found.
|
||||
func (_q *UserQuery) Only(ctx context.Context) (*User, error) {
|
||||
// Only returns a single GeneralQueueState entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one GeneralQueueState entity is found.
|
||||
// Returns a *NotFoundError when no GeneralQueueState entities are found.
|
||||
func (_q *GeneralQueueStateQuery) Only(ctx context.Context) (*GeneralQueueState, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -140,14 +115,14 @@ func (_q *UserQuery) Only(ctx context.Context) (*User, error) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{user.Label}
|
||||
return nil, &NotFoundError{generalqueuestate.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{user.Label}
|
||||
return nil, &NotSingularError{generalqueuestate.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *UserQuery) OnlyX(ctx context.Context) *User {
|
||||
func (_q *GeneralQueueStateQuery) OnlyX(ctx context.Context) *GeneralQueueState {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -155,10 +130,10 @@ func (_q *UserQuery) OnlyX(ctx context.Context) *User {
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only User ID in the query.
|
||||
// Returns a *NotSingularError when more than one User ID is found.
|
||||
// OnlyID is like Only, but returns the only GeneralQueueState ID in the query.
|
||||
// Returns a *NotSingularError when more than one GeneralQueueState ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *UserQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
func (_q *GeneralQueueStateQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
@@ -167,15 +142,15 @@ func (_q *UserQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
err = &NotFoundError{generalqueuestate.Label}
|
||||
default:
|
||||
err = &NotSingularError{user.Label}
|
||||
err = &NotSingularError{generalqueuestate.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *UserQuery) OnlyIDX(ctx context.Context) int {
|
||||
func (_q *GeneralQueueStateQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -183,18 +158,18 @@ func (_q *UserQuery) OnlyIDX(ctx context.Context) int {
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Users.
|
||||
func (_q *UserQuery) All(ctx context.Context) ([]*User, error) {
|
||||
// All executes the query and returns a list of GeneralQueueStates.
|
||||
func (_q *GeneralQueueStateQuery) All(ctx context.Context) ([]*GeneralQueueState, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*User, *UserQuery]()
|
||||
return withInterceptors[[]*User](ctx, _q, qr, _q.inters)
|
||||
qr := querierAll[[]*GeneralQueueState, *GeneralQueueStateQuery]()
|
||||
return withInterceptors[[]*GeneralQueueState](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *UserQuery) AllX(ctx context.Context) []*User {
|
||||
func (_q *GeneralQueueStateQuery) AllX(ctx context.Context) []*GeneralQueueState {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -202,20 +177,20 @@ func (_q *UserQuery) AllX(ctx context.Context) []*User {
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of User IDs.
|
||||
func (_q *UserQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
// IDs executes the query and returns a list of GeneralQueueState IDs.
|
||||
func (_q *GeneralQueueStateQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(user.FieldID).Scan(ctx, &ids); err != nil {
|
||||
if err = _q.Select(generalqueuestate.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *UserQuery) IDsX(ctx context.Context) []int {
|
||||
func (_q *GeneralQueueStateQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -224,16 +199,16 @@ func (_q *UserQuery) IDsX(ctx context.Context) []int {
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *UserQuery) Count(ctx context.Context) (int, error) {
|
||||
func (_q *GeneralQueueStateQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*UserQuery](), _q.inters)
|
||||
return withInterceptors[int](ctx, _q, querierCount[*GeneralQueueStateQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *UserQuery) CountX(ctx context.Context) int {
|
||||
func (_q *GeneralQueueStateQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -242,7 +217,7 @@ func (_q *UserQuery) CountX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *UserQuery) Exist(ctx context.Context) (bool, error) {
|
||||
func (_q *GeneralQueueStateQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
@@ -255,7 +230,7 @@ func (_q *UserQuery) Exist(ctx context.Context) (bool, error) {
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *UserQuery) ExistX(ctx context.Context) bool {
|
||||
func (_q *GeneralQueueStateQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -263,55 +238,43 @@ func (_q *UserQuery) ExistX(ctx context.Context) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the UserQuery builder, including all associated steps. It can be
|
||||
// Clone returns a duplicate of the GeneralQueueStateQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *UserQuery) Clone() *UserQuery {
|
||||
func (_q *GeneralQueueStateQuery) Clone() *GeneralQueueStateQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &UserQuery{
|
||||
return &GeneralQueueStateQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]user.OrderOption{}, _q.order...),
|
||||
order: append([]generalqueuestate.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.User{}, _q.predicates...),
|
||||
withGroup: _q.withGroup.Clone(),
|
||||
predicates: append([]predicate.GeneralQueueState{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithGroup tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *UserQuery) WithGroup(opts ...func(*GroupQuery)) *UserQuery {
|
||||
query := (&GroupClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withGroup = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// GroupBy(user.FieldCreatedAt).
|
||||
// client.GeneralQueueState.Query().
|
||||
// GroupBy(generalqueuestate.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
func (_q *GeneralQueueStateQuery) GroupBy(field string, fields ...string) *GeneralQueueStateGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &UserGroupBy{build: _q}
|
||||
grbuild := &GeneralQueueStateGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = user.Label
|
||||
grbuild.label = generalqueuestate.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
@@ -322,26 +285,26 @@ func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// Select(user.FieldCreatedAt).
|
||||
// client.GeneralQueueState.Query().
|
||||
// Select(generalqueuestate.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *UserQuery) Select(fields ...string) *UserSelect {
|
||||
func (_q *GeneralQueueStateQuery) Select(fields ...string) *GeneralQueueStateSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &UserSelect{UserQuery: _q}
|
||||
sbuild.label = user.Label
|
||||
sbuild := &GeneralQueueStateSelect{GeneralQueueStateQuery: _q}
|
||||
sbuild.label = generalqueuestate.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a UserSelect configured with the given aggregations.
|
||||
func (_q *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
// Aggregate returns a GeneralQueueStateSelect configured with the given aggregations.
|
||||
func (_q *GeneralQueueStateQuery) Aggregate(fns ...AggregateFunc) *GeneralQueueStateSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
func (_q *GeneralQueueStateQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
@@ -353,7 +316,7 @@ func (_q *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !user.ValidColumn(f) {
|
||||
if !generalqueuestate.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
@@ -367,21 +330,17 @@ func (_q *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) {
|
||||
func (_q *GeneralQueueStateQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*GeneralQueueState, error) {
|
||||
var (
|
||||
nodes = []*User{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withGroup != nil,
|
||||
}
|
||||
nodes = []*GeneralQueueState{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*User).scanValues(nil, columns)
|
||||
return (*GeneralQueueState).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &User{config: _q.config}
|
||||
node := &GeneralQueueState{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
@@ -393,79 +352,10 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withGroup; query != nil {
|
||||
if err := _q.loadGroup(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.Group = []*Group{} },
|
||||
func(n *User, e *Group) { n.Edges.Group = append(n.Edges.Group, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *UserQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*User, init func(*User), assign func(*User, *Group)) error {
|
||||
edgeIDs := make([]driver.Value, len(nodes))
|
||||
byID := make(map[int]*User)
|
||||
nids := make(map[int]map[*User]struct{})
|
||||
for i, node := range nodes {
|
||||
edgeIDs[i] = node.ID
|
||||
byID[node.ID] = node
|
||||
if init != nil {
|
||||
init(node)
|
||||
}
|
||||
}
|
||||
query.Where(func(s *sql.Selector) {
|
||||
joinT := sql.Table(user.GroupTable)
|
||||
s.Join(joinT).On(s.C(group.FieldID), joinT.C(user.GroupPrimaryKey[1]))
|
||||
s.Where(sql.InValues(joinT.C(user.GroupPrimaryKey[0]), edgeIDs...))
|
||||
columns := s.SelectedColumns()
|
||||
s.Select(joinT.C(user.GroupPrimaryKey[0]))
|
||||
s.AppendSelect(columns...)
|
||||
s.SetDistinct(false)
|
||||
})
|
||||
if err := query.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append([]any{new(sql.NullInt64)}, values...), nil
|
||||
}
|
||||
spec.Assign = func(columns []string, values []any) error {
|
||||
outValue := int(values[0].(*sql.NullInt64).Int64)
|
||||
inValue := int(values[1].(*sql.NullInt64).Int64)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*User]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
})
|
||||
neighbors, err := withInterceptors[[]*Group](ctx, query, qr, query.inters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected "group" node returned %v`, n.ID)
|
||||
}
|
||||
for kn := range nodes {
|
||||
assign(kn, n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *UserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
func (_q *GeneralQueueStateQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
@@ -474,8 +364,8 @@ func (_q *UserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
func (_q *GeneralQueueStateQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(generalqueuestate.Table, generalqueuestate.Columns, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
@@ -484,9 +374,9 @@ func (_q *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, generalqueuestate.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != user.FieldID {
|
||||
if fields[i] != generalqueuestate.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
@@ -514,12 +404,12 @@ func (_q *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
func (_q *GeneralQueueStateQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(user.Table)
|
||||
t1 := builder.Table(generalqueuestate.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = user.Columns
|
||||
columns = generalqueuestate.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
@@ -546,28 +436,28 @@ func (_q *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
return selector
|
||||
}
|
||||
|
||||
// UserGroupBy is the group-by builder for User entities.
|
||||
type UserGroupBy struct {
|
||||
// GeneralQueueStateGroupBy is the group-by builder for GeneralQueueState entities.
|
||||
type GeneralQueueStateGroupBy struct {
|
||||
selector
|
||||
build *UserQuery
|
||||
build *GeneralQueueStateQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy {
|
||||
func (_g *GeneralQueueStateGroupBy) Aggregate(fns ...AggregateFunc) *GeneralQueueStateGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *UserGroupBy) Scan(ctx context.Context, v any) error {
|
||||
func (_g *GeneralQueueStateGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*UserQuery, *UserGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
return scanWithInterceptors[*GeneralQueueStateQuery, *GeneralQueueStateGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
func (_g *GeneralQueueStateGroupBy) sqlScan(ctx context.Context, root *GeneralQueueStateQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
@@ -594,28 +484,28 @@ func (_g *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) erro
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// UserSelect is the builder for selecting fields of User entities.
|
||||
type UserSelect struct {
|
||||
*UserQuery
|
||||
// GeneralQueueStateSelect is the builder for selecting fields of GeneralQueueState entities.
|
||||
type GeneralQueueStateSelect struct {
|
||||
*GeneralQueueStateQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
func (_s *GeneralQueueStateSelect) Aggregate(fns ...AggregateFunc) *GeneralQueueStateSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *UserSelect) Scan(ctx context.Context, v any) error {
|
||||
func (_s *GeneralQueueStateSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*UserQuery, *UserSelect](ctx, _s.UserQuery, _s, _s.inters, v)
|
||||
return scanWithInterceptors[*GeneralQueueStateQuery, *GeneralQueueStateSelect](ctx, _s.GeneralQueueStateQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *UserSelect) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
func (_s *GeneralQueueStateSelect) sqlScan(ctx context.Context, root *GeneralQueueStateQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
@@ -0,0 +1,244 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueuestate"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/predicate"
|
||||
)
|
||||
|
||||
// GeneralQueueStateUpdate is the builder for updating GeneralQueueState entities.
|
||||
type GeneralQueueStateUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GeneralQueueStateMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GeneralQueueStateUpdate builder.
|
||||
func (_u *GeneralQueueStateUpdate) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetRunning sets the "running" field.
|
||||
func (_u *GeneralQueueStateUpdate) SetRunning(v bool) *GeneralQueueStateUpdate {
|
||||
_u.mutation.SetRunning(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRunning sets the "running" field if the given value is not nil.
|
||||
func (_u *GeneralQueueStateUpdate) SetNillableRunning(v *bool) *GeneralQueueStateUpdate {
|
||||
if v != nil {
|
||||
_u.SetRunning(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *GeneralQueueStateUpdate) SetUpdatedAt(v time.Time) *GeneralQueueStateUpdate {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_u *GeneralQueueStateUpdate) SetNillableUpdatedAt(v *time.Time) *GeneralQueueStateUpdate {
|
||||
if v != nil {
|
||||
_u.SetUpdatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the GeneralQueueStateMutation object of the builder.
|
||||
func (_u *GeneralQueueStateUpdate) Mutation() *GeneralQueueStateMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *GeneralQueueStateUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *GeneralQueueStateUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *GeneralQueueStateUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GeneralQueueStateUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *GeneralQueueStateUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(generalqueuestate.Table, generalqueuestate.Columns, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Running(); ok {
|
||||
_spec.SetField(generalqueuestate.FieldRunning, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(generalqueuestate.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{generalqueuestate.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// GeneralQueueStateUpdateOne is the builder for updating a single GeneralQueueState entity.
|
||||
type GeneralQueueStateUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *GeneralQueueStateMutation
|
||||
}
|
||||
|
||||
// SetRunning sets the "running" field.
|
||||
func (_u *GeneralQueueStateUpdateOne) SetRunning(v bool) *GeneralQueueStateUpdateOne {
|
||||
_u.mutation.SetRunning(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRunning sets the "running" field if the given value is not nil.
|
||||
func (_u *GeneralQueueStateUpdateOne) SetNillableRunning(v *bool) *GeneralQueueStateUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetRunning(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *GeneralQueueStateUpdateOne) SetUpdatedAt(v time.Time) *GeneralQueueStateUpdateOne {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_u *GeneralQueueStateUpdateOne) SetNillableUpdatedAt(v *time.Time) *GeneralQueueStateUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUpdatedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the GeneralQueueStateMutation object of the builder.
|
||||
func (_u *GeneralQueueStateUpdateOne) Mutation() *GeneralQueueStateMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GeneralQueueStateUpdate builder.
|
||||
func (_u *GeneralQueueStateUpdateOne) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *GeneralQueueStateUpdateOne) Select(field string, fields ...string) *GeneralQueueStateUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated GeneralQueueState entity.
|
||||
func (_u *GeneralQueueStateUpdateOne) Save(ctx context.Context) (*GeneralQueueState, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *GeneralQueueStateUpdateOne) SaveX(ctx context.Context) *GeneralQueueState {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *GeneralQueueStateUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GeneralQueueStateUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *GeneralQueueStateUpdateOne) sqlSave(ctx context.Context) (_node *GeneralQueueState, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(generalqueuestate.Table, generalqueuestate.Columns, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "GeneralQueueState.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, generalqueuestate.FieldID)
|
||||
for _, f := range fields {
|
||||
if !generalqueuestate.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != generalqueuestate.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Running(); ok {
|
||||
_spec.SetField(generalqueuestate.FieldRunning, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(generalqueuestate.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
_node = &GeneralQueueState{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{generalqueuestate.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -5,43 +5,32 @@ package hook
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/example/ent"
|
||||
|
||||
"git.gorlug.de/code/ersteller/schema/ent"
|
||||
)
|
||||
|
||||
// The GroupFunc type is an adapter to allow the use of ordinary
|
||||
// function as Group mutator.
|
||||
type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error)
|
||||
// The GeneralQueueFunc type is an adapter to allow the use of ordinary
|
||||
// function as GeneralQueue mutator.
|
||||
type GeneralQueueFunc func(context.Context, *ent.GeneralQueueMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.GroupMutation); ok {
|
||||
func (f GeneralQueueFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.GeneralQueueMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupMutation", m)
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GeneralQueueMutation", m)
|
||||
}
|
||||
|
||||
// The TodoFunc type is an adapter to allow the use of ordinary
|
||||
// function as Todo mutator.
|
||||
type TodoFunc func(context.Context, *ent.TodoMutation) (ent.Value, error)
|
||||
// The GeneralQueueStateFunc type is an adapter to allow the use of ordinary
|
||||
// function as GeneralQueueState mutator.
|
||||
type GeneralQueueStateFunc func(context.Context, *ent.GeneralQueueStateMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f TodoFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.TodoMutation); ok {
|
||||
func (f GeneralQueueStateFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.GeneralQueueStateMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TodoMutation", m)
|
||||
}
|
||||
|
||||
// The UserFunc type is an adapter to allow the use of ordinary
|
||||
// function as User mutator.
|
||||
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.UserMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m)
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GeneralQueueStateMutation", m)
|
||||
}
|
||||
|
||||
// Condition is a hook condition function.
|
||||
@@ -0,0 +1,60 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// GeneralQueueColumns holds the columns for the "generalQueue" table.
|
||||
GeneralQueueColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "payload", Type: field.TypeJSON},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"pending", "in_progress", "completed", "failed"}},
|
||||
{Name: "number_of_tries", Type: field.TypeInt, Default: 0},
|
||||
{Name: "max_retries", Type: field.TypeInt, Default: 3},
|
||||
{Name: "error_message", Type: field.TypeString, Nullable: true},
|
||||
{Name: "failure_payload", Type: field.TypeJSON, Nullable: true},
|
||||
{Name: "result_payload", Type: field.TypeJSON, Nullable: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "processed_at", Type: field.TypeTime, Nullable: true},
|
||||
}
|
||||
// GeneralQueueTable holds the schema information for the "generalQueue" table.
|
||||
GeneralQueueTable = &schema.Table{
|
||||
Name: "generalQueue",
|
||||
Columns: GeneralQueueColumns,
|
||||
PrimaryKey: []*schema.Column{GeneralQueueColumns[0]},
|
||||
}
|
||||
// GeneralQueueStateColumns holds the columns for the "generalQueueState" table.
|
||||
GeneralQueueStateColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString, Unique: true},
|
||||
{Name: "running", Type: field.TypeBool, Default: false},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
}
|
||||
// GeneralQueueStateTable holds the schema information for the "generalQueueState" table.
|
||||
GeneralQueueStateTable = &schema.Table{
|
||||
Name: "generalQueueState",
|
||||
Columns: GeneralQueueStateColumns,
|
||||
PrimaryKey: []*schema.Column{GeneralQueueStateColumns[0]},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
GeneralQueueTable,
|
||||
GeneralQueueStateTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
GeneralQueueTable.Annotation = &entsql.Annotation{
|
||||
Table: "generalQueue",
|
||||
}
|
||||
GeneralQueueStateTable.Annotation = &entsql.Annotation{
|
||||
Table: "generalQueueState",
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,10 +10,10 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// PaginateAfterID paginates Group by monotonically increasing "id".
|
||||
// PaginateAfterID paginates GeneralQueue by monotonically increasing "id".
|
||||
// It preserves any existing filters/joins applied to the query, fetches up to "limit" items,
|
||||
// and returns the next cursor (last ID of this page) and whether a next page exists.
|
||||
func (q *GroupQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*Group, int, bool, error) {
|
||||
func (q *GeneralQueueQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*GeneralQueue, int, bool, error) {
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
@@ -48,48 +48,10 @@ func (q *GroupQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([
|
||||
return rows, next, hasNext, nil
|
||||
}
|
||||
|
||||
// PaginateAfterID paginates Todo by monotonically increasing "id".
|
||||
// PaginateAfterID paginates GeneralQueueState by monotonically increasing "id".
|
||||
// It preserves any existing filters/joins applied to the query, fetches up to "limit" items,
|
||||
// and returns the next cursor (last ID of this page) and whether a next page exists.
|
||||
func (q *TodoQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*Todo, int, bool, error) {
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
|
||||
qq := q.Clone().
|
||||
Order(func(s *sql.Selector) {
|
||||
s.OrderBy(s.C("id"))
|
||||
}).
|
||||
Limit(limit + 1) // fetch one extra to detect "has next"
|
||||
|
||||
if afterID > 0 {
|
||||
qq = qq.Where(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C("id"), afterID))
|
||||
})
|
||||
}
|
||||
|
||||
rows, err := qq.All(ctx)
|
||||
if err != nil {
|
||||
return nil, 0, false, err
|
||||
}
|
||||
|
||||
hasNext := len(rows) > limit
|
||||
if hasNext {
|
||||
rows = rows[:limit]
|
||||
}
|
||||
|
||||
next := 0
|
||||
if len(rows) > 0 {
|
||||
next = rows[len(rows)-1].ID
|
||||
}
|
||||
|
||||
return rows, next, hasNext, nil
|
||||
}
|
||||
|
||||
// PaginateAfterID paginates User by monotonically increasing "id".
|
||||
// It preserves any existing filters/joins applied to the query, fetches up to "limit" items,
|
||||
// and returns the next cursor (last ID of this page) and whether a next page exists.
|
||||
func (q *UserQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*User, int, bool, error) {
|
||||
func (q *GeneralQueueStateQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*GeneralQueueState, int, bool, error) {
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package predicate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// GeneralQueue is the predicate function for generalqueue builders.
|
||||
type GeneralQueue func(*sql.Selector)
|
||||
|
||||
// GeneralQueueState is the predicate function for generalqueuestate builders.
|
||||
type GeneralQueueState func(*sql.Selector)
|
||||
@@ -0,0 +1,31 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueue"
|
||||
"git.gorlug.de/code/ersteller/schema/ent/generalqueuestate"
|
||||
"git.gorlug.de/code/ersteller/schema/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() {
|
||||
generalqueueFields := schema.GeneralQueue{}.Fields()
|
||||
_ = generalqueueFields
|
||||
// generalqueueDescNumberOfTries is the schema descriptor for number_of_tries field.
|
||||
generalqueueDescNumberOfTries := generalqueueFields[3].Descriptor()
|
||||
// generalqueue.DefaultNumberOfTries holds the default value on creation for the number_of_tries field.
|
||||
generalqueue.DefaultNumberOfTries = generalqueueDescNumberOfTries.Default.(int)
|
||||
// generalqueueDescMaxRetries is the schema descriptor for max_retries field.
|
||||
generalqueueDescMaxRetries := generalqueueFields[4].Descriptor()
|
||||
// generalqueue.DefaultMaxRetries holds the default value on creation for the max_retries field.
|
||||
generalqueue.DefaultMaxRetries = generalqueueDescMaxRetries.Default.(int)
|
||||
generalqueuestateFields := schema.GeneralQueueState{}.Fields()
|
||||
_ = generalqueuestateFields
|
||||
// generalqueuestateDescRunning is the schema descriptor for running field.
|
||||
generalqueuestateDescRunning := generalqueuestateFields[1].Descriptor()
|
||||
// generalqueuestate.DefaultRunning holds the default value on creation for the running field.
|
||||
generalqueuestate.DefaultRunning = generalqueuestateDescRunning.Default.(bool)
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
package runtime
|
||||
|
||||
// The schema-stitching logic is generated in ersteller-lib/schema/ent/example/ent/runtime.go
|
||||
// The schema-stitching logic is generated in git.gorlug.de/code/ersteller/schema/ent/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.14.5" // Version of ent codegen.
|
||||
@@ -1,4 +1,4 @@
|
||||
package ersteller_ent
|
||||
package ent
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
@@ -12,12 +12,10 @@ import (
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Group is the client for interacting with the Group builders.
|
||||
Group *GroupClient
|
||||
// Todo is the client for interacting with the Todo builders.
|
||||
Todo *TodoClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
// GeneralQueue is the client for interacting with the GeneralQueue builders.
|
||||
GeneralQueue *GeneralQueueClient
|
||||
// GeneralQueueState is the client for interacting with the GeneralQueueState builders.
|
||||
GeneralQueueState *GeneralQueueStateClient
|
||||
|
||||
// lazily loaded.
|
||||
client *Client
|
||||
@@ -149,9 +147,8 @@ func (tx *Tx) Client() *Client {
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.Group = NewGroupClient(tx.config)
|
||||
tx.Todo = NewTodoClient(tx.config)
|
||||
tx.User = NewUserClient(tx.config)
|
||||
tx.GeneralQueue = NewGeneralQueueClient(tx.config)
|
||||
tx.GeneralQueueState = NewGeneralQueueStateClient(tx.config)
|
||||
}
|
||||
|
||||
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||
@@ -161,7 +158,7 @@ func (tx *Tx) init() {
|
||||
// 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: Group.QueryXXX(), the query will be executed
|
||||
// applies a query, for example: GeneralQueue.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
Reference in New Issue
Block a user