805 lines
27 KiB
Go
805 lines
27 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"reflect"
|
|
|
|
"voidraft/internal/models/ent/migrate"
|
|
|
|
"voidraft/internal/models/ent/document"
|
|
"voidraft/internal/models/ent/extension"
|
|
"voidraft/internal/models/ent/keybinding"
|
|
"voidraft/internal/models/ent/theme"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
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
|
|
// Document is the client for interacting with the Document builders.
|
|
Document *DocumentClient
|
|
// Extension is the client for interacting with the Extension builders.
|
|
Extension *ExtensionClient
|
|
// KeyBinding is the client for interacting with the KeyBinding builders.
|
|
KeyBinding *KeyBindingClient
|
|
// Theme is the client for interacting with the Theme builders.
|
|
Theme *ThemeClient
|
|
}
|
|
|
|
// 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.Document = NewDocumentClient(c.config)
|
|
c.Extension = NewExtensionClient(c.config)
|
|
c.KeyBinding = NewKeyBindingClient(c.config)
|
|
c.Theme = NewThemeClient(c.config)
|
|
}
|
|
|
|
type (
|
|
// config is the configuration for the client and its builder.
|
|
config struct {
|
|
// driver used for executing database requests.
|
|
driver dialect.Driver
|
|
// debug enable a debug logging.
|
|
debug bool
|
|
// log used for logging on debug mode.
|
|
log func(...any)
|
|
// hooks to execute on mutations.
|
|
hooks *hooks
|
|
// interceptors to execute on queries.
|
|
inters *inters
|
|
}
|
|
// Option function to configure the client.
|
|
Option func(*config)
|
|
)
|
|
|
|
// newConfig creates a new config for the client.
|
|
func newConfig(opts ...Option) config {
|
|
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
|
cfg.options(opts...)
|
|
return cfg
|
|
}
|
|
|
|
// options applies the options on the config object.
|
|
func (c *config) options(opts ...Option) {
|
|
for _, opt := range opts {
|
|
opt(c)
|
|
}
|
|
if c.debug {
|
|
c.driver = dialect.Debug(c.driver, c.log)
|
|
}
|
|
}
|
|
|
|
// Debug enables debug logging on the ent.Driver.
|
|
func Debug() Option {
|
|
return func(c *config) {
|
|
c.debug = true
|
|
}
|
|
}
|
|
|
|
// Log sets the logging function for debug mode.
|
|
func Log(fn func(...any)) Option {
|
|
return func(c *config) {
|
|
c.log = fn
|
|
}
|
|
}
|
|
|
|
// Driver configures the client driver.
|
|
func Driver(driver dialect.Driver) Option {
|
|
return func(c *config) {
|
|
c.driver = driver
|
|
}
|
|
}
|
|
|
|
// Open opens a database/sql.DB specified by the driver name and
|
|
// the data source name, and returns a new client attached to it.
|
|
// Optional parameters can be added for configuring the client.
|
|
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
|
switch driverName {
|
|
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
|
drv, err := sql.Open(driverName, dataSourceName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return NewClient(append(options, Driver(drv))...), nil
|
|
default:
|
|
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
|
}
|
|
}
|
|
|
|
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
|
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
|
|
|
|
// Tx returns a new transactional client. The provided context
|
|
// is used until the transaction is committed or rolled back.
|
|
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
|
if _, ok := c.driver.(*txDriver); ok {
|
|
return nil, ErrTxStarted
|
|
}
|
|
tx, err := newTx(ctx, c.driver)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
|
}
|
|
cfg := c.config
|
|
cfg.driver = tx
|
|
return &Tx{
|
|
ctx: ctx,
|
|
config: cfg,
|
|
Document: NewDocumentClient(cfg),
|
|
Extension: NewExtensionClient(cfg),
|
|
KeyBinding: NewKeyBindingClient(cfg),
|
|
Theme: NewThemeClient(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,
|
|
Document: NewDocumentClient(cfg),
|
|
Extension: NewExtensionClient(cfg),
|
|
KeyBinding: NewKeyBindingClient(cfg),
|
|
Theme: NewThemeClient(cfg),
|
|
}, nil
|
|
}
|
|
|
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
|
//
|
|
// client.Debug().
|
|
// Document.
|
|
// Query().
|
|
// Count(ctx)
|
|
func (c *Client) Debug() *Client {
|
|
if c.debug {
|
|
return c
|
|
}
|
|
cfg := c.config
|
|
cfg.driver = dialect.Debug(c.driver, c.log)
|
|
client := &Client{config: cfg}
|
|
client.init()
|
|
return client
|
|
}
|
|
|
|
// Close closes the database connection and prevents new queries from starting.
|
|
func (c *Client) Close() error {
|
|
return c.driver.Close()
|
|
}
|
|
|
|
// Use adds the mutation hooks to all the entity clients.
|
|
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
|
func (c *Client) Use(hooks ...Hook) {
|
|
c.Document.Use(hooks...)
|
|
c.Extension.Use(hooks...)
|
|
c.KeyBinding.Use(hooks...)
|
|
c.Theme.Use(hooks...)
|
|
}
|
|
|
|
// Intercept adds the query interceptors to all the entity clients.
|
|
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
|
c.Document.Intercept(interceptors...)
|
|
c.Extension.Intercept(interceptors...)
|
|
c.KeyBinding.Intercept(interceptors...)
|
|
c.Theme.Intercept(interceptors...)
|
|
}
|
|
|
|
// Mutate implements the ent.Mutator interface.
|
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
|
switch m := m.(type) {
|
|
case *DocumentMutation:
|
|
return c.Document.mutate(ctx, m)
|
|
case *ExtensionMutation:
|
|
return c.Extension.mutate(ctx, m)
|
|
case *KeyBindingMutation:
|
|
return c.KeyBinding.mutate(ctx, m)
|
|
case *ThemeMutation:
|
|
return c.Theme.mutate(ctx, m)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
|
}
|
|
}
|
|
|
|
// DocumentClient is a client for the Document schema.
|
|
type DocumentClient struct {
|
|
config
|
|
}
|
|
|
|
// NewDocumentClient returns a client for the Document from the given config.
|
|
func NewDocumentClient(c config) *DocumentClient {
|
|
return &DocumentClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `document.Hooks(f(g(h())))`.
|
|
func (c *DocumentClient) Use(hooks ...Hook) {
|
|
c.hooks.Document = append(c.hooks.Document, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `document.Intercept(f(g(h())))`.
|
|
func (c *DocumentClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Document = append(c.inters.Document, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Document entity.
|
|
func (c *DocumentClient) Create() *DocumentCreate {
|
|
mutation := newDocumentMutation(c.config, OpCreate)
|
|
return &DocumentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Document entities.
|
|
func (c *DocumentClient) CreateBulk(builders ...*DocumentCreate) *DocumentCreateBulk {
|
|
return &DocumentCreateBulk{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 *DocumentClient) MapCreateBulk(slice any, setFunc func(*DocumentCreate, int)) *DocumentCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &DocumentCreateBulk{err: fmt.Errorf("calling to DocumentClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*DocumentCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &DocumentCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Document.
|
|
func (c *DocumentClient) Update() *DocumentUpdate {
|
|
mutation := newDocumentMutation(c.config, OpUpdate)
|
|
return &DocumentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *DocumentClient) UpdateOne(_m *Document) *DocumentUpdateOne {
|
|
mutation := newDocumentMutation(c.config, OpUpdateOne, withDocument(_m))
|
|
return &DocumentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *DocumentClient) UpdateOneID(id int) *DocumentUpdateOne {
|
|
mutation := newDocumentMutation(c.config, OpUpdateOne, withDocumentID(id))
|
|
return &DocumentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Document.
|
|
func (c *DocumentClient) Delete() *DocumentDelete {
|
|
mutation := newDocumentMutation(c.config, OpDelete)
|
|
return &DocumentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *DocumentClient) DeleteOne(_m *Document) *DocumentDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *DocumentClient) DeleteOneID(id int) *DocumentDeleteOne {
|
|
builder := c.Delete().Where(document.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &DocumentDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Document.
|
|
func (c *DocumentClient) Query() *DocumentQuery {
|
|
return &DocumentQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeDocument},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Document entity by its id.
|
|
func (c *DocumentClient) Get(ctx context.Context, id int) (*Document, error) {
|
|
return c.Query().Where(document.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *DocumentClient) GetX(ctx context.Context, id int) *Document {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *DocumentClient) Hooks() []Hook {
|
|
hooks := c.hooks.Document
|
|
return append(hooks[:len(hooks):len(hooks)], document.Hooks[:]...)
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *DocumentClient) Interceptors() []Interceptor {
|
|
inters := c.inters.Document
|
|
return append(inters[:len(inters):len(inters)], document.Interceptors[:]...)
|
|
}
|
|
|
|
func (c *DocumentClient) mutate(ctx context.Context, m *DocumentMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&DocumentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&DocumentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&DocumentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&DocumentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Document mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// ExtensionClient is a client for the Extension schema.
|
|
type ExtensionClient struct {
|
|
config
|
|
}
|
|
|
|
// NewExtensionClient returns a client for the Extension from the given config.
|
|
func NewExtensionClient(c config) *ExtensionClient {
|
|
return &ExtensionClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `extension.Hooks(f(g(h())))`.
|
|
func (c *ExtensionClient) Use(hooks ...Hook) {
|
|
c.hooks.Extension = append(c.hooks.Extension, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `extension.Intercept(f(g(h())))`.
|
|
func (c *ExtensionClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Extension = append(c.inters.Extension, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Extension entity.
|
|
func (c *ExtensionClient) Create() *ExtensionCreate {
|
|
mutation := newExtensionMutation(c.config, OpCreate)
|
|
return &ExtensionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Extension entities.
|
|
func (c *ExtensionClient) CreateBulk(builders ...*ExtensionCreate) *ExtensionCreateBulk {
|
|
return &ExtensionCreateBulk{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 *ExtensionClient) MapCreateBulk(slice any, setFunc func(*ExtensionCreate, int)) *ExtensionCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &ExtensionCreateBulk{err: fmt.Errorf("calling to ExtensionClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*ExtensionCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &ExtensionCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Extension.
|
|
func (c *ExtensionClient) Update() *ExtensionUpdate {
|
|
mutation := newExtensionMutation(c.config, OpUpdate)
|
|
return &ExtensionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *ExtensionClient) UpdateOne(_m *Extension) *ExtensionUpdateOne {
|
|
mutation := newExtensionMutation(c.config, OpUpdateOne, withExtension(_m))
|
|
return &ExtensionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *ExtensionClient) UpdateOneID(id int) *ExtensionUpdateOne {
|
|
mutation := newExtensionMutation(c.config, OpUpdateOne, withExtensionID(id))
|
|
return &ExtensionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Extension.
|
|
func (c *ExtensionClient) Delete() *ExtensionDelete {
|
|
mutation := newExtensionMutation(c.config, OpDelete)
|
|
return &ExtensionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *ExtensionClient) DeleteOne(_m *Extension) *ExtensionDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *ExtensionClient) DeleteOneID(id int) *ExtensionDeleteOne {
|
|
builder := c.Delete().Where(extension.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &ExtensionDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Extension.
|
|
func (c *ExtensionClient) Query() *ExtensionQuery {
|
|
return &ExtensionQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeExtension},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Extension entity by its id.
|
|
func (c *ExtensionClient) Get(ctx context.Context, id int) (*Extension, error) {
|
|
return c.Query().Where(extension.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *ExtensionClient) GetX(ctx context.Context, id int) *Extension {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *ExtensionClient) Hooks() []Hook {
|
|
hooks := c.hooks.Extension
|
|
return append(hooks[:len(hooks):len(hooks)], extension.Hooks[:]...)
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *ExtensionClient) Interceptors() []Interceptor {
|
|
inters := c.inters.Extension
|
|
return append(inters[:len(inters):len(inters)], extension.Interceptors[:]...)
|
|
}
|
|
|
|
func (c *ExtensionClient) mutate(ctx context.Context, m *ExtensionMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&ExtensionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&ExtensionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&ExtensionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&ExtensionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Extension mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// KeyBindingClient is a client for the KeyBinding schema.
|
|
type KeyBindingClient struct {
|
|
config
|
|
}
|
|
|
|
// NewKeyBindingClient returns a client for the KeyBinding from the given config.
|
|
func NewKeyBindingClient(c config) *KeyBindingClient {
|
|
return &KeyBindingClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `keybinding.Hooks(f(g(h())))`.
|
|
func (c *KeyBindingClient) Use(hooks ...Hook) {
|
|
c.hooks.KeyBinding = append(c.hooks.KeyBinding, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `keybinding.Intercept(f(g(h())))`.
|
|
func (c *KeyBindingClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.KeyBinding = append(c.inters.KeyBinding, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a KeyBinding entity.
|
|
func (c *KeyBindingClient) Create() *KeyBindingCreate {
|
|
mutation := newKeyBindingMutation(c.config, OpCreate)
|
|
return &KeyBindingCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of KeyBinding entities.
|
|
func (c *KeyBindingClient) CreateBulk(builders ...*KeyBindingCreate) *KeyBindingCreateBulk {
|
|
return &KeyBindingCreateBulk{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 *KeyBindingClient) MapCreateBulk(slice any, setFunc func(*KeyBindingCreate, int)) *KeyBindingCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &KeyBindingCreateBulk{err: fmt.Errorf("calling to KeyBindingClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*KeyBindingCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &KeyBindingCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for KeyBinding.
|
|
func (c *KeyBindingClient) Update() *KeyBindingUpdate {
|
|
mutation := newKeyBindingMutation(c.config, OpUpdate)
|
|
return &KeyBindingUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *KeyBindingClient) UpdateOne(_m *KeyBinding) *KeyBindingUpdateOne {
|
|
mutation := newKeyBindingMutation(c.config, OpUpdateOne, withKeyBinding(_m))
|
|
return &KeyBindingUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *KeyBindingClient) UpdateOneID(id int) *KeyBindingUpdateOne {
|
|
mutation := newKeyBindingMutation(c.config, OpUpdateOne, withKeyBindingID(id))
|
|
return &KeyBindingUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for KeyBinding.
|
|
func (c *KeyBindingClient) Delete() *KeyBindingDelete {
|
|
mutation := newKeyBindingMutation(c.config, OpDelete)
|
|
return &KeyBindingDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *KeyBindingClient) DeleteOne(_m *KeyBinding) *KeyBindingDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *KeyBindingClient) DeleteOneID(id int) *KeyBindingDeleteOne {
|
|
builder := c.Delete().Where(keybinding.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &KeyBindingDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for KeyBinding.
|
|
func (c *KeyBindingClient) Query() *KeyBindingQuery {
|
|
return &KeyBindingQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeKeyBinding},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a KeyBinding entity by its id.
|
|
func (c *KeyBindingClient) Get(ctx context.Context, id int) (*KeyBinding, error) {
|
|
return c.Query().Where(keybinding.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *KeyBindingClient) GetX(ctx context.Context, id int) *KeyBinding {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *KeyBindingClient) Hooks() []Hook {
|
|
hooks := c.hooks.KeyBinding
|
|
return append(hooks[:len(hooks):len(hooks)], keybinding.Hooks[:]...)
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *KeyBindingClient) Interceptors() []Interceptor {
|
|
inters := c.inters.KeyBinding
|
|
return append(inters[:len(inters):len(inters)], keybinding.Interceptors[:]...)
|
|
}
|
|
|
|
func (c *KeyBindingClient) mutate(ctx context.Context, m *KeyBindingMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&KeyBindingCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&KeyBindingUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&KeyBindingUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&KeyBindingDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown KeyBinding mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// ThemeClient is a client for the Theme schema.
|
|
type ThemeClient struct {
|
|
config
|
|
}
|
|
|
|
// NewThemeClient returns a client for the Theme from the given config.
|
|
func NewThemeClient(c config) *ThemeClient {
|
|
return &ThemeClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `theme.Hooks(f(g(h())))`.
|
|
func (c *ThemeClient) Use(hooks ...Hook) {
|
|
c.hooks.Theme = append(c.hooks.Theme, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `theme.Intercept(f(g(h())))`.
|
|
func (c *ThemeClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Theme = append(c.inters.Theme, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Theme entity.
|
|
func (c *ThemeClient) Create() *ThemeCreate {
|
|
mutation := newThemeMutation(c.config, OpCreate)
|
|
return &ThemeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Theme entities.
|
|
func (c *ThemeClient) CreateBulk(builders ...*ThemeCreate) *ThemeCreateBulk {
|
|
return &ThemeCreateBulk{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 *ThemeClient) MapCreateBulk(slice any, setFunc func(*ThemeCreate, int)) *ThemeCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &ThemeCreateBulk{err: fmt.Errorf("calling to ThemeClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*ThemeCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &ThemeCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Theme.
|
|
func (c *ThemeClient) Update() *ThemeUpdate {
|
|
mutation := newThemeMutation(c.config, OpUpdate)
|
|
return &ThemeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *ThemeClient) UpdateOne(_m *Theme) *ThemeUpdateOne {
|
|
mutation := newThemeMutation(c.config, OpUpdateOne, withTheme(_m))
|
|
return &ThemeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *ThemeClient) UpdateOneID(id int) *ThemeUpdateOne {
|
|
mutation := newThemeMutation(c.config, OpUpdateOne, withThemeID(id))
|
|
return &ThemeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Theme.
|
|
func (c *ThemeClient) Delete() *ThemeDelete {
|
|
mutation := newThemeMutation(c.config, OpDelete)
|
|
return &ThemeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *ThemeClient) DeleteOne(_m *Theme) *ThemeDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *ThemeClient) DeleteOneID(id int) *ThemeDeleteOne {
|
|
builder := c.Delete().Where(theme.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &ThemeDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Theme.
|
|
func (c *ThemeClient) Query() *ThemeQuery {
|
|
return &ThemeQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeTheme},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Theme entity by its id.
|
|
func (c *ThemeClient) Get(ctx context.Context, id int) (*Theme, error) {
|
|
return c.Query().Where(theme.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *ThemeClient) GetX(ctx context.Context, id int) *Theme {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *ThemeClient) Hooks() []Hook {
|
|
hooks := c.hooks.Theme
|
|
return append(hooks[:len(hooks):len(hooks)], theme.Hooks[:]...)
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *ThemeClient) Interceptors() []Interceptor {
|
|
inters := c.inters.Theme
|
|
return append(inters[:len(inters):len(inters)], theme.Interceptors[:]...)
|
|
}
|
|
|
|
func (c *ThemeClient) mutate(ctx context.Context, m *ThemeMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&ThemeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&ThemeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&ThemeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&ThemeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Theme mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// hooks and interceptors per client, for fast access.
|
|
type (
|
|
hooks struct {
|
|
Document, Extension, KeyBinding, Theme []ent.Hook
|
|
}
|
|
inters struct {
|
|
Document, Extension, KeyBinding, Theme []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...)
|
|
}
|