mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-03 15:23:30 +08:00
2241 lines
81 KiB
Go
2241 lines
81 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"reflect"
|
|
|
|
"github.com/chaitin/MonkeyCode/backend/db/migrate"
|
|
"github.com/google/uuid"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"github.com/chaitin/MonkeyCode/backend/db/admin"
|
|
"github.com/chaitin/MonkeyCode/backend/db/adminloginhistory"
|
|
"github.com/chaitin/MonkeyCode/backend/db/apikey"
|
|
"github.com/chaitin/MonkeyCode/backend/db/billingplan"
|
|
"github.com/chaitin/MonkeyCode/backend/db/billingquota"
|
|
"github.com/chaitin/MonkeyCode/backend/db/billingrecord"
|
|
"github.com/chaitin/MonkeyCode/backend/db/billingusage"
|
|
"github.com/chaitin/MonkeyCode/backend/db/invitecode"
|
|
"github.com/chaitin/MonkeyCode/backend/db/model"
|
|
"github.com/chaitin/MonkeyCode/backend/db/record"
|
|
"github.com/chaitin/MonkeyCode/backend/db/setting"
|
|
"github.com/chaitin/MonkeyCode/backend/db/user"
|
|
"github.com/chaitin/MonkeyCode/backend/db/userloginhistory"
|
|
|
|
stdsql "database/sql"
|
|
)
|
|
|
|
// Client is the client that holds all ent builders.
|
|
type Client struct {
|
|
config
|
|
// Schema is the client for creating, migrating and dropping schema.
|
|
Schema *migrate.Schema
|
|
// Admin is the client for interacting with the Admin builders.
|
|
Admin *AdminClient
|
|
// AdminLoginHistory is the client for interacting with the AdminLoginHistory builders.
|
|
AdminLoginHistory *AdminLoginHistoryClient
|
|
// ApiKey is the client for interacting with the ApiKey builders.
|
|
ApiKey *ApiKeyClient
|
|
// BillingPlan is the client for interacting with the BillingPlan builders.
|
|
BillingPlan *BillingPlanClient
|
|
// BillingQuota is the client for interacting with the BillingQuota builders.
|
|
BillingQuota *BillingQuotaClient
|
|
// BillingRecord is the client for interacting with the BillingRecord builders.
|
|
BillingRecord *BillingRecordClient
|
|
// BillingUsage is the client for interacting with the BillingUsage builders.
|
|
BillingUsage *BillingUsageClient
|
|
// InviteCode is the client for interacting with the InviteCode builders.
|
|
InviteCode *InviteCodeClient
|
|
// Model is the client for interacting with the Model builders.
|
|
Model *ModelClient
|
|
// Record is the client for interacting with the Record builders.
|
|
Record *RecordClient
|
|
// Setting is the client for interacting with the Setting builders.
|
|
Setting *SettingClient
|
|
// User is the client for interacting with the User builders.
|
|
User *UserClient
|
|
// UserLoginHistory is the client for interacting with the UserLoginHistory builders.
|
|
UserLoginHistory *UserLoginHistoryClient
|
|
}
|
|
|
|
// 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.Admin = NewAdminClient(c.config)
|
|
c.AdminLoginHistory = NewAdminLoginHistoryClient(c.config)
|
|
c.ApiKey = NewApiKeyClient(c.config)
|
|
c.BillingPlan = NewBillingPlanClient(c.config)
|
|
c.BillingQuota = NewBillingQuotaClient(c.config)
|
|
c.BillingRecord = NewBillingRecordClient(c.config)
|
|
c.BillingUsage = NewBillingUsageClient(c.config)
|
|
c.InviteCode = NewInviteCodeClient(c.config)
|
|
c.Model = NewModelClient(c.config)
|
|
c.Record = NewRecordClient(c.config)
|
|
c.Setting = NewSettingClient(c.config)
|
|
c.User = NewUserClient(c.config)
|
|
c.UserLoginHistory = NewUserLoginHistoryClient(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("db: 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("db: starting a transaction: %w", err)
|
|
}
|
|
cfg := c.config
|
|
cfg.driver = tx
|
|
return &Tx{
|
|
ctx: ctx,
|
|
config: cfg,
|
|
Admin: NewAdminClient(cfg),
|
|
AdminLoginHistory: NewAdminLoginHistoryClient(cfg),
|
|
ApiKey: NewApiKeyClient(cfg),
|
|
BillingPlan: NewBillingPlanClient(cfg),
|
|
BillingQuota: NewBillingQuotaClient(cfg),
|
|
BillingRecord: NewBillingRecordClient(cfg),
|
|
BillingUsage: NewBillingUsageClient(cfg),
|
|
InviteCode: NewInviteCodeClient(cfg),
|
|
Model: NewModelClient(cfg),
|
|
Record: NewRecordClient(cfg),
|
|
Setting: NewSettingClient(cfg),
|
|
User: NewUserClient(cfg),
|
|
UserLoginHistory: NewUserLoginHistoryClient(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,
|
|
Admin: NewAdminClient(cfg),
|
|
AdminLoginHistory: NewAdminLoginHistoryClient(cfg),
|
|
ApiKey: NewApiKeyClient(cfg),
|
|
BillingPlan: NewBillingPlanClient(cfg),
|
|
BillingQuota: NewBillingQuotaClient(cfg),
|
|
BillingRecord: NewBillingRecordClient(cfg),
|
|
BillingUsage: NewBillingUsageClient(cfg),
|
|
InviteCode: NewInviteCodeClient(cfg),
|
|
Model: NewModelClient(cfg),
|
|
Record: NewRecordClient(cfg),
|
|
Setting: NewSettingClient(cfg),
|
|
User: NewUserClient(cfg),
|
|
UserLoginHistory: NewUserLoginHistoryClient(cfg),
|
|
}, nil
|
|
}
|
|
|
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
|
//
|
|
// client.Debug().
|
|
// Admin.
|
|
// 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.Admin, c.AdminLoginHistory, c.ApiKey, c.BillingPlan, c.BillingQuota,
|
|
c.BillingRecord, c.BillingUsage, c.InviteCode, c.Model, c.Record, c.Setting,
|
|
c.User, c.UserLoginHistory,
|
|
} {
|
|
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.Admin, c.AdminLoginHistory, c.ApiKey, c.BillingPlan, c.BillingQuota,
|
|
c.BillingRecord, c.BillingUsage, c.InviteCode, c.Model, c.Record, c.Setting,
|
|
c.User, c.UserLoginHistory,
|
|
} {
|
|
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 *AdminMutation:
|
|
return c.Admin.mutate(ctx, m)
|
|
case *AdminLoginHistoryMutation:
|
|
return c.AdminLoginHistory.mutate(ctx, m)
|
|
case *ApiKeyMutation:
|
|
return c.ApiKey.mutate(ctx, m)
|
|
case *BillingPlanMutation:
|
|
return c.BillingPlan.mutate(ctx, m)
|
|
case *BillingQuotaMutation:
|
|
return c.BillingQuota.mutate(ctx, m)
|
|
case *BillingRecordMutation:
|
|
return c.BillingRecord.mutate(ctx, m)
|
|
case *BillingUsageMutation:
|
|
return c.BillingUsage.mutate(ctx, m)
|
|
case *InviteCodeMutation:
|
|
return c.InviteCode.mutate(ctx, m)
|
|
case *ModelMutation:
|
|
return c.Model.mutate(ctx, m)
|
|
case *RecordMutation:
|
|
return c.Record.mutate(ctx, m)
|
|
case *SettingMutation:
|
|
return c.Setting.mutate(ctx, m)
|
|
case *UserMutation:
|
|
return c.User.mutate(ctx, m)
|
|
case *UserLoginHistoryMutation:
|
|
return c.UserLoginHistory.mutate(ctx, m)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown mutation type %T", m)
|
|
}
|
|
}
|
|
|
|
// AdminClient is a client for the Admin schema.
|
|
type AdminClient struct {
|
|
config
|
|
}
|
|
|
|
// NewAdminClient returns a client for the Admin from the given config.
|
|
func NewAdminClient(c config) *AdminClient {
|
|
return &AdminClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `admin.Hooks(f(g(h())))`.
|
|
func (c *AdminClient) Use(hooks ...Hook) {
|
|
c.hooks.Admin = append(c.hooks.Admin, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `admin.Intercept(f(g(h())))`.
|
|
func (c *AdminClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Admin = append(c.inters.Admin, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Admin entity.
|
|
func (c *AdminClient) Create() *AdminCreate {
|
|
mutation := newAdminMutation(c.config, OpCreate)
|
|
return &AdminCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Admin entities.
|
|
func (c *AdminClient) CreateBulk(builders ...*AdminCreate) *AdminCreateBulk {
|
|
return &AdminCreateBulk{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 *AdminClient) MapCreateBulk(slice any, setFunc func(*AdminCreate, int)) *AdminCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &AdminCreateBulk{err: fmt.Errorf("calling to AdminClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*AdminCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &AdminCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Admin.
|
|
func (c *AdminClient) Update() *AdminUpdate {
|
|
mutation := newAdminMutation(c.config, OpUpdate)
|
|
return &AdminUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *AdminClient) UpdateOne(a *Admin) *AdminUpdateOne {
|
|
mutation := newAdminMutation(c.config, OpUpdateOne, withAdmin(a))
|
|
return &AdminUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *AdminClient) UpdateOneID(id uuid.UUID) *AdminUpdateOne {
|
|
mutation := newAdminMutation(c.config, OpUpdateOne, withAdminID(id))
|
|
return &AdminUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Admin.
|
|
func (c *AdminClient) Delete() *AdminDelete {
|
|
mutation := newAdminMutation(c.config, OpDelete)
|
|
return &AdminDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *AdminClient) DeleteOne(a *Admin) *AdminDeleteOne {
|
|
return c.DeleteOneID(a.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *AdminClient) DeleteOneID(id uuid.UUID) *AdminDeleteOne {
|
|
builder := c.Delete().Where(admin.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &AdminDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Admin.
|
|
func (c *AdminClient) Query() *AdminQuery {
|
|
return &AdminQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeAdmin},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Admin entity by its id.
|
|
func (c *AdminClient) Get(ctx context.Context, id uuid.UUID) (*Admin, error) {
|
|
return c.Query().Where(admin.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *AdminClient) GetX(ctx context.Context, id uuid.UUID) *Admin {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryLoginHistories queries the login_histories edge of a Admin.
|
|
func (c *AdminClient) QueryLoginHistories(a *Admin) *AdminLoginHistoryQuery {
|
|
query := (&AdminLoginHistoryClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := a.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(admin.Table, admin.FieldID, id),
|
|
sqlgraph.To(adminloginhistory.Table, adminloginhistory.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, admin.LoginHistoriesTable, admin.LoginHistoriesColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(a.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *AdminClient) Hooks() []Hook {
|
|
return c.hooks.Admin
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *AdminClient) Interceptors() []Interceptor {
|
|
return c.inters.Admin
|
|
}
|
|
|
|
func (c *AdminClient) mutate(ctx context.Context, m *AdminMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&AdminCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&AdminUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&AdminUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&AdminDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown Admin mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// AdminLoginHistoryClient is a client for the AdminLoginHistory schema.
|
|
type AdminLoginHistoryClient struct {
|
|
config
|
|
}
|
|
|
|
// NewAdminLoginHistoryClient returns a client for the AdminLoginHistory from the given config.
|
|
func NewAdminLoginHistoryClient(c config) *AdminLoginHistoryClient {
|
|
return &AdminLoginHistoryClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `adminloginhistory.Hooks(f(g(h())))`.
|
|
func (c *AdminLoginHistoryClient) Use(hooks ...Hook) {
|
|
c.hooks.AdminLoginHistory = append(c.hooks.AdminLoginHistory, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `adminloginhistory.Intercept(f(g(h())))`.
|
|
func (c *AdminLoginHistoryClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.AdminLoginHistory = append(c.inters.AdminLoginHistory, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a AdminLoginHistory entity.
|
|
func (c *AdminLoginHistoryClient) Create() *AdminLoginHistoryCreate {
|
|
mutation := newAdminLoginHistoryMutation(c.config, OpCreate)
|
|
return &AdminLoginHistoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of AdminLoginHistory entities.
|
|
func (c *AdminLoginHistoryClient) CreateBulk(builders ...*AdminLoginHistoryCreate) *AdminLoginHistoryCreateBulk {
|
|
return &AdminLoginHistoryCreateBulk{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 *AdminLoginHistoryClient) MapCreateBulk(slice any, setFunc func(*AdminLoginHistoryCreate, int)) *AdminLoginHistoryCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &AdminLoginHistoryCreateBulk{err: fmt.Errorf("calling to AdminLoginHistoryClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*AdminLoginHistoryCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &AdminLoginHistoryCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for AdminLoginHistory.
|
|
func (c *AdminLoginHistoryClient) Update() *AdminLoginHistoryUpdate {
|
|
mutation := newAdminLoginHistoryMutation(c.config, OpUpdate)
|
|
return &AdminLoginHistoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *AdminLoginHistoryClient) UpdateOne(alh *AdminLoginHistory) *AdminLoginHistoryUpdateOne {
|
|
mutation := newAdminLoginHistoryMutation(c.config, OpUpdateOne, withAdminLoginHistory(alh))
|
|
return &AdminLoginHistoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *AdminLoginHistoryClient) UpdateOneID(id uuid.UUID) *AdminLoginHistoryUpdateOne {
|
|
mutation := newAdminLoginHistoryMutation(c.config, OpUpdateOne, withAdminLoginHistoryID(id))
|
|
return &AdminLoginHistoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for AdminLoginHistory.
|
|
func (c *AdminLoginHistoryClient) Delete() *AdminLoginHistoryDelete {
|
|
mutation := newAdminLoginHistoryMutation(c.config, OpDelete)
|
|
return &AdminLoginHistoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *AdminLoginHistoryClient) DeleteOne(alh *AdminLoginHistory) *AdminLoginHistoryDeleteOne {
|
|
return c.DeleteOneID(alh.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *AdminLoginHistoryClient) DeleteOneID(id uuid.UUID) *AdminLoginHistoryDeleteOne {
|
|
builder := c.Delete().Where(adminloginhistory.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &AdminLoginHistoryDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for AdminLoginHistory.
|
|
func (c *AdminLoginHistoryClient) Query() *AdminLoginHistoryQuery {
|
|
return &AdminLoginHistoryQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeAdminLoginHistory},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a AdminLoginHistory entity by its id.
|
|
func (c *AdminLoginHistoryClient) Get(ctx context.Context, id uuid.UUID) (*AdminLoginHistory, error) {
|
|
return c.Query().Where(adminloginhistory.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *AdminLoginHistoryClient) GetX(ctx context.Context, id uuid.UUID) *AdminLoginHistory {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryOwner queries the owner edge of a AdminLoginHistory.
|
|
func (c *AdminLoginHistoryClient) QueryOwner(alh *AdminLoginHistory) *AdminQuery {
|
|
query := (&AdminClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := alh.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(adminloginhistory.Table, adminloginhistory.FieldID, id),
|
|
sqlgraph.To(admin.Table, admin.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, adminloginhistory.OwnerTable, adminloginhistory.OwnerColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(alh.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *AdminLoginHistoryClient) Hooks() []Hook {
|
|
return c.hooks.AdminLoginHistory
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *AdminLoginHistoryClient) Interceptors() []Interceptor {
|
|
return c.inters.AdminLoginHistory
|
|
}
|
|
|
|
func (c *AdminLoginHistoryClient) mutate(ctx context.Context, m *AdminLoginHistoryMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&AdminLoginHistoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&AdminLoginHistoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&AdminLoginHistoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&AdminLoginHistoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown AdminLoginHistory mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// ApiKeyClient is a client for the ApiKey schema.
|
|
type ApiKeyClient struct {
|
|
config
|
|
}
|
|
|
|
// NewApiKeyClient returns a client for the ApiKey from the given config.
|
|
func NewApiKeyClient(c config) *ApiKeyClient {
|
|
return &ApiKeyClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `apikey.Hooks(f(g(h())))`.
|
|
func (c *ApiKeyClient) Use(hooks ...Hook) {
|
|
c.hooks.ApiKey = append(c.hooks.ApiKey, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `apikey.Intercept(f(g(h())))`.
|
|
func (c *ApiKeyClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.ApiKey = append(c.inters.ApiKey, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a ApiKey entity.
|
|
func (c *ApiKeyClient) Create() *ApiKeyCreate {
|
|
mutation := newApiKeyMutation(c.config, OpCreate)
|
|
return &ApiKeyCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of ApiKey entities.
|
|
func (c *ApiKeyClient) CreateBulk(builders ...*ApiKeyCreate) *ApiKeyCreateBulk {
|
|
return &ApiKeyCreateBulk{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 *ApiKeyClient) MapCreateBulk(slice any, setFunc func(*ApiKeyCreate, int)) *ApiKeyCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &ApiKeyCreateBulk{err: fmt.Errorf("calling to ApiKeyClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*ApiKeyCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &ApiKeyCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for ApiKey.
|
|
func (c *ApiKeyClient) Update() *ApiKeyUpdate {
|
|
mutation := newApiKeyMutation(c.config, OpUpdate)
|
|
return &ApiKeyUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *ApiKeyClient) UpdateOne(ak *ApiKey) *ApiKeyUpdateOne {
|
|
mutation := newApiKeyMutation(c.config, OpUpdateOne, withApiKey(ak))
|
|
return &ApiKeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *ApiKeyClient) UpdateOneID(id uuid.UUID) *ApiKeyUpdateOne {
|
|
mutation := newApiKeyMutation(c.config, OpUpdateOne, withApiKeyID(id))
|
|
return &ApiKeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for ApiKey.
|
|
func (c *ApiKeyClient) Delete() *ApiKeyDelete {
|
|
mutation := newApiKeyMutation(c.config, OpDelete)
|
|
return &ApiKeyDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *ApiKeyClient) DeleteOne(ak *ApiKey) *ApiKeyDeleteOne {
|
|
return c.DeleteOneID(ak.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *ApiKeyClient) DeleteOneID(id uuid.UUID) *ApiKeyDeleteOne {
|
|
builder := c.Delete().Where(apikey.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &ApiKeyDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for ApiKey.
|
|
func (c *ApiKeyClient) Query() *ApiKeyQuery {
|
|
return &ApiKeyQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeApiKey},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a ApiKey entity by its id.
|
|
func (c *ApiKeyClient) Get(ctx context.Context, id uuid.UUID) (*ApiKey, error) {
|
|
return c.Query().Where(apikey.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *ApiKeyClient) GetX(ctx context.Context, id uuid.UUID) *ApiKey {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *ApiKeyClient) Hooks() []Hook {
|
|
return c.hooks.ApiKey
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *ApiKeyClient) Interceptors() []Interceptor {
|
|
return c.inters.ApiKey
|
|
}
|
|
|
|
func (c *ApiKeyClient) mutate(ctx context.Context, m *ApiKeyMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&ApiKeyCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&ApiKeyUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&ApiKeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&ApiKeyDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown ApiKey mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// BillingPlanClient is a client for the BillingPlan schema.
|
|
type BillingPlanClient struct {
|
|
config
|
|
}
|
|
|
|
// NewBillingPlanClient returns a client for the BillingPlan from the given config.
|
|
func NewBillingPlanClient(c config) *BillingPlanClient {
|
|
return &BillingPlanClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `billingplan.Hooks(f(g(h())))`.
|
|
func (c *BillingPlanClient) Use(hooks ...Hook) {
|
|
c.hooks.BillingPlan = append(c.hooks.BillingPlan, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `billingplan.Intercept(f(g(h())))`.
|
|
func (c *BillingPlanClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.BillingPlan = append(c.inters.BillingPlan, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a BillingPlan entity.
|
|
func (c *BillingPlanClient) Create() *BillingPlanCreate {
|
|
mutation := newBillingPlanMutation(c.config, OpCreate)
|
|
return &BillingPlanCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of BillingPlan entities.
|
|
func (c *BillingPlanClient) CreateBulk(builders ...*BillingPlanCreate) *BillingPlanCreateBulk {
|
|
return &BillingPlanCreateBulk{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 *BillingPlanClient) MapCreateBulk(slice any, setFunc func(*BillingPlanCreate, int)) *BillingPlanCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &BillingPlanCreateBulk{err: fmt.Errorf("calling to BillingPlanClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*BillingPlanCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &BillingPlanCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for BillingPlan.
|
|
func (c *BillingPlanClient) Update() *BillingPlanUpdate {
|
|
mutation := newBillingPlanMutation(c.config, OpUpdate)
|
|
return &BillingPlanUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *BillingPlanClient) UpdateOne(bp *BillingPlan) *BillingPlanUpdateOne {
|
|
mutation := newBillingPlanMutation(c.config, OpUpdateOne, withBillingPlan(bp))
|
|
return &BillingPlanUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *BillingPlanClient) UpdateOneID(id string) *BillingPlanUpdateOne {
|
|
mutation := newBillingPlanMutation(c.config, OpUpdateOne, withBillingPlanID(id))
|
|
return &BillingPlanUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for BillingPlan.
|
|
func (c *BillingPlanClient) Delete() *BillingPlanDelete {
|
|
mutation := newBillingPlanMutation(c.config, OpDelete)
|
|
return &BillingPlanDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *BillingPlanClient) DeleteOne(bp *BillingPlan) *BillingPlanDeleteOne {
|
|
return c.DeleteOneID(bp.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *BillingPlanClient) DeleteOneID(id string) *BillingPlanDeleteOne {
|
|
builder := c.Delete().Where(billingplan.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &BillingPlanDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for BillingPlan.
|
|
func (c *BillingPlanClient) Query() *BillingPlanQuery {
|
|
return &BillingPlanQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeBillingPlan},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a BillingPlan entity by its id.
|
|
func (c *BillingPlanClient) Get(ctx context.Context, id string) (*BillingPlan, error) {
|
|
return c.Query().Where(billingplan.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *BillingPlanClient) GetX(ctx context.Context, id string) *BillingPlan {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *BillingPlanClient) Hooks() []Hook {
|
|
return c.hooks.BillingPlan
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *BillingPlanClient) Interceptors() []Interceptor {
|
|
return c.inters.BillingPlan
|
|
}
|
|
|
|
func (c *BillingPlanClient) mutate(ctx context.Context, m *BillingPlanMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&BillingPlanCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&BillingPlanUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&BillingPlanUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&BillingPlanDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown BillingPlan mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// BillingQuotaClient is a client for the BillingQuota schema.
|
|
type BillingQuotaClient struct {
|
|
config
|
|
}
|
|
|
|
// NewBillingQuotaClient returns a client for the BillingQuota from the given config.
|
|
func NewBillingQuotaClient(c config) *BillingQuotaClient {
|
|
return &BillingQuotaClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `billingquota.Hooks(f(g(h())))`.
|
|
func (c *BillingQuotaClient) Use(hooks ...Hook) {
|
|
c.hooks.BillingQuota = append(c.hooks.BillingQuota, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `billingquota.Intercept(f(g(h())))`.
|
|
func (c *BillingQuotaClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.BillingQuota = append(c.inters.BillingQuota, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a BillingQuota entity.
|
|
func (c *BillingQuotaClient) Create() *BillingQuotaCreate {
|
|
mutation := newBillingQuotaMutation(c.config, OpCreate)
|
|
return &BillingQuotaCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of BillingQuota entities.
|
|
func (c *BillingQuotaClient) CreateBulk(builders ...*BillingQuotaCreate) *BillingQuotaCreateBulk {
|
|
return &BillingQuotaCreateBulk{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 *BillingQuotaClient) MapCreateBulk(slice any, setFunc func(*BillingQuotaCreate, int)) *BillingQuotaCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &BillingQuotaCreateBulk{err: fmt.Errorf("calling to BillingQuotaClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*BillingQuotaCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &BillingQuotaCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for BillingQuota.
|
|
func (c *BillingQuotaClient) Update() *BillingQuotaUpdate {
|
|
mutation := newBillingQuotaMutation(c.config, OpUpdate)
|
|
return &BillingQuotaUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *BillingQuotaClient) UpdateOne(bq *BillingQuota) *BillingQuotaUpdateOne {
|
|
mutation := newBillingQuotaMutation(c.config, OpUpdateOne, withBillingQuota(bq))
|
|
return &BillingQuotaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *BillingQuotaClient) UpdateOneID(id string) *BillingQuotaUpdateOne {
|
|
mutation := newBillingQuotaMutation(c.config, OpUpdateOne, withBillingQuotaID(id))
|
|
return &BillingQuotaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for BillingQuota.
|
|
func (c *BillingQuotaClient) Delete() *BillingQuotaDelete {
|
|
mutation := newBillingQuotaMutation(c.config, OpDelete)
|
|
return &BillingQuotaDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *BillingQuotaClient) DeleteOne(bq *BillingQuota) *BillingQuotaDeleteOne {
|
|
return c.DeleteOneID(bq.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *BillingQuotaClient) DeleteOneID(id string) *BillingQuotaDeleteOne {
|
|
builder := c.Delete().Where(billingquota.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &BillingQuotaDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for BillingQuota.
|
|
func (c *BillingQuotaClient) Query() *BillingQuotaQuery {
|
|
return &BillingQuotaQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeBillingQuota},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a BillingQuota entity by its id.
|
|
func (c *BillingQuotaClient) Get(ctx context.Context, id string) (*BillingQuota, error) {
|
|
return c.Query().Where(billingquota.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *BillingQuotaClient) GetX(ctx context.Context, id string) *BillingQuota {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *BillingQuotaClient) Hooks() []Hook {
|
|
hooks := c.hooks.BillingQuota
|
|
return append(hooks[:len(hooks):len(hooks)], billingquota.Hooks[:]...)
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *BillingQuotaClient) Interceptors() []Interceptor {
|
|
inters := c.inters.BillingQuota
|
|
return append(inters[:len(inters):len(inters)], billingquota.Interceptors[:]...)
|
|
}
|
|
|
|
func (c *BillingQuotaClient) mutate(ctx context.Context, m *BillingQuotaMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&BillingQuotaCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&BillingQuotaUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&BillingQuotaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&BillingQuotaDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown BillingQuota mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// BillingRecordClient is a client for the BillingRecord schema.
|
|
type BillingRecordClient struct {
|
|
config
|
|
}
|
|
|
|
// NewBillingRecordClient returns a client for the BillingRecord from the given config.
|
|
func NewBillingRecordClient(c config) *BillingRecordClient {
|
|
return &BillingRecordClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `billingrecord.Hooks(f(g(h())))`.
|
|
func (c *BillingRecordClient) Use(hooks ...Hook) {
|
|
c.hooks.BillingRecord = append(c.hooks.BillingRecord, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `billingrecord.Intercept(f(g(h())))`.
|
|
func (c *BillingRecordClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.BillingRecord = append(c.inters.BillingRecord, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a BillingRecord entity.
|
|
func (c *BillingRecordClient) Create() *BillingRecordCreate {
|
|
mutation := newBillingRecordMutation(c.config, OpCreate)
|
|
return &BillingRecordCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of BillingRecord entities.
|
|
func (c *BillingRecordClient) CreateBulk(builders ...*BillingRecordCreate) *BillingRecordCreateBulk {
|
|
return &BillingRecordCreateBulk{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 *BillingRecordClient) MapCreateBulk(slice any, setFunc func(*BillingRecordCreate, int)) *BillingRecordCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &BillingRecordCreateBulk{err: fmt.Errorf("calling to BillingRecordClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*BillingRecordCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &BillingRecordCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for BillingRecord.
|
|
func (c *BillingRecordClient) Update() *BillingRecordUpdate {
|
|
mutation := newBillingRecordMutation(c.config, OpUpdate)
|
|
return &BillingRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *BillingRecordClient) UpdateOne(br *BillingRecord) *BillingRecordUpdateOne {
|
|
mutation := newBillingRecordMutation(c.config, OpUpdateOne, withBillingRecord(br))
|
|
return &BillingRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *BillingRecordClient) UpdateOneID(id string) *BillingRecordUpdateOne {
|
|
mutation := newBillingRecordMutation(c.config, OpUpdateOne, withBillingRecordID(id))
|
|
return &BillingRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for BillingRecord.
|
|
func (c *BillingRecordClient) Delete() *BillingRecordDelete {
|
|
mutation := newBillingRecordMutation(c.config, OpDelete)
|
|
return &BillingRecordDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *BillingRecordClient) DeleteOne(br *BillingRecord) *BillingRecordDeleteOne {
|
|
return c.DeleteOneID(br.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *BillingRecordClient) DeleteOneID(id string) *BillingRecordDeleteOne {
|
|
builder := c.Delete().Where(billingrecord.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &BillingRecordDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for BillingRecord.
|
|
func (c *BillingRecordClient) Query() *BillingRecordQuery {
|
|
return &BillingRecordQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeBillingRecord},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a BillingRecord entity by its id.
|
|
func (c *BillingRecordClient) Get(ctx context.Context, id string) (*BillingRecord, error) {
|
|
return c.Query().Where(billingrecord.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *BillingRecordClient) GetX(ctx context.Context, id string) *BillingRecord {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *BillingRecordClient) Hooks() []Hook {
|
|
return c.hooks.BillingRecord
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *BillingRecordClient) Interceptors() []Interceptor {
|
|
return c.inters.BillingRecord
|
|
}
|
|
|
|
func (c *BillingRecordClient) mutate(ctx context.Context, m *BillingRecordMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&BillingRecordCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&BillingRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&BillingRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&BillingRecordDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown BillingRecord mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// BillingUsageClient is a client for the BillingUsage schema.
|
|
type BillingUsageClient struct {
|
|
config
|
|
}
|
|
|
|
// NewBillingUsageClient returns a client for the BillingUsage from the given config.
|
|
func NewBillingUsageClient(c config) *BillingUsageClient {
|
|
return &BillingUsageClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `billingusage.Hooks(f(g(h())))`.
|
|
func (c *BillingUsageClient) Use(hooks ...Hook) {
|
|
c.hooks.BillingUsage = append(c.hooks.BillingUsage, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `billingusage.Intercept(f(g(h())))`.
|
|
func (c *BillingUsageClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.BillingUsage = append(c.inters.BillingUsage, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a BillingUsage entity.
|
|
func (c *BillingUsageClient) Create() *BillingUsageCreate {
|
|
mutation := newBillingUsageMutation(c.config, OpCreate)
|
|
return &BillingUsageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of BillingUsage entities.
|
|
func (c *BillingUsageClient) CreateBulk(builders ...*BillingUsageCreate) *BillingUsageCreateBulk {
|
|
return &BillingUsageCreateBulk{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 *BillingUsageClient) MapCreateBulk(slice any, setFunc func(*BillingUsageCreate, int)) *BillingUsageCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &BillingUsageCreateBulk{err: fmt.Errorf("calling to BillingUsageClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*BillingUsageCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &BillingUsageCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for BillingUsage.
|
|
func (c *BillingUsageClient) Update() *BillingUsageUpdate {
|
|
mutation := newBillingUsageMutation(c.config, OpUpdate)
|
|
return &BillingUsageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *BillingUsageClient) UpdateOne(bu *BillingUsage) *BillingUsageUpdateOne {
|
|
mutation := newBillingUsageMutation(c.config, OpUpdateOne, withBillingUsage(bu))
|
|
return &BillingUsageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *BillingUsageClient) UpdateOneID(id string) *BillingUsageUpdateOne {
|
|
mutation := newBillingUsageMutation(c.config, OpUpdateOne, withBillingUsageID(id))
|
|
return &BillingUsageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for BillingUsage.
|
|
func (c *BillingUsageClient) Delete() *BillingUsageDelete {
|
|
mutation := newBillingUsageMutation(c.config, OpDelete)
|
|
return &BillingUsageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *BillingUsageClient) DeleteOne(bu *BillingUsage) *BillingUsageDeleteOne {
|
|
return c.DeleteOneID(bu.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *BillingUsageClient) DeleteOneID(id string) *BillingUsageDeleteOne {
|
|
builder := c.Delete().Where(billingusage.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &BillingUsageDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for BillingUsage.
|
|
func (c *BillingUsageClient) Query() *BillingUsageQuery {
|
|
return &BillingUsageQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeBillingUsage},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a BillingUsage entity by its id.
|
|
func (c *BillingUsageClient) Get(ctx context.Context, id string) (*BillingUsage, error) {
|
|
return c.Query().Where(billingusage.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *BillingUsageClient) GetX(ctx context.Context, id string) *BillingUsage {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *BillingUsageClient) Hooks() []Hook {
|
|
hooks := c.hooks.BillingUsage
|
|
return append(hooks[:len(hooks):len(hooks)], billingusage.Hooks[:]...)
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *BillingUsageClient) Interceptors() []Interceptor {
|
|
inters := c.inters.BillingUsage
|
|
return append(inters[:len(inters):len(inters)], billingusage.Interceptors[:]...)
|
|
}
|
|
|
|
func (c *BillingUsageClient) mutate(ctx context.Context, m *BillingUsageMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&BillingUsageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&BillingUsageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&BillingUsageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&BillingUsageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown BillingUsage mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// InviteCodeClient is a client for the InviteCode schema.
|
|
type InviteCodeClient struct {
|
|
config
|
|
}
|
|
|
|
// NewInviteCodeClient returns a client for the InviteCode from the given config.
|
|
func NewInviteCodeClient(c config) *InviteCodeClient {
|
|
return &InviteCodeClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `invitecode.Hooks(f(g(h())))`.
|
|
func (c *InviteCodeClient) Use(hooks ...Hook) {
|
|
c.hooks.InviteCode = append(c.hooks.InviteCode, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `invitecode.Intercept(f(g(h())))`.
|
|
func (c *InviteCodeClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.InviteCode = append(c.inters.InviteCode, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a InviteCode entity.
|
|
func (c *InviteCodeClient) Create() *InviteCodeCreate {
|
|
mutation := newInviteCodeMutation(c.config, OpCreate)
|
|
return &InviteCodeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of InviteCode entities.
|
|
func (c *InviteCodeClient) CreateBulk(builders ...*InviteCodeCreate) *InviteCodeCreateBulk {
|
|
return &InviteCodeCreateBulk{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 *InviteCodeClient) MapCreateBulk(slice any, setFunc func(*InviteCodeCreate, int)) *InviteCodeCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &InviteCodeCreateBulk{err: fmt.Errorf("calling to InviteCodeClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*InviteCodeCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &InviteCodeCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for InviteCode.
|
|
func (c *InviteCodeClient) Update() *InviteCodeUpdate {
|
|
mutation := newInviteCodeMutation(c.config, OpUpdate)
|
|
return &InviteCodeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *InviteCodeClient) UpdateOne(ic *InviteCode) *InviteCodeUpdateOne {
|
|
mutation := newInviteCodeMutation(c.config, OpUpdateOne, withInviteCode(ic))
|
|
return &InviteCodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *InviteCodeClient) UpdateOneID(id uuid.UUID) *InviteCodeUpdateOne {
|
|
mutation := newInviteCodeMutation(c.config, OpUpdateOne, withInviteCodeID(id))
|
|
return &InviteCodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for InviteCode.
|
|
func (c *InviteCodeClient) Delete() *InviteCodeDelete {
|
|
mutation := newInviteCodeMutation(c.config, OpDelete)
|
|
return &InviteCodeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *InviteCodeClient) DeleteOne(ic *InviteCode) *InviteCodeDeleteOne {
|
|
return c.DeleteOneID(ic.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *InviteCodeClient) DeleteOneID(id uuid.UUID) *InviteCodeDeleteOne {
|
|
builder := c.Delete().Where(invitecode.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &InviteCodeDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for InviteCode.
|
|
func (c *InviteCodeClient) Query() *InviteCodeQuery {
|
|
return &InviteCodeQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeInviteCode},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a InviteCode entity by its id.
|
|
func (c *InviteCodeClient) Get(ctx context.Context, id uuid.UUID) (*InviteCode, error) {
|
|
return c.Query().Where(invitecode.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *InviteCodeClient) GetX(ctx context.Context, id uuid.UUID) *InviteCode {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *InviteCodeClient) Hooks() []Hook {
|
|
return c.hooks.InviteCode
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *InviteCodeClient) Interceptors() []Interceptor {
|
|
return c.inters.InviteCode
|
|
}
|
|
|
|
func (c *InviteCodeClient) mutate(ctx context.Context, m *InviteCodeMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&InviteCodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&InviteCodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&InviteCodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&InviteCodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown InviteCode mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// ModelClient is a client for the Model schema.
|
|
type ModelClient struct {
|
|
config
|
|
}
|
|
|
|
// NewModelClient returns a client for the Model from the given config.
|
|
func NewModelClient(c config) *ModelClient {
|
|
return &ModelClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `model.Hooks(f(g(h())))`.
|
|
func (c *ModelClient) Use(hooks ...Hook) {
|
|
c.hooks.Model = append(c.hooks.Model, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `model.Intercept(f(g(h())))`.
|
|
func (c *ModelClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Model = append(c.inters.Model, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Model entity.
|
|
func (c *ModelClient) Create() *ModelCreate {
|
|
mutation := newModelMutation(c.config, OpCreate)
|
|
return &ModelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Model entities.
|
|
func (c *ModelClient) CreateBulk(builders ...*ModelCreate) *ModelCreateBulk {
|
|
return &ModelCreateBulk{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 *ModelClient) MapCreateBulk(slice any, setFunc func(*ModelCreate, int)) *ModelCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &ModelCreateBulk{err: fmt.Errorf("calling to ModelClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*ModelCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &ModelCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Model.
|
|
func (c *ModelClient) Update() *ModelUpdate {
|
|
mutation := newModelMutation(c.config, OpUpdate)
|
|
return &ModelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *ModelClient) UpdateOne(m *Model) *ModelUpdateOne {
|
|
mutation := newModelMutation(c.config, OpUpdateOne, withModel(m))
|
|
return &ModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *ModelClient) UpdateOneID(id uuid.UUID) *ModelUpdateOne {
|
|
mutation := newModelMutation(c.config, OpUpdateOne, withModelID(id))
|
|
return &ModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Model.
|
|
func (c *ModelClient) Delete() *ModelDelete {
|
|
mutation := newModelMutation(c.config, OpDelete)
|
|
return &ModelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *ModelClient) DeleteOne(m *Model) *ModelDeleteOne {
|
|
return c.DeleteOneID(m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *ModelClient) DeleteOneID(id uuid.UUID) *ModelDeleteOne {
|
|
builder := c.Delete().Where(model.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &ModelDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Model.
|
|
func (c *ModelClient) Query() *ModelQuery {
|
|
return &ModelQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeModel},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Model entity by its id.
|
|
func (c *ModelClient) Get(ctx context.Context, id uuid.UUID) (*Model, error) {
|
|
return c.Query().Where(model.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *ModelClient) GetX(ctx context.Context, id uuid.UUID) *Model {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryRecords queries the records edge of a Model.
|
|
func (c *ModelClient) QueryRecords(m *Model) *RecordQuery {
|
|
query := (&RecordClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(model.Table, model.FieldID, id),
|
|
sqlgraph.To(record.Table, record.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, model.RecordsTable, model.RecordsColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryUser queries the user edge of a Model.
|
|
func (c *ModelClient) QueryUser(m *Model) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(model.Table, model.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, model.UserTable, model.UserColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *ModelClient) Hooks() []Hook {
|
|
return c.hooks.Model
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *ModelClient) Interceptors() []Interceptor {
|
|
return c.inters.Model
|
|
}
|
|
|
|
func (c *ModelClient) mutate(ctx context.Context, m *ModelMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&ModelCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&ModelUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&ModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&ModelDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown Model mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// RecordClient is a client for the Record schema.
|
|
type RecordClient struct {
|
|
config
|
|
}
|
|
|
|
// NewRecordClient returns a client for the Record from the given config.
|
|
func NewRecordClient(c config) *RecordClient {
|
|
return &RecordClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `record.Hooks(f(g(h())))`.
|
|
func (c *RecordClient) Use(hooks ...Hook) {
|
|
c.hooks.Record = append(c.hooks.Record, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `record.Intercept(f(g(h())))`.
|
|
func (c *RecordClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Record = append(c.inters.Record, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Record entity.
|
|
func (c *RecordClient) Create() *RecordCreate {
|
|
mutation := newRecordMutation(c.config, OpCreate)
|
|
return &RecordCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Record entities.
|
|
func (c *RecordClient) CreateBulk(builders ...*RecordCreate) *RecordCreateBulk {
|
|
return &RecordCreateBulk{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 *RecordClient) MapCreateBulk(slice any, setFunc func(*RecordCreate, int)) *RecordCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &RecordCreateBulk{err: fmt.Errorf("calling to RecordClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*RecordCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &RecordCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Record.
|
|
func (c *RecordClient) Update() *RecordUpdate {
|
|
mutation := newRecordMutation(c.config, OpUpdate)
|
|
return &RecordUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *RecordClient) UpdateOne(r *Record) *RecordUpdateOne {
|
|
mutation := newRecordMutation(c.config, OpUpdateOne, withRecord(r))
|
|
return &RecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *RecordClient) UpdateOneID(id uuid.UUID) *RecordUpdateOne {
|
|
mutation := newRecordMutation(c.config, OpUpdateOne, withRecordID(id))
|
|
return &RecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Record.
|
|
func (c *RecordClient) Delete() *RecordDelete {
|
|
mutation := newRecordMutation(c.config, OpDelete)
|
|
return &RecordDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *RecordClient) DeleteOne(r *Record) *RecordDeleteOne {
|
|
return c.DeleteOneID(r.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *RecordClient) DeleteOneID(id uuid.UUID) *RecordDeleteOne {
|
|
builder := c.Delete().Where(record.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &RecordDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Record.
|
|
func (c *RecordClient) Query() *RecordQuery {
|
|
return &RecordQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeRecord},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Record entity by its id.
|
|
func (c *RecordClient) Get(ctx context.Context, id uuid.UUID) (*Record, error) {
|
|
return c.Query().Where(record.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *RecordClient) GetX(ctx context.Context, id uuid.UUID) *Record {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryUser queries the user edge of a Record.
|
|
func (c *RecordClient) QueryUser(r *Record) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := r.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(record.Table, record.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, record.UserTable, record.UserColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(r.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryModel queries the model edge of a Record.
|
|
func (c *RecordClient) QueryModel(r *Record) *ModelQuery {
|
|
query := (&ModelClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := r.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(record.Table, record.FieldID, id),
|
|
sqlgraph.To(model.Table, model.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, record.ModelTable, record.ModelColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(r.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *RecordClient) Hooks() []Hook {
|
|
return c.hooks.Record
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *RecordClient) Interceptors() []Interceptor {
|
|
return c.inters.Record
|
|
}
|
|
|
|
func (c *RecordClient) mutate(ctx context.Context, m *RecordMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&RecordCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&RecordUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&RecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&RecordDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown Record mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// SettingClient is a client for the Setting schema.
|
|
type SettingClient struct {
|
|
config
|
|
}
|
|
|
|
// NewSettingClient returns a client for the Setting from the given config.
|
|
func NewSettingClient(c config) *SettingClient {
|
|
return &SettingClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `setting.Hooks(f(g(h())))`.
|
|
func (c *SettingClient) Use(hooks ...Hook) {
|
|
c.hooks.Setting = append(c.hooks.Setting, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `setting.Intercept(f(g(h())))`.
|
|
func (c *SettingClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Setting = append(c.inters.Setting, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Setting entity.
|
|
func (c *SettingClient) Create() *SettingCreate {
|
|
mutation := newSettingMutation(c.config, OpCreate)
|
|
return &SettingCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Setting entities.
|
|
func (c *SettingClient) CreateBulk(builders ...*SettingCreate) *SettingCreateBulk {
|
|
return &SettingCreateBulk{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 *SettingClient) MapCreateBulk(slice any, setFunc func(*SettingCreate, int)) *SettingCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &SettingCreateBulk{err: fmt.Errorf("calling to SettingClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*SettingCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &SettingCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Setting.
|
|
func (c *SettingClient) Update() *SettingUpdate {
|
|
mutation := newSettingMutation(c.config, OpUpdate)
|
|
return &SettingUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *SettingClient) UpdateOne(s *Setting) *SettingUpdateOne {
|
|
mutation := newSettingMutation(c.config, OpUpdateOne, withSetting(s))
|
|
return &SettingUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *SettingClient) UpdateOneID(id uuid.UUID) *SettingUpdateOne {
|
|
mutation := newSettingMutation(c.config, OpUpdateOne, withSettingID(id))
|
|
return &SettingUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Setting.
|
|
func (c *SettingClient) Delete() *SettingDelete {
|
|
mutation := newSettingMutation(c.config, OpDelete)
|
|
return &SettingDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *SettingClient) DeleteOne(s *Setting) *SettingDeleteOne {
|
|
return c.DeleteOneID(s.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *SettingClient) DeleteOneID(id uuid.UUID) *SettingDeleteOne {
|
|
builder := c.Delete().Where(setting.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &SettingDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Setting.
|
|
func (c *SettingClient) Query() *SettingQuery {
|
|
return &SettingQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeSetting},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Setting entity by its id.
|
|
func (c *SettingClient) Get(ctx context.Context, id uuid.UUID) (*Setting, error) {
|
|
return c.Query().Where(setting.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *SettingClient) GetX(ctx context.Context, id uuid.UUID) *Setting {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *SettingClient) Hooks() []Hook {
|
|
return c.hooks.Setting
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *SettingClient) Interceptors() []Interceptor {
|
|
return c.inters.Setting
|
|
}
|
|
|
|
func (c *SettingClient) mutate(ctx context.Context, m *SettingMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&SettingCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&SettingUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&SettingUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&SettingDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown Setting 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 uuid.UUID) *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 uuid.UUID) *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 uuid.UUID) (*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 uuid.UUID) *User {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryRecords queries the records edge of a User.
|
|
func (c *UserClient) QueryRecords(u *User) *RecordQuery {
|
|
query := (&RecordClient{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(record.Table, record.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, user.RecordsTable, user.RecordsColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryLoginHistories queries the login_histories edge of a User.
|
|
func (c *UserClient) QueryLoginHistories(u *User) *UserLoginHistoryQuery {
|
|
query := (&UserLoginHistoryClient{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(userloginhistory.Table, userloginhistory.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, user.LoginHistoriesTable, user.LoginHistoriesColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryModels queries the models edge of a User.
|
|
func (c *UserClient) QueryModels(u *User) *ModelQuery {
|
|
query := (&ModelClient{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(model.Table, model.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, user.ModelsTable, user.ModelsColumn),
|
|
)
|
|
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("db: unknown User mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// UserLoginHistoryClient is a client for the UserLoginHistory schema.
|
|
type UserLoginHistoryClient struct {
|
|
config
|
|
}
|
|
|
|
// NewUserLoginHistoryClient returns a client for the UserLoginHistory from the given config.
|
|
func NewUserLoginHistoryClient(c config) *UserLoginHistoryClient {
|
|
return &UserLoginHistoryClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `userloginhistory.Hooks(f(g(h())))`.
|
|
func (c *UserLoginHistoryClient) Use(hooks ...Hook) {
|
|
c.hooks.UserLoginHistory = append(c.hooks.UserLoginHistory, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `userloginhistory.Intercept(f(g(h())))`.
|
|
func (c *UserLoginHistoryClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.UserLoginHistory = append(c.inters.UserLoginHistory, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a UserLoginHistory entity.
|
|
func (c *UserLoginHistoryClient) Create() *UserLoginHistoryCreate {
|
|
mutation := newUserLoginHistoryMutation(c.config, OpCreate)
|
|
return &UserLoginHistoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of UserLoginHistory entities.
|
|
func (c *UserLoginHistoryClient) CreateBulk(builders ...*UserLoginHistoryCreate) *UserLoginHistoryCreateBulk {
|
|
return &UserLoginHistoryCreateBulk{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 *UserLoginHistoryClient) MapCreateBulk(slice any, setFunc func(*UserLoginHistoryCreate, int)) *UserLoginHistoryCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &UserLoginHistoryCreateBulk{err: fmt.Errorf("calling to UserLoginHistoryClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*UserLoginHistoryCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &UserLoginHistoryCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for UserLoginHistory.
|
|
func (c *UserLoginHistoryClient) Update() *UserLoginHistoryUpdate {
|
|
mutation := newUserLoginHistoryMutation(c.config, OpUpdate)
|
|
return &UserLoginHistoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *UserLoginHistoryClient) UpdateOne(ulh *UserLoginHistory) *UserLoginHistoryUpdateOne {
|
|
mutation := newUserLoginHistoryMutation(c.config, OpUpdateOne, withUserLoginHistory(ulh))
|
|
return &UserLoginHistoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *UserLoginHistoryClient) UpdateOneID(id uuid.UUID) *UserLoginHistoryUpdateOne {
|
|
mutation := newUserLoginHistoryMutation(c.config, OpUpdateOne, withUserLoginHistoryID(id))
|
|
return &UserLoginHistoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for UserLoginHistory.
|
|
func (c *UserLoginHistoryClient) Delete() *UserLoginHistoryDelete {
|
|
mutation := newUserLoginHistoryMutation(c.config, OpDelete)
|
|
return &UserLoginHistoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *UserLoginHistoryClient) DeleteOne(ulh *UserLoginHistory) *UserLoginHistoryDeleteOne {
|
|
return c.DeleteOneID(ulh.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *UserLoginHistoryClient) DeleteOneID(id uuid.UUID) *UserLoginHistoryDeleteOne {
|
|
builder := c.Delete().Where(userloginhistory.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &UserLoginHistoryDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for UserLoginHistory.
|
|
func (c *UserLoginHistoryClient) Query() *UserLoginHistoryQuery {
|
|
return &UserLoginHistoryQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeUserLoginHistory},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a UserLoginHistory entity by its id.
|
|
func (c *UserLoginHistoryClient) Get(ctx context.Context, id uuid.UUID) (*UserLoginHistory, error) {
|
|
return c.Query().Where(userloginhistory.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *UserLoginHistoryClient) GetX(ctx context.Context, id uuid.UUID) *UserLoginHistory {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryOwner queries the owner edge of a UserLoginHistory.
|
|
func (c *UserLoginHistoryClient) QueryOwner(ulh *UserLoginHistory) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := ulh.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(userloginhistory.Table, userloginhistory.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, userloginhistory.OwnerTable, userloginhistory.OwnerColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(ulh.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *UserLoginHistoryClient) Hooks() []Hook {
|
|
return c.hooks.UserLoginHistory
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *UserLoginHistoryClient) Interceptors() []Interceptor {
|
|
return c.inters.UserLoginHistory
|
|
}
|
|
|
|
func (c *UserLoginHistoryClient) mutate(ctx context.Context, m *UserLoginHistoryMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&UserLoginHistoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&UserLoginHistoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&UserLoginHistoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&UserLoginHistoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("db: unknown UserLoginHistory mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// hooks and interceptors per client, for fast access.
|
|
type (
|
|
hooks struct {
|
|
Admin, AdminLoginHistory, ApiKey, BillingPlan, BillingQuota, BillingRecord,
|
|
BillingUsage, InviteCode, Model, Record, Setting, User,
|
|
UserLoginHistory []ent.Hook
|
|
}
|
|
inters struct {
|
|
Admin, AdminLoginHistory, ApiKey, BillingPlan, BillingQuota, BillingRecord,
|
|
BillingUsage, InviteCode, Model, Record, Setting, User,
|
|
UserLoginHistory []ent.Interceptor
|
|
}
|
|
)
|
|
|
|
// ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it.
|
|
// See, database/sql#DB.ExecContext for more information.
|
|
func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
|
|
ex, ok := c.driver.(interface {
|
|
ExecContext(context.Context, string, ...any) (stdsql.Result, error)
|
|
})
|
|
if !ok {
|
|
return nil, fmt.Errorf("Driver.ExecContext is not supported")
|
|
}
|
|
return ex.ExecContext(ctx, query, args...)
|
|
}
|
|
|
|
// QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it.
|
|
// See, database/sql#DB.QueryContext for more information.
|
|
func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
|
|
q, ok := c.driver.(interface {
|
|
QueryContext(context.Context, string, ...any) (*stdsql.Rows, error)
|
|
})
|
|
if !ok {
|
|
return nil, fmt.Errorf("Driver.QueryContext is not supported")
|
|
}
|
|
return q.QueryContext(ctx, query, args...)
|
|
}
|