/ ent / client.go
client.go
   1  // Code generated by ent, DO NOT EDIT.
   2  
   3  package ent
   4  
   5  import (
   6  	"context"
   7  	"errors"
   8  	"fmt"
   9  	"log"
  10  	"reflect"
  11  
  12  	"github.com/google/uuid"
  13  	"github.com/mrusme/journalist/ent/migrate"
  14  
  15  	"entgo.io/ent"
  16  	"entgo.io/ent/dialect"
  17  	"entgo.io/ent/dialect/sql"
  18  	"entgo.io/ent/dialect/sql/sqlgraph"
  19  	"github.com/mrusme/journalist/ent/feed"
  20  	"github.com/mrusme/journalist/ent/item"
  21  	"github.com/mrusme/journalist/ent/read"
  22  	"github.com/mrusme/journalist/ent/subscription"
  23  	"github.com/mrusme/journalist/ent/token"
  24  	"github.com/mrusme/journalist/ent/user"
  25  )
  26  
  27  // Client is the client that holds all ent builders.
  28  type Client struct {
  29  	config
  30  	// Schema is the client for creating, migrating and dropping schema.
  31  	Schema *migrate.Schema
  32  	// Feed is the client for interacting with the Feed builders.
  33  	Feed *FeedClient
  34  	// Item is the client for interacting with the Item builders.
  35  	Item *ItemClient
  36  	// Read is the client for interacting with the Read builders.
  37  	Read *ReadClient
  38  	// Subscription is the client for interacting with the Subscription builders.
  39  	Subscription *SubscriptionClient
  40  	// Token is the client for interacting with the Token builders.
  41  	Token *TokenClient
  42  	// User is the client for interacting with the User builders.
  43  	User *UserClient
  44  }
  45  
  46  // NewClient creates a new client configured with the given options.
  47  func NewClient(opts ...Option) *Client {
  48  	client := &Client{config: newConfig(opts...)}
  49  	client.init()
  50  	return client
  51  }
  52  
  53  func (c *Client) init() {
  54  	c.Schema = migrate.NewSchema(c.driver)
  55  	c.Feed = NewFeedClient(c.config)
  56  	c.Item = NewItemClient(c.config)
  57  	c.Read = NewReadClient(c.config)
  58  	c.Subscription = NewSubscriptionClient(c.config)
  59  	c.Token = NewTokenClient(c.config)
  60  	c.User = NewUserClient(c.config)
  61  }
  62  
  63  type (
  64  	// config is the configuration for the client and its builder.
  65  	config struct {
  66  		// driver used for executing database requests.
  67  		driver dialect.Driver
  68  		// debug enable a debug logging.
  69  		debug bool
  70  		// log used for logging on debug mode.
  71  		log func(...any)
  72  		// hooks to execute on mutations.
  73  		hooks *hooks
  74  		// interceptors to execute on queries.
  75  		inters *inters
  76  	}
  77  	// Option function to configure the client.
  78  	Option func(*config)
  79  )
  80  
  81  // newConfig creates a new config for the client.
  82  func newConfig(opts ...Option) config {
  83  	cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
  84  	cfg.options(opts...)
  85  	return cfg
  86  }
  87  
  88  // options applies the options on the config object.
  89  func (c *config) options(opts ...Option) {
  90  	for _, opt := range opts {
  91  		opt(c)
  92  	}
  93  	if c.debug {
  94  		c.driver = dialect.Debug(c.driver, c.log)
  95  	}
  96  }
  97  
  98  // Debug enables debug logging on the ent.Driver.
  99  func Debug() Option {
 100  	return func(c *config) {
 101  		c.debug = true
 102  	}
 103  }
 104  
 105  // Log sets the logging function for debug mode.
 106  func Log(fn func(...any)) Option {
 107  	return func(c *config) {
 108  		c.log = fn
 109  	}
 110  }
 111  
 112  // Driver configures the client driver.
 113  func Driver(driver dialect.Driver) Option {
 114  	return func(c *config) {
 115  		c.driver = driver
 116  	}
 117  }
 118  
 119  // Open opens a database/sql.DB specified by the driver name and
 120  // the data source name, and returns a new client attached to it.
 121  // Optional parameters can be added for configuring the client.
 122  func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
 123  	switch driverName {
 124  	case dialect.MySQL, dialect.Postgres, dialect.SQLite:
 125  		drv, err := sql.Open(driverName, dataSourceName)
 126  		if err != nil {
 127  			return nil, err
 128  		}
 129  		return NewClient(append(options, Driver(drv))...), nil
 130  	default:
 131  		return nil, fmt.Errorf("unsupported driver: %q", driverName)
 132  	}
 133  }
 134  
 135  // ErrTxStarted is returned when trying to start a new transaction from a transactional client.
 136  var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
 137  
 138  // Tx returns a new transactional client. The provided context
 139  // is used until the transaction is committed or rolled back.
 140  func (c *Client) Tx(ctx context.Context) (*Tx, error) {
 141  	if _, ok := c.driver.(*txDriver); ok {
 142  		return nil, ErrTxStarted
 143  	}
 144  	tx, err := newTx(ctx, c.driver)
 145  	if err != nil {
 146  		return nil, fmt.Errorf("ent: starting a transaction: %w", err)
 147  	}
 148  	cfg := c.config
 149  	cfg.driver = tx
 150  	return &Tx{
 151  		ctx:          ctx,
 152  		config:       cfg,
 153  		Feed:         NewFeedClient(cfg),
 154  		Item:         NewItemClient(cfg),
 155  		Read:         NewReadClient(cfg),
 156  		Subscription: NewSubscriptionClient(cfg),
 157  		Token:        NewTokenClient(cfg),
 158  		User:         NewUserClient(cfg),
 159  	}, nil
 160  }
 161  
 162  // BeginTx returns a transactional client with specified options.
 163  func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
 164  	if _, ok := c.driver.(*txDriver); ok {
 165  		return nil, errors.New("ent: cannot start a transaction within a transaction")
 166  	}
 167  	tx, err := c.driver.(interface {
 168  		BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
 169  	}).BeginTx(ctx, opts)
 170  	if err != nil {
 171  		return nil, fmt.Errorf("ent: starting a transaction: %w", err)
 172  	}
 173  	cfg := c.config
 174  	cfg.driver = &txDriver{tx: tx, drv: c.driver}
 175  	return &Tx{
 176  		ctx:          ctx,
 177  		config:       cfg,
 178  		Feed:         NewFeedClient(cfg),
 179  		Item:         NewItemClient(cfg),
 180  		Read:         NewReadClient(cfg),
 181  		Subscription: NewSubscriptionClient(cfg),
 182  		Token:        NewTokenClient(cfg),
 183  		User:         NewUserClient(cfg),
 184  	}, nil
 185  }
 186  
 187  // Debug returns a new debug-client. It's used to get verbose logging on specific operations.
 188  //
 189  //	client.Debug().
 190  //		Feed.
 191  //		Query().
 192  //		Count(ctx)
 193  func (c *Client) Debug() *Client {
 194  	if c.debug {
 195  		return c
 196  	}
 197  	cfg := c.config
 198  	cfg.driver = dialect.Debug(c.driver, c.log)
 199  	client := &Client{config: cfg}
 200  	client.init()
 201  	return client
 202  }
 203  
 204  // Close closes the database connection and prevents new queries from starting.
 205  func (c *Client) Close() error {
 206  	return c.driver.Close()
 207  }
 208  
 209  // Use adds the mutation hooks to all the entity clients.
 210  // In order to add hooks to a specific client, call: `client.Node.Use(...)`.
 211  func (c *Client) Use(hooks ...Hook) {
 212  	for _, n := range []interface{ Use(...Hook) }{
 213  		c.Feed, c.Item, c.Read, c.Subscription, c.Token, c.User,
 214  	} {
 215  		n.Use(hooks...)
 216  	}
 217  }
 218  
 219  // Intercept adds the query interceptors to all the entity clients.
 220  // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
 221  func (c *Client) Intercept(interceptors ...Interceptor) {
 222  	for _, n := range []interface{ Intercept(...Interceptor) }{
 223  		c.Feed, c.Item, c.Read, c.Subscription, c.Token, c.User,
 224  	} {
 225  		n.Intercept(interceptors...)
 226  	}
 227  }
 228  
 229  // Mutate implements the ent.Mutator interface.
 230  func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
 231  	switch m := m.(type) {
 232  	case *FeedMutation:
 233  		return c.Feed.mutate(ctx, m)
 234  	case *ItemMutation:
 235  		return c.Item.mutate(ctx, m)
 236  	case *ReadMutation:
 237  		return c.Read.mutate(ctx, m)
 238  	case *SubscriptionMutation:
 239  		return c.Subscription.mutate(ctx, m)
 240  	case *TokenMutation:
 241  		return c.Token.mutate(ctx, m)
 242  	case *UserMutation:
 243  		return c.User.mutate(ctx, m)
 244  	default:
 245  		return nil, fmt.Errorf("ent: unknown mutation type %T", m)
 246  	}
 247  }
 248  
 249  // FeedClient is a client for the Feed schema.
 250  type FeedClient struct {
 251  	config
 252  }
 253  
 254  // NewFeedClient returns a client for the Feed from the given config.
 255  func NewFeedClient(c config) *FeedClient {
 256  	return &FeedClient{config: c}
 257  }
 258  
 259  // Use adds a list of mutation hooks to the hooks stack.
 260  // A call to `Use(f, g, h)` equals to `feed.Hooks(f(g(h())))`.
 261  func (c *FeedClient) Use(hooks ...Hook) {
 262  	c.hooks.Feed = append(c.hooks.Feed, hooks...)
 263  }
 264  
 265  // Intercept adds a list of query interceptors to the interceptors stack.
 266  // A call to `Intercept(f, g, h)` equals to `feed.Intercept(f(g(h())))`.
 267  func (c *FeedClient) Intercept(interceptors ...Interceptor) {
 268  	c.inters.Feed = append(c.inters.Feed, interceptors...)
 269  }
 270  
 271  // Create returns a builder for creating a Feed entity.
 272  func (c *FeedClient) Create() *FeedCreate {
 273  	mutation := newFeedMutation(c.config, OpCreate)
 274  	return &FeedCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 275  }
 276  
 277  // CreateBulk returns a builder for creating a bulk of Feed entities.
 278  func (c *FeedClient) CreateBulk(builders ...*FeedCreate) *FeedCreateBulk {
 279  	return &FeedCreateBulk{config: c.config, builders: builders}
 280  }
 281  
 282  // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
 283  // a builder and applies setFunc on it.
 284  func (c *FeedClient) MapCreateBulk(slice any, setFunc func(*FeedCreate, int)) *FeedCreateBulk {
 285  	rv := reflect.ValueOf(slice)
 286  	if rv.Kind() != reflect.Slice {
 287  		return &FeedCreateBulk{err: fmt.Errorf("calling to FeedClient.MapCreateBulk with wrong type %T, need slice", slice)}
 288  	}
 289  	builders := make([]*FeedCreate, rv.Len())
 290  	for i := 0; i < rv.Len(); i++ {
 291  		builders[i] = c.Create()
 292  		setFunc(builders[i], i)
 293  	}
 294  	return &FeedCreateBulk{config: c.config, builders: builders}
 295  }
 296  
 297  // Update returns an update builder for Feed.
 298  func (c *FeedClient) Update() *FeedUpdate {
 299  	mutation := newFeedMutation(c.config, OpUpdate)
 300  	return &FeedUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 301  }
 302  
 303  // UpdateOne returns an update builder for the given entity.
 304  func (c *FeedClient) UpdateOne(f *Feed) *FeedUpdateOne {
 305  	mutation := newFeedMutation(c.config, OpUpdateOne, withFeed(f))
 306  	return &FeedUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
 307  }
 308  
 309  // UpdateOneID returns an update builder for the given id.
 310  func (c *FeedClient) UpdateOneID(id uuid.UUID) *FeedUpdateOne {
 311  	mutation := newFeedMutation(c.config, OpUpdateOne, withFeedID(id))
 312  	return &FeedUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
 313  }
 314  
 315  // Delete returns a delete builder for Feed.
 316  func (c *FeedClient) Delete() *FeedDelete {
 317  	mutation := newFeedMutation(c.config, OpDelete)
 318  	return &FeedDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
 319  }
 320  
 321  // DeleteOne returns a builder for deleting the given entity.
 322  func (c *FeedClient) DeleteOne(f *Feed) *FeedDeleteOne {
 323  	return c.DeleteOneID(f.ID)
 324  }
 325  
 326  // DeleteOneID returns a builder for deleting the given entity by its id.
 327  func (c *FeedClient) DeleteOneID(id uuid.UUID) *FeedDeleteOne {
 328  	builder := c.Delete().Where(feed.ID(id))
 329  	builder.mutation.id = &id
 330  	builder.mutation.op = OpDeleteOne
 331  	return &FeedDeleteOne{builder}
 332  }
 333  
 334  // Query returns a query builder for Feed.
 335  func (c *FeedClient) Query() *FeedQuery {
 336  	return &FeedQuery{
 337  		config: c.config,
 338  		ctx:    &QueryContext{Type: TypeFeed},
 339  		inters: c.Interceptors(),
 340  	}
 341  }
 342  
 343  // Get returns a Feed entity by its id.
 344  func (c *FeedClient) Get(ctx context.Context, id uuid.UUID) (*Feed, error) {
 345  	return c.Query().Where(feed.ID(id)).Only(ctx)
 346  }
 347  
 348  // GetX is like Get, but panics if an error occurs.
 349  func (c *FeedClient) GetX(ctx context.Context, id uuid.UUID) *Feed {
 350  	obj, err := c.Get(ctx, id)
 351  	if err != nil {
 352  		panic(err)
 353  	}
 354  	return obj
 355  }
 356  
 357  // QueryItems queries the items edge of a Feed.
 358  func (c *FeedClient) QueryItems(f *Feed) *ItemQuery {
 359  	query := (&ItemClient{config: c.config}).Query()
 360  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 361  		id := f.ID
 362  		step := sqlgraph.NewStep(
 363  			sqlgraph.From(feed.Table, feed.FieldID, id),
 364  			sqlgraph.To(item.Table, item.FieldID),
 365  			sqlgraph.Edge(sqlgraph.O2M, false, feed.ItemsTable, feed.ItemsColumn),
 366  		)
 367  		fromV = sqlgraph.Neighbors(f.driver.Dialect(), step)
 368  		return fromV, nil
 369  	}
 370  	return query
 371  }
 372  
 373  // QuerySubscribedUsers queries the subscribed_users edge of a Feed.
 374  func (c *FeedClient) QuerySubscribedUsers(f *Feed) *UserQuery {
 375  	query := (&UserClient{config: c.config}).Query()
 376  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 377  		id := f.ID
 378  		step := sqlgraph.NewStep(
 379  			sqlgraph.From(feed.Table, feed.FieldID, id),
 380  			sqlgraph.To(user.Table, user.FieldID),
 381  			sqlgraph.Edge(sqlgraph.M2M, true, feed.SubscribedUsersTable, feed.SubscribedUsersPrimaryKey...),
 382  		)
 383  		fromV = sqlgraph.Neighbors(f.driver.Dialect(), step)
 384  		return fromV, nil
 385  	}
 386  	return query
 387  }
 388  
 389  // QuerySubscriptions queries the subscriptions edge of a Feed.
 390  func (c *FeedClient) QuerySubscriptions(f *Feed) *SubscriptionQuery {
 391  	query := (&SubscriptionClient{config: c.config}).Query()
 392  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 393  		id := f.ID
 394  		step := sqlgraph.NewStep(
 395  			sqlgraph.From(feed.Table, feed.FieldID, id),
 396  			sqlgraph.To(subscription.Table, subscription.FieldID),
 397  			sqlgraph.Edge(sqlgraph.O2M, true, feed.SubscriptionsTable, feed.SubscriptionsColumn),
 398  		)
 399  		fromV = sqlgraph.Neighbors(f.driver.Dialect(), step)
 400  		return fromV, nil
 401  	}
 402  	return query
 403  }
 404  
 405  // Hooks returns the client hooks.
 406  func (c *FeedClient) Hooks() []Hook {
 407  	return c.hooks.Feed
 408  }
 409  
 410  // Interceptors returns the client interceptors.
 411  func (c *FeedClient) Interceptors() []Interceptor {
 412  	return c.inters.Feed
 413  }
 414  
 415  func (c *FeedClient) mutate(ctx context.Context, m *FeedMutation) (Value, error) {
 416  	switch m.Op() {
 417  	case OpCreate:
 418  		return (&FeedCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 419  	case OpUpdate:
 420  		return (&FeedUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 421  	case OpUpdateOne:
 422  		return (&FeedUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 423  	case OpDelete, OpDeleteOne:
 424  		return (&FeedDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
 425  	default:
 426  		return nil, fmt.Errorf("ent: unknown Feed mutation op: %q", m.Op())
 427  	}
 428  }
 429  
 430  // ItemClient is a client for the Item schema.
 431  type ItemClient struct {
 432  	config
 433  }
 434  
 435  // NewItemClient returns a client for the Item from the given config.
 436  func NewItemClient(c config) *ItemClient {
 437  	return &ItemClient{config: c}
 438  }
 439  
 440  // Use adds a list of mutation hooks to the hooks stack.
 441  // A call to `Use(f, g, h)` equals to `item.Hooks(f(g(h())))`.
 442  func (c *ItemClient) Use(hooks ...Hook) {
 443  	c.hooks.Item = append(c.hooks.Item, hooks...)
 444  }
 445  
 446  // Intercept adds a list of query interceptors to the interceptors stack.
 447  // A call to `Intercept(f, g, h)` equals to `item.Intercept(f(g(h())))`.
 448  func (c *ItemClient) Intercept(interceptors ...Interceptor) {
 449  	c.inters.Item = append(c.inters.Item, interceptors...)
 450  }
 451  
 452  // Create returns a builder for creating a Item entity.
 453  func (c *ItemClient) Create() *ItemCreate {
 454  	mutation := newItemMutation(c.config, OpCreate)
 455  	return &ItemCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 456  }
 457  
 458  // CreateBulk returns a builder for creating a bulk of Item entities.
 459  func (c *ItemClient) CreateBulk(builders ...*ItemCreate) *ItemCreateBulk {
 460  	return &ItemCreateBulk{config: c.config, builders: builders}
 461  }
 462  
 463  // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
 464  // a builder and applies setFunc on it.
 465  func (c *ItemClient) MapCreateBulk(slice any, setFunc func(*ItemCreate, int)) *ItemCreateBulk {
 466  	rv := reflect.ValueOf(slice)
 467  	if rv.Kind() != reflect.Slice {
 468  		return &ItemCreateBulk{err: fmt.Errorf("calling to ItemClient.MapCreateBulk with wrong type %T, need slice", slice)}
 469  	}
 470  	builders := make([]*ItemCreate, rv.Len())
 471  	for i := 0; i < rv.Len(); i++ {
 472  		builders[i] = c.Create()
 473  		setFunc(builders[i], i)
 474  	}
 475  	return &ItemCreateBulk{config: c.config, builders: builders}
 476  }
 477  
 478  // Update returns an update builder for Item.
 479  func (c *ItemClient) Update() *ItemUpdate {
 480  	mutation := newItemMutation(c.config, OpUpdate)
 481  	return &ItemUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 482  }
 483  
 484  // UpdateOne returns an update builder for the given entity.
 485  func (c *ItemClient) UpdateOne(i *Item) *ItemUpdateOne {
 486  	mutation := newItemMutation(c.config, OpUpdateOne, withItem(i))
 487  	return &ItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
 488  }
 489  
 490  // UpdateOneID returns an update builder for the given id.
 491  func (c *ItemClient) UpdateOneID(id uuid.UUID) *ItemUpdateOne {
 492  	mutation := newItemMutation(c.config, OpUpdateOne, withItemID(id))
 493  	return &ItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
 494  }
 495  
 496  // Delete returns a delete builder for Item.
 497  func (c *ItemClient) Delete() *ItemDelete {
 498  	mutation := newItemMutation(c.config, OpDelete)
 499  	return &ItemDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
 500  }
 501  
 502  // DeleteOne returns a builder for deleting the given entity.
 503  func (c *ItemClient) DeleteOne(i *Item) *ItemDeleteOne {
 504  	return c.DeleteOneID(i.ID)
 505  }
 506  
 507  // DeleteOneID returns a builder for deleting the given entity by its id.
 508  func (c *ItemClient) DeleteOneID(id uuid.UUID) *ItemDeleteOne {
 509  	builder := c.Delete().Where(item.ID(id))
 510  	builder.mutation.id = &id
 511  	builder.mutation.op = OpDeleteOne
 512  	return &ItemDeleteOne{builder}
 513  }
 514  
 515  // Query returns a query builder for Item.
 516  func (c *ItemClient) Query() *ItemQuery {
 517  	return &ItemQuery{
 518  		config: c.config,
 519  		ctx:    &QueryContext{Type: TypeItem},
 520  		inters: c.Interceptors(),
 521  	}
 522  }
 523  
 524  // Get returns a Item entity by its id.
 525  func (c *ItemClient) Get(ctx context.Context, id uuid.UUID) (*Item, error) {
 526  	return c.Query().Where(item.ID(id)).Only(ctx)
 527  }
 528  
 529  // GetX is like Get, but panics if an error occurs.
 530  func (c *ItemClient) GetX(ctx context.Context, id uuid.UUID) *Item {
 531  	obj, err := c.Get(ctx, id)
 532  	if err != nil {
 533  		panic(err)
 534  	}
 535  	return obj
 536  }
 537  
 538  // QueryFeed queries the feed edge of a Item.
 539  func (c *ItemClient) QueryFeed(i *Item) *FeedQuery {
 540  	query := (&FeedClient{config: c.config}).Query()
 541  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 542  		id := i.ID
 543  		step := sqlgraph.NewStep(
 544  			sqlgraph.From(item.Table, item.FieldID, id),
 545  			sqlgraph.To(feed.Table, feed.FieldID),
 546  			sqlgraph.Edge(sqlgraph.M2O, true, item.FeedTable, item.FeedColumn),
 547  		)
 548  		fromV = sqlgraph.Neighbors(i.driver.Dialect(), step)
 549  		return fromV, nil
 550  	}
 551  	return query
 552  }
 553  
 554  // QueryReadByUsers queries the read_by_users edge of a Item.
 555  func (c *ItemClient) QueryReadByUsers(i *Item) *UserQuery {
 556  	query := (&UserClient{config: c.config}).Query()
 557  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 558  		id := i.ID
 559  		step := sqlgraph.NewStep(
 560  			sqlgraph.From(item.Table, item.FieldID, id),
 561  			sqlgraph.To(user.Table, user.FieldID),
 562  			sqlgraph.Edge(sqlgraph.M2M, true, item.ReadByUsersTable, item.ReadByUsersPrimaryKey...),
 563  		)
 564  		fromV = sqlgraph.Neighbors(i.driver.Dialect(), step)
 565  		return fromV, nil
 566  	}
 567  	return query
 568  }
 569  
 570  // QueryReads queries the reads edge of a Item.
 571  func (c *ItemClient) QueryReads(i *Item) *ReadQuery {
 572  	query := (&ReadClient{config: c.config}).Query()
 573  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 574  		id := i.ID
 575  		step := sqlgraph.NewStep(
 576  			sqlgraph.From(item.Table, item.FieldID, id),
 577  			sqlgraph.To(read.Table, read.FieldID),
 578  			sqlgraph.Edge(sqlgraph.O2M, true, item.ReadsTable, item.ReadsColumn),
 579  		)
 580  		fromV = sqlgraph.Neighbors(i.driver.Dialect(), step)
 581  		return fromV, nil
 582  	}
 583  	return query
 584  }
 585  
 586  // Hooks returns the client hooks.
 587  func (c *ItemClient) Hooks() []Hook {
 588  	return c.hooks.Item
 589  }
 590  
 591  // Interceptors returns the client interceptors.
 592  func (c *ItemClient) Interceptors() []Interceptor {
 593  	return c.inters.Item
 594  }
 595  
 596  func (c *ItemClient) mutate(ctx context.Context, m *ItemMutation) (Value, error) {
 597  	switch m.Op() {
 598  	case OpCreate:
 599  		return (&ItemCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 600  	case OpUpdate:
 601  		return (&ItemUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 602  	case OpUpdateOne:
 603  		return (&ItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 604  	case OpDelete, OpDeleteOne:
 605  		return (&ItemDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
 606  	default:
 607  		return nil, fmt.Errorf("ent: unknown Item mutation op: %q", m.Op())
 608  	}
 609  }
 610  
 611  // ReadClient is a client for the Read schema.
 612  type ReadClient struct {
 613  	config
 614  }
 615  
 616  // NewReadClient returns a client for the Read from the given config.
 617  func NewReadClient(c config) *ReadClient {
 618  	return &ReadClient{config: c}
 619  }
 620  
 621  // Use adds a list of mutation hooks to the hooks stack.
 622  // A call to `Use(f, g, h)` equals to `read.Hooks(f(g(h())))`.
 623  func (c *ReadClient) Use(hooks ...Hook) {
 624  	c.hooks.Read = append(c.hooks.Read, hooks...)
 625  }
 626  
 627  // Intercept adds a list of query interceptors to the interceptors stack.
 628  // A call to `Intercept(f, g, h)` equals to `read.Intercept(f(g(h())))`.
 629  func (c *ReadClient) Intercept(interceptors ...Interceptor) {
 630  	c.inters.Read = append(c.inters.Read, interceptors...)
 631  }
 632  
 633  // Create returns a builder for creating a Read entity.
 634  func (c *ReadClient) Create() *ReadCreate {
 635  	mutation := newReadMutation(c.config, OpCreate)
 636  	return &ReadCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 637  }
 638  
 639  // CreateBulk returns a builder for creating a bulk of Read entities.
 640  func (c *ReadClient) CreateBulk(builders ...*ReadCreate) *ReadCreateBulk {
 641  	return &ReadCreateBulk{config: c.config, builders: builders}
 642  }
 643  
 644  // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
 645  // a builder and applies setFunc on it.
 646  func (c *ReadClient) MapCreateBulk(slice any, setFunc func(*ReadCreate, int)) *ReadCreateBulk {
 647  	rv := reflect.ValueOf(slice)
 648  	if rv.Kind() != reflect.Slice {
 649  		return &ReadCreateBulk{err: fmt.Errorf("calling to ReadClient.MapCreateBulk with wrong type %T, need slice", slice)}
 650  	}
 651  	builders := make([]*ReadCreate, rv.Len())
 652  	for i := 0; i < rv.Len(); i++ {
 653  		builders[i] = c.Create()
 654  		setFunc(builders[i], i)
 655  	}
 656  	return &ReadCreateBulk{config: c.config, builders: builders}
 657  }
 658  
 659  // Update returns an update builder for Read.
 660  func (c *ReadClient) Update() *ReadUpdate {
 661  	mutation := newReadMutation(c.config, OpUpdate)
 662  	return &ReadUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 663  }
 664  
 665  // UpdateOne returns an update builder for the given entity.
 666  func (c *ReadClient) UpdateOne(r *Read) *ReadUpdateOne {
 667  	mutation := newReadMutation(c.config, OpUpdateOne, withRead(r))
 668  	return &ReadUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
 669  }
 670  
 671  // UpdateOneID returns an update builder for the given id.
 672  func (c *ReadClient) UpdateOneID(id uuid.UUID) *ReadUpdateOne {
 673  	mutation := newReadMutation(c.config, OpUpdateOne, withReadID(id))
 674  	return &ReadUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
 675  }
 676  
 677  // Delete returns a delete builder for Read.
 678  func (c *ReadClient) Delete() *ReadDelete {
 679  	mutation := newReadMutation(c.config, OpDelete)
 680  	return &ReadDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
 681  }
 682  
 683  // DeleteOne returns a builder for deleting the given entity.
 684  func (c *ReadClient) DeleteOne(r *Read) *ReadDeleteOne {
 685  	return c.DeleteOneID(r.ID)
 686  }
 687  
 688  // DeleteOneID returns a builder for deleting the given entity by its id.
 689  func (c *ReadClient) DeleteOneID(id uuid.UUID) *ReadDeleteOne {
 690  	builder := c.Delete().Where(read.ID(id))
 691  	builder.mutation.id = &id
 692  	builder.mutation.op = OpDeleteOne
 693  	return &ReadDeleteOne{builder}
 694  }
 695  
 696  // Query returns a query builder for Read.
 697  func (c *ReadClient) Query() *ReadQuery {
 698  	return &ReadQuery{
 699  		config: c.config,
 700  		ctx:    &QueryContext{Type: TypeRead},
 701  		inters: c.Interceptors(),
 702  	}
 703  }
 704  
 705  // Get returns a Read entity by its id.
 706  func (c *ReadClient) Get(ctx context.Context, id uuid.UUID) (*Read, error) {
 707  	return c.Query().Where(read.ID(id)).Only(ctx)
 708  }
 709  
 710  // GetX is like Get, but panics if an error occurs.
 711  func (c *ReadClient) GetX(ctx context.Context, id uuid.UUID) *Read {
 712  	obj, err := c.Get(ctx, id)
 713  	if err != nil {
 714  		panic(err)
 715  	}
 716  	return obj
 717  }
 718  
 719  // QueryUser queries the user edge of a Read.
 720  func (c *ReadClient) QueryUser(r *Read) *UserQuery {
 721  	query := (&UserClient{config: c.config}).Query()
 722  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 723  		id := r.ID
 724  		step := sqlgraph.NewStep(
 725  			sqlgraph.From(read.Table, read.FieldID, id),
 726  			sqlgraph.To(user.Table, user.FieldID),
 727  			sqlgraph.Edge(sqlgraph.M2O, false, read.UserTable, read.UserColumn),
 728  		)
 729  		fromV = sqlgraph.Neighbors(r.driver.Dialect(), step)
 730  		return fromV, nil
 731  	}
 732  	return query
 733  }
 734  
 735  // QueryItem queries the item edge of a Read.
 736  func (c *ReadClient) QueryItem(r *Read) *ItemQuery {
 737  	query := (&ItemClient{config: c.config}).Query()
 738  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 739  		id := r.ID
 740  		step := sqlgraph.NewStep(
 741  			sqlgraph.From(read.Table, read.FieldID, id),
 742  			sqlgraph.To(item.Table, item.FieldID),
 743  			sqlgraph.Edge(sqlgraph.M2O, false, read.ItemTable, read.ItemColumn),
 744  		)
 745  		fromV = sqlgraph.Neighbors(r.driver.Dialect(), step)
 746  		return fromV, nil
 747  	}
 748  	return query
 749  }
 750  
 751  // Hooks returns the client hooks.
 752  func (c *ReadClient) Hooks() []Hook {
 753  	return c.hooks.Read
 754  }
 755  
 756  // Interceptors returns the client interceptors.
 757  func (c *ReadClient) Interceptors() []Interceptor {
 758  	return c.inters.Read
 759  }
 760  
 761  func (c *ReadClient) mutate(ctx context.Context, m *ReadMutation) (Value, error) {
 762  	switch m.Op() {
 763  	case OpCreate:
 764  		return (&ReadCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 765  	case OpUpdate:
 766  		return (&ReadUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 767  	case OpUpdateOne:
 768  		return (&ReadUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 769  	case OpDelete, OpDeleteOne:
 770  		return (&ReadDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
 771  	default:
 772  		return nil, fmt.Errorf("ent: unknown Read mutation op: %q", m.Op())
 773  	}
 774  }
 775  
 776  // SubscriptionClient is a client for the Subscription schema.
 777  type SubscriptionClient struct {
 778  	config
 779  }
 780  
 781  // NewSubscriptionClient returns a client for the Subscription from the given config.
 782  func NewSubscriptionClient(c config) *SubscriptionClient {
 783  	return &SubscriptionClient{config: c}
 784  }
 785  
 786  // Use adds a list of mutation hooks to the hooks stack.
 787  // A call to `Use(f, g, h)` equals to `subscription.Hooks(f(g(h())))`.
 788  func (c *SubscriptionClient) Use(hooks ...Hook) {
 789  	c.hooks.Subscription = append(c.hooks.Subscription, hooks...)
 790  }
 791  
 792  // Intercept adds a list of query interceptors to the interceptors stack.
 793  // A call to `Intercept(f, g, h)` equals to `subscription.Intercept(f(g(h())))`.
 794  func (c *SubscriptionClient) Intercept(interceptors ...Interceptor) {
 795  	c.inters.Subscription = append(c.inters.Subscription, interceptors...)
 796  }
 797  
 798  // Create returns a builder for creating a Subscription entity.
 799  func (c *SubscriptionClient) Create() *SubscriptionCreate {
 800  	mutation := newSubscriptionMutation(c.config, OpCreate)
 801  	return &SubscriptionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 802  }
 803  
 804  // CreateBulk returns a builder for creating a bulk of Subscription entities.
 805  func (c *SubscriptionClient) CreateBulk(builders ...*SubscriptionCreate) *SubscriptionCreateBulk {
 806  	return &SubscriptionCreateBulk{config: c.config, builders: builders}
 807  }
 808  
 809  // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
 810  // a builder and applies setFunc on it.
 811  func (c *SubscriptionClient) MapCreateBulk(slice any, setFunc func(*SubscriptionCreate, int)) *SubscriptionCreateBulk {
 812  	rv := reflect.ValueOf(slice)
 813  	if rv.Kind() != reflect.Slice {
 814  		return &SubscriptionCreateBulk{err: fmt.Errorf("calling to SubscriptionClient.MapCreateBulk with wrong type %T, need slice", slice)}
 815  	}
 816  	builders := make([]*SubscriptionCreate, rv.Len())
 817  	for i := 0; i < rv.Len(); i++ {
 818  		builders[i] = c.Create()
 819  		setFunc(builders[i], i)
 820  	}
 821  	return &SubscriptionCreateBulk{config: c.config, builders: builders}
 822  }
 823  
 824  // Update returns an update builder for Subscription.
 825  func (c *SubscriptionClient) Update() *SubscriptionUpdate {
 826  	mutation := newSubscriptionMutation(c.config, OpUpdate)
 827  	return &SubscriptionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 828  }
 829  
 830  // UpdateOne returns an update builder for the given entity.
 831  func (c *SubscriptionClient) UpdateOne(s *Subscription) *SubscriptionUpdateOne {
 832  	mutation := newSubscriptionMutation(c.config, OpUpdateOne, withSubscription(s))
 833  	return &SubscriptionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
 834  }
 835  
 836  // UpdateOneID returns an update builder for the given id.
 837  func (c *SubscriptionClient) UpdateOneID(id uuid.UUID) *SubscriptionUpdateOne {
 838  	mutation := newSubscriptionMutation(c.config, OpUpdateOne, withSubscriptionID(id))
 839  	return &SubscriptionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
 840  }
 841  
 842  // Delete returns a delete builder for Subscription.
 843  func (c *SubscriptionClient) Delete() *SubscriptionDelete {
 844  	mutation := newSubscriptionMutation(c.config, OpDelete)
 845  	return &SubscriptionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
 846  }
 847  
 848  // DeleteOne returns a builder for deleting the given entity.
 849  func (c *SubscriptionClient) DeleteOne(s *Subscription) *SubscriptionDeleteOne {
 850  	return c.DeleteOneID(s.ID)
 851  }
 852  
 853  // DeleteOneID returns a builder for deleting the given entity by its id.
 854  func (c *SubscriptionClient) DeleteOneID(id uuid.UUID) *SubscriptionDeleteOne {
 855  	builder := c.Delete().Where(subscription.ID(id))
 856  	builder.mutation.id = &id
 857  	builder.mutation.op = OpDeleteOne
 858  	return &SubscriptionDeleteOne{builder}
 859  }
 860  
 861  // Query returns a query builder for Subscription.
 862  func (c *SubscriptionClient) Query() *SubscriptionQuery {
 863  	return &SubscriptionQuery{
 864  		config: c.config,
 865  		ctx:    &QueryContext{Type: TypeSubscription},
 866  		inters: c.Interceptors(),
 867  	}
 868  }
 869  
 870  // Get returns a Subscription entity by its id.
 871  func (c *SubscriptionClient) Get(ctx context.Context, id uuid.UUID) (*Subscription, error) {
 872  	return c.Query().Where(subscription.ID(id)).Only(ctx)
 873  }
 874  
 875  // GetX is like Get, but panics if an error occurs.
 876  func (c *SubscriptionClient) GetX(ctx context.Context, id uuid.UUID) *Subscription {
 877  	obj, err := c.Get(ctx, id)
 878  	if err != nil {
 879  		panic(err)
 880  	}
 881  	return obj
 882  }
 883  
 884  // QueryUser queries the user edge of a Subscription.
 885  func (c *SubscriptionClient) QueryUser(s *Subscription) *UserQuery {
 886  	query := (&UserClient{config: c.config}).Query()
 887  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 888  		id := s.ID
 889  		step := sqlgraph.NewStep(
 890  			sqlgraph.From(subscription.Table, subscription.FieldID, id),
 891  			sqlgraph.To(user.Table, user.FieldID),
 892  			sqlgraph.Edge(sqlgraph.M2O, false, subscription.UserTable, subscription.UserColumn),
 893  		)
 894  		fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
 895  		return fromV, nil
 896  	}
 897  	return query
 898  }
 899  
 900  // QueryFeed queries the feed edge of a Subscription.
 901  func (c *SubscriptionClient) QueryFeed(s *Subscription) *FeedQuery {
 902  	query := (&FeedClient{config: c.config}).Query()
 903  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
 904  		id := s.ID
 905  		step := sqlgraph.NewStep(
 906  			sqlgraph.From(subscription.Table, subscription.FieldID, id),
 907  			sqlgraph.To(feed.Table, feed.FieldID),
 908  			sqlgraph.Edge(sqlgraph.M2O, false, subscription.FeedTable, subscription.FeedColumn),
 909  		)
 910  		fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
 911  		return fromV, nil
 912  	}
 913  	return query
 914  }
 915  
 916  // Hooks returns the client hooks.
 917  func (c *SubscriptionClient) Hooks() []Hook {
 918  	return c.hooks.Subscription
 919  }
 920  
 921  // Interceptors returns the client interceptors.
 922  func (c *SubscriptionClient) Interceptors() []Interceptor {
 923  	return c.inters.Subscription
 924  }
 925  
 926  func (c *SubscriptionClient) mutate(ctx context.Context, m *SubscriptionMutation) (Value, error) {
 927  	switch m.Op() {
 928  	case OpCreate:
 929  		return (&SubscriptionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 930  	case OpUpdate:
 931  		return (&SubscriptionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 932  	case OpUpdateOne:
 933  		return (&SubscriptionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
 934  	case OpDelete, OpDeleteOne:
 935  		return (&SubscriptionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
 936  	default:
 937  		return nil, fmt.Errorf("ent: unknown Subscription mutation op: %q", m.Op())
 938  	}
 939  }
 940  
 941  // TokenClient is a client for the Token schema.
 942  type TokenClient struct {
 943  	config
 944  }
 945  
 946  // NewTokenClient returns a client for the Token from the given config.
 947  func NewTokenClient(c config) *TokenClient {
 948  	return &TokenClient{config: c}
 949  }
 950  
 951  // Use adds a list of mutation hooks to the hooks stack.
 952  // A call to `Use(f, g, h)` equals to `token.Hooks(f(g(h())))`.
 953  func (c *TokenClient) Use(hooks ...Hook) {
 954  	c.hooks.Token = append(c.hooks.Token, hooks...)
 955  }
 956  
 957  // Intercept adds a list of query interceptors to the interceptors stack.
 958  // A call to `Intercept(f, g, h)` equals to `token.Intercept(f(g(h())))`.
 959  func (c *TokenClient) Intercept(interceptors ...Interceptor) {
 960  	c.inters.Token = append(c.inters.Token, interceptors...)
 961  }
 962  
 963  // Create returns a builder for creating a Token entity.
 964  func (c *TokenClient) Create() *TokenCreate {
 965  	mutation := newTokenMutation(c.config, OpCreate)
 966  	return &TokenCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 967  }
 968  
 969  // CreateBulk returns a builder for creating a bulk of Token entities.
 970  func (c *TokenClient) CreateBulk(builders ...*TokenCreate) *TokenCreateBulk {
 971  	return &TokenCreateBulk{config: c.config, builders: builders}
 972  }
 973  
 974  // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
 975  // a builder and applies setFunc on it.
 976  func (c *TokenClient) MapCreateBulk(slice any, setFunc func(*TokenCreate, int)) *TokenCreateBulk {
 977  	rv := reflect.ValueOf(slice)
 978  	if rv.Kind() != reflect.Slice {
 979  		return &TokenCreateBulk{err: fmt.Errorf("calling to TokenClient.MapCreateBulk with wrong type %T, need slice", slice)}
 980  	}
 981  	builders := make([]*TokenCreate, rv.Len())
 982  	for i := 0; i < rv.Len(); i++ {
 983  		builders[i] = c.Create()
 984  		setFunc(builders[i], i)
 985  	}
 986  	return &TokenCreateBulk{config: c.config, builders: builders}
 987  }
 988  
 989  // Update returns an update builder for Token.
 990  func (c *TokenClient) Update() *TokenUpdate {
 991  	mutation := newTokenMutation(c.config, OpUpdate)
 992  	return &TokenUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
 993  }
 994  
 995  // UpdateOne returns an update builder for the given entity.
 996  func (c *TokenClient) UpdateOne(t *Token) *TokenUpdateOne {
 997  	mutation := newTokenMutation(c.config, OpUpdateOne, withToken(t))
 998  	return &TokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
 999  }
1000  
1001  // UpdateOneID returns an update builder for the given id.
1002  func (c *TokenClient) UpdateOneID(id uuid.UUID) *TokenUpdateOne {
1003  	mutation := newTokenMutation(c.config, OpUpdateOne, withTokenID(id))
1004  	return &TokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
1005  }
1006  
1007  // Delete returns a delete builder for Token.
1008  func (c *TokenClient) Delete() *TokenDelete {
1009  	mutation := newTokenMutation(c.config, OpDelete)
1010  	return &TokenDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
1011  }
1012  
1013  // DeleteOne returns a builder for deleting the given entity.
1014  func (c *TokenClient) DeleteOne(t *Token) *TokenDeleteOne {
1015  	return c.DeleteOneID(t.ID)
1016  }
1017  
1018  // DeleteOneID returns a builder for deleting the given entity by its id.
1019  func (c *TokenClient) DeleteOneID(id uuid.UUID) *TokenDeleteOne {
1020  	builder := c.Delete().Where(token.ID(id))
1021  	builder.mutation.id = &id
1022  	builder.mutation.op = OpDeleteOne
1023  	return &TokenDeleteOne{builder}
1024  }
1025  
1026  // Query returns a query builder for Token.
1027  func (c *TokenClient) Query() *TokenQuery {
1028  	return &TokenQuery{
1029  		config: c.config,
1030  		ctx:    &QueryContext{Type: TypeToken},
1031  		inters: c.Interceptors(),
1032  	}
1033  }
1034  
1035  // Get returns a Token entity by its id.
1036  func (c *TokenClient) Get(ctx context.Context, id uuid.UUID) (*Token, error) {
1037  	return c.Query().Where(token.ID(id)).Only(ctx)
1038  }
1039  
1040  // GetX is like Get, but panics if an error occurs.
1041  func (c *TokenClient) GetX(ctx context.Context, id uuid.UUID) *Token {
1042  	obj, err := c.Get(ctx, id)
1043  	if err != nil {
1044  		panic(err)
1045  	}
1046  	return obj
1047  }
1048  
1049  // QueryOwner queries the owner edge of a Token.
1050  func (c *TokenClient) QueryOwner(t *Token) *UserQuery {
1051  	query := (&UserClient{config: c.config}).Query()
1052  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
1053  		id := t.ID
1054  		step := sqlgraph.NewStep(
1055  			sqlgraph.From(token.Table, token.FieldID, id),
1056  			sqlgraph.To(user.Table, user.FieldID),
1057  			sqlgraph.Edge(sqlgraph.M2O, true, token.OwnerTable, token.OwnerColumn),
1058  		)
1059  		fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
1060  		return fromV, nil
1061  	}
1062  	return query
1063  }
1064  
1065  // Hooks returns the client hooks.
1066  func (c *TokenClient) Hooks() []Hook {
1067  	return c.hooks.Token
1068  }
1069  
1070  // Interceptors returns the client interceptors.
1071  func (c *TokenClient) Interceptors() []Interceptor {
1072  	return c.inters.Token
1073  }
1074  
1075  func (c *TokenClient) mutate(ctx context.Context, m *TokenMutation) (Value, error) {
1076  	switch m.Op() {
1077  	case OpCreate:
1078  		return (&TokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
1079  	case OpUpdate:
1080  		return (&TokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
1081  	case OpUpdateOne:
1082  		return (&TokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
1083  	case OpDelete, OpDeleteOne:
1084  		return (&TokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
1085  	default:
1086  		return nil, fmt.Errorf("ent: unknown Token mutation op: %q", m.Op())
1087  	}
1088  }
1089  
1090  // UserClient is a client for the User schema.
1091  type UserClient struct {
1092  	config
1093  }
1094  
1095  // NewUserClient returns a client for the User from the given config.
1096  func NewUserClient(c config) *UserClient {
1097  	return &UserClient{config: c}
1098  }
1099  
1100  // Use adds a list of mutation hooks to the hooks stack.
1101  // A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`.
1102  func (c *UserClient) Use(hooks ...Hook) {
1103  	c.hooks.User = append(c.hooks.User, hooks...)
1104  }
1105  
1106  // Intercept adds a list of query interceptors to the interceptors stack.
1107  // A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`.
1108  func (c *UserClient) Intercept(interceptors ...Interceptor) {
1109  	c.inters.User = append(c.inters.User, interceptors...)
1110  }
1111  
1112  // Create returns a builder for creating a User entity.
1113  func (c *UserClient) Create() *UserCreate {
1114  	mutation := newUserMutation(c.config, OpCreate)
1115  	return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
1116  }
1117  
1118  // CreateBulk returns a builder for creating a bulk of User entities.
1119  func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk {
1120  	return &UserCreateBulk{config: c.config, builders: builders}
1121  }
1122  
1123  // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
1124  // a builder and applies setFunc on it.
1125  func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk {
1126  	rv := reflect.ValueOf(slice)
1127  	if rv.Kind() != reflect.Slice {
1128  		return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)}
1129  	}
1130  	builders := make([]*UserCreate, rv.Len())
1131  	for i := 0; i < rv.Len(); i++ {
1132  		builders[i] = c.Create()
1133  		setFunc(builders[i], i)
1134  	}
1135  	return &UserCreateBulk{config: c.config, builders: builders}
1136  }
1137  
1138  // Update returns an update builder for User.
1139  func (c *UserClient) Update() *UserUpdate {
1140  	mutation := newUserMutation(c.config, OpUpdate)
1141  	return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
1142  }
1143  
1144  // UpdateOne returns an update builder for the given entity.
1145  func (c *UserClient) UpdateOne(u *User) *UserUpdateOne {
1146  	mutation := newUserMutation(c.config, OpUpdateOne, withUser(u))
1147  	return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
1148  }
1149  
1150  // UpdateOneID returns an update builder for the given id.
1151  func (c *UserClient) UpdateOneID(id uuid.UUID) *UserUpdateOne {
1152  	mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id))
1153  	return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
1154  }
1155  
1156  // Delete returns a delete builder for User.
1157  func (c *UserClient) Delete() *UserDelete {
1158  	mutation := newUserMutation(c.config, OpDelete)
1159  	return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
1160  }
1161  
1162  // DeleteOne returns a builder for deleting the given entity.
1163  func (c *UserClient) DeleteOne(u *User) *UserDeleteOne {
1164  	return c.DeleteOneID(u.ID)
1165  }
1166  
1167  // DeleteOneID returns a builder for deleting the given entity by its id.
1168  func (c *UserClient) DeleteOneID(id uuid.UUID) *UserDeleteOne {
1169  	builder := c.Delete().Where(user.ID(id))
1170  	builder.mutation.id = &id
1171  	builder.mutation.op = OpDeleteOne
1172  	return &UserDeleteOne{builder}
1173  }
1174  
1175  // Query returns a query builder for User.
1176  func (c *UserClient) Query() *UserQuery {
1177  	return &UserQuery{
1178  		config: c.config,
1179  		ctx:    &QueryContext{Type: TypeUser},
1180  		inters: c.Interceptors(),
1181  	}
1182  }
1183  
1184  // Get returns a User entity by its id.
1185  func (c *UserClient) Get(ctx context.Context, id uuid.UUID) (*User, error) {
1186  	return c.Query().Where(user.ID(id)).Only(ctx)
1187  }
1188  
1189  // GetX is like Get, but panics if an error occurs.
1190  func (c *UserClient) GetX(ctx context.Context, id uuid.UUID) *User {
1191  	obj, err := c.Get(ctx, id)
1192  	if err != nil {
1193  		panic(err)
1194  	}
1195  	return obj
1196  }
1197  
1198  // QueryTokens queries the tokens edge of a User.
1199  func (c *UserClient) QueryTokens(u *User) *TokenQuery {
1200  	query := (&TokenClient{config: c.config}).Query()
1201  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
1202  		id := u.ID
1203  		step := sqlgraph.NewStep(
1204  			sqlgraph.From(user.Table, user.FieldID, id),
1205  			sqlgraph.To(token.Table, token.FieldID),
1206  			sqlgraph.Edge(sqlgraph.O2M, false, user.TokensTable, user.TokensColumn),
1207  		)
1208  		fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
1209  		return fromV, nil
1210  	}
1211  	return query
1212  }
1213  
1214  // QuerySubscribedFeeds queries the subscribed_feeds edge of a User.
1215  func (c *UserClient) QuerySubscribedFeeds(u *User) *FeedQuery {
1216  	query := (&FeedClient{config: c.config}).Query()
1217  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
1218  		id := u.ID
1219  		step := sqlgraph.NewStep(
1220  			sqlgraph.From(user.Table, user.FieldID, id),
1221  			sqlgraph.To(feed.Table, feed.FieldID),
1222  			sqlgraph.Edge(sqlgraph.M2M, false, user.SubscribedFeedsTable, user.SubscribedFeedsPrimaryKey...),
1223  		)
1224  		fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
1225  		return fromV, nil
1226  	}
1227  	return query
1228  }
1229  
1230  // QueryReadItems queries the read_items edge of a User.
1231  func (c *UserClient) QueryReadItems(u *User) *ItemQuery {
1232  	query := (&ItemClient{config: c.config}).Query()
1233  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
1234  		id := u.ID
1235  		step := sqlgraph.NewStep(
1236  			sqlgraph.From(user.Table, user.FieldID, id),
1237  			sqlgraph.To(item.Table, item.FieldID),
1238  			sqlgraph.Edge(sqlgraph.M2M, false, user.ReadItemsTable, user.ReadItemsPrimaryKey...),
1239  		)
1240  		fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
1241  		return fromV, nil
1242  	}
1243  	return query
1244  }
1245  
1246  // QuerySubscriptions queries the subscriptions edge of a User.
1247  func (c *UserClient) QuerySubscriptions(u *User) *SubscriptionQuery {
1248  	query := (&SubscriptionClient{config: c.config}).Query()
1249  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
1250  		id := u.ID
1251  		step := sqlgraph.NewStep(
1252  			sqlgraph.From(user.Table, user.FieldID, id),
1253  			sqlgraph.To(subscription.Table, subscription.FieldID),
1254  			sqlgraph.Edge(sqlgraph.O2M, true, user.SubscriptionsTable, user.SubscriptionsColumn),
1255  		)
1256  		fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
1257  		return fromV, nil
1258  	}
1259  	return query
1260  }
1261  
1262  // QueryReads queries the reads edge of a User.
1263  func (c *UserClient) QueryReads(u *User) *ReadQuery {
1264  	query := (&ReadClient{config: c.config}).Query()
1265  	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
1266  		id := u.ID
1267  		step := sqlgraph.NewStep(
1268  			sqlgraph.From(user.Table, user.FieldID, id),
1269  			sqlgraph.To(read.Table, read.FieldID),
1270  			sqlgraph.Edge(sqlgraph.O2M, true, user.ReadsTable, user.ReadsColumn),
1271  		)
1272  		fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
1273  		return fromV, nil
1274  	}
1275  	return query
1276  }
1277  
1278  // Hooks returns the client hooks.
1279  func (c *UserClient) Hooks() []Hook {
1280  	return c.hooks.User
1281  }
1282  
1283  // Interceptors returns the client interceptors.
1284  func (c *UserClient) Interceptors() []Interceptor {
1285  	return c.inters.User
1286  }
1287  
1288  func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) {
1289  	switch m.Op() {
1290  	case OpCreate:
1291  		return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
1292  	case OpUpdate:
1293  		return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
1294  	case OpUpdateOne:
1295  		return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
1296  	case OpDelete, OpDeleteOne:
1297  		return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
1298  	default:
1299  		return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op())
1300  	}
1301  }
1302  
1303  // hooks and interceptors per client, for fast access.
1304  type (
1305  	hooks struct {
1306  		Feed, Item, Read, Subscription, Token, User []ent.Hook
1307  	}
1308  	inters struct {
1309  		Feed, Item, Read, Subscription, Token, User []ent.Interceptor
1310  	}
1311  )