2024-08-11 03:51:22 +02:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
|
|
|
|
|
|
|
|
|
package ent
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2024-08-28 00:25:25 +02:00
|
|
|
"github.com/versia-pub/versia-go/ent/migrate"
|
2024-08-11 03:51:22 +02:00
|
|
|
|
|
|
|
|
"entgo.io/ent"
|
|
|
|
|
"entgo.io/ent/dialect"
|
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
2024-08-28 00:25:25 +02:00
|
|
|
"github.com/versia-pub/versia-go/ent/attachment"
|
|
|
|
|
"github.com/versia-pub/versia-go/ent/follow"
|
|
|
|
|
"github.com/versia-pub/versia-go/ent/image"
|
|
|
|
|
"github.com/versia-pub/versia-go/ent/instancemetadata"
|
|
|
|
|
"github.com/versia-pub/versia-go/ent/note"
|
|
|
|
|
"github.com/versia-pub/versia-go/ent/user"
|
2024-08-11 03:51:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
// Attachment is the client for interacting with the Attachment builders.
|
|
|
|
|
Attachment *AttachmentClient
|
|
|
|
|
// Follow is the client for interacting with the Follow builders.
|
|
|
|
|
Follow *FollowClient
|
|
|
|
|
// Image is the client for interacting with the Image builders.
|
|
|
|
|
Image *ImageClient
|
2024-08-20 22:43:26 +02:00
|
|
|
// InstanceMetadata is the client for interacting with the InstanceMetadata builders.
|
|
|
|
|
InstanceMetadata *InstanceMetadataClient
|
2024-08-11 03:51:22 +02:00
|
|
|
// Note is the client for interacting with the Note builders.
|
|
|
|
|
Note *NoteClient
|
|
|
|
|
// User is the client for interacting with the User builders.
|
|
|
|
|
User *UserClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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.Attachment = NewAttachmentClient(c.config)
|
|
|
|
|
c.Follow = NewFollowClient(c.config)
|
|
|
|
|
c.Image = NewImageClient(c.config)
|
2024-08-20 22:43:26 +02:00
|
|
|
c.InstanceMetadata = NewInstanceMetadataClient(c.config)
|
2024-08-11 03:51:22 +02:00
|
|
|
c.Note = NewNoteClient(c.config)
|
|
|
|
|
c.User = NewUserClient(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{
|
2024-08-20 22:43:26 +02:00
|
|
|
ctx: ctx,
|
|
|
|
|
config: cfg,
|
|
|
|
|
Attachment: NewAttachmentClient(cfg),
|
|
|
|
|
Follow: NewFollowClient(cfg),
|
|
|
|
|
Image: NewImageClient(cfg),
|
|
|
|
|
InstanceMetadata: NewInstanceMetadataClient(cfg),
|
|
|
|
|
Note: NewNoteClient(cfg),
|
|
|
|
|
User: NewUserClient(cfg),
|
2024-08-11 03:51:22 +02:00
|
|
|
}, 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{
|
2024-08-20 22:43:26 +02:00
|
|
|
ctx: ctx,
|
|
|
|
|
config: cfg,
|
|
|
|
|
Attachment: NewAttachmentClient(cfg),
|
|
|
|
|
Follow: NewFollowClient(cfg),
|
|
|
|
|
Image: NewImageClient(cfg),
|
|
|
|
|
InstanceMetadata: NewInstanceMetadataClient(cfg),
|
|
|
|
|
Note: NewNoteClient(cfg),
|
|
|
|
|
User: NewUserClient(cfg),
|
2024-08-11 03:51:22 +02:00
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
|
|
|
|
//
|
|
|
|
|
// client.Debug().
|
|
|
|
|
// Attachment.
|
|
|
|
|
// 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) }{
|
2024-08-20 22:43:26 +02:00
|
|
|
c.Attachment, c.Follow, c.Image, c.InstanceMetadata, c.Note, c.User,
|
2024-08-11 03:51:22 +02:00
|
|
|
} {
|
|
|
|
|
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) }{
|
2024-08-20 22:43:26 +02:00
|
|
|
c.Attachment, c.Follow, c.Image, c.InstanceMetadata, c.Note, c.User,
|
2024-08-11 03:51:22 +02:00
|
|
|
} {
|
|
|
|
|
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 *AttachmentMutation:
|
|
|
|
|
return c.Attachment.mutate(ctx, m)
|
|
|
|
|
case *FollowMutation:
|
|
|
|
|
return c.Follow.mutate(ctx, m)
|
|
|
|
|
case *ImageMutation:
|
|
|
|
|
return c.Image.mutate(ctx, m)
|
2024-08-20 22:43:26 +02:00
|
|
|
case *InstanceMetadataMutation:
|
|
|
|
|
return c.InstanceMetadata.mutate(ctx, m)
|
2024-08-11 03:51:22 +02:00
|
|
|
case *NoteMutation:
|
|
|
|
|
return c.Note.mutate(ctx, m)
|
|
|
|
|
case *UserMutation:
|
|
|
|
|
return c.User.mutate(ctx, m)
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AttachmentClient is a client for the Attachment schema.
|
|
|
|
|
type AttachmentClient struct {
|
|
|
|
|
config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewAttachmentClient returns a client for the Attachment from the given config.
|
|
|
|
|
func NewAttachmentClient(c config) *AttachmentClient {
|
|
|
|
|
return &AttachmentClient{config: c}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
|
|
|
// A call to `Use(f, g, h)` equals to `attachment.Hooks(f(g(h())))`.
|
|
|
|
|
func (c *AttachmentClient) Use(hooks ...Hook) {
|
|
|
|
|
c.hooks.Attachment = append(c.hooks.Attachment, hooks...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
|
|
|
// A call to `Intercept(f, g, h)` equals to `attachment.Intercept(f(g(h())))`.
|
|
|
|
|
func (c *AttachmentClient) Intercept(interceptors ...Interceptor) {
|
|
|
|
|
c.inters.Attachment = append(c.inters.Attachment, interceptors...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create returns a builder for creating a Attachment entity.
|
|
|
|
|
func (c *AttachmentClient) Create() *AttachmentCreate {
|
|
|
|
|
mutation := newAttachmentMutation(c.config, OpCreate)
|
|
|
|
|
return &AttachmentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Attachment entities.
|
|
|
|
|
func (c *AttachmentClient) CreateBulk(builders ...*AttachmentCreate) *AttachmentCreateBulk {
|
|
|
|
|
return &AttachmentCreateBulk{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 *AttachmentClient) MapCreateBulk(slice any, setFunc func(*AttachmentCreate, int)) *AttachmentCreateBulk {
|
|
|
|
|
rv := reflect.ValueOf(slice)
|
|
|
|
|
if rv.Kind() != reflect.Slice {
|
|
|
|
|
return &AttachmentCreateBulk{err: fmt.Errorf("calling to AttachmentClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
|
|
|
}
|
|
|
|
|
builders := make([]*AttachmentCreate, rv.Len())
|
|
|
|
|
for i := 0; i < rv.Len(); i++ {
|
|
|
|
|
builders[i] = c.Create()
|
|
|
|
|
setFunc(builders[i], i)
|
|
|
|
|
}
|
|
|
|
|
return &AttachmentCreateBulk{config: c.config, builders: builders}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update returns an update builder for Attachment.
|
|
|
|
|
func (c *AttachmentClient) Update() *AttachmentUpdate {
|
|
|
|
|
mutation := newAttachmentMutation(c.config, OpUpdate)
|
|
|
|
|
return &AttachmentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
|
|
|
func (c *AttachmentClient) UpdateOne(a *Attachment) *AttachmentUpdateOne {
|
|
|
|
|
mutation := newAttachmentMutation(c.config, OpUpdateOne, withAttachment(a))
|
|
|
|
|
return &AttachmentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
|
|
|
func (c *AttachmentClient) UpdateOneID(id uuid.UUID) *AttachmentUpdateOne {
|
|
|
|
|
mutation := newAttachmentMutation(c.config, OpUpdateOne, withAttachmentID(id))
|
|
|
|
|
return &AttachmentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete returns a delete builder for Attachment.
|
|
|
|
|
func (c *AttachmentClient) Delete() *AttachmentDelete {
|
|
|
|
|
mutation := newAttachmentMutation(c.config, OpDelete)
|
|
|
|
|
return &AttachmentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
|
|
|
func (c *AttachmentClient) DeleteOne(a *Attachment) *AttachmentDeleteOne {
|
|
|
|
|
return c.DeleteOneID(a.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
|
|
|
func (c *AttachmentClient) DeleteOneID(id uuid.UUID) *AttachmentDeleteOne {
|
|
|
|
|
builder := c.Delete().Where(attachment.ID(id))
|
|
|
|
|
builder.mutation.id = &id
|
|
|
|
|
builder.mutation.op = OpDeleteOne
|
|
|
|
|
return &AttachmentDeleteOne{builder}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Query returns a query builder for Attachment.
|
|
|
|
|
func (c *AttachmentClient) Query() *AttachmentQuery {
|
|
|
|
|
return &AttachmentQuery{
|
|
|
|
|
config: c.config,
|
|
|
|
|
ctx: &QueryContext{Type: TypeAttachment},
|
|
|
|
|
inters: c.Interceptors(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get returns a Attachment entity by its id.
|
|
|
|
|
func (c *AttachmentClient) Get(ctx context.Context, id uuid.UUID) (*Attachment, error) {
|
|
|
|
|
return c.Query().Where(attachment.ID(id)).Only(ctx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
|
|
|
func (c *AttachmentClient) GetX(ctx context.Context, id uuid.UUID) *Attachment {
|
|
|
|
|
obj, err := c.Get(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return obj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryAuthor queries the author edge of a Attachment.
|
|
|
|
|
func (c *AttachmentClient) QueryAuthor(a *Attachment) *UserQuery {
|
|
|
|
|
query := (&UserClient{config: c.config}).Query()
|
|
|
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
|
|
|
id := a.ID
|
|
|
|
|
step := sqlgraph.NewStep(
|
|
|
|
|
sqlgraph.From(attachment.Table, attachment.FieldID, id),
|
|
|
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2O, false, attachment.AuthorTable, attachment.AuthorColumn),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(a.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hooks returns the client hooks.
|
|
|
|
|
func (c *AttachmentClient) Hooks() []Hook {
|
|
|
|
|
return c.hooks.Attachment
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Interceptors returns the client interceptors.
|
|
|
|
|
func (c *AttachmentClient) Interceptors() []Interceptor {
|
|
|
|
|
return c.inters.Attachment
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *AttachmentClient) mutate(ctx context.Context, m *AttachmentMutation) (Value, error) {
|
|
|
|
|
switch m.Op() {
|
|
|
|
|
case OpCreate:
|
|
|
|
|
return (&AttachmentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpUpdate:
|
|
|
|
|
return (&AttachmentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpUpdateOne:
|
|
|
|
|
return (&AttachmentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpDelete, OpDeleteOne:
|
|
|
|
|
return (&AttachmentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("ent: unknown Attachment mutation op: %q", m.Op())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FollowClient is a client for the Follow schema.
|
|
|
|
|
type FollowClient struct {
|
|
|
|
|
config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewFollowClient returns a client for the Follow from the given config.
|
|
|
|
|
func NewFollowClient(c config) *FollowClient {
|
|
|
|
|
return &FollowClient{config: c}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
|
|
|
// A call to `Use(f, g, h)` equals to `follow.Hooks(f(g(h())))`.
|
|
|
|
|
func (c *FollowClient) Use(hooks ...Hook) {
|
|
|
|
|
c.hooks.Follow = append(c.hooks.Follow, hooks...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
|
|
|
// A call to `Intercept(f, g, h)` equals to `follow.Intercept(f(g(h())))`.
|
|
|
|
|
func (c *FollowClient) Intercept(interceptors ...Interceptor) {
|
|
|
|
|
c.inters.Follow = append(c.inters.Follow, interceptors...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create returns a builder for creating a Follow entity.
|
|
|
|
|
func (c *FollowClient) Create() *FollowCreate {
|
|
|
|
|
mutation := newFollowMutation(c.config, OpCreate)
|
|
|
|
|
return &FollowCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Follow entities.
|
|
|
|
|
func (c *FollowClient) CreateBulk(builders ...*FollowCreate) *FollowCreateBulk {
|
|
|
|
|
return &FollowCreateBulk{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 *FollowClient) MapCreateBulk(slice any, setFunc func(*FollowCreate, int)) *FollowCreateBulk {
|
|
|
|
|
rv := reflect.ValueOf(slice)
|
|
|
|
|
if rv.Kind() != reflect.Slice {
|
|
|
|
|
return &FollowCreateBulk{err: fmt.Errorf("calling to FollowClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
|
|
|
}
|
|
|
|
|
builders := make([]*FollowCreate, rv.Len())
|
|
|
|
|
for i := 0; i < rv.Len(); i++ {
|
|
|
|
|
builders[i] = c.Create()
|
|
|
|
|
setFunc(builders[i], i)
|
|
|
|
|
}
|
|
|
|
|
return &FollowCreateBulk{config: c.config, builders: builders}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update returns an update builder for Follow.
|
|
|
|
|
func (c *FollowClient) Update() *FollowUpdate {
|
|
|
|
|
mutation := newFollowMutation(c.config, OpUpdate)
|
|
|
|
|
return &FollowUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
|
|
|
func (c *FollowClient) UpdateOne(f *Follow) *FollowUpdateOne {
|
|
|
|
|
mutation := newFollowMutation(c.config, OpUpdateOne, withFollow(f))
|
|
|
|
|
return &FollowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
|
|
|
func (c *FollowClient) UpdateOneID(id uuid.UUID) *FollowUpdateOne {
|
|
|
|
|
mutation := newFollowMutation(c.config, OpUpdateOne, withFollowID(id))
|
|
|
|
|
return &FollowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete returns a delete builder for Follow.
|
|
|
|
|
func (c *FollowClient) Delete() *FollowDelete {
|
|
|
|
|
mutation := newFollowMutation(c.config, OpDelete)
|
|
|
|
|
return &FollowDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
|
|
|
func (c *FollowClient) DeleteOne(f *Follow) *FollowDeleteOne {
|
|
|
|
|
return c.DeleteOneID(f.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
|
|
|
func (c *FollowClient) DeleteOneID(id uuid.UUID) *FollowDeleteOne {
|
|
|
|
|
builder := c.Delete().Where(follow.ID(id))
|
|
|
|
|
builder.mutation.id = &id
|
|
|
|
|
builder.mutation.op = OpDeleteOne
|
|
|
|
|
return &FollowDeleteOne{builder}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Query returns a query builder for Follow.
|
|
|
|
|
func (c *FollowClient) Query() *FollowQuery {
|
|
|
|
|
return &FollowQuery{
|
|
|
|
|
config: c.config,
|
|
|
|
|
ctx: &QueryContext{Type: TypeFollow},
|
|
|
|
|
inters: c.Interceptors(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get returns a Follow entity by its id.
|
|
|
|
|
func (c *FollowClient) Get(ctx context.Context, id uuid.UUID) (*Follow, error) {
|
|
|
|
|
return c.Query().Where(follow.ID(id)).Only(ctx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
|
|
|
func (c *FollowClient) GetX(ctx context.Context, id uuid.UUID) *Follow {
|
|
|
|
|
obj, err := c.Get(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return obj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryFollower queries the follower edge of a Follow.
|
|
|
|
|
func (c *FollowClient) QueryFollower(f *Follow) *UserQuery {
|
|
|
|
|
query := (&UserClient{config: c.config}).Query()
|
|
|
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
|
|
|
id := f.ID
|
|
|
|
|
step := sqlgraph.NewStep(
|
|
|
|
|
sqlgraph.From(follow.Table, follow.FieldID, id),
|
|
|
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2O, false, follow.FollowerTable, follow.FollowerColumn),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(f.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryFollowee queries the followee edge of a Follow.
|
|
|
|
|
func (c *FollowClient) QueryFollowee(f *Follow) *UserQuery {
|
|
|
|
|
query := (&UserClient{config: c.config}).Query()
|
|
|
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
|
|
|
id := f.ID
|
|
|
|
|
step := sqlgraph.NewStep(
|
|
|
|
|
sqlgraph.From(follow.Table, follow.FieldID, id),
|
|
|
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2O, false, follow.FolloweeTable, follow.FolloweeColumn),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(f.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hooks returns the client hooks.
|
|
|
|
|
func (c *FollowClient) Hooks() []Hook {
|
|
|
|
|
return c.hooks.Follow
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Interceptors returns the client interceptors.
|
|
|
|
|
func (c *FollowClient) Interceptors() []Interceptor {
|
|
|
|
|
return c.inters.Follow
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *FollowClient) mutate(ctx context.Context, m *FollowMutation) (Value, error) {
|
|
|
|
|
switch m.Op() {
|
|
|
|
|
case OpCreate:
|
|
|
|
|
return (&FollowCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpUpdate:
|
|
|
|
|
return (&FollowUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpUpdateOne:
|
|
|
|
|
return (&FollowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpDelete, OpDeleteOne:
|
|
|
|
|
return (&FollowDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("ent: unknown Follow mutation op: %q", m.Op())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ImageClient is a client for the Image schema.
|
|
|
|
|
type ImageClient struct {
|
|
|
|
|
config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewImageClient returns a client for the Image from the given config.
|
|
|
|
|
func NewImageClient(c config) *ImageClient {
|
|
|
|
|
return &ImageClient{config: c}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
|
|
|
// A call to `Use(f, g, h)` equals to `image.Hooks(f(g(h())))`.
|
|
|
|
|
func (c *ImageClient) Use(hooks ...Hook) {
|
|
|
|
|
c.hooks.Image = append(c.hooks.Image, hooks...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
|
|
|
// A call to `Intercept(f, g, h)` equals to `image.Intercept(f(g(h())))`.
|
|
|
|
|
func (c *ImageClient) Intercept(interceptors ...Interceptor) {
|
|
|
|
|
c.inters.Image = append(c.inters.Image, interceptors...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create returns a builder for creating a Image entity.
|
|
|
|
|
func (c *ImageClient) Create() *ImageCreate {
|
|
|
|
|
mutation := newImageMutation(c.config, OpCreate)
|
|
|
|
|
return &ImageCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Image entities.
|
|
|
|
|
func (c *ImageClient) CreateBulk(builders ...*ImageCreate) *ImageCreateBulk {
|
|
|
|
|
return &ImageCreateBulk{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 *ImageClient) MapCreateBulk(slice any, setFunc func(*ImageCreate, int)) *ImageCreateBulk {
|
|
|
|
|
rv := reflect.ValueOf(slice)
|
|
|
|
|
if rv.Kind() != reflect.Slice {
|
|
|
|
|
return &ImageCreateBulk{err: fmt.Errorf("calling to ImageClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
|
|
|
}
|
|
|
|
|
builders := make([]*ImageCreate, rv.Len())
|
|
|
|
|
for i := 0; i < rv.Len(); i++ {
|
|
|
|
|
builders[i] = c.Create()
|
|
|
|
|
setFunc(builders[i], i)
|
|
|
|
|
}
|
|
|
|
|
return &ImageCreateBulk{config: c.config, builders: builders}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update returns an update builder for Image.
|
|
|
|
|
func (c *ImageClient) Update() *ImageUpdate {
|
|
|
|
|
mutation := newImageMutation(c.config, OpUpdate)
|
|
|
|
|
return &ImageUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
|
|
|
func (c *ImageClient) UpdateOne(i *Image) *ImageUpdateOne {
|
|
|
|
|
mutation := newImageMutation(c.config, OpUpdateOne, withImage(i))
|
|
|
|
|
return &ImageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
|
|
|
func (c *ImageClient) UpdateOneID(id int) *ImageUpdateOne {
|
|
|
|
|
mutation := newImageMutation(c.config, OpUpdateOne, withImageID(id))
|
|
|
|
|
return &ImageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete returns a delete builder for Image.
|
|
|
|
|
func (c *ImageClient) Delete() *ImageDelete {
|
|
|
|
|
mutation := newImageMutation(c.config, OpDelete)
|
|
|
|
|
return &ImageDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
|
|
|
func (c *ImageClient) DeleteOne(i *Image) *ImageDeleteOne {
|
|
|
|
|
return c.DeleteOneID(i.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
|
|
|
func (c *ImageClient) DeleteOneID(id int) *ImageDeleteOne {
|
|
|
|
|
builder := c.Delete().Where(image.ID(id))
|
|
|
|
|
builder.mutation.id = &id
|
|
|
|
|
builder.mutation.op = OpDeleteOne
|
|
|
|
|
return &ImageDeleteOne{builder}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Query returns a query builder for Image.
|
|
|
|
|
func (c *ImageClient) Query() *ImageQuery {
|
|
|
|
|
return &ImageQuery{
|
|
|
|
|
config: c.config,
|
|
|
|
|
ctx: &QueryContext{Type: TypeImage},
|
|
|
|
|
inters: c.Interceptors(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get returns a Image entity by its id.
|
|
|
|
|
func (c *ImageClient) Get(ctx context.Context, id int) (*Image, error) {
|
|
|
|
|
return c.Query().Where(image.ID(id)).Only(ctx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
|
|
|
func (c *ImageClient) GetX(ctx context.Context, id int) *Image {
|
|
|
|
|
obj, err := c.Get(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return obj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hooks returns the client hooks.
|
|
|
|
|
func (c *ImageClient) Hooks() []Hook {
|
|
|
|
|
return c.hooks.Image
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Interceptors returns the client interceptors.
|
|
|
|
|
func (c *ImageClient) Interceptors() []Interceptor {
|
|
|
|
|
return c.inters.Image
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ImageClient) mutate(ctx context.Context, m *ImageMutation) (Value, error) {
|
|
|
|
|
switch m.Op() {
|
|
|
|
|
case OpCreate:
|
|
|
|
|
return (&ImageCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpUpdate:
|
|
|
|
|
return (&ImageUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpUpdateOne:
|
|
|
|
|
return (&ImageUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpDelete, OpDeleteOne:
|
|
|
|
|
return (&ImageDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("ent: unknown Image mutation op: %q", m.Op())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// InstanceMetadataClient is a client for the InstanceMetadata schema.
|
|
|
|
|
type InstanceMetadataClient struct {
|
2024-08-11 03:51:22 +02:00
|
|
|
config
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// NewInstanceMetadataClient returns a client for the InstanceMetadata from the given config.
|
|
|
|
|
func NewInstanceMetadataClient(c config) *InstanceMetadataClient {
|
|
|
|
|
return &InstanceMetadataClient{config: c}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
2024-08-20 22:43:26 +02:00
|
|
|
// A call to `Use(f, g, h)` equals to `instancemetadata.Hooks(f(g(h())))`.
|
|
|
|
|
func (c *InstanceMetadataClient) Use(hooks ...Hook) {
|
|
|
|
|
c.hooks.InstanceMetadata = append(c.hooks.InstanceMetadata, hooks...)
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
2024-08-20 22:43:26 +02:00
|
|
|
// A call to `Intercept(f, g, h)` equals to `instancemetadata.Intercept(f(g(h())))`.
|
|
|
|
|
func (c *InstanceMetadataClient) Intercept(interceptors ...Interceptor) {
|
|
|
|
|
c.inters.InstanceMetadata = append(c.inters.InstanceMetadata, interceptors...)
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Create returns a builder for creating a InstanceMetadata entity.
|
|
|
|
|
func (c *InstanceMetadataClient) Create() *InstanceMetadataCreate {
|
|
|
|
|
mutation := newInstanceMetadataMutation(c.config, OpCreate)
|
|
|
|
|
return &InstanceMetadataCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// CreateBulk returns a builder for creating a bulk of InstanceMetadata entities.
|
|
|
|
|
func (c *InstanceMetadataClient) CreateBulk(builders ...*InstanceMetadataCreate) *InstanceMetadataCreateBulk {
|
|
|
|
|
return &InstanceMetadataCreateBulk{config: c.config, builders: builders}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *InstanceMetadataClient) MapCreateBulk(slice any, setFunc func(*InstanceMetadataCreate, int)) *InstanceMetadataCreateBulk {
|
2024-08-11 03:51:22 +02:00
|
|
|
rv := reflect.ValueOf(slice)
|
|
|
|
|
if rv.Kind() != reflect.Slice {
|
2024-08-20 22:43:26 +02:00
|
|
|
return &InstanceMetadataCreateBulk{err: fmt.Errorf("calling to InstanceMetadataClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
2024-08-20 22:43:26 +02:00
|
|
|
builders := make([]*InstanceMetadataCreate, rv.Len())
|
2024-08-11 03:51:22 +02:00
|
|
|
for i := 0; i < rv.Len(); i++ {
|
|
|
|
|
builders[i] = c.Create()
|
|
|
|
|
setFunc(builders[i], i)
|
|
|
|
|
}
|
2024-08-20 22:43:26 +02:00
|
|
|
return &InstanceMetadataCreateBulk{config: c.config, builders: builders}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Update returns an update builder for InstanceMetadata.
|
|
|
|
|
func (c *InstanceMetadataClient) Update() *InstanceMetadataUpdate {
|
|
|
|
|
mutation := newInstanceMetadataMutation(c.config, OpUpdate)
|
|
|
|
|
return &InstanceMetadataUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *InstanceMetadataClient) UpdateOne(im *InstanceMetadata) *InstanceMetadataUpdateOne {
|
|
|
|
|
mutation := newInstanceMetadataMutation(c.config, OpUpdateOne, withInstanceMetadata(im))
|
|
|
|
|
return &InstanceMetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *InstanceMetadataClient) UpdateOneID(id uuid.UUID) *InstanceMetadataUpdateOne {
|
|
|
|
|
mutation := newInstanceMetadataMutation(c.config, OpUpdateOne, withInstanceMetadataID(id))
|
|
|
|
|
return &InstanceMetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Delete returns a delete builder for InstanceMetadata.
|
|
|
|
|
func (c *InstanceMetadataClient) Delete() *InstanceMetadataDelete {
|
|
|
|
|
mutation := newInstanceMetadataMutation(c.config, OpDelete)
|
|
|
|
|
return &InstanceMetadataDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *InstanceMetadataClient) DeleteOne(im *InstanceMetadata) *InstanceMetadataDeleteOne {
|
|
|
|
|
return c.DeleteOneID(im.ID)
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *InstanceMetadataClient) DeleteOneID(id uuid.UUID) *InstanceMetadataDeleteOne {
|
|
|
|
|
builder := c.Delete().Where(instancemetadata.ID(id))
|
2024-08-11 03:51:22 +02:00
|
|
|
builder.mutation.id = &id
|
|
|
|
|
builder.mutation.op = OpDeleteOne
|
2024-08-20 22:43:26 +02:00
|
|
|
return &InstanceMetadataDeleteOne{builder}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Query returns a query builder for InstanceMetadata.
|
|
|
|
|
func (c *InstanceMetadataClient) Query() *InstanceMetadataQuery {
|
|
|
|
|
return &InstanceMetadataQuery{
|
2024-08-11 03:51:22 +02:00
|
|
|
config: c.config,
|
2024-08-20 22:43:26 +02:00
|
|
|
ctx: &QueryContext{Type: TypeInstanceMetadata},
|
2024-08-11 03:51:22 +02:00
|
|
|
inters: c.Interceptors(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Get returns a InstanceMetadata entity by its id.
|
|
|
|
|
func (c *InstanceMetadataClient) Get(ctx context.Context, id uuid.UUID) (*InstanceMetadata, error) {
|
|
|
|
|
return c.Query().Where(instancemetadata.ID(id)).Only(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *InstanceMetadataClient) GetX(ctx context.Context, id uuid.UUID) *InstanceMetadata {
|
2024-08-11 03:51:22 +02:00
|
|
|
obj, err := c.Get(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return obj
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// QueryUsers queries the users edge of a InstanceMetadata.
|
|
|
|
|
func (c *InstanceMetadataClient) QueryUsers(im *InstanceMetadata) *UserQuery {
|
2024-08-11 03:51:22 +02:00
|
|
|
query := (&UserClient{config: c.config}).Query()
|
|
|
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
2024-08-20 22:43:26 +02:00
|
|
|
id := im.ID
|
2024-08-11 03:51:22 +02:00
|
|
|
step := sqlgraph.NewStep(
|
2024-08-20 22:43:26 +02:00
|
|
|
sqlgraph.From(instancemetadata.Table, instancemetadata.FieldID, id),
|
2024-08-11 03:51:22 +02:00
|
|
|
sqlgraph.To(user.Table, user.FieldID),
|
2024-08-20 22:43:26 +02:00
|
|
|
sqlgraph.Edge(sqlgraph.M2M, false, instancemetadata.UsersTable, instancemetadata.UsersPrimaryKey...),
|
2024-08-11 03:51:22 +02:00
|
|
|
)
|
2024-08-20 22:43:26 +02:00
|
|
|
fromV = sqlgraph.Neighbors(im.driver.Dialect(), step)
|
2024-08-11 03:51:22 +02:00
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// QueryModerators queries the moderators edge of a InstanceMetadata.
|
|
|
|
|
func (c *InstanceMetadataClient) QueryModerators(im *InstanceMetadata) *UserQuery {
|
2024-08-11 03:51:22 +02:00
|
|
|
query := (&UserClient{config: c.config}).Query()
|
|
|
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
2024-08-20 22:43:26 +02:00
|
|
|
id := im.ID
|
2024-08-11 03:51:22 +02:00
|
|
|
step := sqlgraph.NewStep(
|
2024-08-20 22:43:26 +02:00
|
|
|
sqlgraph.From(instancemetadata.Table, instancemetadata.FieldID, id),
|
2024-08-11 03:51:22 +02:00
|
|
|
sqlgraph.To(user.Table, user.FieldID),
|
2024-08-20 22:43:26 +02:00
|
|
|
sqlgraph.Edge(sqlgraph.M2M, false, instancemetadata.ModeratorsTable, instancemetadata.ModeratorsPrimaryKey...),
|
2024-08-11 03:51:22 +02:00
|
|
|
)
|
2024-08-20 22:43:26 +02:00
|
|
|
fromV = sqlgraph.Neighbors(im.driver.Dialect(), step)
|
2024-08-11 03:51:22 +02:00
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// QueryAdmins queries the admins edge of a InstanceMetadata.
|
|
|
|
|
func (c *InstanceMetadataClient) QueryAdmins(im *InstanceMetadata) *UserQuery {
|
|
|
|
|
query := (&UserClient{config: c.config}).Query()
|
2024-08-11 03:51:22 +02:00
|
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
2024-08-20 22:43:26 +02:00
|
|
|
id := im.ID
|
2024-08-11 03:51:22 +02:00
|
|
|
step := sqlgraph.NewStep(
|
2024-08-20 22:43:26 +02:00
|
|
|
sqlgraph.From(instancemetadata.Table, instancemetadata.FieldID, id),
|
|
|
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2M, false, instancemetadata.AdminsTable, instancemetadata.AdminsPrimaryKey...),
|
2024-08-11 03:51:22 +02:00
|
|
|
)
|
2024-08-20 22:43:26 +02:00
|
|
|
fromV = sqlgraph.Neighbors(im.driver.Dialect(), step)
|
2024-08-11 03:51:22 +02:00
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hooks returns the client hooks.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *InstanceMetadataClient) Hooks() []Hook {
|
|
|
|
|
return c.hooks.InstanceMetadata
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Interceptors returns the client interceptors.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *InstanceMetadataClient) Interceptors() []Interceptor {
|
|
|
|
|
return c.inters.InstanceMetadata
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *InstanceMetadataClient) mutate(ctx context.Context, m *InstanceMetadataMutation) (Value, error) {
|
2024-08-11 03:51:22 +02:00
|
|
|
switch m.Op() {
|
|
|
|
|
case OpCreate:
|
2024-08-20 22:43:26 +02:00
|
|
|
return (&InstanceMetadataCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
case OpUpdate:
|
2024-08-20 22:43:26 +02:00
|
|
|
return (&InstanceMetadataUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
case OpUpdateOne:
|
2024-08-20 22:43:26 +02:00
|
|
|
return (&InstanceMetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
case OpDelete, OpDeleteOne:
|
2024-08-20 22:43:26 +02:00
|
|
|
return (&InstanceMetadataDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
default:
|
2024-08-20 22:43:26 +02:00
|
|
|
return nil, fmt.Errorf("ent: unknown InstanceMetadata mutation op: %q", m.Op())
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// NoteClient is a client for the Note schema.
|
|
|
|
|
type NoteClient struct {
|
2024-08-11 03:51:22 +02:00
|
|
|
config
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// NewNoteClient returns a client for the Note from the given config.
|
|
|
|
|
func NewNoteClient(c config) *NoteClient {
|
|
|
|
|
return &NoteClient{config: c}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
2024-08-20 22:43:26 +02:00
|
|
|
// A call to `Use(f, g, h)` equals to `note.Hooks(f(g(h())))`.
|
|
|
|
|
func (c *NoteClient) Use(hooks ...Hook) {
|
|
|
|
|
c.hooks.Note = append(c.hooks.Note, hooks...)
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
2024-08-20 22:43:26 +02:00
|
|
|
// A call to `Intercept(f, g, h)` equals to `note.Intercept(f(g(h())))`.
|
|
|
|
|
func (c *NoteClient) Intercept(interceptors ...Interceptor) {
|
|
|
|
|
c.inters.Note = append(c.inters.Note, interceptors...)
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Create returns a builder for creating a Note entity.
|
|
|
|
|
func (c *NoteClient) Create() *NoteCreate {
|
|
|
|
|
mutation := newNoteMutation(c.config, OpCreate)
|
|
|
|
|
return &NoteCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// CreateBulk returns a builder for creating a bulk of Note entities.
|
|
|
|
|
func (c *NoteClient) CreateBulk(builders ...*NoteCreate) *NoteCreateBulk {
|
|
|
|
|
return &NoteCreateBulk{config: c.config, builders: builders}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *NoteClient) MapCreateBulk(slice any, setFunc func(*NoteCreate, int)) *NoteCreateBulk {
|
2024-08-11 03:51:22 +02:00
|
|
|
rv := reflect.ValueOf(slice)
|
|
|
|
|
if rv.Kind() != reflect.Slice {
|
2024-08-20 22:43:26 +02:00
|
|
|
return &NoteCreateBulk{err: fmt.Errorf("calling to NoteClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
2024-08-20 22:43:26 +02:00
|
|
|
builders := make([]*NoteCreate, rv.Len())
|
2024-08-11 03:51:22 +02:00
|
|
|
for i := 0; i < rv.Len(); i++ {
|
|
|
|
|
builders[i] = c.Create()
|
|
|
|
|
setFunc(builders[i], i)
|
|
|
|
|
}
|
2024-08-20 22:43:26 +02:00
|
|
|
return &NoteCreateBulk{config: c.config, builders: builders}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Update returns an update builder for Note.
|
|
|
|
|
func (c *NoteClient) Update() *NoteUpdate {
|
|
|
|
|
mutation := newNoteMutation(c.config, OpUpdate)
|
|
|
|
|
return &NoteUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *NoteClient) UpdateOne(n *Note) *NoteUpdateOne {
|
|
|
|
|
mutation := newNoteMutation(c.config, OpUpdateOne, withNote(n))
|
|
|
|
|
return &NoteUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *NoteClient) UpdateOneID(id uuid.UUID) *NoteUpdateOne {
|
|
|
|
|
mutation := newNoteMutation(c.config, OpUpdateOne, withNoteID(id))
|
|
|
|
|
return &NoteUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Delete returns a delete builder for Note.
|
|
|
|
|
func (c *NoteClient) Delete() *NoteDelete {
|
|
|
|
|
mutation := newNoteMutation(c.config, OpDelete)
|
|
|
|
|
return &NoteDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *NoteClient) DeleteOne(n *Note) *NoteDeleteOne {
|
|
|
|
|
return c.DeleteOneID(n.ID)
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *NoteClient) DeleteOneID(id uuid.UUID) *NoteDeleteOne {
|
|
|
|
|
builder := c.Delete().Where(note.ID(id))
|
2024-08-11 03:51:22 +02:00
|
|
|
builder.mutation.id = &id
|
|
|
|
|
builder.mutation.op = OpDeleteOne
|
2024-08-20 22:43:26 +02:00
|
|
|
return &NoteDeleteOne{builder}
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Query returns a query builder for Note.
|
|
|
|
|
func (c *NoteClient) Query() *NoteQuery {
|
|
|
|
|
return &NoteQuery{
|
2024-08-11 03:51:22 +02:00
|
|
|
config: c.config,
|
2024-08-20 22:43:26 +02:00
|
|
|
ctx: &QueryContext{Type: TypeNote},
|
2024-08-11 03:51:22 +02:00
|
|
|
inters: c.Interceptors(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// Get returns a Note entity by its id.
|
|
|
|
|
func (c *NoteClient) Get(ctx context.Context, id uuid.UUID) (*Note, error) {
|
|
|
|
|
return c.Query().Where(note.ID(id)).Only(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *NoteClient) GetX(ctx context.Context, id uuid.UUID) *Note {
|
2024-08-11 03:51:22 +02:00
|
|
|
obj, err := c.Get(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return obj
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// QueryAuthor queries the author edge of a Note.
|
|
|
|
|
func (c *NoteClient) QueryAuthor(n *Note) *UserQuery {
|
2024-08-11 03:51:22 +02:00
|
|
|
query := (&UserClient{config: c.config}).Query()
|
|
|
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
2024-08-20 22:43:26 +02:00
|
|
|
id := n.ID
|
2024-08-11 03:51:22 +02:00
|
|
|
step := sqlgraph.NewStep(
|
2024-08-20 22:43:26 +02:00
|
|
|
sqlgraph.From(note.Table, note.FieldID, id),
|
2024-08-11 03:51:22 +02:00
|
|
|
sqlgraph.To(user.Table, user.FieldID),
|
2024-08-20 22:43:26 +02:00
|
|
|
sqlgraph.Edge(sqlgraph.M2O, false, note.AuthorTable, note.AuthorColumn),
|
2024-08-11 03:51:22 +02:00
|
|
|
)
|
2024-08-20 22:43:26 +02:00
|
|
|
fromV = sqlgraph.Neighbors(n.driver.Dialect(), step)
|
2024-08-11 03:51:22 +02:00
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// QueryMentions queries the mentions edge of a Note.
|
|
|
|
|
func (c *NoteClient) QueryMentions(n *Note) *UserQuery {
|
2024-08-11 03:51:22 +02:00
|
|
|
query := (&UserClient{config: c.config}).Query()
|
|
|
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
2024-08-20 22:43:26 +02:00
|
|
|
id := n.ID
|
2024-08-11 03:51:22 +02:00
|
|
|
step := sqlgraph.NewStep(
|
2024-08-20 22:43:26 +02:00
|
|
|
sqlgraph.From(note.Table, note.FieldID, id),
|
2024-08-11 03:51:22 +02:00
|
|
|
sqlgraph.To(user.Table, user.FieldID),
|
2024-08-20 22:43:26 +02:00
|
|
|
sqlgraph.Edge(sqlgraph.M2M, false, note.MentionsTable, note.MentionsPrimaryKey...),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(n.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryAttachments queries the attachments edge of a Note.
|
|
|
|
|
func (c *NoteClient) QueryAttachments(n *Note) *AttachmentQuery {
|
|
|
|
|
query := (&AttachmentClient{config: c.config}).Query()
|
|
|
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
|
|
|
id := n.ID
|
|
|
|
|
step := sqlgraph.NewStep(
|
|
|
|
|
sqlgraph.From(note.Table, note.FieldID, id),
|
|
|
|
|
sqlgraph.To(attachment.Table, attachment.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.O2M, false, note.AttachmentsTable, note.AttachmentsColumn),
|
2024-08-11 03:51:22 +02:00
|
|
|
)
|
2024-08-20 22:43:26 +02:00
|
|
|
fromV = sqlgraph.Neighbors(n.driver.Dialect(), step)
|
2024-08-11 03:51:22 +02:00
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hooks returns the client hooks.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *NoteClient) Hooks() []Hook {
|
|
|
|
|
return c.hooks.Note
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Interceptors returns the client interceptors.
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *NoteClient) Interceptors() []Interceptor {
|
|
|
|
|
return c.inters.Note
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
func (c *NoteClient) mutate(ctx context.Context, m *NoteMutation) (Value, error) {
|
2024-08-11 03:51:22 +02:00
|
|
|
switch m.Op() {
|
|
|
|
|
case OpCreate:
|
2024-08-20 22:43:26 +02:00
|
|
|
return (&NoteCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
case OpUpdate:
|
2024-08-20 22:43:26 +02:00
|
|
|
return (&NoteUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
case OpUpdateOne:
|
2024-08-20 22:43:26 +02:00
|
|
|
return (&NoteUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
case OpDelete, OpDeleteOne:
|
2024-08-20 22:43:26 +02:00
|
|
|
return (&NoteDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
2024-08-11 03:51:22 +02:00
|
|
|
default:
|
2024-08-20 22:43:26 +02:00
|
|
|
return nil, fmt.Errorf("ent: unknown Note mutation op: %q", m.Op())
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryAvatarImage queries the avatarImage edge of a User.
|
|
|
|
|
func (c *UserClient) QueryAvatarImage(u *User) *ImageQuery {
|
|
|
|
|
query := (&ImageClient{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(image.Table, image.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2O, false, user.AvatarImageTable, user.AvatarImageColumn),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryHeaderImage queries the headerImage edge of a User.
|
|
|
|
|
func (c *UserClient) QueryHeaderImage(u *User) *ImageQuery {
|
|
|
|
|
query := (&ImageClient{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(image.Table, image.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2O, false, user.HeaderImageTable, user.HeaderImageColumn),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryAuthoredNotes queries the authoredNotes edge of a User.
|
|
|
|
|
func (c *UserClient) QueryAuthoredNotes(u *User) *NoteQuery {
|
|
|
|
|
query := (&NoteClient{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(note.Table, note.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.O2M, true, user.AuthoredNotesTable, user.AuthoredNotesColumn),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryMentionedNotes queries the mentionedNotes edge of a User.
|
|
|
|
|
func (c *UserClient) QueryMentionedNotes(u *User) *NoteQuery {
|
|
|
|
|
query := (&NoteClient{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(note.Table, note.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2M, true, user.MentionedNotesTable, user.MentionedNotesPrimaryKey...),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
// QueryServers queries the servers edge of a User.
|
|
|
|
|
func (c *UserClient) QueryServers(u *User) *InstanceMetadataQuery {
|
|
|
|
|
query := (&InstanceMetadataClient{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(instancemetadata.Table, instancemetadata.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2M, true, user.ServersTable, user.ServersPrimaryKey...),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryModeratedServers queries the moderatedServers edge of a User.
|
|
|
|
|
func (c *UserClient) QueryModeratedServers(u *User) *InstanceMetadataQuery {
|
|
|
|
|
query := (&InstanceMetadataClient{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(instancemetadata.Table, instancemetadata.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2M, true, user.ModeratedServersTable, user.ModeratedServersPrimaryKey...),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QueryAdministeredServers queries the administeredServers edge of a User.
|
|
|
|
|
func (c *UserClient) QueryAdministeredServers(u *User) *InstanceMetadataQuery {
|
|
|
|
|
query := (&InstanceMetadataClient{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(instancemetadata.Table, instancemetadata.FieldID),
|
|
|
|
|
sqlgraph.Edge(sqlgraph.M2M, true, user.AdministeredServersTable, user.AdministeredServersPrimaryKey...),
|
|
|
|
|
)
|
|
|
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
|
|
|
return fromV, nil
|
|
|
|
|
}
|
|
|
|
|
return query
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-11 03:51:22 +02:00
|
|
|
// Hooks returns the client hooks.
|
|
|
|
|
func (c *UserClient) Hooks() []Hook {
|
|
|
|
|
return c.hooks.User
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Interceptors returns the client interceptors.
|
|
|
|
|
func (c *UserClient) Interceptors() []Interceptor {
|
|
|
|
|
return c.inters.User
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) {
|
|
|
|
|
switch m.Op() {
|
|
|
|
|
case OpCreate:
|
|
|
|
|
return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpUpdate:
|
|
|
|
|
return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpUpdateOne:
|
|
|
|
|
return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
|
|
|
case OpDelete, OpDeleteOne:
|
|
|
|
|
return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// hooks and interceptors per client, for fast access.
|
|
|
|
|
type (
|
|
|
|
|
hooks struct {
|
2024-08-20 22:43:26 +02:00
|
|
|
Attachment, Follow, Image, InstanceMetadata, Note, User []ent.Hook
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
inters struct {
|
2024-08-20 22:43:26 +02:00
|
|
|
Attachment, Follow, Image, InstanceMetadata, Note, User []ent.Interceptor
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|
|
|
|
|
)
|