1043 lines
35 KiB
Go
1043 lines
35 KiB
Go
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
||
|
package ent
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"reflect"
|
||
|
|
||
|
"thesis/ent/migrate"
|
||
|
|
||
|
"thesis/ent/blocks"
|
||
|
"thesis/ent/key"
|
||
|
"thesis/ent/transactions"
|
||
|
"thesis/ent/validators"
|
||
|
"thesis/ent/whitelist"
|
||
|
|
||
|
"entgo.io/ent"
|
||
|
"entgo.io/ent/dialect"
|
||
|
"entgo.io/ent/dialect/sql"
|
||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
)
|
||
|
|
||
|
// Client is the client that holds all ent builders.
|
||
|
type Client struct {
|
||
|
config
|
||
|
// Schema is the client for creating, migrating and dropping schema.
|
||
|
Schema *migrate.Schema
|
||
|
// Blocks is the client for interacting with the Blocks builders.
|
||
|
Blocks *BlocksClient
|
||
|
// Key is the client for interacting with the Key builders.
|
||
|
Key *KeyClient
|
||
|
// Transactions is the client for interacting with the Transactions builders.
|
||
|
Transactions *TransactionsClient
|
||
|
// Validators is the client for interacting with the Validators builders.
|
||
|
Validators *ValidatorsClient
|
||
|
// WhiteList is the client for interacting with the WhiteList builders.
|
||
|
WhiteList *WhiteListClient
|
||
|
}
|
||
|
|
||
|
// 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.Blocks = NewBlocksClient(c.config)
|
||
|
c.Key = NewKeyClient(c.config)
|
||
|
c.Transactions = NewTransactionsClient(c.config)
|
||
|
c.Validators = NewValidatorsClient(c.config)
|
||
|
c.WhiteList = NewWhiteListClient(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,
|
||
|
Blocks: NewBlocksClient(cfg),
|
||
|
Key: NewKeyClient(cfg),
|
||
|
Transactions: NewTransactionsClient(cfg),
|
||
|
Validators: NewValidatorsClient(cfg),
|
||
|
WhiteList: NewWhiteListClient(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,
|
||
|
Blocks: NewBlocksClient(cfg),
|
||
|
Key: NewKeyClient(cfg),
|
||
|
Transactions: NewTransactionsClient(cfg),
|
||
|
Validators: NewValidatorsClient(cfg),
|
||
|
WhiteList: NewWhiteListClient(cfg),
|
||
|
}, nil
|
||
|
}
|
||
|
|
||
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||
|
//
|
||
|
// client.Debug().
|
||
|
// Blocks.
|
||
|
// 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.Blocks.Use(hooks...)
|
||
|
c.Key.Use(hooks...)
|
||
|
c.Transactions.Use(hooks...)
|
||
|
c.Validators.Use(hooks...)
|
||
|
c.WhiteList.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.Blocks.Intercept(interceptors...)
|
||
|
c.Key.Intercept(interceptors...)
|
||
|
c.Transactions.Intercept(interceptors...)
|
||
|
c.Validators.Intercept(interceptors...)
|
||
|
c.WhiteList.Intercept(interceptors...)
|
||
|
}
|
||
|
|
||
|
// Mutate implements the ent.Mutator interface.
|
||
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||
|
switch m := m.(type) {
|
||
|
case *BlocksMutation:
|
||
|
return c.Blocks.mutate(ctx, m)
|
||
|
case *KeyMutation:
|
||
|
return c.Key.mutate(ctx, m)
|
||
|
case *TransactionsMutation:
|
||
|
return c.Transactions.mutate(ctx, m)
|
||
|
case *ValidatorsMutation:
|
||
|
return c.Validators.mutate(ctx, m)
|
||
|
case *WhiteListMutation:
|
||
|
return c.WhiteList.mutate(ctx, m)
|
||
|
default:
|
||
|
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// BlocksClient is a client for the Blocks schema.
|
||
|
type BlocksClient struct {
|
||
|
config
|
||
|
}
|
||
|
|
||
|
// NewBlocksClient returns a client for the Blocks from the given config.
|
||
|
func NewBlocksClient(c config) *BlocksClient {
|
||
|
return &BlocksClient{config: c}
|
||
|
}
|
||
|
|
||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||
|
// A call to `Use(f, g, h)` equals to `blocks.Hooks(f(g(h())))`.
|
||
|
func (c *BlocksClient) Use(hooks ...Hook) {
|
||
|
c.hooks.Blocks = append(c.hooks.Blocks, hooks...)
|
||
|
}
|
||
|
|
||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||
|
// A call to `Intercept(f, g, h)` equals to `blocks.Intercept(f(g(h())))`.
|
||
|
func (c *BlocksClient) Intercept(interceptors ...Interceptor) {
|
||
|
c.inters.Blocks = append(c.inters.Blocks, interceptors...)
|
||
|
}
|
||
|
|
||
|
// Create returns a builder for creating a Blocks entity.
|
||
|
func (c *BlocksClient) Create() *BlocksCreate {
|
||
|
mutation := newBlocksMutation(c.config, OpCreate)
|
||
|
return &BlocksCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// CreateBulk returns a builder for creating a bulk of Blocks entities.
|
||
|
func (c *BlocksClient) CreateBulk(builders ...*BlocksCreate) *BlocksCreateBulk {
|
||
|
return &BlocksCreateBulk{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 *BlocksClient) MapCreateBulk(slice any, setFunc func(*BlocksCreate, int)) *BlocksCreateBulk {
|
||
|
rv := reflect.ValueOf(slice)
|
||
|
if rv.Kind() != reflect.Slice {
|
||
|
return &BlocksCreateBulk{err: fmt.Errorf("calling to BlocksClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||
|
}
|
||
|
builders := make([]*BlocksCreate, rv.Len())
|
||
|
for i := 0; i < rv.Len(); i++ {
|
||
|
builders[i] = c.Create()
|
||
|
setFunc(builders[i], i)
|
||
|
}
|
||
|
return &BlocksCreateBulk{config: c.config, builders: builders}
|
||
|
}
|
||
|
|
||
|
// Update returns an update builder for Blocks.
|
||
|
func (c *BlocksClient) Update() *BlocksUpdate {
|
||
|
mutation := newBlocksMutation(c.config, OpUpdate)
|
||
|
return &BlocksUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOne returns an update builder for the given entity.
|
||
|
func (c *BlocksClient) UpdateOne(b *Blocks) *BlocksUpdateOne {
|
||
|
mutation := newBlocksMutation(c.config, OpUpdateOne, withBlocks(b))
|
||
|
return &BlocksUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOneID returns an update builder for the given id.
|
||
|
func (c *BlocksClient) UpdateOneID(id int) *BlocksUpdateOne {
|
||
|
mutation := newBlocksMutation(c.config, OpUpdateOne, withBlocksID(id))
|
||
|
return &BlocksUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// Delete returns a delete builder for Blocks.
|
||
|
func (c *BlocksClient) Delete() *BlocksDelete {
|
||
|
mutation := newBlocksMutation(c.config, OpDelete)
|
||
|
return &BlocksDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// DeleteOne returns a builder for deleting the given entity.
|
||
|
func (c *BlocksClient) DeleteOne(b *Blocks) *BlocksDeleteOne {
|
||
|
return c.DeleteOneID(b.ID)
|
||
|
}
|
||
|
|
||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||
|
func (c *BlocksClient) DeleteOneID(id int) *BlocksDeleteOne {
|
||
|
builder := c.Delete().Where(blocks.ID(id))
|
||
|
builder.mutation.id = &id
|
||
|
builder.mutation.op = OpDeleteOne
|
||
|
return &BlocksDeleteOne{builder}
|
||
|
}
|
||
|
|
||
|
// Query returns a query builder for Blocks.
|
||
|
func (c *BlocksClient) Query() *BlocksQuery {
|
||
|
return &BlocksQuery{
|
||
|
config: c.config,
|
||
|
ctx: &QueryContext{Type: TypeBlocks},
|
||
|
inters: c.Interceptors(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Get returns a Blocks entity by its id.
|
||
|
func (c *BlocksClient) Get(ctx context.Context, id int) (*Blocks, error) {
|
||
|
return c.Query().Where(blocks.ID(id)).Only(ctx)
|
||
|
}
|
||
|
|
||
|
// GetX is like Get, but panics if an error occurs.
|
||
|
func (c *BlocksClient) GetX(ctx context.Context, id int) *Blocks {
|
||
|
obj, err := c.Get(ctx, id)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return obj
|
||
|
}
|
||
|
|
||
|
// QueryCaster queries the Caster edge of a Blocks.
|
||
|
func (c *BlocksClient) QueryCaster(b *Blocks) *ValidatorsQuery {
|
||
|
query := (&ValidatorsClient{config: c.config}).Query()
|
||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||
|
id := b.ID
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(blocks.Table, blocks.FieldID, id),
|
||
|
sqlgraph.To(validators.Table, validators.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.O2M, false, blocks.CasterTable, blocks.CasterColumn),
|
||
|
)
|
||
|
fromV = sqlgraph.Neighbors(b.driver.Dialect(), step)
|
||
|
return fromV, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// QueryMinedTxs queries the MinedTxs edge of a Blocks.
|
||
|
func (c *BlocksClient) QueryMinedTxs(b *Blocks) *TransactionsQuery {
|
||
|
query := (&TransactionsClient{config: c.config}).Query()
|
||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||
|
id := b.ID
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(blocks.Table, blocks.FieldID, id),
|
||
|
sqlgraph.To(transactions.Table, transactions.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.M2M, false, blocks.MinedTxsTable, blocks.MinedTxsPrimaryKey...),
|
||
|
)
|
||
|
fromV = sqlgraph.Neighbors(b.driver.Dialect(), step)
|
||
|
return fromV, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// Hooks returns the client hooks.
|
||
|
func (c *BlocksClient) Hooks() []Hook {
|
||
|
return c.hooks.Blocks
|
||
|
}
|
||
|
|
||
|
// Interceptors returns the client interceptors.
|
||
|
func (c *BlocksClient) Interceptors() []Interceptor {
|
||
|
return c.inters.Blocks
|
||
|
}
|
||
|
|
||
|
func (c *BlocksClient) mutate(ctx context.Context, m *BlocksMutation) (Value, error) {
|
||
|
switch m.Op() {
|
||
|
case OpCreate:
|
||
|
return (&BlocksCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdate:
|
||
|
return (&BlocksUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdateOne:
|
||
|
return (&BlocksUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpDelete, OpDeleteOne:
|
||
|
return (&BlocksDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||
|
default:
|
||
|
return nil, fmt.Errorf("ent: unknown Blocks mutation op: %q", m.Op())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// KeyClient is a client for the Key schema.
|
||
|
type KeyClient struct {
|
||
|
config
|
||
|
}
|
||
|
|
||
|
// NewKeyClient returns a client for the Key from the given config.
|
||
|
func NewKeyClient(c config) *KeyClient {
|
||
|
return &KeyClient{config: c}
|
||
|
}
|
||
|
|
||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||
|
// A call to `Use(f, g, h)` equals to `key.Hooks(f(g(h())))`.
|
||
|
func (c *KeyClient) Use(hooks ...Hook) {
|
||
|
c.hooks.Key = append(c.hooks.Key, hooks...)
|
||
|
}
|
||
|
|
||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||
|
// A call to `Intercept(f, g, h)` equals to `key.Intercept(f(g(h())))`.
|
||
|
func (c *KeyClient) Intercept(interceptors ...Interceptor) {
|
||
|
c.inters.Key = append(c.inters.Key, interceptors...)
|
||
|
}
|
||
|
|
||
|
// Create returns a builder for creating a Key entity.
|
||
|
func (c *KeyClient) Create() *KeyCreate {
|
||
|
mutation := newKeyMutation(c.config, OpCreate)
|
||
|
return &KeyCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// CreateBulk returns a builder for creating a bulk of Key entities.
|
||
|
func (c *KeyClient) CreateBulk(builders ...*KeyCreate) *KeyCreateBulk {
|
||
|
return &KeyCreateBulk{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 *KeyClient) MapCreateBulk(slice any, setFunc func(*KeyCreate, int)) *KeyCreateBulk {
|
||
|
rv := reflect.ValueOf(slice)
|
||
|
if rv.Kind() != reflect.Slice {
|
||
|
return &KeyCreateBulk{err: fmt.Errorf("calling to KeyClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||
|
}
|
||
|
builders := make([]*KeyCreate, rv.Len())
|
||
|
for i := 0; i < rv.Len(); i++ {
|
||
|
builders[i] = c.Create()
|
||
|
setFunc(builders[i], i)
|
||
|
}
|
||
|
return &KeyCreateBulk{config: c.config, builders: builders}
|
||
|
}
|
||
|
|
||
|
// Update returns an update builder for Key.
|
||
|
func (c *KeyClient) Update() *KeyUpdate {
|
||
|
mutation := newKeyMutation(c.config, OpUpdate)
|
||
|
return &KeyUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOne returns an update builder for the given entity.
|
||
|
func (c *KeyClient) UpdateOne(k *Key) *KeyUpdateOne {
|
||
|
mutation := newKeyMutation(c.config, OpUpdateOne, withKey(k))
|
||
|
return &KeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOneID returns an update builder for the given id.
|
||
|
func (c *KeyClient) UpdateOneID(id int) *KeyUpdateOne {
|
||
|
mutation := newKeyMutation(c.config, OpUpdateOne, withKeyID(id))
|
||
|
return &KeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// Delete returns a delete builder for Key.
|
||
|
func (c *KeyClient) Delete() *KeyDelete {
|
||
|
mutation := newKeyMutation(c.config, OpDelete)
|
||
|
return &KeyDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// DeleteOne returns a builder for deleting the given entity.
|
||
|
func (c *KeyClient) DeleteOne(k *Key) *KeyDeleteOne {
|
||
|
return c.DeleteOneID(k.ID)
|
||
|
}
|
||
|
|
||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||
|
func (c *KeyClient) DeleteOneID(id int) *KeyDeleteOne {
|
||
|
builder := c.Delete().Where(key.ID(id))
|
||
|
builder.mutation.id = &id
|
||
|
builder.mutation.op = OpDeleteOne
|
||
|
return &KeyDeleteOne{builder}
|
||
|
}
|
||
|
|
||
|
// Query returns a query builder for Key.
|
||
|
func (c *KeyClient) Query() *KeyQuery {
|
||
|
return &KeyQuery{
|
||
|
config: c.config,
|
||
|
ctx: &QueryContext{Type: TypeKey},
|
||
|
inters: c.Interceptors(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Get returns a Key entity by its id.
|
||
|
func (c *KeyClient) Get(ctx context.Context, id int) (*Key, error) {
|
||
|
return c.Query().Where(key.ID(id)).Only(ctx)
|
||
|
}
|
||
|
|
||
|
// GetX is like Get, but panics if an error occurs.
|
||
|
func (c *KeyClient) GetX(ctx context.Context, id int) *Key {
|
||
|
obj, err := c.Get(ctx, id)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return obj
|
||
|
}
|
||
|
|
||
|
// QuerySigned queries the Signed edge of a Key.
|
||
|
func (c *KeyClient) QuerySigned(k *Key) *TransactionsQuery {
|
||
|
query := (&TransactionsClient{config: c.config}).Query()
|
||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||
|
id := k.ID
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(key.Table, key.FieldID, id),
|
||
|
sqlgraph.To(transactions.Table, transactions.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.M2M, false, key.SignedTable, key.SignedPrimaryKey...),
|
||
|
)
|
||
|
fromV = sqlgraph.Neighbors(k.driver.Dialect(), step)
|
||
|
return fromV, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// Hooks returns the client hooks.
|
||
|
func (c *KeyClient) Hooks() []Hook {
|
||
|
return c.hooks.Key
|
||
|
}
|
||
|
|
||
|
// Interceptors returns the client interceptors.
|
||
|
func (c *KeyClient) Interceptors() []Interceptor {
|
||
|
return c.inters.Key
|
||
|
}
|
||
|
|
||
|
func (c *KeyClient) mutate(ctx context.Context, m *KeyMutation) (Value, error) {
|
||
|
switch m.Op() {
|
||
|
case OpCreate:
|
||
|
return (&KeyCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdate:
|
||
|
return (&KeyUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdateOne:
|
||
|
return (&KeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpDelete, OpDeleteOne:
|
||
|
return (&KeyDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||
|
default:
|
||
|
return nil, fmt.Errorf("ent: unknown Key mutation op: %q", m.Op())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// TransactionsClient is a client for the Transactions schema.
|
||
|
type TransactionsClient struct {
|
||
|
config
|
||
|
}
|
||
|
|
||
|
// NewTransactionsClient returns a client for the Transactions from the given config.
|
||
|
func NewTransactionsClient(c config) *TransactionsClient {
|
||
|
return &TransactionsClient{config: c}
|
||
|
}
|
||
|
|
||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||
|
// A call to `Use(f, g, h)` equals to `transactions.Hooks(f(g(h())))`.
|
||
|
func (c *TransactionsClient) Use(hooks ...Hook) {
|
||
|
c.hooks.Transactions = append(c.hooks.Transactions, hooks...)
|
||
|
}
|
||
|
|
||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||
|
// A call to `Intercept(f, g, h)` equals to `transactions.Intercept(f(g(h())))`.
|
||
|
func (c *TransactionsClient) Intercept(interceptors ...Interceptor) {
|
||
|
c.inters.Transactions = append(c.inters.Transactions, interceptors...)
|
||
|
}
|
||
|
|
||
|
// Create returns a builder for creating a Transactions entity.
|
||
|
func (c *TransactionsClient) Create() *TransactionsCreate {
|
||
|
mutation := newTransactionsMutation(c.config, OpCreate)
|
||
|
return &TransactionsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// CreateBulk returns a builder for creating a bulk of Transactions entities.
|
||
|
func (c *TransactionsClient) CreateBulk(builders ...*TransactionsCreate) *TransactionsCreateBulk {
|
||
|
return &TransactionsCreateBulk{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 *TransactionsClient) MapCreateBulk(slice any, setFunc func(*TransactionsCreate, int)) *TransactionsCreateBulk {
|
||
|
rv := reflect.ValueOf(slice)
|
||
|
if rv.Kind() != reflect.Slice {
|
||
|
return &TransactionsCreateBulk{err: fmt.Errorf("calling to TransactionsClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||
|
}
|
||
|
builders := make([]*TransactionsCreate, rv.Len())
|
||
|
for i := 0; i < rv.Len(); i++ {
|
||
|
builders[i] = c.Create()
|
||
|
setFunc(builders[i], i)
|
||
|
}
|
||
|
return &TransactionsCreateBulk{config: c.config, builders: builders}
|
||
|
}
|
||
|
|
||
|
// Update returns an update builder for Transactions.
|
||
|
func (c *TransactionsClient) Update() *TransactionsUpdate {
|
||
|
mutation := newTransactionsMutation(c.config, OpUpdate)
|
||
|
return &TransactionsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOne returns an update builder for the given entity.
|
||
|
func (c *TransactionsClient) UpdateOne(t *Transactions) *TransactionsUpdateOne {
|
||
|
mutation := newTransactionsMutation(c.config, OpUpdateOne, withTransactions(t))
|
||
|
return &TransactionsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOneID returns an update builder for the given id.
|
||
|
func (c *TransactionsClient) UpdateOneID(id int) *TransactionsUpdateOne {
|
||
|
mutation := newTransactionsMutation(c.config, OpUpdateOne, withTransactionsID(id))
|
||
|
return &TransactionsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// Delete returns a delete builder for Transactions.
|
||
|
func (c *TransactionsClient) Delete() *TransactionsDelete {
|
||
|
mutation := newTransactionsMutation(c.config, OpDelete)
|
||
|
return &TransactionsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// DeleteOne returns a builder for deleting the given entity.
|
||
|
func (c *TransactionsClient) DeleteOne(t *Transactions) *TransactionsDeleteOne {
|
||
|
return c.DeleteOneID(t.ID)
|
||
|
}
|
||
|
|
||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||
|
func (c *TransactionsClient) DeleteOneID(id int) *TransactionsDeleteOne {
|
||
|
builder := c.Delete().Where(transactions.ID(id))
|
||
|
builder.mutation.id = &id
|
||
|
builder.mutation.op = OpDeleteOne
|
||
|
return &TransactionsDeleteOne{builder}
|
||
|
}
|
||
|
|
||
|
// Query returns a query builder for Transactions.
|
||
|
func (c *TransactionsClient) Query() *TransactionsQuery {
|
||
|
return &TransactionsQuery{
|
||
|
config: c.config,
|
||
|
ctx: &QueryContext{Type: TypeTransactions},
|
||
|
inters: c.Interceptors(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Get returns a Transactions entity by its id.
|
||
|
func (c *TransactionsClient) Get(ctx context.Context, id int) (*Transactions, error) {
|
||
|
return c.Query().Where(transactions.ID(id)).Only(ctx)
|
||
|
}
|
||
|
|
||
|
// GetX is like Get, but panics if an error occurs.
|
||
|
func (c *TransactionsClient) GetX(ctx context.Context, id int) *Transactions {
|
||
|
obj, err := c.Get(ctx, id)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return obj
|
||
|
}
|
||
|
|
||
|
// QuerySigner queries the Signer edge of a Transactions.
|
||
|
func (c *TransactionsClient) QuerySigner(t *Transactions) *KeyQuery {
|
||
|
query := (&KeyClient{config: c.config}).Query()
|
||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||
|
id := t.ID
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(transactions.Table, transactions.FieldID, id),
|
||
|
sqlgraph.To(key.Table, key.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.M2M, true, transactions.SignerTable, transactions.SignerPrimaryKey...),
|
||
|
)
|
||
|
fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
|
||
|
return fromV, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// QueryBlock queries the Block edge of a Transactions.
|
||
|
func (c *TransactionsClient) QueryBlock(t *Transactions) *BlocksQuery {
|
||
|
query := (&BlocksClient{config: c.config}).Query()
|
||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||
|
id := t.ID
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(transactions.Table, transactions.FieldID, id),
|
||
|
sqlgraph.To(blocks.Table, blocks.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.M2M, true, transactions.BlockTable, transactions.BlockPrimaryKey...),
|
||
|
)
|
||
|
fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
|
||
|
return fromV, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// Hooks returns the client hooks.
|
||
|
func (c *TransactionsClient) Hooks() []Hook {
|
||
|
return c.hooks.Transactions
|
||
|
}
|
||
|
|
||
|
// Interceptors returns the client interceptors.
|
||
|
func (c *TransactionsClient) Interceptors() []Interceptor {
|
||
|
return c.inters.Transactions
|
||
|
}
|
||
|
|
||
|
func (c *TransactionsClient) mutate(ctx context.Context, m *TransactionsMutation) (Value, error) {
|
||
|
switch m.Op() {
|
||
|
case OpCreate:
|
||
|
return (&TransactionsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdate:
|
||
|
return (&TransactionsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdateOne:
|
||
|
return (&TransactionsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpDelete, OpDeleteOne:
|
||
|
return (&TransactionsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||
|
default:
|
||
|
return nil, fmt.Errorf("ent: unknown Transactions mutation op: %q", m.Op())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ValidatorsClient is a client for the Validators schema.
|
||
|
type ValidatorsClient struct {
|
||
|
config
|
||
|
}
|
||
|
|
||
|
// NewValidatorsClient returns a client for the Validators from the given config.
|
||
|
func NewValidatorsClient(c config) *ValidatorsClient {
|
||
|
return &ValidatorsClient{config: c}
|
||
|
}
|
||
|
|
||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||
|
// A call to `Use(f, g, h)` equals to `validators.Hooks(f(g(h())))`.
|
||
|
func (c *ValidatorsClient) Use(hooks ...Hook) {
|
||
|
c.hooks.Validators = append(c.hooks.Validators, hooks...)
|
||
|
}
|
||
|
|
||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||
|
// A call to `Intercept(f, g, h)` equals to `validators.Intercept(f(g(h())))`.
|
||
|
func (c *ValidatorsClient) Intercept(interceptors ...Interceptor) {
|
||
|
c.inters.Validators = append(c.inters.Validators, interceptors...)
|
||
|
}
|
||
|
|
||
|
// Create returns a builder for creating a Validators entity.
|
||
|
func (c *ValidatorsClient) Create() *ValidatorsCreate {
|
||
|
mutation := newValidatorsMutation(c.config, OpCreate)
|
||
|
return &ValidatorsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// CreateBulk returns a builder for creating a bulk of Validators entities.
|
||
|
func (c *ValidatorsClient) CreateBulk(builders ...*ValidatorsCreate) *ValidatorsCreateBulk {
|
||
|
return &ValidatorsCreateBulk{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 *ValidatorsClient) MapCreateBulk(slice any, setFunc func(*ValidatorsCreate, int)) *ValidatorsCreateBulk {
|
||
|
rv := reflect.ValueOf(slice)
|
||
|
if rv.Kind() != reflect.Slice {
|
||
|
return &ValidatorsCreateBulk{err: fmt.Errorf("calling to ValidatorsClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||
|
}
|
||
|
builders := make([]*ValidatorsCreate, rv.Len())
|
||
|
for i := 0; i < rv.Len(); i++ {
|
||
|
builders[i] = c.Create()
|
||
|
setFunc(builders[i], i)
|
||
|
}
|
||
|
return &ValidatorsCreateBulk{config: c.config, builders: builders}
|
||
|
}
|
||
|
|
||
|
// Update returns an update builder for Validators.
|
||
|
func (c *ValidatorsClient) Update() *ValidatorsUpdate {
|
||
|
mutation := newValidatorsMutation(c.config, OpUpdate)
|
||
|
return &ValidatorsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOne returns an update builder for the given entity.
|
||
|
func (c *ValidatorsClient) UpdateOne(v *Validators) *ValidatorsUpdateOne {
|
||
|
mutation := newValidatorsMutation(c.config, OpUpdateOne, withValidators(v))
|
||
|
return &ValidatorsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOneID returns an update builder for the given id.
|
||
|
func (c *ValidatorsClient) UpdateOneID(id int) *ValidatorsUpdateOne {
|
||
|
mutation := newValidatorsMutation(c.config, OpUpdateOne, withValidatorsID(id))
|
||
|
return &ValidatorsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// Delete returns a delete builder for Validators.
|
||
|
func (c *ValidatorsClient) Delete() *ValidatorsDelete {
|
||
|
mutation := newValidatorsMutation(c.config, OpDelete)
|
||
|
return &ValidatorsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// DeleteOne returns a builder for deleting the given entity.
|
||
|
func (c *ValidatorsClient) DeleteOne(v *Validators) *ValidatorsDeleteOne {
|
||
|
return c.DeleteOneID(v.ID)
|
||
|
}
|
||
|
|
||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||
|
func (c *ValidatorsClient) DeleteOneID(id int) *ValidatorsDeleteOne {
|
||
|
builder := c.Delete().Where(validators.ID(id))
|
||
|
builder.mutation.id = &id
|
||
|
builder.mutation.op = OpDeleteOne
|
||
|
return &ValidatorsDeleteOne{builder}
|
||
|
}
|
||
|
|
||
|
// Query returns a query builder for Validators.
|
||
|
func (c *ValidatorsClient) Query() *ValidatorsQuery {
|
||
|
return &ValidatorsQuery{
|
||
|
config: c.config,
|
||
|
ctx: &QueryContext{Type: TypeValidators},
|
||
|
inters: c.Interceptors(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Get returns a Validators entity by its id.
|
||
|
func (c *ValidatorsClient) Get(ctx context.Context, id int) (*Validators, error) {
|
||
|
return c.Query().Where(validators.ID(id)).Only(ctx)
|
||
|
}
|
||
|
|
||
|
// GetX is like Get, but panics if an error occurs.
|
||
|
func (c *ValidatorsClient) GetX(ctx context.Context, id int) *Validators {
|
||
|
obj, err := c.Get(ctx, id)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return obj
|
||
|
}
|
||
|
|
||
|
// QueryKey queries the key edge of a Validators.
|
||
|
func (c *ValidatorsClient) QueryKey(v *Validators) *KeyQuery {
|
||
|
query := (&KeyClient{config: c.config}).Query()
|
||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||
|
id := v.ID
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(validators.Table, validators.FieldID, id),
|
||
|
sqlgraph.To(key.Table, key.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.O2M, false, validators.KeyTable, validators.KeyColumn),
|
||
|
)
|
||
|
fromV = sqlgraph.Neighbors(v.driver.Dialect(), step)
|
||
|
return fromV, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// Hooks returns the client hooks.
|
||
|
func (c *ValidatorsClient) Hooks() []Hook {
|
||
|
return c.hooks.Validators
|
||
|
}
|
||
|
|
||
|
// Interceptors returns the client interceptors.
|
||
|
func (c *ValidatorsClient) Interceptors() []Interceptor {
|
||
|
return c.inters.Validators
|
||
|
}
|
||
|
|
||
|
func (c *ValidatorsClient) mutate(ctx context.Context, m *ValidatorsMutation) (Value, error) {
|
||
|
switch m.Op() {
|
||
|
case OpCreate:
|
||
|
return (&ValidatorsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdate:
|
||
|
return (&ValidatorsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdateOne:
|
||
|
return (&ValidatorsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpDelete, OpDeleteOne:
|
||
|
return (&ValidatorsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||
|
default:
|
||
|
return nil, fmt.Errorf("ent: unknown Validators mutation op: %q", m.Op())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WhiteListClient is a client for the WhiteList schema.
|
||
|
type WhiteListClient struct {
|
||
|
config
|
||
|
}
|
||
|
|
||
|
// NewWhiteListClient returns a client for the WhiteList from the given config.
|
||
|
func NewWhiteListClient(c config) *WhiteListClient {
|
||
|
return &WhiteListClient{config: c}
|
||
|
}
|
||
|
|
||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||
|
// A call to `Use(f, g, h)` equals to `whitelist.Hooks(f(g(h())))`.
|
||
|
func (c *WhiteListClient) Use(hooks ...Hook) {
|
||
|
c.hooks.WhiteList = append(c.hooks.WhiteList, hooks...)
|
||
|
}
|
||
|
|
||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||
|
// A call to `Intercept(f, g, h)` equals to `whitelist.Intercept(f(g(h())))`.
|
||
|
func (c *WhiteListClient) Intercept(interceptors ...Interceptor) {
|
||
|
c.inters.WhiteList = append(c.inters.WhiteList, interceptors...)
|
||
|
}
|
||
|
|
||
|
// Create returns a builder for creating a WhiteList entity.
|
||
|
func (c *WhiteListClient) Create() *WhiteListCreate {
|
||
|
mutation := newWhiteListMutation(c.config, OpCreate)
|
||
|
return &WhiteListCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// CreateBulk returns a builder for creating a bulk of WhiteList entities.
|
||
|
func (c *WhiteListClient) CreateBulk(builders ...*WhiteListCreate) *WhiteListCreateBulk {
|
||
|
return &WhiteListCreateBulk{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 *WhiteListClient) MapCreateBulk(slice any, setFunc func(*WhiteListCreate, int)) *WhiteListCreateBulk {
|
||
|
rv := reflect.ValueOf(slice)
|
||
|
if rv.Kind() != reflect.Slice {
|
||
|
return &WhiteListCreateBulk{err: fmt.Errorf("calling to WhiteListClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||
|
}
|
||
|
builders := make([]*WhiteListCreate, rv.Len())
|
||
|
for i := 0; i < rv.Len(); i++ {
|
||
|
builders[i] = c.Create()
|
||
|
setFunc(builders[i], i)
|
||
|
}
|
||
|
return &WhiteListCreateBulk{config: c.config, builders: builders}
|
||
|
}
|
||
|
|
||
|
// Update returns an update builder for WhiteList.
|
||
|
func (c *WhiteListClient) Update() *WhiteListUpdate {
|
||
|
mutation := newWhiteListMutation(c.config, OpUpdate)
|
||
|
return &WhiteListUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOne returns an update builder for the given entity.
|
||
|
func (c *WhiteListClient) UpdateOne(wl *WhiteList) *WhiteListUpdateOne {
|
||
|
mutation := newWhiteListMutation(c.config, OpUpdateOne, withWhiteList(wl))
|
||
|
return &WhiteListUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// UpdateOneID returns an update builder for the given id.
|
||
|
func (c *WhiteListClient) UpdateOneID(id int) *WhiteListUpdateOne {
|
||
|
mutation := newWhiteListMutation(c.config, OpUpdateOne, withWhiteListID(id))
|
||
|
return &WhiteListUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// Delete returns a delete builder for WhiteList.
|
||
|
func (c *WhiteListClient) Delete() *WhiteListDelete {
|
||
|
mutation := newWhiteListMutation(c.config, OpDelete)
|
||
|
return &WhiteListDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||
|
}
|
||
|
|
||
|
// DeleteOne returns a builder for deleting the given entity.
|
||
|
func (c *WhiteListClient) DeleteOne(wl *WhiteList) *WhiteListDeleteOne {
|
||
|
return c.DeleteOneID(wl.ID)
|
||
|
}
|
||
|
|
||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||
|
func (c *WhiteListClient) DeleteOneID(id int) *WhiteListDeleteOne {
|
||
|
builder := c.Delete().Where(whitelist.ID(id))
|
||
|
builder.mutation.id = &id
|
||
|
builder.mutation.op = OpDeleteOne
|
||
|
return &WhiteListDeleteOne{builder}
|
||
|
}
|
||
|
|
||
|
// Query returns a query builder for WhiteList.
|
||
|
func (c *WhiteListClient) Query() *WhiteListQuery {
|
||
|
return &WhiteListQuery{
|
||
|
config: c.config,
|
||
|
ctx: &QueryContext{Type: TypeWhiteList},
|
||
|
inters: c.Interceptors(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Get returns a WhiteList entity by its id.
|
||
|
func (c *WhiteListClient) Get(ctx context.Context, id int) (*WhiteList, error) {
|
||
|
return c.Query().Where(whitelist.ID(id)).Only(ctx)
|
||
|
}
|
||
|
|
||
|
// GetX is like Get, but panics if an error occurs.
|
||
|
func (c *WhiteListClient) GetX(ctx context.Context, id int) *WhiteList {
|
||
|
obj, err := c.Get(ctx, id)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return obj
|
||
|
}
|
||
|
|
||
|
// QuerySponsor queries the Sponsor edge of a WhiteList.
|
||
|
func (c *WhiteListClient) QuerySponsor(wl *WhiteList) *ValidatorsQuery {
|
||
|
query := (&ValidatorsClient{config: c.config}).Query()
|
||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||
|
id := wl.ID
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(whitelist.Table, whitelist.FieldID, id),
|
||
|
sqlgraph.To(validators.Table, validators.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.O2M, false, whitelist.SponsorTable, whitelist.SponsorColumn),
|
||
|
)
|
||
|
fromV = sqlgraph.Neighbors(wl.driver.Dialect(), step)
|
||
|
return fromV, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// QueryAccount queries the Account edge of a WhiteList.
|
||
|
func (c *WhiteListClient) QueryAccount(wl *WhiteList) *KeyQuery {
|
||
|
query := (&KeyClient{config: c.config}).Query()
|
||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||
|
id := wl.ID
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(whitelist.Table, whitelist.FieldID, id),
|
||
|
sqlgraph.To(key.Table, key.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.O2M, false, whitelist.AccountTable, whitelist.AccountColumn),
|
||
|
)
|
||
|
fromV = sqlgraph.Neighbors(wl.driver.Dialect(), step)
|
||
|
return fromV, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// Hooks returns the client hooks.
|
||
|
func (c *WhiteListClient) Hooks() []Hook {
|
||
|
return c.hooks.WhiteList
|
||
|
}
|
||
|
|
||
|
// Interceptors returns the client interceptors.
|
||
|
func (c *WhiteListClient) Interceptors() []Interceptor {
|
||
|
return c.inters.WhiteList
|
||
|
}
|
||
|
|
||
|
func (c *WhiteListClient) mutate(ctx context.Context, m *WhiteListMutation) (Value, error) {
|
||
|
switch m.Op() {
|
||
|
case OpCreate:
|
||
|
return (&WhiteListCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdate:
|
||
|
return (&WhiteListUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpUpdateOne:
|
||
|
return (&WhiteListUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||
|
case OpDelete, OpDeleteOne:
|
||
|
return (&WhiteListDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||
|
default:
|
||
|
return nil, fmt.Errorf("ent: unknown WhiteList mutation op: %q", m.Op())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// hooks and interceptors per client, for fast access.
|
||
|
type (
|
||
|
hooks struct {
|
||
|
Blocks, Key, Transactions, Validators, WhiteList []ent.Hook
|
||
|
}
|
||
|
inters struct {
|
||
|
Blocks, Key, Transactions, Validators, WhiteList []ent.Interceptor
|
||
|
}
|
||
|
)
|