fixes 45 - cant generate
This commit is contained in:
parent
ed327dc066
commit
ff82ba532a
29 changed files with 1605 additions and 2481 deletions
213
ent/client.go
213
ent/client.go
|
|
@ -1,20 +1,22 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"github.com/mikestefanello/pagoda/ent/migrate"
|
||||
|
||||
"github.com/mikestefanello/pagoda/ent/passwordtoken"
|
||||
"github.com/mikestefanello/pagoda/ent/user"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/mikestefanello/pagoda/ent/passwordtoken"
|
||||
"github.com/mikestefanello/pagoda/ent/user"
|
||||
)
|
||||
|
||||
// Client is the client that holds all ent builders.
|
||||
|
|
@ -30,9 +32,7 @@ type Client struct {
|
|||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
func NewClient(opts ...Option) *Client {
|
||||
cfg := config{log: log.Println, hooks: &hooks{}}
|
||||
cfg.options(opts...)
|
||||
client := &Client{config: cfg}
|
||||
client := &Client{config: newConfig(opts...)}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
|
@ -43,6 +43,62 @@ func (c *Client) init() {
|
|||
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.
|
||||
|
|
@ -59,11 +115,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error)
|
|||
}
|
||||
}
|
||||
|
||||
// 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, fmt.Errorf("ent: cannot start a transaction within a transaction")
|
||||
return nil, ErrTxStarted
|
||||
}
|
||||
tx, err := newTx(ctx, c.driver)
|
||||
if err != nil {
|
||||
|
|
@ -82,7 +141,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
|||
// 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, fmt.Errorf("ent: cannot start a transaction within a transaction")
|
||||
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)
|
||||
|
|
@ -106,7 +165,6 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
|||
// PasswordToken.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
//
|
||||
func (c *Client) Debug() *Client {
|
||||
if c.debug {
|
||||
return c
|
||||
|
|
@ -130,6 +188,25 @@ func (c *Client) Use(hooks ...Hook) {
|
|||
c.User.Use(hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds the query interceptors to all the entity clients.
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
c.PasswordToken.Intercept(interceptors...)
|
||||
c.User.Intercept(interceptors...)
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *PasswordTokenMutation:
|
||||
return c.PasswordToken.mutate(ctx, m)
|
||||
case *UserMutation:
|
||||
return c.User.mutate(ctx, m)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
||||
}
|
||||
}
|
||||
|
||||
// PasswordTokenClient is a client for the PasswordToken schema.
|
||||
type PasswordTokenClient struct {
|
||||
config
|
||||
|
|
@ -146,7 +223,13 @@ func (c *PasswordTokenClient) Use(hooks ...Hook) {
|
|||
c.hooks.PasswordToken = append(c.hooks.PasswordToken, hooks...)
|
||||
}
|
||||
|
||||
// Create returns a create builder for PasswordToken.
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `passwordtoken.Intercept(f(g(h())))`.
|
||||
func (c *PasswordTokenClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.PasswordToken = append(c.inters.PasswordToken, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a PasswordToken entity.
|
||||
func (c *PasswordTokenClient) Create() *PasswordTokenCreate {
|
||||
mutation := newPasswordTokenMutation(c.config, OpCreate)
|
||||
return &PasswordTokenCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
|
|
@ -157,6 +240,21 @@ func (c *PasswordTokenClient) CreateBulk(builders ...*PasswordTokenCreate) *Pass
|
|||
return &PasswordTokenCreateBulk{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 *PasswordTokenClient) MapCreateBulk(slice any, setFunc func(*PasswordTokenCreate, int)) *PasswordTokenCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &PasswordTokenCreateBulk{err: fmt.Errorf("calling to PasswordTokenClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*PasswordTokenCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &PasswordTokenCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for PasswordToken.
|
||||
func (c *PasswordTokenClient) Update() *PasswordTokenUpdate {
|
||||
mutation := newPasswordTokenMutation(c.config, OpUpdate)
|
||||
|
|
@ -181,12 +279,12 @@ func (c *PasswordTokenClient) Delete() *PasswordTokenDelete {
|
|||
return &PasswordTokenDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *PasswordTokenClient) DeleteOne(pt *PasswordToken) *PasswordTokenDeleteOne {
|
||||
return c.DeleteOneID(pt.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *PasswordTokenClient) DeleteOneID(id int) *PasswordTokenDeleteOne {
|
||||
builder := c.Delete().Where(passwordtoken.ID(id))
|
||||
builder.mutation.id = &id
|
||||
|
|
@ -198,6 +296,8 @@ func (c *PasswordTokenClient) DeleteOneID(id int) *PasswordTokenDeleteOne {
|
|||
func (c *PasswordTokenClient) Query() *PasswordTokenQuery {
|
||||
return &PasswordTokenQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypePasswordToken},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -217,8 +317,8 @@ func (c *PasswordTokenClient) GetX(ctx context.Context, id int) *PasswordToken {
|
|||
|
||||
// QueryUser queries the user edge of a PasswordToken.
|
||||
func (c *PasswordTokenClient) QueryUser(pt *PasswordToken) *UserQuery {
|
||||
query := &UserQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := pt.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(passwordtoken.Table, passwordtoken.FieldID, id),
|
||||
|
|
@ -236,6 +336,26 @@ func (c *PasswordTokenClient) Hooks() []Hook {
|
|||
return c.hooks.PasswordToken
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *PasswordTokenClient) Interceptors() []Interceptor {
|
||||
return c.inters.PasswordToken
|
||||
}
|
||||
|
||||
func (c *PasswordTokenClient) mutate(ctx context.Context, m *PasswordTokenMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&PasswordTokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&PasswordTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&PasswordTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&PasswordTokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown PasswordToken mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// UserClient is a client for the User schema.
|
||||
type UserClient struct {
|
||||
config
|
||||
|
|
@ -252,7 +372,13 @@ func (c *UserClient) Use(hooks ...Hook) {
|
|||
c.hooks.User = append(c.hooks.User, hooks...)
|
||||
}
|
||||
|
||||
// Create returns a create builder for User.
|
||||
// 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}
|
||||
|
|
@ -263,6 +389,21 @@ 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)
|
||||
|
|
@ -287,12 +428,12 @@ func (c *UserClient) Delete() *UserDelete {
|
|||
return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *UserClient) DeleteOne(u *User) *UserDeleteOne {
|
||||
return c.DeleteOneID(u.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *UserClient) DeleteOneID(id int) *UserDeleteOne {
|
||||
builder := c.Delete().Where(user.ID(id))
|
||||
builder.mutation.id = &id
|
||||
|
|
@ -304,6 +445,8 @@ func (c *UserClient) DeleteOneID(id int) *UserDeleteOne {
|
|||
func (c *UserClient) Query() *UserQuery {
|
||||
return &UserQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeUser},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -323,8 +466,8 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User {
|
|||
|
||||
// QueryOwner queries the owner edge of a User.
|
||||
func (c *UserClient) QueryOwner(u *User) *PasswordTokenQuery {
|
||||
query := &PasswordTokenQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query := (&PasswordTokenClient{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),
|
||||
|
|
@ -342,3 +485,33 @@ func (c *UserClient) Hooks() []Hook {
|
|||
hooks := c.hooks.User
|
||||
return append(hooks[:len(hooks):len(hooks)], user.Hooks[:]...)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
PasswordToken, User []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
PasswordToken, User []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
)
|
||||
|
||||
// Option function to configure the client.
|
||||
type Option func(*config)
|
||||
|
||||
// Config is the configuration for the client and its builder.
|
||||
type 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(...interface{})
|
||||
// hooks to execute on mutations.
|
||||
hooks *hooks
|
||||
}
|
||||
|
||||
// hooks per client, for fast access.
|
||||
type hooks struct {
|
||||
PasswordToken []ent.Hook
|
||||
User []ent.Hook
|
||||
}
|
||||
|
||||
// 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(...interface{})) 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
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type clientCtxKey struct{}
|
||||
|
||||
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||
func FromContext(ctx context.Context) *Client {
|
||||
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewContext returns a new context with the given Client attached.
|
||||
func NewContext(parent context.Context, c *Client) context.Context {
|
||||
return context.WithValue(parent, clientCtxKey{}, c)
|
||||
}
|
||||
|
||||
type txCtxKey struct{}
|
||||
|
||||
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||
func TxFromContext(ctx context.Context) *Tx {
|
||||
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||
return tx
|
||||
}
|
||||
|
||||
// NewTxContext returns a new context with the given Tx attached.
|
||||
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||
return context.WithValue(parent, txCtxKey{}, tx)
|
||||
}
|
||||
433
ent/ent.go
433
ent/ent.go
|
|
@ -1,58 +1,91 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/mikestefanello/pagoda/ent/passwordtoken"
|
||||
"github.com/mikestefanello/pagoda/ent/user"
|
||||
)
|
||||
|
||||
// ent aliases to avoid import conflicts in user's code.
|
||||
type (
|
||||
Op = ent.Op
|
||||
Hook = ent.Hook
|
||||
Value = ent.Value
|
||||
Query = ent.Query
|
||||
Policy = ent.Policy
|
||||
Mutator = ent.Mutator
|
||||
Mutation = ent.Mutation
|
||||
MutateFunc = ent.MutateFunc
|
||||
Op = ent.Op
|
||||
Hook = ent.Hook
|
||||
Value = ent.Value
|
||||
Query = ent.Query
|
||||
QueryContext = ent.QueryContext
|
||||
Querier = ent.Querier
|
||||
QuerierFunc = ent.QuerierFunc
|
||||
Interceptor = ent.Interceptor
|
||||
InterceptFunc = ent.InterceptFunc
|
||||
Traverser = ent.Traverser
|
||||
TraverseFunc = ent.TraverseFunc
|
||||
Policy = ent.Policy
|
||||
Mutator = ent.Mutator
|
||||
Mutation = ent.Mutation
|
||||
MutateFunc = ent.MutateFunc
|
||||
)
|
||||
|
||||
type clientCtxKey struct{}
|
||||
|
||||
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||
func FromContext(ctx context.Context) *Client {
|
||||
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewContext returns a new context with the given Client attached.
|
||||
func NewContext(parent context.Context, c *Client) context.Context {
|
||||
return context.WithValue(parent, clientCtxKey{}, c)
|
||||
}
|
||||
|
||||
type txCtxKey struct{}
|
||||
|
||||
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||
func TxFromContext(ctx context.Context) *Tx {
|
||||
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||
return tx
|
||||
}
|
||||
|
||||
// NewTxContext returns a new context with the given Tx attached.
|
||||
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||
return context.WithValue(parent, txCtxKey{}, tx)
|
||||
}
|
||||
|
||||
// OrderFunc applies an ordering on the sql selector.
|
||||
// Deprecated: Use Asc/Desc functions or the package builders instead.
|
||||
type OrderFunc func(*sql.Selector)
|
||||
|
||||
// columnChecker returns a function indicates if the column exists in the given column.
|
||||
func columnChecker(table string) func(string) error {
|
||||
checks := map[string]func(string) bool{
|
||||
passwordtoken.Table: passwordtoken.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
}
|
||||
check, ok := checks[table]
|
||||
if !ok {
|
||||
return func(string) error {
|
||||
return fmt.Errorf("unknown table %q", table)
|
||||
}
|
||||
}
|
||||
return func(column string) error {
|
||||
if !check(column) {
|
||||
return fmt.Errorf("unknown column %q for table %q", column, table)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
var (
|
||||
initCheck sync.Once
|
||||
columnCheck sql.ColumnCheck
|
||||
)
|
||||
|
||||
// columnChecker checks if the column exists in the given table.
|
||||
func checkColumn(table, column string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
passwordtoken.Table: passwordtoken.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
})
|
||||
})
|
||||
return columnCheck(table, column)
|
||||
}
|
||||
|
||||
// Asc applies the given fields in ASC order.
|
||||
func Asc(fields ...string) OrderFunc {
|
||||
func Asc(fields ...string) func(*sql.Selector) {
|
||||
return func(s *sql.Selector) {
|
||||
check := columnChecker(s.TableName())
|
||||
for _, f := range fields {
|
||||
if err := check(f); err != nil {
|
||||
if err := checkColumn(s.TableName(), f); err != nil {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||
}
|
||||
s.OrderBy(sql.Asc(s.C(f)))
|
||||
|
|
@ -61,11 +94,10 @@ func Asc(fields ...string) OrderFunc {
|
|||
}
|
||||
|
||||
// Desc applies the given fields in DESC order.
|
||||
func Desc(fields ...string) OrderFunc {
|
||||
func Desc(fields ...string) func(*sql.Selector) {
|
||||
return func(s *sql.Selector) {
|
||||
check := columnChecker(s.TableName())
|
||||
for _, f := range fields {
|
||||
if err := check(f); err != nil {
|
||||
if err := checkColumn(s.TableName(), f); err != nil {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||
}
|
||||
s.OrderBy(sql.Desc(s.C(f)))
|
||||
|
|
@ -81,7 +113,6 @@ type AggregateFunc func(*sql.Selector) string
|
|||
// GroupBy(field1, field2).
|
||||
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.As(fn(s), end)
|
||||
|
|
@ -98,8 +129,7 @@ func Count() AggregateFunc {
|
|||
// Max applies the "max" aggregation function on the given field of each group.
|
||||
func Max(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
check := columnChecker(s.TableName())
|
||||
if err := check(field); err != nil {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||
return ""
|
||||
}
|
||||
|
|
@ -110,8 +140,7 @@ func Max(field string) AggregateFunc {
|
|||
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||
func Mean(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
check := columnChecker(s.TableName())
|
||||
if err := check(field); err != nil {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||
return ""
|
||||
}
|
||||
|
|
@ -122,8 +151,7 @@ func Mean(field string) AggregateFunc {
|
|||
// Min applies the "min" aggregation function on the given field of each group.
|
||||
func Min(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
check := columnChecker(s.TableName())
|
||||
if err := check(field); err != nil {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||
return ""
|
||||
}
|
||||
|
|
@ -134,8 +162,7 @@ func Min(field string) AggregateFunc {
|
|||
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||
func Sum(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
check := columnChecker(s.TableName())
|
||||
if err := check(field); err != nil {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||
return ""
|
||||
}
|
||||
|
|
@ -259,3 +286,325 @@ func IsConstraintError(err error) bool {
|
|||
var e *ConstraintError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// selector embedded by the different Select/GroupBy builders.
|
||||
type selector struct {
|
||||
label string
|
||||
flds *[]string
|
||||
fns []AggregateFunc
|
||||
scan func(context.Context, any) error
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||
if err := s.scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (s *selector) StringsX(ctx context.Context) []string {
|
||||
v, err := s.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = s.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (s *selector) StringX(ctx context.Context) string {
|
||||
v, err := s.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (s *selector) IntsX(ctx context.Context) []int {
|
||||
v, err := s.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = s.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (s *selector) IntX(ctx context.Context) int {
|
||||
v, err := s.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := s.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = s.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||
v, err := s.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||
v, err := s.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = s.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (s *selector) BoolX(ctx context.Context) bool {
|
||||
v, err := s.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// withHooks invokes the builder operation with the given hooks, if any.
|
||||
func withHooks[V Value, M any, PM interface {
|
||||
*M
|
||||
Mutation
|
||||
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||
if len(hooks) == 0 {
|
||||
return exec(ctx)
|
||||
}
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutationT, ok := any(m).(PM)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
// Set the mutation to the builder.
|
||||
*mutation = *mutationT
|
||||
return exec(ctx)
|
||||
})
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
if hooks[i] == nil {
|
||||
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = hooks[i](mut)
|
||||
}
|
||||
v, err := mut.Mutate(ctx, mutation)
|
||||
if err != nil {
|
||||
return value, err
|
||||
}
|
||||
nv, ok := v.(V)
|
||||
if !ok {
|
||||
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||
}
|
||||
return nv, nil
|
||||
}
|
||||
|
||||
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||
if ent.QueryFromContext(ctx) == nil {
|
||||
qc.Op = op
|
||||
ctx = ent.NewQueryContext(ctx, qc)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
func querierAll[V Value, Q interface {
|
||||
sqlAll(context.Context, ...queryHook) (V, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlAll(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func querierCount[Q interface {
|
||||
sqlCount(context.Context) (int, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlCount(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
rv, err := qr.Query(ctx, q)
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
vt, ok := rv.(V)
|
||||
if !ok {
|
||||
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||
}
|
||||
return vt, nil
|
||||
}
|
||||
|
||||
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||
sqlScan(context.Context, Q1, any) error
|
||||
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||
rv := reflect.ValueOf(v)
|
||||
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q1)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||
return rv.Elem().Interface(), nil
|
||||
}
|
||||
return v, nil
|
||||
})
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
vv, err := qr.Query(ctx, rootQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch rv2 := reflect.ValueOf(vv); {
|
||||
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||
case rv.Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2.Elem())
|
||||
case rv.Elem().Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// queryHook describes an internal hook for the different sqlAll methods.
|
||||
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package enttest
|
||||
|
||||
|
|
@ -10,6 +10,7 @@ import (
|
|||
_ "github.com/mikestefanello/pagoda/ent/runtime"
|
||||
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"github.com/mikestefanello/pagoda/ent/migrate"
|
||||
)
|
||||
|
||||
type (
|
||||
|
|
@ -17,7 +18,7 @@ type (
|
|||
// testing.T and testing.B and used by enttest.
|
||||
TestingT interface {
|
||||
FailNow()
|
||||
Error(...interface{})
|
||||
Error(...any)
|
||||
}
|
||||
|
||||
// Option configures client creation.
|
||||
|
|
@ -59,10 +60,7 @@ func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Cl
|
|||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
|
||||
|
|
@ -70,9 +68,17 @@ func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Cl
|
|||
func NewClient(t TestingT, opts ...Option) *ent.Client {
|
||||
o := newOptions(opts)
|
||||
c := ent.NewClient(o.opts...)
|
||||
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
func migrateSchema(t TestingT, c *ent.Client, o *options) {
|
||||
tables, err := schema.CopyTables(migrate.Tables)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package hook
|
||||
|
||||
|
|
@ -15,11 +15,10 @@ type PasswordTokenFunc func(context.Context, *ent.PasswordTokenMutation) (ent.Va
|
|||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f PasswordTokenFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
mv, ok := m.(*ent.PasswordTokenMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PasswordTokenMutation", m)
|
||||
if mv, ok := m.(*ent.PasswordTokenMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return f(ctx, mv)
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PasswordTokenMutation", m)
|
||||
}
|
||||
|
||||
// The UserFunc type is an adapter to allow the use of ordinary
|
||||
|
|
@ -28,11 +27,10 @@ type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
|
|||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
mv, ok := m.(*ent.UserMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m)
|
||||
if mv, ok := m.(*ent.UserMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return f(ctx, mv)
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m)
|
||||
}
|
||||
|
||||
// Condition is a hook condition function.
|
||||
|
|
@ -130,7 +128,6 @@ func HasFields(field string, fields ...string) Condition {
|
|||
// If executes the given hook under condition.
|
||||
//
|
||||
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||
//
|
||||
func If(hk ent.Hook, cond Condition) ent.Hook {
|
||||
return func(next ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
|
|
@ -145,7 +142,6 @@ func If(hk ent.Hook, cond Condition) ent.Hook {
|
|||
// On executes the given hook only for the given operation.
|
||||
//
|
||||
// hook.On(Log, ent.Delete|ent.Create)
|
||||
//
|
||||
func On(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, HasOp(op))
|
||||
}
|
||||
|
|
@ -153,7 +149,6 @@ func On(hk ent.Hook, op ent.Op) ent.Hook {
|
|||
// Unless skips the given hook only for the given operation.
|
||||
//
|
||||
// hook.Unless(Log, ent.Update|ent.UpdateOne)
|
||||
//
|
||||
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
|
@ -174,7 +169,6 @@ func FixedError(err error) ent.Hook {
|
|||
// Reject(ent.Delete|ent.Update),
|
||||
// }
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
|
|
@ -28,9 +28,6 @@ var (
|
|||
// and therefore, it's recommended to enable this option to get more
|
||||
// flexibility in the schema changes.
|
||||
WithDropIndex = schema.WithDropIndex
|
||||
// WithFixture sets the foreign-key renaming option to the migration when upgrading
|
||||
// ent from v0.1.0 (issue-#285). Defaults to false.
|
||||
WithFixture = schema.WithFixture
|
||||
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||
WithForeignKeys = schema.WithForeignKeys
|
||||
)
|
||||
|
|
@ -45,27 +42,23 @@ func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
|||
|
||||
// Create creates all schema resources.
|
||||
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||
return Create(ctx, s, Tables, opts...)
|
||||
}
|
||||
|
||||
// Create creates all table resources using the given schema driver.
|
||||
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %w", err)
|
||||
}
|
||||
return migrate.Create(ctx, Tables...)
|
||||
return migrate.Create(ctx, tables...)
|
||||
}
|
||||
|
||||
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||
//
|
||||
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||
drv := &schema.WriteDriver{
|
||||
Writer: w,
|
||||
Driver: s.drv,
|
||||
}
|
||||
migrate, err := schema.NewMigrate(drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %w", err)
|
||||
}
|
||||
return migrate.Create(ctx, Tables...)
|
||||
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ var (
|
|||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "hash", Type: field.TypeString},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "password_token_user", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "password_token_user", Type: field.TypeInt},
|
||||
}
|
||||
// PasswordTokensTable holds the schema information for the "password_tokens" table.
|
||||
PasswordTokensTable = &schema.Table{
|
||||
|
|
@ -25,7 +25,7 @@ var (
|
|||
Symbol: "password_tokens_users_user",
|
||||
Columns: []*schema.Column{PasswordTokensColumns[3]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
|
@ -9,11 +9,11 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/mikestefanello/pagoda/ent/passwordtoken"
|
||||
"github.com/mikestefanello/pagoda/ent/predicate"
|
||||
"github.com/mikestefanello/pagoda/ent/user"
|
||||
|
||||
"entgo.io/ent"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -259,11 +259,26 @@ func (m *PasswordTokenMutation) Where(ps ...predicate.PasswordToken) {
|
|||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the PasswordTokenMutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *PasswordTokenMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.PasswordToken, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *PasswordTokenMutation) Op() Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *PasswordTokenMutation) SetOp(op Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (PasswordToken).
|
||||
func (m *PasswordTokenMutation) Type() string {
|
||||
return m.typ
|
||||
|
|
@ -417,8 +432,6 @@ func (m *PasswordTokenMutation) RemovedEdges() []string {
|
|||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *PasswordTokenMutation) RemovedIDs(name string) []ent.Value {
|
||||
switch name {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -820,11 +833,26 @@ func (m *UserMutation) Where(ps ...predicate.User) {
|
|||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the UserMutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.User, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *UserMutation) Op() Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *UserMutation) SetOp(op Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (User).
|
||||
func (m *UserMutation) Type() string {
|
||||
return m.typ
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/mikestefanello/pagoda/ent/passwordtoken"
|
||||
"github.com/mikestefanello/pagoda/ent/user"
|
||||
|
|
@ -25,6 +26,7 @@ type PasswordToken struct {
|
|||
// The values are being populated by the PasswordTokenQuery when eager-loading is set.
|
||||
Edges PasswordTokenEdges `json:"edges"`
|
||||
password_token_user *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// PasswordTokenEdges holds the relations/edges for other nodes in the graph.
|
||||
|
|
@ -41,8 +43,7 @@ type PasswordTokenEdges struct {
|
|||
func (e PasswordTokenEdges) UserOrErr() (*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.User == nil {
|
||||
// The edge user was loaded in eager-loading,
|
||||
// but was not found.
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return e.User, nil
|
||||
|
|
@ -51,8 +52,8 @@ func (e PasswordTokenEdges) UserOrErr() (*User, error) {
|
|||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*PasswordToken) scanValues(columns []string) ([]interface{}, error) {
|
||||
values := make([]interface{}, len(columns))
|
||||
func (*PasswordToken) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case passwordtoken.FieldID:
|
||||
|
|
@ -64,7 +65,7 @@ func (*PasswordToken) scanValues(columns []string) ([]interface{}, error) {
|
|||
case passwordtoken.ForeignKeys[0]: // password_token_user
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected column %q for type PasswordToken", columns[i])
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
|
|
@ -72,7 +73,7 @@ func (*PasswordToken) scanValues(columns []string) ([]interface{}, error) {
|
|||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the PasswordToken fields.
|
||||
func (pt *PasswordToken) assignValues(columns []string, values []interface{}) error {
|
||||
func (pt *PasswordToken) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
|
|
@ -103,31 +104,39 @@ func (pt *PasswordToken) assignValues(columns []string, values []interface{}) er
|
|||
pt.password_token_user = new(int)
|
||||
*pt.password_token_user = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
pt.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the PasswordToken.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (pt *PasswordToken) Value(name string) (ent.Value, error) {
|
||||
return pt.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the PasswordToken entity.
|
||||
func (pt *PasswordToken) QueryUser() *UserQuery {
|
||||
return (&PasswordTokenClient{config: pt.config}).QueryUser(pt)
|
||||
return NewPasswordTokenClient(pt.config).QueryUser(pt)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this PasswordToken.
|
||||
// Note that you need to call PasswordToken.Unwrap() before calling this method if this PasswordToken
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (pt *PasswordToken) Update() *PasswordTokenUpdateOne {
|
||||
return (&PasswordTokenClient{config: pt.config}).UpdateOne(pt)
|
||||
return NewPasswordTokenClient(pt.config).UpdateOne(pt)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the PasswordToken entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (pt *PasswordToken) Unwrap() *PasswordToken {
|
||||
tx, ok := pt.config.driver.(*txDriver)
|
||||
_tx, ok := pt.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: PasswordToken is not a transactional entity")
|
||||
}
|
||||
pt.config.driver = tx.drv
|
||||
pt.config.driver = _tx.drv
|
||||
return pt
|
||||
}
|
||||
|
||||
|
|
@ -135,9 +144,10 @@ func (pt *PasswordToken) Unwrap() *PasswordToken {
|
|||
func (pt *PasswordToken) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("PasswordToken(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", pt.ID))
|
||||
builder.WriteString(", hash=<sensitive>")
|
||||
builder.WriteString(", created_at=")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", pt.ID))
|
||||
builder.WriteString("hash=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(pt.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
|
|
@ -145,9 +155,3 @@ func (pt *PasswordToken) String() string {
|
|||
|
||||
// PasswordTokens is a parsable slice of PasswordToken.
|
||||
type PasswordTokens []*PasswordToken
|
||||
|
||||
func (pt PasswordTokens) config(cfg config) {
|
||||
for _i := range pt {
|
||||
pt[_i].config = cfg
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package passwordtoken
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -62,3 +65,35 @@ var (
|
|||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the PasswordToken queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByHash orders the results by the hash field.
|
||||
func ByHash(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldHash, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package passwordtoken
|
||||
|
||||
|
|
@ -12,286 +12,162 @@ import (
|
|||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Hash applies equality check predicate on the "hash" field. It's identical to HashEQ.
|
||||
func Hash(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldHash, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// HashEQ applies the EQ predicate on the "hash" field.
|
||||
func HashEQ(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashNEQ applies the NEQ predicate on the "hash" field.
|
||||
func HashNEQ(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldNEQ(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashIn applies the In predicate on the "hash" field.
|
||||
func HashIn(vs ...string) predicate.PasswordToken {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldHash), v...))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldIn(FieldHash, vs...))
|
||||
}
|
||||
|
||||
// HashNotIn applies the NotIn predicate on the "hash" field.
|
||||
func HashNotIn(vs ...string) predicate.PasswordToken {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldHash), v...))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldNotIn(FieldHash, vs...))
|
||||
}
|
||||
|
||||
// HashGT applies the GT predicate on the "hash" field.
|
||||
func HashGT(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldGT(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashGTE applies the GTE predicate on the "hash" field.
|
||||
func HashGTE(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldGTE(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashLT applies the LT predicate on the "hash" field.
|
||||
func HashLT(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldLT(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashLTE applies the LTE predicate on the "hash" field.
|
||||
func HashLTE(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldLTE(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashContains applies the Contains predicate on the "hash" field.
|
||||
func HashContains(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldContains(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashHasPrefix applies the HasPrefix predicate on the "hash" field.
|
||||
func HashHasPrefix(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldHasPrefix(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashHasSuffix applies the HasSuffix predicate on the "hash" field.
|
||||
func HashHasSuffix(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldHasSuffix(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashEqualFold applies the EqualFold predicate on the "hash" field.
|
||||
func HashEqualFold(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldEqualFold(FieldHash, v))
|
||||
}
|
||||
|
||||
// HashContainsFold applies the ContainsFold predicate on the "hash" field.
|
||||
func HashContainsFold(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldHash), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldContainsFold(FieldHash, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.PasswordToken {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldCreatedAt), v...))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.PasswordToken {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldCreatedAt), v...))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.PasswordToken(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
|
|
@ -299,7 +175,6 @@ func HasUser() predicate.PasswordToken {
|
|||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
|
|
@ -309,11 +184,7 @@ func HasUser() predicate.PasswordToken {
|
|||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn),
|
||||
)
|
||||
step := newUserStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
|
|
@ -324,32 +195,15 @@ func HasUserWith(preds ...predicate.User) predicate.PasswordToken {
|
|||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.PasswordToken) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
return predicate.PasswordToken(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.PasswordToken) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
return predicate.PasswordToken(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.PasswordToken) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
return predicate.PasswordToken(sql.NotPredicates(p))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
|
@ -59,44 +59,8 @@ func (ptc *PasswordTokenCreate) Mutation() *PasswordTokenMutation {
|
|||
|
||||
// Save creates the PasswordToken in the database.
|
||||
func (ptc *PasswordTokenCreate) Save(ctx context.Context) (*PasswordToken, error) {
|
||||
var (
|
||||
err error
|
||||
node *PasswordToken
|
||||
)
|
||||
ptc.defaults()
|
||||
if len(ptc.hooks) == 0 {
|
||||
if err = ptc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = ptc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*PasswordTokenMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = ptc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ptc.mutation = mutation
|
||||
if node, err = ptc.sqlSave(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &node.ID
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(ptc.hooks) - 1; i >= 0; i-- {
|
||||
if ptc.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = ptc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, ptc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
return withHooks(ctx, ptc.sqlSave, ptc.mutation, ptc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
|
|
@ -149,43 +113,34 @@ func (ptc *PasswordTokenCreate) check() error {
|
|||
}
|
||||
|
||||
func (ptc *PasswordTokenCreate) sqlSave(ctx context.Context) (*PasswordToken, error) {
|
||||
if err := ptc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := ptc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, ptc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
ptc.mutation.id = &_node.ID
|
||||
ptc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (ptc *PasswordTokenCreate) createSpec() (*PasswordToken, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &PasswordToken{config: ptc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: passwordtoken.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
}
|
||||
_spec = sqlgraph.NewCreateSpec(passwordtoken.Table, sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := ptc.mutation.Hash(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: passwordtoken.FieldHash,
|
||||
})
|
||||
_spec.SetField(passwordtoken.FieldHash, field.TypeString, value)
|
||||
_node.Hash = value
|
||||
}
|
||||
if value, ok := ptc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: passwordtoken.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(passwordtoken.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if nodes := ptc.mutation.UserIDs(); len(nodes) > 0 {
|
||||
|
|
@ -196,10 +151,7 @@ func (ptc *PasswordTokenCreate) createSpec() (*PasswordToken, *sqlgraph.CreateSp
|
|||
Columns: []string{passwordtoken.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
|
|
@ -214,11 +166,15 @@ func (ptc *PasswordTokenCreate) createSpec() (*PasswordToken, *sqlgraph.CreateSp
|
|||
// PasswordTokenCreateBulk is the builder for creating many PasswordToken entities in bulk.
|
||||
type PasswordTokenCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*PasswordTokenCreate
|
||||
}
|
||||
|
||||
// Save creates the PasswordToken entities in the database.
|
||||
func (ptcb *PasswordTokenCreateBulk) Save(ctx context.Context) ([]*PasswordToken, error) {
|
||||
if ptcb.err != nil {
|
||||
return nil, ptcb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(ptcb.builders))
|
||||
nodes := make([]*PasswordToken, len(ptcb.builders))
|
||||
mutators := make([]Mutator, len(ptcb.builders))
|
||||
|
|
@ -235,8 +191,8 @@ func (ptcb *PasswordTokenCreateBulk) Save(ctx context.Context) ([]*PasswordToken
|
|||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, ptcb.builders[i+1].mutation)
|
||||
} else {
|
||||
|
|
@ -244,7 +200,7 @@ func (ptcb *PasswordTokenCreateBulk) Save(ctx context.Context) ([]*PasswordToken
|
|||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, ptcb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -252,11 +208,11 @@ func (ptcb *PasswordTokenCreateBulk) Save(ctx context.Context) ([]*PasswordToken
|
|||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
mutation.done = true
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
|
@ -28,34 +27,7 @@ func (ptd *PasswordTokenDelete) Where(ps ...predicate.PasswordToken) *PasswordTo
|
|||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ptd *PasswordTokenDelete) Exec(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(ptd.hooks) == 0 {
|
||||
affected, err = ptd.sqlExec(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*PasswordTokenMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
ptd.mutation = mutation
|
||||
affected, err = ptd.sqlExec(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(ptd.hooks) - 1; i >= 0; i-- {
|
||||
if ptd.hooks[i] == nil {
|
||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = ptd.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, ptd.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
return withHooks(ctx, ptd.sqlExec, ptd.mutation, ptd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
|
|
@ -68,15 +40,7 @@ func (ptd *PasswordTokenDelete) ExecX(ctx context.Context) int {
|
|||
}
|
||||
|
||||
func (ptd *PasswordTokenDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: passwordtoken.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec := sqlgraph.NewDeleteSpec(passwordtoken.Table, sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt))
|
||||
if ps := ptd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
|
|
@ -84,7 +48,12 @@ func (ptd *PasswordTokenDelete) sqlExec(ctx context.Context) (int, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
return sqlgraph.DeleteNodes(ctx, ptd.driver, _spec)
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, ptd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
ptd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// PasswordTokenDeleteOne is the builder for deleting a single PasswordToken entity.
|
||||
|
|
@ -92,6 +61,12 @@ type PasswordTokenDeleteOne struct {
|
|||
ptd *PasswordTokenDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PasswordTokenDelete builder.
|
||||
func (ptdo *PasswordTokenDeleteOne) Where(ps ...predicate.PasswordToken) *PasswordTokenDeleteOne {
|
||||
ptdo.ptd.mutation.Where(ps...)
|
||||
return ptdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ptdo *PasswordTokenDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := ptdo.ptd.Exec(ctx)
|
||||
|
|
@ -107,5 +82,7 @@ func (ptdo *PasswordTokenDeleteOne) Exec(ctx context.Context) error {
|
|||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ptdo *PasswordTokenDeleteOne) ExecX(ctx context.Context) {
|
||||
ptdo.ptd.ExecX(ctx)
|
||||
if err := ptdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
|
|
@ -19,15 +18,12 @@ import (
|
|||
// PasswordTokenQuery is the builder for querying PasswordToken entities.
|
||||
type PasswordTokenQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
ctx *QueryContext
|
||||
order []passwordtoken.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.PasswordToken
|
||||
// eager-loading edges.
|
||||
withUser *UserQuery
|
||||
withFKs bool
|
||||
withUser *UserQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
|
@ -39,34 +35,34 @@ func (ptq *PasswordTokenQuery) Where(ps ...predicate.PasswordToken) *PasswordTok
|
|||
return ptq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (ptq *PasswordTokenQuery) Limit(limit int) *PasswordTokenQuery {
|
||||
ptq.limit = &limit
|
||||
ptq.ctx.Limit = &limit
|
||||
return ptq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
// Offset to start from.
|
||||
func (ptq *PasswordTokenQuery) Offset(offset int) *PasswordTokenQuery {
|
||||
ptq.offset = &offset
|
||||
ptq.ctx.Offset = &offset
|
||||
return ptq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (ptq *PasswordTokenQuery) Unique(unique bool) *PasswordTokenQuery {
|
||||
ptq.unique = &unique
|
||||
ptq.ctx.Unique = &unique
|
||||
return ptq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (ptq *PasswordTokenQuery) Order(o ...OrderFunc) *PasswordTokenQuery {
|
||||
// Order specifies how the records should be ordered.
|
||||
func (ptq *PasswordTokenQuery) Order(o ...passwordtoken.OrderOption) *PasswordTokenQuery {
|
||||
ptq.order = append(ptq.order, o...)
|
||||
return ptq
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (ptq *PasswordTokenQuery) QueryUser() *UserQuery {
|
||||
query := &UserQuery{config: ptq.config}
|
||||
query := (&UserClient{config: ptq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := ptq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -89,7 +85,7 @@ func (ptq *PasswordTokenQuery) QueryUser() *UserQuery {
|
|||
// First returns the first PasswordToken entity from the query.
|
||||
// Returns a *NotFoundError when no PasswordToken was found.
|
||||
func (ptq *PasswordTokenQuery) First(ctx context.Context) (*PasswordToken, error) {
|
||||
nodes, err := ptq.Limit(1).All(ctx)
|
||||
nodes, err := ptq.Limit(1).All(setContextOp(ctx, ptq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -112,7 +108,7 @@ func (ptq *PasswordTokenQuery) FirstX(ctx context.Context) *PasswordToken {
|
|||
// Returns a *NotFoundError when no PasswordToken ID was found.
|
||||
func (ptq *PasswordTokenQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ptq.Limit(1).IDs(ctx); err != nil {
|
||||
if ids, err = ptq.Limit(1).IDs(setContextOp(ctx, ptq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
|
|
@ -132,10 +128,10 @@ func (ptq *PasswordTokenQuery) FirstIDX(ctx context.Context) int {
|
|||
}
|
||||
|
||||
// Only returns a single PasswordToken entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when exactly one PasswordToken entity is not found.
|
||||
// Returns a *NotSingularError when more than one PasswordToken entity is found.
|
||||
// Returns a *NotFoundError when no PasswordToken entities are found.
|
||||
func (ptq *PasswordTokenQuery) Only(ctx context.Context) (*PasswordToken, error) {
|
||||
nodes, err := ptq.Limit(2).All(ctx)
|
||||
nodes, err := ptq.Limit(2).All(setContextOp(ctx, ptq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -159,11 +155,11 @@ func (ptq *PasswordTokenQuery) OnlyX(ctx context.Context) *PasswordToken {
|
|||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only PasswordToken ID in the query.
|
||||
// Returns a *NotSingularError when exactly one PasswordToken ID is not found.
|
||||
// Returns a *NotSingularError when more than one PasswordToken ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (ptq *PasswordTokenQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ptq.Limit(2).IDs(ctx); err != nil {
|
||||
if ids, err = ptq.Limit(2).IDs(setContextOp(ctx, ptq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
|
|
@ -188,10 +184,12 @@ func (ptq *PasswordTokenQuery) OnlyIDX(ctx context.Context) int {
|
|||
|
||||
// All executes the query and returns a list of PasswordTokens.
|
||||
func (ptq *PasswordTokenQuery) All(ctx context.Context) ([]*PasswordToken, error) {
|
||||
ctx = setContextOp(ctx, ptq.ctx, "All")
|
||||
if err := ptq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ptq.sqlAll(ctx)
|
||||
qr := querierAll[[]*PasswordToken, *PasswordTokenQuery]()
|
||||
return withInterceptors[[]*PasswordToken](ctx, ptq, qr, ptq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
|
|
@ -204,9 +202,12 @@ func (ptq *PasswordTokenQuery) AllX(ctx context.Context) []*PasswordToken {
|
|||
}
|
||||
|
||||
// IDs executes the query and returns a list of PasswordToken IDs.
|
||||
func (ptq *PasswordTokenQuery) IDs(ctx context.Context) ([]int, error) {
|
||||
var ids []int
|
||||
if err := ptq.Select(passwordtoken.FieldID).Scan(ctx, &ids); err != nil {
|
||||
func (ptq *PasswordTokenQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if ptq.ctx.Unique == nil && ptq.path != nil {
|
||||
ptq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, ptq.ctx, "IDs")
|
||||
if err = ptq.Select(passwordtoken.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
|
|
@ -223,10 +224,11 @@ func (ptq *PasswordTokenQuery) IDsX(ctx context.Context) []int {
|
|||
|
||||
// Count returns the count of the given query.
|
||||
func (ptq *PasswordTokenQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, ptq.ctx, "Count")
|
||||
if err := ptq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return ptq.sqlCount(ctx)
|
||||
return withInterceptors[int](ctx, ptq, querierCount[*PasswordTokenQuery](), ptq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
|
|
@ -240,10 +242,15 @@ func (ptq *PasswordTokenQuery) CountX(ctx context.Context) int {
|
|||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (ptq *PasswordTokenQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := ptq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
ctx = setContextOp(ctx, ptq.ctx, "Exist")
|
||||
switch _, err := ptq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
return ptq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
|
|
@ -263,9 +270,9 @@ func (ptq *PasswordTokenQuery) Clone() *PasswordTokenQuery {
|
|||
}
|
||||
return &PasswordTokenQuery{
|
||||
config: ptq.config,
|
||||
limit: ptq.limit,
|
||||
offset: ptq.offset,
|
||||
order: append([]OrderFunc{}, ptq.order...),
|
||||
ctx: ptq.ctx.Clone(),
|
||||
order: append([]passwordtoken.OrderOption{}, ptq.order...),
|
||||
inters: append([]Interceptor{}, ptq.inters...),
|
||||
predicates: append([]predicate.PasswordToken{}, ptq.predicates...),
|
||||
withUser: ptq.withUser.Clone(),
|
||||
// clone intermediate query.
|
||||
|
|
@ -277,7 +284,7 @@ func (ptq *PasswordTokenQuery) Clone() *PasswordTokenQuery {
|
|||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (ptq *PasswordTokenQuery) WithUser(opts ...func(*UserQuery)) *PasswordTokenQuery {
|
||||
query := &UserQuery{config: ptq.config}
|
||||
query := (&UserClient{config: ptq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
|
|
@ -299,17 +306,13 @@ func (ptq *PasswordTokenQuery) WithUser(opts ...func(*UserQuery)) *PasswordToken
|
|||
// GroupBy(passwordtoken.FieldHash).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (ptq *PasswordTokenQuery) GroupBy(field string, fields ...string) *PasswordTokenGroupBy {
|
||||
group := &PasswordTokenGroupBy{config: ptq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := ptq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ptq.sqlQuery(ctx), nil
|
||||
}
|
||||
return group
|
||||
ptq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &PasswordTokenGroupBy{build: ptq}
|
||||
grbuild.flds = &ptq.ctx.Fields
|
||||
grbuild.label = passwordtoken.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
|
|
@ -324,14 +327,31 @@ func (ptq *PasswordTokenQuery) GroupBy(field string, fields ...string) *Password
|
|||
// client.PasswordToken.Query().
|
||||
// Select(passwordtoken.FieldHash).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (ptq *PasswordTokenQuery) Select(fields ...string) *PasswordTokenSelect {
|
||||
ptq.fields = append(ptq.fields, fields...)
|
||||
return &PasswordTokenSelect{PasswordTokenQuery: ptq}
|
||||
ptq.ctx.Fields = append(ptq.ctx.Fields, fields...)
|
||||
sbuild := &PasswordTokenSelect{PasswordTokenQuery: ptq}
|
||||
sbuild.label = passwordtoken.Label
|
||||
sbuild.flds, sbuild.scan = &ptq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a PasswordTokenSelect configured with the given aggregations.
|
||||
func (ptq *PasswordTokenQuery) Aggregate(fns ...AggregateFunc) *PasswordTokenSelect {
|
||||
return ptq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (ptq *PasswordTokenQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range ptq.fields {
|
||||
for _, inter := range ptq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, ptq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range ptq.ctx.Fields {
|
||||
if !passwordtoken.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
|
|
@ -346,7 +366,7 @@ func (ptq *PasswordTokenQuery) prepareQuery(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ptq *PasswordTokenQuery) sqlAll(ctx context.Context) ([]*PasswordToken, error) {
|
||||
func (ptq *PasswordTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*PasswordToken, error) {
|
||||
var (
|
||||
nodes = []*PasswordToken{}
|
||||
withFKs = ptq.withFKs
|
||||
|
|
@ -361,92 +381,84 @@ func (ptq *PasswordTokenQuery) sqlAll(ctx context.Context) ([]*PasswordToken, er
|
|||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, passwordtoken.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*PasswordToken).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &PasswordToken{config: ptq.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.scanValues(columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []interface{}) error {
|
||||
if len(nodes) == 0 {
|
||||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, ptq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := ptq.withUser; query != nil {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*PasswordToken)
|
||||
for i := range nodes {
|
||||
if nodes[i].password_token_user == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].password_token_user
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
if err := ptq.loadUser(ctx, query, nodes, nil,
|
||||
func(n *PasswordToken, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`unexpected foreign-key "password_token_user" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
nodes[i].Edges.User = n
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (ptq *PasswordTokenQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*PasswordToken, init func(*PasswordToken), assign func(*PasswordToken, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*PasswordToken)
|
||||
for i := range nodes {
|
||||
if nodes[i].password_token_user == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].password_token_user
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "password_token_user" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
|
||||
return nodes, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ptq *PasswordTokenQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := ptq.querySpec()
|
||||
_spec.Node.Columns = ptq.fields
|
||||
if len(ptq.fields) > 0 {
|
||||
_spec.Unique = ptq.unique != nil && *ptq.unique
|
||||
_spec.Node.Columns = ptq.ctx.Fields
|
||||
if len(ptq.ctx.Fields) > 0 {
|
||||
_spec.Unique = ptq.ctx.Unique != nil && *ptq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, ptq.driver, _spec)
|
||||
}
|
||||
|
||||
func (ptq *PasswordTokenQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
n, err := ptq.sqlCount(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (ptq *PasswordTokenQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: passwordtoken.Table,
|
||||
Columns: passwordtoken.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
},
|
||||
From: ptq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if unique := ptq.unique; unique != nil {
|
||||
_spec := sqlgraph.NewQuerySpec(passwordtoken.Table, passwordtoken.Columns, sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt))
|
||||
_spec.From = ptq.sql
|
||||
if unique := ptq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if ptq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := ptq.fields; len(fields) > 0 {
|
||||
if fields := ptq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, passwordtoken.FieldID)
|
||||
for i := range fields {
|
||||
|
|
@ -462,10 +474,10 @@ func (ptq *PasswordTokenQuery) querySpec() *sqlgraph.QuerySpec {
|
|||
}
|
||||
}
|
||||
}
|
||||
if limit := ptq.limit; limit != nil {
|
||||
if limit := ptq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := ptq.offset; offset != nil {
|
||||
if offset := ptq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := ptq.order; len(ps) > 0 {
|
||||
|
|
@ -481,7 +493,7 @@ func (ptq *PasswordTokenQuery) querySpec() *sqlgraph.QuerySpec {
|
|||
func (ptq *PasswordTokenQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(ptq.driver.Dialect())
|
||||
t1 := builder.Table(passwordtoken.Table)
|
||||
columns := ptq.fields
|
||||
columns := ptq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = passwordtoken.Columns
|
||||
}
|
||||
|
|
@ -490,7 +502,7 @@ func (ptq *PasswordTokenQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|||
selector = ptq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if ptq.unique != nil && *ptq.unique {
|
||||
if ptq.ctx.Unique != nil && *ptq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range ptq.predicates {
|
||||
|
|
@ -499,12 +511,12 @@ func (ptq *PasswordTokenQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|||
for _, p := range ptq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := ptq.offset; offset != nil {
|
||||
if offset := ptq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := ptq.limit; limit != nil {
|
||||
if limit := ptq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
|
|
@ -512,12 +524,8 @@ func (ptq *PasswordTokenQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|||
|
||||
// PasswordTokenGroupBy is the group-by builder for PasswordToken entities.
|
||||
type PasswordTokenGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
selector
|
||||
build *PasswordTokenQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
|
|
@ -526,471 +534,77 @@ func (ptgb *PasswordTokenGroupBy) Aggregate(fns ...AggregateFunc) *PasswordToken
|
|||
return ptgb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scans the result into the given value.
|
||||
func (ptgb *PasswordTokenGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := ptgb.path(ctx)
|
||||
if err != nil {
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ptgb *PasswordTokenGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ptgb.build.ctx, "GroupBy")
|
||||
if err := ptgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
ptgb.sql = query
|
||||
return ptgb.sqlScan(ctx, v)
|
||||
return scanWithInterceptors[*PasswordTokenQuery, *PasswordTokenGroupBy](ctx, ptgb.build, ptgb, ptgb.build.inters, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (ptgb *PasswordTokenGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := ptgb.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
func (ptgb *PasswordTokenGroupBy) sqlScan(ctx context.Context, root *PasswordTokenQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(ptgb.fns))
|
||||
for _, fn := range ptgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ptgb *PasswordTokenGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(ptgb.fields) > 1 {
|
||||
return nil, errors.New("ent: PasswordTokenGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := ptgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (ptgb *PasswordTokenGroupBy) StringsX(ctx context.Context) []string {
|
||||
v, err := ptgb.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ptgb *PasswordTokenGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = ptgb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PasswordTokenGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (ptgb *PasswordTokenGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := ptgb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ptgb *PasswordTokenGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(ptgb.fields) > 1 {
|
||||
return nil, errors.New("ent: PasswordTokenGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := ptgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (ptgb *PasswordTokenGroupBy) IntsX(ctx context.Context) []int {
|
||||
v, err := ptgb.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ptgb *PasswordTokenGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = ptgb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PasswordTokenGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (ptgb *PasswordTokenGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := ptgb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ptgb *PasswordTokenGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(ptgb.fields) > 1 {
|
||||
return nil, errors.New("ent: PasswordTokenGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := ptgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (ptgb *PasswordTokenGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := ptgb.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ptgb *PasswordTokenGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = ptgb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PasswordTokenGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (ptgb *PasswordTokenGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := ptgb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ptgb *PasswordTokenGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(ptgb.fields) > 1 {
|
||||
return nil, errors.New("ent: PasswordTokenGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := ptgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (ptgb *PasswordTokenGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
v, err := ptgb.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ptgb *PasswordTokenGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = ptgb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PasswordTokenGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (ptgb *PasswordTokenGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := ptgb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (ptgb *PasswordTokenGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
for _, f := range ptgb.fields {
|
||||
if !passwordtoken.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*ptgb.flds)+len(ptgb.fns))
|
||||
for _, f := range *ptgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector := ptgb.sqlQuery()
|
||||
selector.GroupBy(selector.Columns(*ptgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ptgb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
if err := ptgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (ptgb *PasswordTokenGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := ptgb.sql.Select()
|
||||
aggregation := make([]string, 0, len(ptgb.fns))
|
||||
for _, fn := range ptgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(ptgb.fields)+len(ptgb.fns))
|
||||
for _, f := range ptgb.fields {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
return selector.GroupBy(selector.Columns(ptgb.fields...)...)
|
||||
}
|
||||
|
||||
// PasswordTokenSelect is the builder for selecting fields of PasswordToken entities.
|
||||
type PasswordTokenSelect struct {
|
||||
*PasswordTokenQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (pts *PasswordTokenSelect) Aggregate(fns ...AggregateFunc) *PasswordTokenSelect {
|
||||
pts.fns = append(pts.fns, fns...)
|
||||
return pts
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (pts *PasswordTokenSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
func (pts *PasswordTokenSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, pts.ctx, "Select")
|
||||
if err := pts.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
pts.sql = pts.PasswordTokenQuery.sqlQuery(ctx)
|
||||
return pts.sqlScan(ctx, v)
|
||||
return scanWithInterceptors[*PasswordTokenQuery, *PasswordTokenSelect](ctx, pts.PasswordTokenQuery, pts, pts.inters, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (pts *PasswordTokenSelect) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := pts.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
func (pts *PasswordTokenSelect) sqlScan(ctx context.Context, root *PasswordTokenQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(pts.fns))
|
||||
for _, fn := range pts.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||
func (pts *PasswordTokenSelect) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(pts.fields) > 1 {
|
||||
return nil, errors.New("ent: PasswordTokenSelect.Strings is not achievable when selecting more than 1 field")
|
||||
switch n := len(*pts.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
var v []string
|
||||
if err := pts.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (pts *PasswordTokenSelect) StringsX(ctx context.Context) []string {
|
||||
v, err := pts.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||
func (pts *PasswordTokenSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = pts.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PasswordTokenSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (pts *PasswordTokenSelect) StringX(ctx context.Context) string {
|
||||
v, err := pts.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||
func (pts *PasswordTokenSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(pts.fields) > 1 {
|
||||
return nil, errors.New("ent: PasswordTokenSelect.Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := pts.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (pts *PasswordTokenSelect) IntsX(ctx context.Context) []int {
|
||||
v, err := pts.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||
func (pts *PasswordTokenSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = pts.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PasswordTokenSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (pts *PasswordTokenSelect) IntX(ctx context.Context) int {
|
||||
v, err := pts.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||
func (pts *PasswordTokenSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(pts.fields) > 1 {
|
||||
return nil, errors.New("ent: PasswordTokenSelect.Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := pts.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (pts *PasswordTokenSelect) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := pts.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||
func (pts *PasswordTokenSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = pts.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PasswordTokenSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (pts *PasswordTokenSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := pts.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||
func (pts *PasswordTokenSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(pts.fields) > 1 {
|
||||
return nil, errors.New("ent: PasswordTokenSelect.Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := pts.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (pts *PasswordTokenSelect) BoolsX(ctx context.Context) []bool {
|
||||
v, err := pts.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||
func (pts *PasswordTokenSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = pts.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PasswordTokenSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (pts *PasswordTokenSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := pts.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (pts *PasswordTokenSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := pts.sql.Query()
|
||||
query, args := selector.Query()
|
||||
if err := pts.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
|
@ -35,6 +35,14 @@ func (ptu *PasswordTokenUpdate) SetHash(s string) *PasswordTokenUpdate {
|
|||
return ptu
|
||||
}
|
||||
|
||||
// SetNillableHash sets the "hash" field if the given value is not nil.
|
||||
func (ptu *PasswordTokenUpdate) SetNillableHash(s *string) *PasswordTokenUpdate {
|
||||
if s != nil {
|
||||
ptu.SetHash(*s)
|
||||
}
|
||||
return ptu
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (ptu *PasswordTokenUpdate) SetCreatedAt(t time.Time) *PasswordTokenUpdate {
|
||||
ptu.mutation.SetCreatedAt(t)
|
||||
|
|
@ -73,40 +81,7 @@ func (ptu *PasswordTokenUpdate) ClearUser() *PasswordTokenUpdate {
|
|||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (ptu *PasswordTokenUpdate) Save(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(ptu.hooks) == 0 {
|
||||
if err = ptu.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
affected, err = ptu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*PasswordTokenMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = ptu.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
ptu.mutation = mutation
|
||||
affected, err = ptu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(ptu.hooks) - 1; i >= 0; i-- {
|
||||
if ptu.hooks[i] == nil {
|
||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = ptu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, ptu.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
return withHooks(ctx, ptu.sqlSave, ptu.mutation, ptu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
|
|
@ -145,16 +120,10 @@ func (ptu *PasswordTokenUpdate) check() error {
|
|||
}
|
||||
|
||||
func (ptu *PasswordTokenUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: passwordtoken.Table,
|
||||
Columns: passwordtoken.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
},
|
||||
if err := ptu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(passwordtoken.Table, passwordtoken.Columns, sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt))
|
||||
if ps := ptu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
|
|
@ -163,18 +132,10 @@ func (ptu *PasswordTokenUpdate) sqlSave(ctx context.Context) (n int, err error)
|
|||
}
|
||||
}
|
||||
if value, ok := ptu.mutation.Hash(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: passwordtoken.FieldHash,
|
||||
})
|
||||
_spec.SetField(passwordtoken.FieldHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ptu.mutation.CreatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: passwordtoken.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(passwordtoken.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
if ptu.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
|
@ -184,10 +145,7 @@ func (ptu *PasswordTokenUpdate) sqlSave(ctx context.Context) (n int, err error)
|
|||
Columns: []string{passwordtoken.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
|
|
@ -200,10 +158,7 @@ func (ptu *PasswordTokenUpdate) sqlSave(ctx context.Context) (n int, err error)
|
|||
Columns: []string{passwordtoken.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
|
|
@ -215,10 +170,11 @@ func (ptu *PasswordTokenUpdate) sqlSave(ctx context.Context) (n int, err error)
|
|||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
ptu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
|
|
@ -236,6 +192,14 @@ func (ptuo *PasswordTokenUpdateOne) SetHash(s string) *PasswordTokenUpdateOne {
|
|||
return ptuo
|
||||
}
|
||||
|
||||
// SetNillableHash sets the "hash" field if the given value is not nil.
|
||||
func (ptuo *PasswordTokenUpdateOne) SetNillableHash(s *string) *PasswordTokenUpdateOne {
|
||||
if s != nil {
|
||||
ptuo.SetHash(*s)
|
||||
}
|
||||
return ptuo
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (ptuo *PasswordTokenUpdateOne) SetCreatedAt(t time.Time) *PasswordTokenUpdateOne {
|
||||
ptuo.mutation.SetCreatedAt(t)
|
||||
|
|
@ -272,6 +236,12 @@ func (ptuo *PasswordTokenUpdateOne) ClearUser() *PasswordTokenUpdateOne {
|
|||
return ptuo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PasswordTokenUpdate builder.
|
||||
func (ptuo *PasswordTokenUpdateOne) Where(ps ...predicate.PasswordToken) *PasswordTokenUpdateOne {
|
||||
ptuo.mutation.Where(ps...)
|
||||
return ptuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (ptuo *PasswordTokenUpdateOne) Select(field string, fields ...string) *PasswordTokenUpdateOne {
|
||||
|
|
@ -281,40 +251,7 @@ func (ptuo *PasswordTokenUpdateOne) Select(field string, fields ...string) *Pass
|
|||
|
||||
// Save executes the query and returns the updated PasswordToken entity.
|
||||
func (ptuo *PasswordTokenUpdateOne) Save(ctx context.Context) (*PasswordToken, error) {
|
||||
var (
|
||||
err error
|
||||
node *PasswordToken
|
||||
)
|
||||
if len(ptuo.hooks) == 0 {
|
||||
if err = ptuo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = ptuo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*PasswordTokenMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = ptuo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ptuo.mutation = mutation
|
||||
node, err = ptuo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(ptuo.hooks) - 1; i >= 0; i-- {
|
||||
if ptuo.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = ptuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, ptuo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
return withHooks(ctx, ptuo.sqlSave, ptuo.mutation, ptuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
|
|
@ -353,16 +290,10 @@ func (ptuo *PasswordTokenUpdateOne) check() error {
|
|||
}
|
||||
|
||||
func (ptuo *PasswordTokenUpdateOne) sqlSave(ctx context.Context) (_node *PasswordToken, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: passwordtoken.Table,
|
||||
Columns: passwordtoken.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
},
|
||||
if err := ptuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(passwordtoken.Table, passwordtoken.Columns, sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt))
|
||||
id, ok := ptuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PasswordToken.id" for update`)}
|
||||
|
|
@ -388,18 +319,10 @@ func (ptuo *PasswordTokenUpdateOne) sqlSave(ctx context.Context) (_node *Passwor
|
|||
}
|
||||
}
|
||||
if value, ok := ptuo.mutation.Hash(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: passwordtoken.FieldHash,
|
||||
})
|
||||
_spec.SetField(passwordtoken.FieldHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ptuo.mutation.CreatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: passwordtoken.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(passwordtoken.FieldCreatedAt, field.TypeTime, value)
|
||||
}
|
||||
if ptuo.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
|
@ -409,10 +332,7 @@ func (ptuo *PasswordTokenUpdateOne) sqlSave(ctx context.Context) (_node *Passwor
|
|||
Columns: []string{passwordtoken.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
|
|
@ -425,10 +345,7 @@ func (ptuo *PasswordTokenUpdateOne) sqlSave(ctx context.Context) (_node *Passwor
|
|||
Columns: []string{passwordtoken.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
|
|
@ -443,9 +360,10 @@ func (ptuo *PasswordTokenUpdateOne) sqlSave(ctx context.Context) (_node *Passwor
|
|||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{passwordtoken.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
ptuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package predicate
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package runtime
|
||||
|
||||
|
|
@ -51,6 +51,6 @@ func init() {
|
|||
}
|
||||
|
||||
const (
|
||||
Version = "v0.10.0" // Version of ent codegen.
|
||||
Sum = "h1:9cBomE1fh+WX34DPYQL7tDNAIvhKa3tXvwxuLyhYCMo=" // Sum of ent codegen.
|
||||
Version = "v0.12.5" // Version of ent codegen.
|
||||
Sum = "h1:KREM5E4CSoej4zeGa88Ou/gfturAnpUv0mzAjch1sj4=" // Sum of ent codegen.
|
||||
)
|
||||
|
|
|
|||
42
ent/tx.go
42
ent/tx.go
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
|
@ -20,12 +20,6 @@ type Tx struct {
|
|||
// lazily loaded.
|
||||
client *Client
|
||||
clientOnce sync.Once
|
||||
|
||||
// completion callbacks.
|
||||
mu sync.Mutex
|
||||
onCommit []CommitHook
|
||||
onRollback []RollbackHook
|
||||
|
||||
// ctx lives for the life of the transaction. It is
|
||||
// the same context used by the underlying connection.
|
||||
ctx context.Context
|
||||
|
|
@ -70,9 +64,9 @@ func (tx *Tx) Commit() error {
|
|||
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Commit()
|
||||
})
|
||||
tx.mu.Lock()
|
||||
hooks := append([]CommitHook(nil), tx.onCommit...)
|
||||
tx.mu.Unlock()
|
||||
txDriver.mu.Lock()
|
||||
hooks := append([]CommitHook(nil), txDriver.onCommit...)
|
||||
txDriver.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
|
|
@ -81,9 +75,10 @@ func (tx *Tx) Commit() error {
|
|||
|
||||
// OnCommit adds a hook to call on commit.
|
||||
func (tx *Tx) OnCommit(f CommitHook) {
|
||||
tx.mu.Lock()
|
||||
defer tx.mu.Unlock()
|
||||
tx.onCommit = append(tx.onCommit, f)
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
txDriver.mu.Lock()
|
||||
txDriver.onCommit = append(txDriver.onCommit, f)
|
||||
txDriver.mu.Unlock()
|
||||
}
|
||||
|
||||
type (
|
||||
|
|
@ -125,9 +120,9 @@ func (tx *Tx) Rollback() error {
|
|||
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Rollback()
|
||||
})
|
||||
tx.mu.Lock()
|
||||
hooks := append([]RollbackHook(nil), tx.onRollback...)
|
||||
tx.mu.Unlock()
|
||||
txDriver.mu.Lock()
|
||||
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
|
||||
txDriver.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
|
|
@ -136,9 +131,10 @@ func (tx *Tx) Rollback() error {
|
|||
|
||||
// OnRollback adds a hook to call on rollback.
|
||||
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||
tx.mu.Lock()
|
||||
defer tx.mu.Unlock()
|
||||
tx.onRollback = append(tx.onRollback, f)
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
txDriver.mu.Lock()
|
||||
txDriver.onRollback = append(txDriver.onRollback, f)
|
||||
txDriver.mu.Unlock()
|
||||
}
|
||||
|
||||
// Client returns a Client that binds to current transaction.
|
||||
|
|
@ -171,6 +167,10 @@ type txDriver struct {
|
|||
drv dialect.Driver
|
||||
// tx is the underlying transaction.
|
||||
tx dialect.Tx
|
||||
// completion hooks.
|
||||
mu sync.Mutex
|
||||
onCommit []CommitHook
|
||||
onRollback []RollbackHook
|
||||
}
|
||||
|
||||
// newTx creates a new transactional driver.
|
||||
|
|
@ -201,12 +201,12 @@ func (*txDriver) Commit() error { return nil }
|
|||
func (*txDriver) Rollback() error { return nil }
|
||||
|
||||
// Exec calls tx.Exec.
|
||||
func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error {
|
||||
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
|
||||
return tx.tx.Exec(ctx, query, args, v)
|
||||
}
|
||||
|
||||
// Query calls tx.Query.
|
||||
func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error {
|
||||
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
|
||||
return tx.tx.Query(ctx, query, args, v)
|
||||
}
|
||||
|
||||
|
|
|
|||
52
ent/user.go
52
ent/user.go
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/mikestefanello/pagoda/ent/user"
|
||||
)
|
||||
|
|
@ -28,7 +29,8 @@ type User struct {
|
|||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the UserQuery when eager-loading is set.
|
||||
Edges UserEdges `json:"edges"`
|
||||
Edges UserEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// UserEdges holds the relations/edges for other nodes in the graph.
|
||||
|
|
@ -50,8 +52,8 @@ func (e UserEdges) OwnerOrErr() ([]*PasswordToken, error) {
|
|||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*User) scanValues(columns []string) ([]interface{}, error) {
|
||||
values := make([]interface{}, len(columns))
|
||||
func (*User) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case user.FieldVerified:
|
||||
|
|
@ -63,7 +65,7 @@ func (*User) scanValues(columns []string) ([]interface{}, error) {
|
|||
case user.FieldCreatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected column %q for type User", columns[i])
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
|
|
@ -71,7 +73,7 @@ func (*User) scanValues(columns []string) ([]interface{}, error) {
|
|||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the User fields.
|
||||
func (u *User) assignValues(columns []string, values []interface{}) error {
|
||||
func (u *User) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
|
|
@ -113,31 +115,39 @@ func (u *User) assignValues(columns []string, values []interface{}) error {
|
|||
} else if value.Valid {
|
||||
u.CreatedAt = value.Time
|
||||
}
|
||||
default:
|
||||
u.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the User.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (u *User) Value(name string) (ent.Value, error) {
|
||||
return u.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryOwner queries the "owner" edge of the User entity.
|
||||
func (u *User) QueryOwner() *PasswordTokenQuery {
|
||||
return (&UserClient{config: u.config}).QueryOwner(u)
|
||||
return NewUserClient(u.config).QueryOwner(u)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this User.
|
||||
// Note that you need to call User.Unwrap() before calling this method if this User
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (u *User) Update() *UserUpdateOne {
|
||||
return (&UserClient{config: u.config}).UpdateOne(u)
|
||||
return NewUserClient(u.config).UpdateOne(u)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the User entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (u *User) Unwrap() *User {
|
||||
tx, ok := u.config.driver.(*txDriver)
|
||||
_tx, ok := u.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: User is not a transactional entity")
|
||||
}
|
||||
u.config.driver = tx.drv
|
||||
u.config.driver = _tx.drv
|
||||
return u
|
||||
}
|
||||
|
||||
|
|
@ -145,15 +155,19 @@ func (u *User) Unwrap() *User {
|
|||
func (u *User) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("User(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", u.ID))
|
||||
builder.WriteString(", name=")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", u.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(u.Name)
|
||||
builder.WriteString(", email=")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("email=")
|
||||
builder.WriteString(u.Email)
|
||||
builder.WriteString(", password=<sensitive>")
|
||||
builder.WriteString(", verified=")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("password=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("verified=")
|
||||
builder.WriteString(fmt.Sprintf("%v", u.Verified))
|
||||
builder.WriteString(", created_at=")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(u.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
|
|
@ -161,9 +175,3 @@ func (u *User) String() string {
|
|||
|
||||
// Users is a parsable slice of User.
|
||||
type Users []*User
|
||||
|
||||
func (u Users) config(cfg config) {
|
||||
for _i := range u {
|
||||
u[_i].config = cfg
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package user
|
||||
|
||||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -61,7 +63,6 @@ func ValidColumn(column string) bool {
|
|||
// it should be imported in the main as follows:
|
||||
//
|
||||
// import _ "github.com/mikestefanello/pagoda/ent/runtime"
|
||||
//
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
// NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
|
|
@ -75,3 +76,57 @@ var (
|
|||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the User queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByEmail orders the results by the email field.
|
||||
func ByEmail(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldEmail, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPassword orders the results by the password field.
|
||||
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPassword, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByVerified orders the results by the verified field.
|
||||
func ByVerified(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldVerified, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOwnerCount orders the results by owner count.
|
||||
func ByOwnerCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newOwnerStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByOwner orders the results by owner terms.
|
||||
func ByOwner(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newOwnerStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(OwnerInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, OwnerTable, OwnerColumn),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package user
|
||||
|
||||
|
|
@ -12,543 +12,317 @@ import (
|
|||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.User(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.User(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.User(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.User(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
})
|
||||
return predicate.User(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// Email applies equality check predicate on the "email" field. It's identical to EmailEQ.
|
||||
func Email(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldEmail, v))
|
||||
}
|
||||
|
||||
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
|
||||
func Password(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// Verified applies equality check predicate on the "verified" field. It's identical to VerifiedEQ.
|
||||
func Verified(v bool) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldVerified), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldVerified, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.User {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldName), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.User {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldName), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldName), v))
|
||||
})
|
||||
return predicate.User(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// EmailEQ applies the EQ predicate on the "email" field.
|
||||
func EmailEQ(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailNEQ applies the NEQ predicate on the "email" field.
|
||||
func EmailNEQ(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldNEQ(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailIn applies the In predicate on the "email" field.
|
||||
func EmailIn(vs ...string) predicate.User {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldEmail), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldIn(FieldEmail, vs...))
|
||||
}
|
||||
|
||||
// EmailNotIn applies the NotIn predicate on the "email" field.
|
||||
func EmailNotIn(vs ...string) predicate.User {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldEmail), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldNotIn(FieldEmail, vs...))
|
||||
}
|
||||
|
||||
// EmailGT applies the GT predicate on the "email" field.
|
||||
func EmailGT(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldGT(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailGTE applies the GTE predicate on the "email" field.
|
||||
func EmailGTE(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldGTE(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailLT applies the LT predicate on the "email" field.
|
||||
func EmailLT(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldLT(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailLTE applies the LTE predicate on the "email" field.
|
||||
func EmailLTE(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldLTE(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailContains applies the Contains predicate on the "email" field.
|
||||
func EmailContains(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldContains(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailHasPrefix applies the HasPrefix predicate on the "email" field.
|
||||
func EmailHasPrefix(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldHasPrefix(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailHasSuffix applies the HasSuffix predicate on the "email" field.
|
||||
func EmailHasSuffix(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldHasSuffix(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailEqualFold applies the EqualFold predicate on the "email" field.
|
||||
func EmailEqualFold(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEqualFold(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailContainsFold applies the ContainsFold predicate on the "email" field.
|
||||
func EmailContainsFold(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldEmail), v))
|
||||
})
|
||||
return predicate.User(sql.FieldContainsFold(FieldEmail, v))
|
||||
}
|
||||
|
||||
// PasswordEQ applies the EQ predicate on the "password" field.
|
||||
func PasswordEQ(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordNEQ applies the NEQ predicate on the "password" field.
|
||||
func PasswordNEQ(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldNEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordIn applies the In predicate on the "password" field.
|
||||
func PasswordIn(vs ...string) predicate.User {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldPassword), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldIn(FieldPassword, vs...))
|
||||
}
|
||||
|
||||
// PasswordNotIn applies the NotIn predicate on the "password" field.
|
||||
func PasswordNotIn(vs ...string) predicate.User {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldPassword), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldNotIn(FieldPassword, vs...))
|
||||
}
|
||||
|
||||
// PasswordGT applies the GT predicate on the "password" field.
|
||||
func PasswordGT(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldGT(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordGTE applies the GTE predicate on the "password" field.
|
||||
func PasswordGTE(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldGTE(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordLT applies the LT predicate on the "password" field.
|
||||
func PasswordLT(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldLT(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordLTE applies the LTE predicate on the "password" field.
|
||||
func PasswordLTE(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldLTE(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordContains applies the Contains predicate on the "password" field.
|
||||
func PasswordContains(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldContains(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
|
||||
func PasswordHasPrefix(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldHasPrefix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
|
||||
func PasswordHasSuffix(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldHasSuffix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
|
||||
func PasswordEqualFold(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEqualFold(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
|
||||
func PasswordContainsFold(v string) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldPassword), v))
|
||||
})
|
||||
return predicate.User(sql.FieldContainsFold(FieldPassword, v))
|
||||
}
|
||||
|
||||
// VerifiedEQ applies the EQ predicate on the "verified" field.
|
||||
func VerifiedEQ(v bool) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldVerified), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldVerified, v))
|
||||
}
|
||||
|
||||
// VerifiedNEQ applies the NEQ predicate on the "verified" field.
|
||||
func VerifiedNEQ(v bool) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldVerified), v))
|
||||
})
|
||||
return predicate.User(sql.FieldNEQ(FieldVerified, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.User(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.User {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldCreatedAt), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.User {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldCreatedAt), v...))
|
||||
})
|
||||
return predicate.User(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.User(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.User(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.User(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldCreatedAt), v))
|
||||
})
|
||||
return predicate.User(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// HasOwner applies the HasEdge predicate on the "owner" edge.
|
||||
|
|
@ -556,7 +330,6 @@ func HasOwner() predicate.User {
|
|||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(OwnerTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, OwnerTable, OwnerColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
|
|
@ -566,11 +339,7 @@ func HasOwner() predicate.User {
|
|||
// HasOwnerWith applies the HasEdge predicate on the "owner" edge with a given conditions (other predicates).
|
||||
func HasOwnerWith(preds ...predicate.PasswordToken) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(OwnerInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, OwnerTable, OwnerColumn),
|
||||
)
|
||||
step := newOwnerStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
|
|
@ -581,32 +350,15 @@ func HasOwnerWith(preds ...predicate.PasswordToken) predicate.User {
|
|||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
return predicate.User(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
return predicate.User(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.User) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
return predicate.User(sql.NotPredicates(p))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
|
@ -89,46 +89,10 @@ func (uc *UserCreate) Mutation() *UserMutation {
|
|||
|
||||
// Save creates the User in the database.
|
||||
func (uc *UserCreate) Save(ctx context.Context) (*User, error) {
|
||||
var (
|
||||
err error
|
||||
node *User
|
||||
)
|
||||
if err := uc.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(uc.hooks) == 0 {
|
||||
if err = uc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = uc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*UserMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = uc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uc.mutation = mutation
|
||||
if node, err = uc.sqlSave(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &node.ID
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(uc.hooks) - 1; i >= 0; i-- {
|
||||
if uc.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = uc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, uc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
|
|
@ -205,67 +169,46 @@ func (uc *UserCreate) check() error {
|
|||
}
|
||||
|
||||
func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
if err := uc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := uc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, uc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
uc.mutation.id = &_node.ID
|
||||
uc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &User{config: uc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: user.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
}
|
||||
_spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := uc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldName,
|
||||
})
|
||||
_spec.SetField(user.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := uc.mutation.Email(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldEmail,
|
||||
})
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
_node.Email = value
|
||||
}
|
||||
if value, ok := uc.mutation.Password(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldPassword,
|
||||
})
|
||||
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
||||
_node.Password = value
|
||||
}
|
||||
if value, ok := uc.mutation.Verified(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: user.FieldVerified,
|
||||
})
|
||||
_spec.SetField(user.FieldVerified, field.TypeBool, value)
|
||||
_node.Verified = value
|
||||
}
|
||||
if value, ok := uc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: user.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if nodes := uc.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
|
|
@ -276,10 +219,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||
Columns: []string{user.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
|
|
@ -293,11 +233,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||
// UserCreateBulk is the builder for creating many User entities in bulk.
|
||||
type UserCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*UserCreate
|
||||
}
|
||||
|
||||
// Save creates the User entities in the database.
|
||||
func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
||||
if ucb.err != nil {
|
||||
return nil, ucb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(ucb.builders))
|
||||
nodes := make([]*User, len(ucb.builders))
|
||||
mutators := make([]Mutator, len(ucb.builders))
|
||||
|
|
@ -314,8 +258,8 @@ func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
|||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, ucb.builders[i+1].mutation)
|
||||
} else {
|
||||
|
|
@ -323,7 +267,7 @@ func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
|||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, ucb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -331,11 +275,11 @@ func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
|||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
mutation.done = true
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
|
@ -28,34 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete {
|
|||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ud *UserDelete) Exec(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(ud.hooks) == 0 {
|
||||
affected, err = ud.sqlExec(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*UserMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
ud.mutation = mutation
|
||||
affected, err = ud.sqlExec(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(ud.hooks) - 1; i >= 0; i-- {
|
||||
if ud.hooks[i] == nil {
|
||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = ud.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, ud.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
|
|
@ -68,15 +40,7 @@ func (ud *UserDelete) ExecX(ctx context.Context) int {
|
|||
}
|
||||
|
||||
func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: user.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec := sqlgraph.NewDeleteSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
if ps := ud.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
|
|
@ -84,7 +48,12 @@ func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
return sqlgraph.DeleteNodes(ctx, ud.driver, _spec)
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, ud.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
ud.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// UserDeleteOne is the builder for deleting a single User entity.
|
||||
|
|
@ -92,6 +61,12 @@ type UserDeleteOne struct {
|
|||
ud *UserDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserDelete builder.
|
||||
func (udo *UserDeleteOne) Where(ps ...predicate.User) *UserDeleteOne {
|
||||
udo.ud.mutation.Where(ps...)
|
||||
return udo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (udo *UserDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := udo.ud.Exec(ctx)
|
||||
|
|
@ -107,5 +82,7 @@ func (udo *UserDeleteOne) Exec(ctx context.Context) error {
|
|||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (udo *UserDeleteOne) ExecX(ctx context.Context) {
|
||||
udo.ud.ExecX(ctx)
|
||||
if err := udo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
|
|
@ -20,14 +19,11 @@ import (
|
|||
// UserQuery is the builder for querying User entities.
|
||||
type UserQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
ctx *QueryContext
|
||||
order []user.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.User
|
||||
// eager-loading edges.
|
||||
withOwner *PasswordTokenQuery
|
||||
withOwner *PasswordTokenQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
|
@ -39,34 +35,34 @@ func (uq *UserQuery) Where(ps ...predicate.User) *UserQuery {
|
|||
return uq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (uq *UserQuery) Limit(limit int) *UserQuery {
|
||||
uq.limit = &limit
|
||||
uq.ctx.Limit = &limit
|
||||
return uq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
// Offset to start from.
|
||||
func (uq *UserQuery) Offset(offset int) *UserQuery {
|
||||
uq.offset = &offset
|
||||
uq.ctx.Offset = &offset
|
||||
return uq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (uq *UserQuery) Unique(unique bool) *UserQuery {
|
||||
uq.unique = &unique
|
||||
uq.ctx.Unique = &unique
|
||||
return uq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery {
|
||||
// Order specifies how the records should be ordered.
|
||||
func (uq *UserQuery) Order(o ...user.OrderOption) *UserQuery {
|
||||
uq.order = append(uq.order, o...)
|
||||
return uq
|
||||
}
|
||||
|
||||
// QueryOwner chains the current query on the "owner" edge.
|
||||
func (uq *UserQuery) QueryOwner() *PasswordTokenQuery {
|
||||
query := &PasswordTokenQuery{config: uq.config}
|
||||
query := (&PasswordTokenClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
|
|
@ -89,7 +85,7 @@ func (uq *UserQuery) QueryOwner() *PasswordTokenQuery {
|
|||
// First returns the first User entity from the query.
|
||||
// Returns a *NotFoundError when no User was found.
|
||||
func (uq *UserQuery) First(ctx context.Context) (*User, error) {
|
||||
nodes, err := uq.Limit(1).All(ctx)
|
||||
nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -112,7 +108,7 @@ func (uq *UserQuery) FirstX(ctx context.Context) *User {
|
|||
// Returns a *NotFoundError when no User ID was found.
|
||||
func (uq *UserQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = uq.Limit(1).IDs(ctx); err != nil {
|
||||
if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
|
|
@ -132,10 +128,10 @@ func (uq *UserQuery) FirstIDX(ctx context.Context) int {
|
|||
}
|
||||
|
||||
// Only returns a single User entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when exactly one User entity is not found.
|
||||
// Returns a *NotSingularError when more than one User entity is found.
|
||||
// Returns a *NotFoundError when no User entities are found.
|
||||
func (uq *UserQuery) Only(ctx context.Context) (*User, error) {
|
||||
nodes, err := uq.Limit(2).All(ctx)
|
||||
nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -159,11 +155,11 @@ func (uq *UserQuery) OnlyX(ctx context.Context) *User {
|
|||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only User ID in the query.
|
||||
// Returns a *NotSingularError when exactly one User ID is not found.
|
||||
// Returns a *NotSingularError when more than one User ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (uq *UserQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = uq.Limit(2).IDs(ctx); err != nil {
|
||||
if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
|
|
@ -188,10 +184,12 @@ func (uq *UserQuery) OnlyIDX(ctx context.Context) int {
|
|||
|
||||
// All executes the query and returns a list of Users.
|
||||
func (uq *UserQuery) All(ctx context.Context) ([]*User, error) {
|
||||
ctx = setContextOp(ctx, uq.ctx, "All")
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uq.sqlAll(ctx)
|
||||
qr := querierAll[[]*User, *UserQuery]()
|
||||
return withInterceptors[[]*User](ctx, uq, qr, uq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
|
|
@ -204,9 +202,12 @@ func (uq *UserQuery) AllX(ctx context.Context) []*User {
|
|||
}
|
||||
|
||||
// IDs executes the query and returns a list of User IDs.
|
||||
func (uq *UserQuery) IDs(ctx context.Context) ([]int, error) {
|
||||
var ids []int
|
||||
if err := uq.Select(user.FieldID).Scan(ctx, &ids); err != nil {
|
||||
func (uq *UserQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if uq.ctx.Unique == nil && uq.path != nil {
|
||||
uq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, uq.ctx, "IDs")
|
||||
if err = uq.Select(user.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
|
|
@ -223,10 +224,11 @@ func (uq *UserQuery) IDsX(ctx context.Context) []int {
|
|||
|
||||
// Count returns the count of the given query.
|
||||
func (uq *UserQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, uq.ctx, "Count")
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uq.sqlCount(ctx)
|
||||
return withInterceptors[int](ctx, uq, querierCount[*UserQuery](), uq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
|
|
@ -240,10 +242,15 @@ func (uq *UserQuery) CountX(ctx context.Context) int {
|
|||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (uq *UserQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
ctx = setContextOp(ctx, uq.ctx, "Exist")
|
||||
switch _, err := uq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
return uq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
|
|
@ -263,9 +270,9 @@ func (uq *UserQuery) Clone() *UserQuery {
|
|||
}
|
||||
return &UserQuery{
|
||||
config: uq.config,
|
||||
limit: uq.limit,
|
||||
offset: uq.offset,
|
||||
order: append([]OrderFunc{}, uq.order...),
|
||||
ctx: uq.ctx.Clone(),
|
||||
order: append([]user.OrderOption{}, uq.order...),
|
||||
inters: append([]Interceptor{}, uq.inters...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
withOwner: uq.withOwner.Clone(),
|
||||
// clone intermediate query.
|
||||
|
|
@ -277,7 +284,7 @@ func (uq *UserQuery) Clone() *UserQuery {
|
|||
// WithOwner tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "owner" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithOwner(opts ...func(*PasswordTokenQuery)) *UserQuery {
|
||||
query := &PasswordTokenQuery{config: uq.config}
|
||||
query := (&PasswordTokenClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
|
|
@ -299,17 +306,13 @@ func (uq *UserQuery) WithOwner(opts ...func(*PasswordTokenQuery)) *UserQuery {
|
|||
// GroupBy(user.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
group := &UserGroupBy{config: uq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uq.sqlQuery(ctx), nil
|
||||
}
|
||||
return group
|
||||
uq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &UserGroupBy{build: uq}
|
||||
grbuild.flds = &uq.ctx.Fields
|
||||
grbuild.label = user.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
|
|
@ -324,14 +327,31 @@ func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
|||
// client.User.Query().
|
||||
// Select(user.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (uq *UserQuery) Select(fields ...string) *UserSelect {
|
||||
uq.fields = append(uq.fields, fields...)
|
||||
return &UserSelect{UserQuery: uq}
|
||||
uq.ctx.Fields = append(uq.ctx.Fields, fields...)
|
||||
sbuild := &UserSelect{UserQuery: uq}
|
||||
sbuild.label = user.Label
|
||||
sbuild.flds, sbuild.scan = &uq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a UserSelect configured with the given aggregations.
|
||||
func (uq *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
return uq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (uq *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range uq.fields {
|
||||
for _, inter := range uq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, uq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range uq.ctx.Fields {
|
||||
if !user.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
|
|
@ -346,7 +366,7 @@ func (uq *UserQuery) prepareQuery(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) {
|
||||
var (
|
||||
nodes = []*User{}
|
||||
_spec = uq.querySpec()
|
||||
|
|
@ -354,92 +374,84 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
|||
uq.withOwner != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*User).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &User{config: uq.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.scanValues(columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []interface{}) error {
|
||||
if len(nodes) == 0 {
|
||||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, uq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := uq.withOwner; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
nodes[i].Edges.Owner = []*PasswordToken{}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(user.OwnerColumn, fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
if err := uq.loadOwner(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.Owner = []*PasswordToken{} },
|
||||
func(n *User, e *PasswordToken) { n.Edges.Owner = append(n.Edges.Owner, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.password_token_user
|
||||
if fk == nil {
|
||||
return nil, fmt.Errorf(`foreign-key "password_token_user" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`unexpected foreign-key "password_token_user" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
node.Edges.Owner = append(node.Edges.Owner, n)
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) loadOwner(ctx context.Context, query *PasswordTokenQuery, nodes []*User, init func(*User), assign func(*User, *PasswordToken)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
|
||||
return nodes, nil
|
||||
query.withFKs = true
|
||||
query.Where(predicate.PasswordToken(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.OwnerColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.password_token_user
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "password_token_user" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "password_token_user" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := uq.querySpec()
|
||||
_spec.Node.Columns = uq.fields
|
||||
if len(uq.fields) > 0 {
|
||||
_spec.Unique = uq.unique != nil && *uq.unique
|
||||
_spec.Node.Columns = uq.ctx.Fields
|
||||
if len(uq.ctx.Fields) > 0 {
|
||||
_spec.Unique = uq.ctx.Unique != nil && *uq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, uq.driver, _spec)
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
n, err := uq.sqlCount(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: user.Table,
|
||||
Columns: user.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
From: uq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if unique := uq.unique; unique != nil {
|
||||
_spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
_spec.From = uq.sql
|
||||
if unique := uq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if uq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := uq.fields; len(fields) > 0 {
|
||||
if fields := uq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
|
||||
for i := range fields {
|
||||
|
|
@ -455,10 +467,10 @@ func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
|||
}
|
||||
}
|
||||
}
|
||||
if limit := uq.limit; limit != nil {
|
||||
if limit := uq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := uq.offset; offset != nil {
|
||||
if offset := uq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := uq.order; len(ps) > 0 {
|
||||
|
|
@ -474,7 +486,7 @@ func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
|||
func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(uq.driver.Dialect())
|
||||
t1 := builder.Table(user.Table)
|
||||
columns := uq.fields
|
||||
columns := uq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = user.Columns
|
||||
}
|
||||
|
|
@ -483,7 +495,7 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|||
selector = uq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if uq.unique != nil && *uq.unique {
|
||||
if uq.ctx.Unique != nil && *uq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range uq.predicates {
|
||||
|
|
@ -492,12 +504,12 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|||
for _, p := range uq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := uq.offset; offset != nil {
|
||||
if offset := uq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := uq.limit; limit != nil {
|
||||
if limit := uq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
|
|
@ -505,12 +517,8 @@ func (uq *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|||
|
||||
// UserGroupBy is the group-by builder for User entities.
|
||||
type UserGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
selector
|
||||
build *UserQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
|
|
@ -519,471 +527,77 @@ func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy {
|
|||
return ugb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scans the result into the given value.
|
||||
func (ugb *UserGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := ugb.path(ctx)
|
||||
if err != nil {
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ugb *UserGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ugb.build.ctx, "GroupBy")
|
||||
if err := ugb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
ugb.sql = query
|
||||
return ugb.sqlScan(ctx, v)
|
||||
return scanWithInterceptors[*UserQuery, *UserGroupBy](ctx, ugb.build, ugb, ugb.build.inters, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := ugb.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
func (ugb *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(ugb.fns))
|
||||
for _, fn := range ugb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ugb *UserGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(ugb.fields) > 1 {
|
||||
return nil, errors.New("ent: UserGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := ugb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) StringsX(ctx context.Context) []string {
|
||||
v, err := ugb.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ugb *UserGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = ugb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := ugb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ugb *UserGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(ugb.fields) > 1 {
|
||||
return nil, errors.New("ent: UserGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := ugb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) IntsX(ctx context.Context) []int {
|
||||
v, err := ugb.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ugb *UserGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = ugb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := ugb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ugb *UserGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(ugb.fields) > 1 {
|
||||
return nil, errors.New("ent: UserGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := ugb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := ugb.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ugb *UserGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = ugb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := ugb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ugb *UserGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(ugb.fields) > 1 {
|
||||
return nil, errors.New("ent: UserGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := ugb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
v, err := ugb.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (ugb *UserGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = ugb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := ugb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (ugb *UserGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
for _, f := range ugb.fields {
|
||||
if !user.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*ugb.flds)+len(ugb.fns))
|
||||
for _, f := range *ugb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector := ugb.sqlQuery()
|
||||
selector.GroupBy(selector.Columns(*ugb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ugb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
if err := ugb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (ugb *UserGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := ugb.sql.Select()
|
||||
aggregation := make([]string, 0, len(ugb.fns))
|
||||
for _, fn := range ugb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(ugb.fields)+len(ugb.fns))
|
||||
for _, f := range ugb.fields {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
return selector.GroupBy(selector.Columns(ugb.fields...)...)
|
||||
}
|
||||
|
||||
// UserSelect is the builder for selecting fields of User entities.
|
||||
type UserSelect struct {
|
||||
*UserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (us *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
us.fns = append(us.fns, fns...)
|
||||
return us
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (us *UserSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
func (us *UserSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, us.ctx, "Select")
|
||||
if err := us.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
us.sql = us.UserQuery.sqlQuery(ctx)
|
||||
return us.sqlScan(ctx, v)
|
||||
return scanWithInterceptors[*UserQuery, *UserSelect](ctx, us.UserQuery, us, us.inters, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (us *UserSelect) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := us.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
func (us *UserSelect) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(us.fns))
|
||||
for _, fn := range us.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(us.fields) > 1 {
|
||||
return nil, errors.New("ent: UserSelect.Strings is not achievable when selecting more than 1 field")
|
||||
switch n := len(*us.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
var v []string
|
||||
if err := us.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (us *UserSelect) StringsX(ctx context.Context) []string {
|
||||
v, err := us.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = us.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (us *UserSelect) StringX(ctx context.Context) string {
|
||||
v, err := us.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(us.fields) > 1 {
|
||||
return nil, errors.New("ent: UserSelect.Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := us.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (us *UserSelect) IntsX(ctx context.Context) []int {
|
||||
v, err := us.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = us.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (us *UserSelect) IntX(ctx context.Context) int {
|
||||
v, err := us.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(us.fields) > 1 {
|
||||
return nil, errors.New("ent: UserSelect.Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := us.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (us *UserSelect) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := us.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = us.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (us *UserSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := us.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(us.fields) > 1 {
|
||||
return nil, errors.New("ent: UserSelect.Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := us.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (us *UserSelect) BoolsX(ctx context.Context) []bool {
|
||||
v, err := us.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = us.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (us *UserSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := us.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (us *UserSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := us.sql.Query()
|
||||
query, args := selector.Query()
|
||||
if err := us.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
|
|
@ -34,18 +34,42 @@ func (uu *UserUpdate) SetName(s string) *UserUpdate {
|
|||
return uu
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate {
|
||||
if s != nil {
|
||||
uu.SetName(*s)
|
||||
}
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (uu *UserUpdate) SetEmail(s string) *UserUpdate {
|
||||
uu.mutation.SetEmail(s)
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (uu *UserUpdate) SetNillableEmail(s *string) *UserUpdate {
|
||||
if s != nil {
|
||||
uu.SetEmail(*s)
|
||||
}
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (uu *UserUpdate) SetPassword(s string) *UserUpdate {
|
||||
uu.mutation.SetPassword(s)
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (uu *UserUpdate) SetNillablePassword(s *string) *UserUpdate {
|
||||
if s != nil {
|
||||
uu.SetPassword(*s)
|
||||
}
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetVerified sets the "verified" field.
|
||||
func (uu *UserUpdate) SetVerified(b bool) *UserUpdate {
|
||||
uu.mutation.SetVerified(b)
|
||||
|
|
@ -103,40 +127,7 @@ func (uu *UserUpdate) RemoveOwner(p ...*PasswordToken) *UserUpdate {
|
|||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(uu.hooks) == 0 {
|
||||
if err = uu.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
affected, err = uu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*UserMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = uu.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
uu.mutation = mutation
|
||||
affected, err = uu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(uu.hooks) - 1; i >= 0; i-- {
|
||||
if uu.hooks[i] == nil {
|
||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = uu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, uu.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
|
|
@ -182,16 +173,10 @@ func (uu *UserUpdate) check() error {
|
|||
}
|
||||
|
||||
func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: user.Table,
|
||||
Columns: user.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
if err := uu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
if ps := uu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
|
|
@ -200,32 +185,16 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
}
|
||||
}
|
||||
if value, ok := uu.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldName,
|
||||
})
|
||||
_spec.SetField(user.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uu.mutation.Email(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldEmail,
|
||||
})
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uu.mutation.Password(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldPassword,
|
||||
})
|
||||
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uu.mutation.Verified(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: user.FieldVerified,
|
||||
})
|
||||
_spec.SetField(user.FieldVerified, field.TypeBool, value)
|
||||
}
|
||||
if uu.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
|
@ -235,10 +204,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
Columns: []string{user.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
|
|
@ -251,10 +217,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
Columns: []string{user.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
|
|
@ -270,10 +233,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
Columns: []string{user.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
|
|
@ -285,10 +245,11 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
uu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
|
|
@ -306,18 +267,42 @@ func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne {
|
|||
return uuo
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne {
|
||||
if s != nil {
|
||||
uuo.SetName(*s)
|
||||
}
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (uuo *UserUpdateOne) SetEmail(s string) *UserUpdateOne {
|
||||
uuo.mutation.SetEmail(s)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (uuo *UserUpdateOne) SetNillableEmail(s *string) *UserUpdateOne {
|
||||
if s != nil {
|
||||
uuo.SetEmail(*s)
|
||||
}
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (uuo *UserUpdateOne) SetPassword(s string) *UserUpdateOne {
|
||||
uuo.mutation.SetPassword(s)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (uuo *UserUpdateOne) SetNillablePassword(s *string) *UserUpdateOne {
|
||||
if s != nil {
|
||||
uuo.SetPassword(*s)
|
||||
}
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetVerified sets the "verified" field.
|
||||
func (uuo *UserUpdateOne) SetVerified(b bool) *UserUpdateOne {
|
||||
uuo.mutation.SetVerified(b)
|
||||
|
|
@ -373,6 +358,12 @@ func (uuo *UserUpdateOne) RemoveOwner(p ...*PasswordToken) *UserUpdateOne {
|
|||
return uuo.RemoveOwnerIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserUpdate builder.
|
||||
func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
|
||||
uuo.mutation.Where(ps...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
|
||||
|
|
@ -382,40 +373,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne
|
|||
|
||||
// Save executes the query and returns the updated User entity.
|
||||
func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
||||
var (
|
||||
err error
|
||||
node *User
|
||||
)
|
||||
if len(uuo.hooks) == 0 {
|
||||
if err = uuo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = uuo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*UserMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = uuo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uuo.mutation = mutation
|
||||
node, err = uuo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(uuo.hooks) - 1; i >= 0; i-- {
|
||||
if uuo.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = uuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, uuo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
|
|
@ -461,16 +419,10 @@ func (uuo *UserUpdateOne) check() error {
|
|||
}
|
||||
|
||||
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: user.Table,
|
||||
Columns: user.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
if err := uuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
id, ok := uuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)}
|
||||
|
|
@ -496,32 +448,16 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
|||
}
|
||||
}
|
||||
if value, ok := uuo.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldName,
|
||||
})
|
||||
_spec.SetField(user.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uuo.mutation.Email(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldEmail,
|
||||
})
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uuo.mutation.Password(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: user.FieldPassword,
|
||||
})
|
||||
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if value, ok := uuo.mutation.Verified(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: user.FieldVerified,
|
||||
})
|
||||
_spec.SetField(user.FieldVerified, field.TypeBool, value)
|
||||
}
|
||||
if uuo.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
|
@ -531,10 +467,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
|||
Columns: []string{user.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
|
|
@ -547,10 +480,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
|||
Columns: []string{user.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
|
|
@ -566,10 +496,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
|||
Columns: []string{user.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: passwordtoken.FieldID,
|
||||
},
|
||||
IDSpec: sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
|
|
@ -584,9 +511,10 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
|||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{err.Error(), err}
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
uuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue