// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "log" "reflect" "gitserver.in/patialtech/rano/db/ent/migrate" "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "gitserver.in/patialtech/rano/db/ent/accesscontrol" "gitserver.in/patialtech/rano/db/ent/audit" "gitserver.in/patialtech/rano/db/ent/role" "gitserver.in/patialtech/rano/db/ent/todo" "gitserver.in/patialtech/rano/db/ent/user" "gitserver.in/patialtech/rano/db/ent/usersession" "gitserver.in/patialtech/rano/db/ent/verifytoken" ) // 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 // AccessControl is the client for interacting with the AccessControl builders. AccessControl *AccessControlClient // Audit is the client for interacting with the Audit builders. Audit *AuditClient // Role is the client for interacting with the Role builders. Role *RoleClient // Todo is the client for interacting with the Todo builders. Todo *TodoClient // User is the client for interacting with the User builders. User *UserClient // UserSession is the client for interacting with the UserSession builders. UserSession *UserSessionClient // VerifyToken is the client for interacting with the VerifyToken builders. VerifyToken *VerifyTokenClient } // 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.AccessControl = NewAccessControlClient(c.config) c.Audit = NewAuditClient(c.config) c.Role = NewRoleClient(c.config) c.Todo = NewTodoClient(c.config) c.User = NewUserClient(c.config) c.UserSession = NewUserSessionClient(c.config) c.VerifyToken = NewVerifyTokenClient(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, AccessControl: NewAccessControlClient(cfg), Audit: NewAuditClient(cfg), Role: NewRoleClient(cfg), Todo: NewTodoClient(cfg), User: NewUserClient(cfg), UserSession: NewUserSessionClient(cfg), VerifyToken: NewVerifyTokenClient(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, AccessControl: NewAccessControlClient(cfg), Audit: NewAuditClient(cfg), Role: NewRoleClient(cfg), Todo: NewTodoClient(cfg), User: NewUserClient(cfg), UserSession: NewUserSessionClient(cfg), VerifyToken: NewVerifyTokenClient(cfg), }, nil } // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). // AccessControl. // 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) { for _, n := range []interface{ Use(...Hook) }{ c.AccessControl, c.Audit, c.Role, c.Todo, c.User, c.UserSession, c.VerifyToken, } { n.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) { for _, n := range []interface{ Intercept(...Interceptor) }{ c.AccessControl, c.Audit, c.Role, c.Todo, c.User, c.UserSession, c.VerifyToken, } { n.Intercept(interceptors...) } } // Mutate implements the ent.Mutator interface. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { case *AccessControlMutation: return c.AccessControl.mutate(ctx, m) case *AuditMutation: return c.Audit.mutate(ctx, m) case *RoleMutation: return c.Role.mutate(ctx, m) case *TodoMutation: return c.Todo.mutate(ctx, m) case *UserMutation: return c.User.mutate(ctx, m) case *UserSessionMutation: return c.UserSession.mutate(ctx, m) case *VerifyTokenMutation: return c.VerifyToken.mutate(ctx, m) default: return nil, fmt.Errorf("ent: unknown mutation type %T", m) } } // AccessControlClient is a client for the AccessControl schema. type AccessControlClient struct { config } // NewAccessControlClient returns a client for the AccessControl from the given config. func NewAccessControlClient(c config) *AccessControlClient { return &AccessControlClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `accesscontrol.Hooks(f(g(h())))`. func (c *AccessControlClient) Use(hooks ...Hook) { c.hooks.AccessControl = append(c.hooks.AccessControl, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `accesscontrol.Intercept(f(g(h())))`. func (c *AccessControlClient) Intercept(interceptors ...Interceptor) { c.inters.AccessControl = append(c.inters.AccessControl, interceptors...) } // Create returns a builder for creating a AccessControl entity. func (c *AccessControlClient) Create() *AccessControlCreate { mutation := newAccessControlMutation(c.config, OpCreate) return &AccessControlCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of AccessControl entities. func (c *AccessControlClient) CreateBulk(builders ...*AccessControlCreate) *AccessControlCreateBulk { return &AccessControlCreateBulk{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 *AccessControlClient) MapCreateBulk(slice any, setFunc func(*AccessControlCreate, int)) *AccessControlCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &AccessControlCreateBulk{err: fmt.Errorf("calling to AccessControlClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*AccessControlCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &AccessControlCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for AccessControl. func (c *AccessControlClient) Update() *AccessControlUpdate { mutation := newAccessControlMutation(c.config, OpUpdate) return &AccessControlUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *AccessControlClient) UpdateOne(ac *AccessControl) *AccessControlUpdateOne { mutation := newAccessControlMutation(c.config, OpUpdateOne, withAccessControl(ac)) return &AccessControlUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *AccessControlClient) UpdateOneID(id int64) *AccessControlUpdateOne { mutation := newAccessControlMutation(c.config, OpUpdateOne, withAccessControlID(id)) return &AccessControlUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for AccessControl. func (c *AccessControlClient) Delete() *AccessControlDelete { mutation := newAccessControlMutation(c.config, OpDelete) return &AccessControlDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *AccessControlClient) DeleteOne(ac *AccessControl) *AccessControlDeleteOne { return c.DeleteOneID(ac.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *AccessControlClient) DeleteOneID(id int64) *AccessControlDeleteOne { builder := c.Delete().Where(accesscontrol.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &AccessControlDeleteOne{builder} } // Query returns a query builder for AccessControl. func (c *AccessControlClient) Query() *AccessControlQuery { return &AccessControlQuery{ config: c.config, ctx: &QueryContext{Type: TypeAccessControl}, inters: c.Interceptors(), } } // Get returns a AccessControl entity by its id. func (c *AccessControlClient) Get(ctx context.Context, id int64) (*AccessControl, error) { return c.Query().Where(accesscontrol.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *AccessControlClient) GetX(ctx context.Context, id int64) *AccessControl { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *AccessControlClient) Hooks() []Hook { return c.hooks.AccessControl } // Interceptors returns the client interceptors. func (c *AccessControlClient) Interceptors() []Interceptor { return c.inters.AccessControl } func (c *AccessControlClient) mutate(ctx context.Context, m *AccessControlMutation) (Value, error) { switch m.Op() { case OpCreate: return (&AccessControlCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&AccessControlUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&AccessControlUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&AccessControlDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown AccessControl mutation op: %q", m.Op()) } } // AuditClient is a client for the Audit schema. type AuditClient struct { config } // NewAuditClient returns a client for the Audit from the given config. func NewAuditClient(c config) *AuditClient { return &AuditClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `audit.Hooks(f(g(h())))`. func (c *AuditClient) Use(hooks ...Hook) { c.hooks.Audit = append(c.hooks.Audit, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `audit.Intercept(f(g(h())))`. func (c *AuditClient) Intercept(interceptors ...Interceptor) { c.inters.Audit = append(c.inters.Audit, interceptors...) } // Create returns a builder for creating a Audit entity. func (c *AuditClient) Create() *AuditCreate { mutation := newAuditMutation(c.config, OpCreate) return &AuditCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Audit entities. func (c *AuditClient) CreateBulk(builders ...*AuditCreate) *AuditCreateBulk { return &AuditCreateBulk{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 *AuditClient) MapCreateBulk(slice any, setFunc func(*AuditCreate, int)) *AuditCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &AuditCreateBulk{err: fmt.Errorf("calling to AuditClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*AuditCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &AuditCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Audit. func (c *AuditClient) Update() *AuditUpdate { mutation := newAuditMutation(c.config, OpUpdate) return &AuditUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *AuditClient) UpdateOne(a *Audit) *AuditUpdateOne { mutation := newAuditMutation(c.config, OpUpdateOne, withAudit(a)) return &AuditUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *AuditClient) UpdateOneID(id int64) *AuditUpdateOne { mutation := newAuditMutation(c.config, OpUpdateOne, withAuditID(id)) return &AuditUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Audit. func (c *AuditClient) Delete() *AuditDelete { mutation := newAuditMutation(c.config, OpDelete) return &AuditDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *AuditClient) DeleteOne(a *Audit) *AuditDeleteOne { return c.DeleteOneID(a.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *AuditClient) DeleteOneID(id int64) *AuditDeleteOne { builder := c.Delete().Where(audit.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &AuditDeleteOne{builder} } // Query returns a query builder for Audit. func (c *AuditClient) Query() *AuditQuery { return &AuditQuery{ config: c.config, ctx: &QueryContext{Type: TypeAudit}, inters: c.Interceptors(), } } // Get returns a Audit entity by its id. func (c *AuditClient) Get(ctx context.Context, id int64) (*Audit, error) { return c.Query().Where(audit.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *AuditClient) GetX(ctx context.Context, id int64) *Audit { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryUser queries the user edge of a Audit. func (c *AuditClient) QueryUser(a *Audit) *UserQuery { query := (&UserClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := a.ID step := sqlgraph.NewStep( sqlgraph.From(audit.Table, audit.FieldID, id), sqlgraph.To(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, audit.UserTable, audit.UserColumn), ) fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *AuditClient) Hooks() []Hook { return c.hooks.Audit } // Interceptors returns the client interceptors. func (c *AuditClient) Interceptors() []Interceptor { return c.inters.Audit } func (c *AuditClient) mutate(ctx context.Context, m *AuditMutation) (Value, error) { switch m.Op() { case OpCreate: return (&AuditCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&AuditUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&AuditUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&AuditDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Audit mutation op: %q", m.Op()) } } // RoleClient is a client for the Role schema. type RoleClient struct { config } // NewRoleClient returns a client for the Role from the given config. func NewRoleClient(c config) *RoleClient { return &RoleClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `role.Hooks(f(g(h())))`. func (c *RoleClient) Use(hooks ...Hook) { c.hooks.Role = append(c.hooks.Role, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `role.Intercept(f(g(h())))`. func (c *RoleClient) Intercept(interceptors ...Interceptor) { c.inters.Role = append(c.inters.Role, interceptors...) } // Create returns a builder for creating a Role entity. func (c *RoleClient) Create() *RoleCreate { mutation := newRoleMutation(c.config, OpCreate) return &RoleCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Role entities. func (c *RoleClient) CreateBulk(builders ...*RoleCreate) *RoleCreateBulk { return &RoleCreateBulk{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 *RoleClient) MapCreateBulk(slice any, setFunc func(*RoleCreate, int)) *RoleCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &RoleCreateBulk{err: fmt.Errorf("calling to RoleClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*RoleCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &RoleCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Role. func (c *RoleClient) Update() *RoleUpdate { mutation := newRoleMutation(c.config, OpUpdate) return &RoleUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *RoleClient) UpdateOne(r *Role) *RoleUpdateOne { mutation := newRoleMutation(c.config, OpUpdateOne, withRole(r)) return &RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *RoleClient) UpdateOneID(id int64) *RoleUpdateOne { mutation := newRoleMutation(c.config, OpUpdateOne, withRoleID(id)) return &RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Role. func (c *RoleClient) Delete() *RoleDelete { mutation := newRoleMutation(c.config, OpDelete) return &RoleDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *RoleClient) DeleteOne(r *Role) *RoleDeleteOne { return c.DeleteOneID(r.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *RoleClient) DeleteOneID(id int64) *RoleDeleteOne { builder := c.Delete().Where(role.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &RoleDeleteOne{builder} } // Query returns a query builder for Role. func (c *RoleClient) Query() *RoleQuery { return &RoleQuery{ config: c.config, ctx: &QueryContext{Type: TypeRole}, inters: c.Interceptors(), } } // Get returns a Role entity by its id. func (c *RoleClient) Get(ctx context.Context, id int64) (*Role, error) { return c.Query().Where(role.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *RoleClient) GetX(ctx context.Context, id int64) *Role { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *RoleClient) Hooks() []Hook { return c.hooks.Role } // Interceptors returns the client interceptors. func (c *RoleClient) Interceptors() []Interceptor { return c.inters.Role } func (c *RoleClient) mutate(ctx context.Context, m *RoleMutation) (Value, error) { switch m.Op() { case OpCreate: return (&RoleCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&RoleUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&RoleDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Role 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(t *Todo) *TodoUpdateOne { mutation := newTodoMutation(c.config, OpUpdateOne, withTodo(t)) 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(t *Todo) *TodoDeleteOne { return c.DeleteOneID(t.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 } // 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(u *User) *UserUpdateOne { mutation := newUserMutation(c.config, OpUpdateOne, withUser(u)) return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *UserClient) UpdateOneID(id int64) *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(u *User) *UserDeleteOne { return c.DeleteOneID(u.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *UserClient) DeleteOneID(id int64) *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 int64) (*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 int64) *User { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QuerySessions queries the sessions edge of a User. func (c *UserClient) QuerySessions(u *User) *UserSessionQuery { query := (&UserSessionClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), sqlgraph.To(usersession.Table, usersession.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, user.SessionsTable, user.SessionsColumn), ) fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) return fromV, nil } return query } // QueryAuditLogs queries the audit_logs edge of a User. func (c *UserClient) QueryAuditLogs(u *User) *AuditQuery { query := (&AuditClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), sqlgraph.To(audit.Table, audit.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, user.AuditLogsTable, user.AuditLogsColumn), ) fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) return fromV, nil } return query } // QueryVerifyTokens queries the verify_tokens edge of a User. func (c *UserClient) QueryVerifyTokens(u *User) *VerifyTokenQuery { query := (&VerifyTokenClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), sqlgraph.To(verifytoken.Table, verifytoken.FieldID), sqlgraph.Edge(sqlgraph.O2M, false, user.VerifyTokensTable, user.VerifyTokensColumn), ) fromV = sqlgraph.Neighbors(u.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()) } } // UserSessionClient is a client for the UserSession schema. type UserSessionClient struct { config } // NewUserSessionClient returns a client for the UserSession from the given config. func NewUserSessionClient(c config) *UserSessionClient { return &UserSessionClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `usersession.Hooks(f(g(h())))`. func (c *UserSessionClient) Use(hooks ...Hook) { c.hooks.UserSession = append(c.hooks.UserSession, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `usersession.Intercept(f(g(h())))`. func (c *UserSessionClient) Intercept(interceptors ...Interceptor) { c.inters.UserSession = append(c.inters.UserSession, interceptors...) } // Create returns a builder for creating a UserSession entity. func (c *UserSessionClient) Create() *UserSessionCreate { mutation := newUserSessionMutation(c.config, OpCreate) return &UserSessionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of UserSession entities. func (c *UserSessionClient) CreateBulk(builders ...*UserSessionCreate) *UserSessionCreateBulk { return &UserSessionCreateBulk{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 *UserSessionClient) MapCreateBulk(slice any, setFunc func(*UserSessionCreate, int)) *UserSessionCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &UserSessionCreateBulk{err: fmt.Errorf("calling to UserSessionClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*UserSessionCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &UserSessionCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for UserSession. func (c *UserSessionClient) Update() *UserSessionUpdate { mutation := newUserSessionMutation(c.config, OpUpdate) return &UserSessionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *UserSessionClient) UpdateOne(us *UserSession) *UserSessionUpdateOne { mutation := newUserSessionMutation(c.config, OpUpdateOne, withUserSession(us)) return &UserSessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *UserSessionClient) UpdateOneID(id int64) *UserSessionUpdateOne { mutation := newUserSessionMutation(c.config, OpUpdateOne, withUserSessionID(id)) return &UserSessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for UserSession. func (c *UserSessionClient) Delete() *UserSessionDelete { mutation := newUserSessionMutation(c.config, OpDelete) return &UserSessionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *UserSessionClient) DeleteOne(us *UserSession) *UserSessionDeleteOne { return c.DeleteOneID(us.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *UserSessionClient) DeleteOneID(id int64) *UserSessionDeleteOne { builder := c.Delete().Where(usersession.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &UserSessionDeleteOne{builder} } // Query returns a query builder for UserSession. func (c *UserSessionClient) Query() *UserSessionQuery { return &UserSessionQuery{ config: c.config, ctx: &QueryContext{Type: TypeUserSession}, inters: c.Interceptors(), } } // Get returns a UserSession entity by its id. func (c *UserSessionClient) Get(ctx context.Context, id int64) (*UserSession, error) { return c.Query().Where(usersession.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *UserSessionClient) GetX(ctx context.Context, id int64) *UserSession { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryUser queries the user edge of a UserSession. func (c *UserSessionClient) QueryUser(us *UserSession) *UserQuery { query := (&UserClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := us.ID step := sqlgraph.NewStep( sqlgraph.From(usersession.Table, usersession.FieldID, id), sqlgraph.To(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, usersession.UserTable, usersession.UserColumn), ) fromV = sqlgraph.Neighbors(us.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *UserSessionClient) Hooks() []Hook { return c.hooks.UserSession } // Interceptors returns the client interceptors. func (c *UserSessionClient) Interceptors() []Interceptor { return c.inters.UserSession } func (c *UserSessionClient) mutate(ctx context.Context, m *UserSessionMutation) (Value, error) { switch m.Op() { case OpCreate: return (&UserSessionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&UserSessionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&UserSessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&UserSessionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown UserSession mutation op: %q", m.Op()) } } // VerifyTokenClient is a client for the VerifyToken schema. type VerifyTokenClient struct { config } // NewVerifyTokenClient returns a client for the VerifyToken from the given config. func NewVerifyTokenClient(c config) *VerifyTokenClient { return &VerifyTokenClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `verifytoken.Hooks(f(g(h())))`. func (c *VerifyTokenClient) Use(hooks ...Hook) { c.hooks.VerifyToken = append(c.hooks.VerifyToken, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `verifytoken.Intercept(f(g(h())))`. func (c *VerifyTokenClient) Intercept(interceptors ...Interceptor) { c.inters.VerifyToken = append(c.inters.VerifyToken, interceptors...) } // Create returns a builder for creating a VerifyToken entity. func (c *VerifyTokenClient) Create() *VerifyTokenCreate { mutation := newVerifyTokenMutation(c.config, OpCreate) return &VerifyTokenCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of VerifyToken entities. func (c *VerifyTokenClient) CreateBulk(builders ...*VerifyTokenCreate) *VerifyTokenCreateBulk { return &VerifyTokenCreateBulk{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 *VerifyTokenClient) MapCreateBulk(slice any, setFunc func(*VerifyTokenCreate, int)) *VerifyTokenCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &VerifyTokenCreateBulk{err: fmt.Errorf("calling to VerifyTokenClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*VerifyTokenCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &VerifyTokenCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for VerifyToken. func (c *VerifyTokenClient) Update() *VerifyTokenUpdate { mutation := newVerifyTokenMutation(c.config, OpUpdate) return &VerifyTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *VerifyTokenClient) UpdateOne(vt *VerifyToken) *VerifyTokenUpdateOne { mutation := newVerifyTokenMutation(c.config, OpUpdateOne, withVerifyToken(vt)) return &VerifyTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *VerifyTokenClient) UpdateOneID(id int64) *VerifyTokenUpdateOne { mutation := newVerifyTokenMutation(c.config, OpUpdateOne, withVerifyTokenID(id)) return &VerifyTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for VerifyToken. func (c *VerifyTokenClient) Delete() *VerifyTokenDelete { mutation := newVerifyTokenMutation(c.config, OpDelete) return &VerifyTokenDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *VerifyTokenClient) DeleteOne(vt *VerifyToken) *VerifyTokenDeleteOne { return c.DeleteOneID(vt.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *VerifyTokenClient) DeleteOneID(id int64) *VerifyTokenDeleteOne { builder := c.Delete().Where(verifytoken.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &VerifyTokenDeleteOne{builder} } // Query returns a query builder for VerifyToken. func (c *VerifyTokenClient) Query() *VerifyTokenQuery { return &VerifyTokenQuery{ config: c.config, ctx: &QueryContext{Type: TypeVerifyToken}, inters: c.Interceptors(), } } // Get returns a VerifyToken entity by its id. func (c *VerifyTokenClient) Get(ctx context.Context, id int64) (*VerifyToken, error) { return c.Query().Where(verifytoken.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *VerifyTokenClient) GetX(ctx context.Context, id int64) *VerifyToken { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // QueryUser queries the user edge of a VerifyToken. func (c *VerifyTokenClient) QueryUser(vt *VerifyToken) *UserQuery { query := (&UserClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := vt.ID step := sqlgraph.NewStep( sqlgraph.From(verifytoken.Table, verifytoken.FieldID, id), sqlgraph.To(user.Table, user.FieldID), sqlgraph.Edge(sqlgraph.M2O, true, verifytoken.UserTable, verifytoken.UserColumn), ) fromV = sqlgraph.Neighbors(vt.driver.Dialect(), step) return fromV, nil } return query } // Hooks returns the client hooks. func (c *VerifyTokenClient) Hooks() []Hook { return c.hooks.VerifyToken } // Interceptors returns the client interceptors. func (c *VerifyTokenClient) Interceptors() []Interceptor { return c.inters.VerifyToken } func (c *VerifyTokenClient) mutate(ctx context.Context, m *VerifyTokenMutation) (Value, error) { switch m.Op() { case OpCreate: return (&VerifyTokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&VerifyTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&VerifyTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&VerifyTokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown VerifyToken mutation op: %q", m.Op()) } } // hooks and interceptors per client, for fast access. type ( hooks struct { AccessControl, Audit, Role, Todo, User, UserSession, VerifyToken []ent.Hook } inters struct { AccessControl, Audit, Role, Todo, User, UserSession, VerifyToken []ent.Interceptor } )