// Code generated by entc, DO NOT EDIT. package ent import ( "context" "fmt" "log" "github.com/kallydev/privacy/ent/migrate" "github.com/kallydev/privacy/ent/jdmodel" "github.com/kallydev/privacy/ent/qqmodel" "github.com/kallydev/privacy/ent/sfmodel" "github.com/facebook/ent/dialect" "github.com/facebook/ent/dialect/sql" ) // Client is the client that holds all ent builders. type Client struct { config // Schema is the client for creating, migrating and dropping schema. Schema *migrate.Schema // JDModel is the client for interacting with the JDModel builders. JDModel *JDModelClient // QQModel is the client for interacting with the QQModel builders. QQModel *QQModelClient // SFModel is the client for interacting with the SFModel builders. SFModel *SFModelClient } // NewClient creates a new client configured with the given options. func NewClient(opts ...Option) *Client { cfg := config{log: log.Println, hooks: &hooks{}} cfg.options(opts...) client := &Client{config: cfg} client.init() return client } func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) c.JDModel = NewJDModelClient(c.config) c.QQModel = NewQQModelClient(c.config) c.SFModel = NewSFModelClient(c.config) } // Open opens a database/sql.DB specified by the driver name and // the data source name, and returns a new client attached to it. // Optional parameters can be added for configuring the client. func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { switch driverName { case dialect.MySQL, dialect.Postgres, dialect.SQLite: drv, err := sql.Open(driverName, dataSourceName) if err != nil { return nil, err } return NewClient(append(options, Driver(drv))...), nil default: return nil, fmt.Errorf("unsupported driver: %q", driverName) } } // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") } tx, err := newTx(ctx, c.driver) if err != nil { return nil, fmt.Errorf("ent: starting a transaction: %v", err) } cfg := config{driver: tx, log: c.log, debug: c.debug, hooks: c.hooks} return &Tx{ ctx: ctx, config: cfg, JDModel: NewJDModelClient(cfg), QQModel: NewQQModelClient(cfg), SFModel: NewSFModelClient(cfg), }, nil } // BeginTx returns a transactional client with options. func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") } tx, err := c.driver.(*sql.Driver).BeginTx(ctx, opts) if err != nil { return nil, fmt.Errorf("ent: starting a transaction: %v", err) } cfg := config{driver: &txDriver{tx: tx, drv: c.driver}, log: c.log, debug: c.debug, hooks: c.hooks} return &Tx{ config: cfg, JDModel: NewJDModelClient(cfg), QQModel: NewQQModelClient(cfg), SFModel: NewSFModelClient(cfg), }, nil } // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). // JDModel. // Query(). // Count(ctx) // func (c *Client) Debug() *Client { if c.debug { return c } cfg := config{driver: dialect.Debug(c.driver, c.log), log: c.log, debug: true, hooks: c.hooks} client := &Client{config: cfg} client.init() return client } // Close closes the database connection and prevents new queries from starting. func (c *Client) Close() error { return c.driver.Close() } // Use adds the mutation hooks to all the entity clients. // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { c.JDModel.Use(hooks...) c.QQModel.Use(hooks...) c.SFModel.Use(hooks...) } // JDModelClient is a client for the JDModel schema. type JDModelClient struct { config } // NewJDModelClient returns a client for the JDModel from the given config. func NewJDModelClient(c config) *JDModelClient { return &JDModelClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `jdmodel.Hooks(f(g(h())))`. func (c *JDModelClient) Use(hooks ...Hook) { c.hooks.JDModel = append(c.hooks.JDModel, hooks...) } // Create returns a create builder for JDModel. func (c *JDModelClient) Create() *JDModelCreate { mutation := newJDModelMutation(c.config, OpCreate) return &JDModelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // BulkCreate returns a builder for creating a bulk of JDModel entities. func (c *JDModelClient) CreateBulk(builders ...*JDModelCreate) *JDModelCreateBulk { return &JDModelCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for JDModel. func (c *JDModelClient) Update() *JDModelUpdate { mutation := newJDModelMutation(c.config, OpUpdate) return &JDModelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *JDModelClient) UpdateOne(jm *JDModel) *JDModelUpdateOne { mutation := newJDModelMutation(c.config, OpUpdateOne, withJDModel(jm)) return &JDModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *JDModelClient) UpdateOneID(id int) *JDModelUpdateOne { mutation := newJDModelMutation(c.config, OpUpdateOne, withJDModelID(id)) return &JDModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for JDModel. func (c *JDModelClient) Delete() *JDModelDelete { mutation := newJDModelMutation(c.config, OpDelete) return &JDModelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a delete builder for the given entity. func (c *JDModelClient) DeleteOne(jm *JDModel) *JDModelDeleteOne { return c.DeleteOneID(jm.ID) } // DeleteOneID returns a delete builder for the given id. func (c *JDModelClient) DeleteOneID(id int) *JDModelDeleteOne { builder := c.Delete().Where(jdmodel.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &JDModelDeleteOne{builder} } // Query returns a query builder for JDModel. func (c *JDModelClient) Query() *JDModelQuery { return &JDModelQuery{config: c.config} } // Get returns a JDModel entity by its id. func (c *JDModelClient) Get(ctx context.Context, id int) (*JDModel, error) { return c.Query().Where(jdmodel.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *JDModelClient) GetX(ctx context.Context, id int) *JDModel { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *JDModelClient) Hooks() []Hook { return c.hooks.JDModel } // QQModelClient is a client for the QQModel schema. type QQModelClient struct { config } // NewQQModelClient returns a client for the QQModel from the given config. func NewQQModelClient(c config) *QQModelClient { return &QQModelClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `qqmodel.Hooks(f(g(h())))`. func (c *QQModelClient) Use(hooks ...Hook) { c.hooks.QQModel = append(c.hooks.QQModel, hooks...) } // Create returns a create builder for QQModel. func (c *QQModelClient) Create() *QQModelCreate { mutation := newQQModelMutation(c.config, OpCreate) return &QQModelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // BulkCreate returns a builder for creating a bulk of QQModel entities. func (c *QQModelClient) CreateBulk(builders ...*QQModelCreate) *QQModelCreateBulk { return &QQModelCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for QQModel. func (c *QQModelClient) Update() *QQModelUpdate { mutation := newQQModelMutation(c.config, OpUpdate) return &QQModelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *QQModelClient) UpdateOne(qm *QQModel) *QQModelUpdateOne { mutation := newQQModelMutation(c.config, OpUpdateOne, withQQModel(qm)) return &QQModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *QQModelClient) UpdateOneID(id int) *QQModelUpdateOne { mutation := newQQModelMutation(c.config, OpUpdateOne, withQQModelID(id)) return &QQModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for QQModel. func (c *QQModelClient) Delete() *QQModelDelete { mutation := newQQModelMutation(c.config, OpDelete) return &QQModelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a delete builder for the given entity. func (c *QQModelClient) DeleteOne(qm *QQModel) *QQModelDeleteOne { return c.DeleteOneID(qm.ID) } // DeleteOneID returns a delete builder for the given id. func (c *QQModelClient) DeleteOneID(id int) *QQModelDeleteOne { builder := c.Delete().Where(qqmodel.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &QQModelDeleteOne{builder} } // Query returns a query builder for QQModel. func (c *QQModelClient) Query() *QQModelQuery { return &QQModelQuery{config: c.config} } // Get returns a QQModel entity by its id. func (c *QQModelClient) Get(ctx context.Context, id int) (*QQModel, error) { return c.Query().Where(qqmodel.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *QQModelClient) GetX(ctx context.Context, id int) *QQModel { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *QQModelClient) Hooks() []Hook { return c.hooks.QQModel } // SFModelClient is a client for the SFModel schema. type SFModelClient struct { config } // NewSFModelClient returns a client for the SFModel from the given config. func NewSFModelClient(c config) *SFModelClient { return &SFModelClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `sfmodel.Hooks(f(g(h())))`. func (c *SFModelClient) Use(hooks ...Hook) { c.hooks.SFModel = append(c.hooks.SFModel, hooks...) } // Create returns a create builder for SFModel. func (c *SFModelClient) Create() *SFModelCreate { mutation := newSFModelMutation(c.config, OpCreate) return &SFModelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // BulkCreate returns a builder for creating a bulk of SFModel entities. func (c *SFModelClient) CreateBulk(builders ...*SFModelCreate) *SFModelCreateBulk { return &SFModelCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for SFModel. func (c *SFModelClient) Update() *SFModelUpdate { mutation := newSFModelMutation(c.config, OpUpdate) return &SFModelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *SFModelClient) UpdateOne(sm *SFModel) *SFModelUpdateOne { mutation := newSFModelMutation(c.config, OpUpdateOne, withSFModel(sm)) return &SFModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *SFModelClient) UpdateOneID(id int) *SFModelUpdateOne { mutation := newSFModelMutation(c.config, OpUpdateOne, withSFModelID(id)) return &SFModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for SFModel. func (c *SFModelClient) Delete() *SFModelDelete { mutation := newSFModelMutation(c.config, OpDelete) return &SFModelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a delete builder for the given entity. func (c *SFModelClient) DeleteOne(sm *SFModel) *SFModelDeleteOne { return c.DeleteOneID(sm.ID) } // DeleteOneID returns a delete builder for the given id. func (c *SFModelClient) DeleteOneID(id int) *SFModelDeleteOne { builder := c.Delete().Where(sfmodel.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &SFModelDeleteOne{builder} } // Query returns a query builder for SFModel. func (c *SFModelClient) Query() *SFModelQuery { return &SFModelQuery{config: c.config} } // Get returns a SFModel entity by its id. func (c *SFModelClient) Get(ctx context.Context, id int) (*SFModel, error) { return c.Query().Where(sfmodel.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *SFModelClient) GetX(ctx context.Context, id int) *SFModel { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *SFModelClient) Hooks() []Hook { return c.hooks.SFModel }