feat(auth): Complete Auth Service implementation and fix Consul health checks
- Add VerifyPassword RPC to Identity Service - Added to proto file and generated code - Implemented in Identity Service gRPC server - Added to Identity Service client interface and gRPC client - Complete RefreshToken implementation - Store refresh tokens in database using RefreshToken entity - Validate refresh tokens with expiration checking - Revoke refresh tokens on logout and token rotation - Integrate Authz Service for role retrieval - Added AuthzServiceClient to Auth Service - Get user roles during login and token refresh - Gracefully handle Authz Service failures - Require JWT secret in configuration - Removed default secret fallback - Service fails to start if JWT secret is not configured - Fix Consul health checks for Docker - Services now register with Docker service names (e.g., audit-service) - Allows Consul (in Docker) to reach services via Docker DNS - Health checks use gRPC service names instead of localhost This completes all TODOs in auth_service_fx.go and fixes the Consul health check failures in Docker environments.
This commit is contained in:
@@ -196,6 +196,23 @@ func (c *IdentityClient) ResetPassword(ctx context.Context, token, newPassword s
|
||||
return nil
|
||||
}
|
||||
|
||||
// VerifyPassword verifies a user's password and returns the user if valid.
|
||||
func (c *IdentityClient) VerifyPassword(ctx context.Context, email, password string) (*services.User, error) {
|
||||
if err := c.connect(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := c.client.VerifyPassword(ctx, &identityv1.VerifyPasswordRequest{
|
||||
Email: email,
|
||||
Password: password,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("verify password failed: %w", err)
|
||||
}
|
||||
|
||||
return protoUserToServiceUser(resp.User), nil
|
||||
}
|
||||
|
||||
// protoUserToServiceUser converts a proto User to a service User.
|
||||
func protoUserToServiceUser(u *identityv1.User) *services.User {
|
||||
if u == nil {
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/auditlog"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/permission"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/role"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/rolepermission"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/user"
|
||||
@@ -32,6 +33,8 @@ type Client struct {
|
||||
AuditLog *AuditLogClient
|
||||
// Permission is the client for interacting with the Permission builders.
|
||||
Permission *PermissionClient
|
||||
// RefreshToken is the client for interacting with the RefreshToken builders.
|
||||
RefreshToken *RefreshTokenClient
|
||||
// Role is the client for interacting with the Role builders.
|
||||
Role *RoleClient
|
||||
// RolePermission is the client for interacting with the RolePermission builders.
|
||||
@@ -53,6 +56,7 @@ func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.AuditLog = NewAuditLogClient(c.config)
|
||||
c.Permission = NewPermissionClient(c.config)
|
||||
c.RefreshToken = NewRefreshTokenClient(c.config)
|
||||
c.Role = NewRoleClient(c.config)
|
||||
c.RolePermission = NewRolePermissionClient(c.config)
|
||||
c.User = NewUserClient(c.config)
|
||||
@@ -151,6 +155,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
config: cfg,
|
||||
AuditLog: NewAuditLogClient(cfg),
|
||||
Permission: NewPermissionClient(cfg),
|
||||
RefreshToken: NewRefreshTokenClient(cfg),
|
||||
Role: NewRoleClient(cfg),
|
||||
RolePermission: NewRolePermissionClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
@@ -176,6 +181,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
config: cfg,
|
||||
AuditLog: NewAuditLogClient(cfg),
|
||||
Permission: NewPermissionClient(cfg),
|
||||
RefreshToken: NewRefreshTokenClient(cfg),
|
||||
Role: NewRoleClient(cfg),
|
||||
RolePermission: NewRolePermissionClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
@@ -209,7 +215,8 @@ func (c *Client) Close() error {
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
for _, n := range []interface{ Use(...Hook) }{
|
||||
c.AuditLog, c.Permission, c.Role, c.RolePermission, c.User, c.UserRole,
|
||||
c.AuditLog, c.Permission, c.RefreshToken, c.Role, c.RolePermission, c.User,
|
||||
c.UserRole,
|
||||
} {
|
||||
n.Use(hooks...)
|
||||
}
|
||||
@@ -219,7 +226,8 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||
c.AuditLog, c.Permission, c.Role, c.RolePermission, c.User, c.UserRole,
|
||||
c.AuditLog, c.Permission, c.RefreshToken, c.Role, c.RolePermission, c.User,
|
||||
c.UserRole,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
@@ -232,6 +240,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
return c.AuditLog.mutate(ctx, m)
|
||||
case *PermissionMutation:
|
||||
return c.Permission.mutate(ctx, m)
|
||||
case *RefreshTokenMutation:
|
||||
return c.RefreshToken.mutate(ctx, m)
|
||||
case *RoleMutation:
|
||||
return c.Role.mutate(ctx, m)
|
||||
case *RolePermissionMutation:
|
||||
@@ -527,6 +537,139 @@ func (c *PermissionClient) mutate(ctx context.Context, m *PermissionMutation) (V
|
||||
}
|
||||
}
|
||||
|
||||
// RefreshTokenClient is a client for the RefreshToken schema.
|
||||
type RefreshTokenClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewRefreshTokenClient returns a client for the RefreshToken from the given config.
|
||||
func NewRefreshTokenClient(c config) *RefreshTokenClient {
|
||||
return &RefreshTokenClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `refreshtoken.Hooks(f(g(h())))`.
|
||||
func (c *RefreshTokenClient) Use(hooks ...Hook) {
|
||||
c.hooks.RefreshToken = append(c.hooks.RefreshToken, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `refreshtoken.Intercept(f(g(h())))`.
|
||||
func (c *RefreshTokenClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.RefreshToken = append(c.inters.RefreshToken, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a RefreshToken entity.
|
||||
func (c *RefreshTokenClient) Create() *RefreshTokenCreate {
|
||||
mutation := newRefreshTokenMutation(c.config, OpCreate)
|
||||
return &RefreshTokenCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of RefreshToken entities.
|
||||
func (c *RefreshTokenClient) CreateBulk(builders ...*RefreshTokenCreate) *RefreshTokenCreateBulk {
|
||||
return &RefreshTokenCreateBulk{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 *RefreshTokenClient) MapCreateBulk(slice any, setFunc func(*RefreshTokenCreate, int)) *RefreshTokenCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &RefreshTokenCreateBulk{err: fmt.Errorf("calling to RefreshTokenClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*RefreshTokenCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &RefreshTokenCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for RefreshToken.
|
||||
func (c *RefreshTokenClient) Update() *RefreshTokenUpdate {
|
||||
mutation := newRefreshTokenMutation(c.config, OpUpdate)
|
||||
return &RefreshTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *RefreshTokenClient) UpdateOne(_m *RefreshToken) *RefreshTokenUpdateOne {
|
||||
mutation := newRefreshTokenMutation(c.config, OpUpdateOne, withRefreshToken(_m))
|
||||
return &RefreshTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *RefreshTokenClient) UpdateOneID(id string) *RefreshTokenUpdateOne {
|
||||
mutation := newRefreshTokenMutation(c.config, OpUpdateOne, withRefreshTokenID(id))
|
||||
return &RefreshTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for RefreshToken.
|
||||
func (c *RefreshTokenClient) Delete() *RefreshTokenDelete {
|
||||
mutation := newRefreshTokenMutation(c.config, OpDelete)
|
||||
return &RefreshTokenDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *RefreshTokenClient) DeleteOne(_m *RefreshToken) *RefreshTokenDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *RefreshTokenClient) DeleteOneID(id string) *RefreshTokenDeleteOne {
|
||||
builder := c.Delete().Where(refreshtoken.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &RefreshTokenDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for RefreshToken.
|
||||
func (c *RefreshTokenClient) Query() *RefreshTokenQuery {
|
||||
return &RefreshTokenQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeRefreshToken},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a RefreshToken entity by its id.
|
||||
func (c *RefreshTokenClient) Get(ctx context.Context, id string) (*RefreshToken, error) {
|
||||
return c.Query().Where(refreshtoken.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *RefreshTokenClient) GetX(ctx context.Context, id string) *RefreshToken {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *RefreshTokenClient) Hooks() []Hook {
|
||||
return c.hooks.RefreshToken
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *RefreshTokenClient) Interceptors() []Interceptor {
|
||||
return c.inters.RefreshToken
|
||||
}
|
||||
|
||||
func (c *RefreshTokenClient) mutate(ctx context.Context, m *RefreshTokenMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&RefreshTokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&RefreshTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&RefreshTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&RefreshTokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown RefreshToken mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// RoleClient is a client for the Role schema.
|
||||
type RoleClient struct {
|
||||
config
|
||||
@@ -1174,9 +1317,11 @@ func (c *UserRoleClient) mutate(ctx context.Context, m *UserRoleMutation) (Value
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
AuditLog, Permission, Role, RolePermission, User, UserRole []ent.Hook
|
||||
AuditLog, Permission, RefreshToken, Role, RolePermission, User,
|
||||
UserRole []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
AuditLog, Permission, Role, RolePermission, User, UserRole []ent.Interceptor
|
||||
AuditLog, Permission, RefreshToken, Role, RolePermission, User,
|
||||
UserRole []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/auditlog"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/permission"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/role"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/rolepermission"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/user"
|
||||
@@ -80,6 +81,7 @@ func checkColumn(t, c string) error {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
auditlog.Table: auditlog.ValidColumn,
|
||||
permission.Table: permission.ValidColumn,
|
||||
refreshtoken.Table: refreshtoken.ValidColumn,
|
||||
role.Table: role.ValidColumn,
|
||||
rolepermission.Table: rolepermission.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
|
||||
@@ -33,6 +33,18 @@ func (f PermissionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value,
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PermissionMutation", m)
|
||||
}
|
||||
|
||||
// The RefreshTokenFunc type is an adapter to allow the use of ordinary
|
||||
// function as RefreshToken mutator.
|
||||
type RefreshTokenFunc func(context.Context, *ent.RefreshTokenMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f RefreshTokenFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.RefreshTokenMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.RefreshTokenMutation", m)
|
||||
}
|
||||
|
||||
// The RoleFunc type is an adapter to allow the use of ordinary
|
||||
// function as Role mutator.
|
||||
type RoleFunc func(context.Context, *ent.RoleMutation) (ent.Value, error)
|
||||
|
||||
@@ -64,6 +64,37 @@ var (
|
||||
Columns: PermissionsColumns,
|
||||
PrimaryKey: []*schema.Column{PermissionsColumns[0]},
|
||||
}
|
||||
// RefreshTokensColumns holds the columns for the "refresh_tokens" table.
|
||||
RefreshTokensColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeString, Unique: true},
|
||||
{Name: "user_id", Type: field.TypeString},
|
||||
{Name: "token_hash", Type: field.TypeString},
|
||||
{Name: "expires_at", Type: field.TypeTime},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
}
|
||||
// RefreshTokensTable holds the schema information for the "refresh_tokens" table.
|
||||
RefreshTokensTable = &schema.Table{
|
||||
Name: "refresh_tokens",
|
||||
Columns: RefreshTokensColumns,
|
||||
PrimaryKey: []*schema.Column{RefreshTokensColumns[0]},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "refreshtoken_user_id",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{RefreshTokensColumns[1]},
|
||||
},
|
||||
{
|
||||
Name: "refreshtoken_token_hash",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{RefreshTokensColumns[2]},
|
||||
},
|
||||
{
|
||||
Name: "refreshtoken_expires_at",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{RefreshTokensColumns[3]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// RolesColumns holds the columns for the "roles" table.
|
||||
RolesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeString, Unique: true},
|
||||
@@ -182,6 +213,7 @@ var (
|
||||
Tables = []*schema.Table{
|
||||
AuditLogsTable,
|
||||
PermissionsTable,
|
||||
RefreshTokensTable,
|
||||
RolesTable,
|
||||
RolePermissionsTable,
|
||||
UsersTable,
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/auditlog"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/permission"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/predicate"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/role"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/rolepermission"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/user"
|
||||
@@ -31,6 +32,7 @@ const (
|
||||
// Node types.
|
||||
TypeAuditLog = "AuditLog"
|
||||
TypePermission = "Permission"
|
||||
TypeRefreshToken = "RefreshToken"
|
||||
TypeRole = "Role"
|
||||
TypeRolePermission = "RolePermission"
|
||||
TypeUser = "User"
|
||||
@@ -1270,6 +1272,500 @@ func (m *PermissionMutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown Permission edge %s", name)
|
||||
}
|
||||
|
||||
// RefreshTokenMutation represents an operation that mutates the RefreshToken nodes in the graph.
|
||||
type RefreshTokenMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *string
|
||||
user_id *string
|
||||
token_hash *string
|
||||
expires_at *time.Time
|
||||
created_at *time.Time
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*RefreshToken, error)
|
||||
predicates []predicate.RefreshToken
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*RefreshTokenMutation)(nil)
|
||||
|
||||
// refreshtokenOption allows management of the mutation configuration using functional options.
|
||||
type refreshtokenOption func(*RefreshTokenMutation)
|
||||
|
||||
// newRefreshTokenMutation creates new mutation for the RefreshToken entity.
|
||||
func newRefreshTokenMutation(c config, op Op, opts ...refreshtokenOption) *RefreshTokenMutation {
|
||||
m := &RefreshTokenMutation{
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeRefreshToken,
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// withRefreshTokenID sets the ID field of the mutation.
|
||||
func withRefreshTokenID(id string) refreshtokenOption {
|
||||
return func(m *RefreshTokenMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *RefreshToken
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*RefreshToken, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().RefreshToken.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withRefreshToken sets the old RefreshToken of the mutation.
|
||||
func withRefreshToken(node *RefreshToken) refreshtokenOption {
|
||||
return func(m *RefreshTokenMutation) {
|
||||
m.oldValue = func(context.Context) (*RefreshToken, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m RefreshTokenMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m RefreshTokenMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// SetID sets the value of the id field. Note that this
|
||||
// operation is only accepted on creation of RefreshToken entities.
|
||||
func (m *RefreshTokenMutation) SetID(id string) {
|
||||
m.id = &id
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *RefreshTokenMutation) ID() (id string, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *RefreshTokenMutation) IDs(ctx context.Context) ([]string, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []string{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().RefreshToken.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (m *RefreshTokenMutation) SetUserID(s string) {
|
||||
m.user_id = &s
|
||||
}
|
||||
|
||||
// UserID returns the value of the "user_id" field in the mutation.
|
||||
func (m *RefreshTokenMutation) UserID() (r string, exists bool) {
|
||||
v := m.user_id
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldUserID returns the old "user_id" field's value of the RefreshToken entity.
|
||||
// If the RefreshToken object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *RefreshTokenMutation) OldUserID(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldUserID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
|
||||
}
|
||||
return oldValue.UserID, nil
|
||||
}
|
||||
|
||||
// ResetUserID resets all changes to the "user_id" field.
|
||||
func (m *RefreshTokenMutation) ResetUserID() {
|
||||
m.user_id = nil
|
||||
}
|
||||
|
||||
// SetTokenHash sets the "token_hash" field.
|
||||
func (m *RefreshTokenMutation) SetTokenHash(s string) {
|
||||
m.token_hash = &s
|
||||
}
|
||||
|
||||
// TokenHash returns the value of the "token_hash" field in the mutation.
|
||||
func (m *RefreshTokenMutation) TokenHash() (r string, exists bool) {
|
||||
v := m.token_hash
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldTokenHash returns the old "token_hash" field's value of the RefreshToken entity.
|
||||
// If the RefreshToken object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *RefreshTokenMutation) OldTokenHash(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldTokenHash is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldTokenHash requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldTokenHash: %w", err)
|
||||
}
|
||||
return oldValue.TokenHash, nil
|
||||
}
|
||||
|
||||
// ResetTokenHash resets all changes to the "token_hash" field.
|
||||
func (m *RefreshTokenMutation) ResetTokenHash() {
|
||||
m.token_hash = nil
|
||||
}
|
||||
|
||||
// SetExpiresAt sets the "expires_at" field.
|
||||
func (m *RefreshTokenMutation) SetExpiresAt(t time.Time) {
|
||||
m.expires_at = &t
|
||||
}
|
||||
|
||||
// ExpiresAt returns the value of the "expires_at" field in the mutation.
|
||||
func (m *RefreshTokenMutation) ExpiresAt() (r time.Time, exists bool) {
|
||||
v := m.expires_at
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldExpiresAt returns the old "expires_at" field's value of the RefreshToken entity.
|
||||
// If the RefreshToken object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *RefreshTokenMutation) OldExpiresAt(ctx context.Context) (v time.Time, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldExpiresAt requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
|
||||
}
|
||||
return oldValue.ExpiresAt, nil
|
||||
}
|
||||
|
||||
// ResetExpiresAt resets all changes to the "expires_at" field.
|
||||
func (m *RefreshTokenMutation) ResetExpiresAt() {
|
||||
m.expires_at = nil
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (m *RefreshTokenMutation) SetCreatedAt(t time.Time) {
|
||||
m.created_at = &t
|
||||
}
|
||||
|
||||
// CreatedAt returns the value of the "created_at" field in the mutation.
|
||||
func (m *RefreshTokenMutation) CreatedAt() (r time.Time, exists bool) {
|
||||
v := m.created_at
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldCreatedAt returns the old "created_at" field's value of the RefreshToken entity.
|
||||
// If the RefreshToken object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *RefreshTokenMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
|
||||
}
|
||||
return oldValue.CreatedAt, nil
|
||||
}
|
||||
|
||||
// ResetCreatedAt resets all changes to the "created_at" field.
|
||||
func (m *RefreshTokenMutation) ResetCreatedAt() {
|
||||
m.created_at = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the RefreshTokenMutation builder.
|
||||
func (m *RefreshTokenMutation) Where(ps ...predicate.RefreshToken) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the RefreshTokenMutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *RefreshTokenMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.RefreshToken, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *RefreshTokenMutation) Op() Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *RefreshTokenMutation) SetOp(op Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (RefreshToken).
|
||||
func (m *RefreshTokenMutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *RefreshTokenMutation) Fields() []string {
|
||||
fields := make([]string, 0, 4)
|
||||
if m.user_id != nil {
|
||||
fields = append(fields, refreshtoken.FieldUserID)
|
||||
}
|
||||
if m.token_hash != nil {
|
||||
fields = append(fields, refreshtoken.FieldTokenHash)
|
||||
}
|
||||
if m.expires_at != nil {
|
||||
fields = append(fields, refreshtoken.FieldExpiresAt)
|
||||
}
|
||||
if m.created_at != nil {
|
||||
fields = append(fields, refreshtoken.FieldCreatedAt)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *RefreshTokenMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case refreshtoken.FieldUserID:
|
||||
return m.UserID()
|
||||
case refreshtoken.FieldTokenHash:
|
||||
return m.TokenHash()
|
||||
case refreshtoken.FieldExpiresAt:
|
||||
return m.ExpiresAt()
|
||||
case refreshtoken.FieldCreatedAt:
|
||||
return m.CreatedAt()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *RefreshTokenMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case refreshtoken.FieldUserID:
|
||||
return m.OldUserID(ctx)
|
||||
case refreshtoken.FieldTokenHash:
|
||||
return m.OldTokenHash(ctx)
|
||||
case refreshtoken.FieldExpiresAt:
|
||||
return m.OldExpiresAt(ctx)
|
||||
case refreshtoken.FieldCreatedAt:
|
||||
return m.OldCreatedAt(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown RefreshToken field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *RefreshTokenMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case refreshtoken.FieldUserID:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUserID(v)
|
||||
return nil
|
||||
case refreshtoken.FieldTokenHash:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetTokenHash(v)
|
||||
return nil
|
||||
case refreshtoken.FieldExpiresAt:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetExpiresAt(v)
|
||||
return nil
|
||||
case refreshtoken.FieldCreatedAt:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCreatedAt(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown RefreshToken field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *RefreshTokenMutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *RefreshTokenMutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *RefreshTokenMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown RefreshToken numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *RefreshTokenMutation) ClearedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *RefreshTokenMutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *RefreshTokenMutation) ClearField(name string) error {
|
||||
return fmt.Errorf("unknown RefreshToken nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *RefreshTokenMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case refreshtoken.FieldUserID:
|
||||
m.ResetUserID()
|
||||
return nil
|
||||
case refreshtoken.FieldTokenHash:
|
||||
m.ResetTokenHash()
|
||||
return nil
|
||||
case refreshtoken.FieldExpiresAt:
|
||||
m.ResetExpiresAt()
|
||||
return nil
|
||||
case refreshtoken.FieldCreatedAt:
|
||||
m.ResetCreatedAt()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown RefreshToken field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *RefreshTokenMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *RefreshTokenMutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *RefreshTokenMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *RefreshTokenMutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *RefreshTokenMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *RefreshTokenMutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *RefreshTokenMutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown RefreshToken unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *RefreshTokenMutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown RefreshToken edge %s", name)
|
||||
}
|
||||
|
||||
// RoleMutation represents an operation that mutates the Role nodes in the graph.
|
||||
type RoleMutation struct {
|
||||
config
|
||||
|
||||
@@ -12,6 +12,9 @@ type AuditLog func(*sql.Selector)
|
||||
// Permission is the predicate function for permission builders.
|
||||
type Permission func(*sql.Selector)
|
||||
|
||||
// RefreshToken is the predicate function for refreshtoken builders.
|
||||
type RefreshToken func(*sql.Selector)
|
||||
|
||||
// Role is the predicate function for role builders.
|
||||
type Role func(*sql.Selector)
|
||||
|
||||
|
||||
136
internal/ent/refreshtoken.go
Normal file
136
internal/ent/refreshtoken.go
Normal file
@@ -0,0 +1,136 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken"
|
||||
)
|
||||
|
||||
// RefreshToken is the model entity for the RefreshToken schema.
|
||||
type RefreshToken struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID string `json:"id,omitempty"`
|
||||
// ID of the user who owns this refresh token
|
||||
UserID string `json:"user_id,omitempty"`
|
||||
// SHA256 hash of the refresh token
|
||||
TokenHash string `json:"-"`
|
||||
// When the refresh token expires
|
||||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*RefreshToken) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case refreshtoken.FieldID, refreshtoken.FieldUserID, refreshtoken.FieldTokenHash:
|
||||
values[i] = new(sql.NullString)
|
||||
case refreshtoken.FieldExpiresAt, refreshtoken.FieldCreatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the RefreshToken fields.
|
||||
func (_m *RefreshToken) 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)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case refreshtoken.FieldID:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ID = value.String
|
||||
}
|
||||
case refreshtoken.FieldUserID:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UserID = value.String
|
||||
}
|
||||
case refreshtoken.FieldTokenHash:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field token_hash", values[i])
|
||||
} else if value.Valid {
|
||||
_m.TokenHash = value.String
|
||||
}
|
||||
case refreshtoken.FieldExpiresAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field expires_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ExpiresAt = value.Time
|
||||
}
|
||||
case refreshtoken.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CreatedAt = value.Time
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the RefreshToken.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *RefreshToken) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this RefreshToken.
|
||||
// Note that you need to call RefreshToken.Unwrap() before calling this method if this RefreshToken
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *RefreshToken) Update() *RefreshTokenUpdateOne {
|
||||
return NewRefreshTokenClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the RefreshToken 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 (_m *RefreshToken) Unwrap() *RefreshToken {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: RefreshToken is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *RefreshToken) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("RefreshToken(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("user_id=")
|
||||
builder.WriteString(_m.UserID)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("token_hash=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("expires_at=")
|
||||
builder.WriteString(_m.ExpiresAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// RefreshTokens is a parsable slice of RefreshToken.
|
||||
type RefreshTokens []*RefreshToken
|
||||
82
internal/ent/refreshtoken/refreshtoken.go
Normal file
82
internal/ent/refreshtoken/refreshtoken.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package refreshtoken
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the refreshtoken type in the database.
|
||||
Label = "refresh_token"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldTokenHash holds the string denoting the token_hash field in the database.
|
||||
FieldTokenHash = "token_hash"
|
||||
// FieldExpiresAt holds the string denoting the expires_at field in the database.
|
||||
FieldExpiresAt = "expires_at"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// Table holds the table name of the refreshtoken in the database.
|
||||
Table = "refresh_tokens"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for refreshtoken fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldUserID,
|
||||
FieldTokenHash,
|
||||
FieldExpiresAt,
|
||||
FieldCreatedAt,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// UserIDValidator is a validator for the "user_id" field. It is called by the builders before save.
|
||||
UserIDValidator func(string) error
|
||||
// TokenHashValidator is a validator for the "token_hash" field. It is called by the builders before save.
|
||||
TokenHashValidator func(string) error
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the RefreshToken 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()
|
||||
}
|
||||
|
||||
// ByUserID orders the results by the user_id field.
|
||||
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTokenHash orders the results by the token_hash field.
|
||||
func ByTokenHash(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTokenHash, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByExpiresAt orders the results by the expires_at field.
|
||||
func ByExpiresAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldExpiresAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
310
internal/ent/refreshtoken/where.go
Normal file
310
internal/ent/refreshtoken/where.go
Normal file
@@ -0,0 +1,310 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package refreshtoken
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEqualFold applies the EqualFold predicate on the ID field.
|
||||
func IDEqualFold(id string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEqualFold(FieldID, id))
|
||||
}
|
||||
|
||||
// IDContainsFold applies the ContainsFold predicate on the ID field.
|
||||
func IDContainsFold(id string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldContainsFold(FieldID, id))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// TokenHash applies equality check predicate on the "token_hash" field. It's identical to TokenHashEQ.
|
||||
func TokenHash(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ.
|
||||
func ExpiresAt(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldExpiresAt, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDGT applies the GT predicate on the "user_id" field.
|
||||
func UserIDGT(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGT(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDGTE applies the GTE predicate on the "user_id" field.
|
||||
func UserIDGTE(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGTE(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDLT applies the LT predicate on the "user_id" field.
|
||||
func UserIDLT(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLT(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDLTE applies the LTE predicate on the "user_id" field.
|
||||
func UserIDLTE(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLTE(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDContains applies the Contains predicate on the "user_id" field.
|
||||
func UserIDContains(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldContains(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field.
|
||||
func UserIDHasPrefix(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldHasPrefix(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field.
|
||||
func UserIDHasSuffix(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldHasSuffix(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDEqualFold applies the EqualFold predicate on the "user_id" field.
|
||||
func UserIDEqualFold(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEqualFold(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDContainsFold applies the ContainsFold predicate on the "user_id" field.
|
||||
func UserIDContainsFold(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldContainsFold(FieldUserID, v))
|
||||
}
|
||||
|
||||
// TokenHashEQ applies the EQ predicate on the "token_hash" field.
|
||||
func TokenHashEQ(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashNEQ applies the NEQ predicate on the "token_hash" field.
|
||||
func TokenHashNEQ(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNEQ(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashIn applies the In predicate on the "token_hash" field.
|
||||
func TokenHashIn(vs ...string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldIn(FieldTokenHash, vs...))
|
||||
}
|
||||
|
||||
// TokenHashNotIn applies the NotIn predicate on the "token_hash" field.
|
||||
func TokenHashNotIn(vs ...string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNotIn(FieldTokenHash, vs...))
|
||||
}
|
||||
|
||||
// TokenHashGT applies the GT predicate on the "token_hash" field.
|
||||
func TokenHashGT(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGT(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashGTE applies the GTE predicate on the "token_hash" field.
|
||||
func TokenHashGTE(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGTE(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashLT applies the LT predicate on the "token_hash" field.
|
||||
func TokenHashLT(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLT(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashLTE applies the LTE predicate on the "token_hash" field.
|
||||
func TokenHashLTE(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLTE(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashContains applies the Contains predicate on the "token_hash" field.
|
||||
func TokenHashContains(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldContains(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashHasPrefix applies the HasPrefix predicate on the "token_hash" field.
|
||||
func TokenHashHasPrefix(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldHasPrefix(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashHasSuffix applies the HasSuffix predicate on the "token_hash" field.
|
||||
func TokenHashHasSuffix(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldHasSuffix(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashEqualFold applies the EqualFold predicate on the "token_hash" field.
|
||||
func TokenHashEqualFold(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEqualFold(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// TokenHashContainsFold applies the ContainsFold predicate on the "token_hash" field.
|
||||
func TokenHashContainsFold(v string) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldContainsFold(FieldTokenHash, v))
|
||||
}
|
||||
|
||||
// ExpiresAtEQ applies the EQ predicate on the "expires_at" field.
|
||||
func ExpiresAtEQ(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldExpiresAt, v))
|
||||
}
|
||||
|
||||
// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field.
|
||||
func ExpiresAtNEQ(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNEQ(FieldExpiresAt, v))
|
||||
}
|
||||
|
||||
// ExpiresAtIn applies the In predicate on the "expires_at" field.
|
||||
func ExpiresAtIn(vs ...time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldIn(FieldExpiresAt, vs...))
|
||||
}
|
||||
|
||||
// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field.
|
||||
func ExpiresAtNotIn(vs ...time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNotIn(FieldExpiresAt, vs...))
|
||||
}
|
||||
|
||||
// ExpiresAtGT applies the GT predicate on the "expires_at" field.
|
||||
func ExpiresAtGT(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGT(FieldExpiresAt, v))
|
||||
}
|
||||
|
||||
// ExpiresAtGTE applies the GTE predicate on the "expires_at" field.
|
||||
func ExpiresAtGTE(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGTE(FieldExpiresAt, v))
|
||||
}
|
||||
|
||||
// ExpiresAtLT applies the LT predicate on the "expires_at" field.
|
||||
func ExpiresAtLT(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLT(FieldExpiresAt, v))
|
||||
}
|
||||
|
||||
// ExpiresAtLTE applies the LTE predicate on the "expires_at" field.
|
||||
func ExpiresAtLTE(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLTE(FieldExpiresAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.RefreshToken) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.RefreshToken) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.RefreshToken) predicate.RefreshToken {
|
||||
return predicate.RefreshToken(sql.NotPredicates(p))
|
||||
}
|
||||
262
internal/ent/refreshtoken_create.go
Normal file
262
internal/ent/refreshtoken_create.go
Normal file
@@ -0,0 +1,262 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken"
|
||||
)
|
||||
|
||||
// RefreshTokenCreate is the builder for creating a RefreshToken entity.
|
||||
type RefreshTokenCreate struct {
|
||||
config
|
||||
mutation *RefreshTokenMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_c *RefreshTokenCreate) SetUserID(v string) *RefreshTokenCreate {
|
||||
_c.mutation.SetUserID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetTokenHash sets the "token_hash" field.
|
||||
func (_c *RefreshTokenCreate) SetTokenHash(v string) *RefreshTokenCreate {
|
||||
_c.mutation.SetTokenHash(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetExpiresAt sets the "expires_at" field.
|
||||
func (_c *RefreshTokenCreate) SetExpiresAt(v time.Time) *RefreshTokenCreate {
|
||||
_c.mutation.SetExpiresAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *RefreshTokenCreate) SetCreatedAt(v time.Time) *RefreshTokenCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *RefreshTokenCreate) SetNillableCreatedAt(v *time.Time) *RefreshTokenCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *RefreshTokenCreate) SetID(v string) *RefreshTokenCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the RefreshTokenMutation object of the builder.
|
||||
func (_c *RefreshTokenCreate) Mutation() *RefreshTokenMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the RefreshToken in the database.
|
||||
func (_c *RefreshTokenCreate) Save(ctx context.Context) (*RefreshToken, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *RefreshTokenCreate) SaveX(ctx context.Context) *RefreshToken {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *RefreshTokenCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *RefreshTokenCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *RefreshTokenCreate) defaults() {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := refreshtoken.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *RefreshTokenCreate) check() error {
|
||||
if _, ok := _c.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "RefreshToken.user_id"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.UserID(); ok {
|
||||
if err := refreshtoken.UserIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "RefreshToken.user_id": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.TokenHash(); !ok {
|
||||
return &ValidationError{Name: "token_hash", err: errors.New(`ent: missing required field "RefreshToken.token_hash"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.TokenHash(); ok {
|
||||
if err := refreshtoken.TokenHashValidator(v); err != nil {
|
||||
return &ValidationError{Name: "token_hash", err: fmt.Errorf(`ent: validator failed for field "RefreshToken.token_hash": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.ExpiresAt(); !ok {
|
||||
return &ValidationError{Name: "expires_at", err: errors.New(`ent: missing required field "RefreshToken.expires_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "RefreshToken.created_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *RefreshTokenCreate) sqlSave(ctx context.Context) (*RefreshToken, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if _spec.ID.Value != nil {
|
||||
if id, ok := _spec.ID.Value.(string); ok {
|
||||
_node.ID = id
|
||||
} else {
|
||||
return nil, fmt.Errorf("unexpected RefreshToken.ID type: %T", _spec.ID.Value)
|
||||
}
|
||||
}
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *RefreshTokenCreate) createSpec() (*RefreshToken, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &RefreshToken{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(refreshtoken.Table, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.UserID(); ok {
|
||||
_spec.SetField(refreshtoken.FieldUserID, field.TypeString, value)
|
||||
_node.UserID = value
|
||||
}
|
||||
if value, ok := _c.mutation.TokenHash(); ok {
|
||||
_spec.SetField(refreshtoken.FieldTokenHash, field.TypeString, value)
|
||||
_node.TokenHash = value
|
||||
}
|
||||
if value, ok := _c.mutation.ExpiresAt(); ok {
|
||||
_spec.SetField(refreshtoken.FieldExpiresAt, field.TypeTime, value)
|
||||
_node.ExpiresAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(refreshtoken.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// RefreshTokenCreateBulk is the builder for creating many RefreshToken entities in bulk.
|
||||
type RefreshTokenCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*RefreshTokenCreate
|
||||
}
|
||||
|
||||
// Save creates the RefreshToken entities in the database.
|
||||
func (_c *RefreshTokenCreateBulk) Save(ctx context.Context) ([]*RefreshToken, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*RefreshToken, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*RefreshTokenMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *RefreshTokenCreateBulk) SaveX(ctx context.Context) []*RefreshToken {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *RefreshTokenCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *RefreshTokenCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
88
internal/ent/refreshtoken_delete.go
Normal file
88
internal/ent/refreshtoken_delete.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/predicate"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken"
|
||||
)
|
||||
|
||||
// RefreshTokenDelete is the builder for deleting a RefreshToken entity.
|
||||
type RefreshTokenDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *RefreshTokenMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the RefreshTokenDelete builder.
|
||||
func (_d *RefreshTokenDelete) Where(ps ...predicate.RefreshToken) *RefreshTokenDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *RefreshTokenDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *RefreshTokenDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *RefreshTokenDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(refreshtoken.Table, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString))
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// RefreshTokenDeleteOne is the builder for deleting a single RefreshToken entity.
|
||||
type RefreshTokenDeleteOne struct {
|
||||
_d *RefreshTokenDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the RefreshTokenDelete builder.
|
||||
func (_d *RefreshTokenDeleteOne) Where(ps ...predicate.RefreshToken) *RefreshTokenDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *RefreshTokenDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{refreshtoken.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *RefreshTokenDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
527
internal/ent/refreshtoken_query.go
Normal file
527
internal/ent/refreshtoken_query.go
Normal file
@@ -0,0 +1,527 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/predicate"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken"
|
||||
)
|
||||
|
||||
// RefreshTokenQuery is the builder for querying RefreshToken entities.
|
||||
type RefreshTokenQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []refreshtoken.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.RefreshToken
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the RefreshTokenQuery builder.
|
||||
func (_q *RefreshTokenQuery) Where(ps ...predicate.RefreshToken) *RefreshTokenQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *RefreshTokenQuery) Limit(limit int) *RefreshTokenQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *RefreshTokenQuery) Offset(offset int) *RefreshTokenQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// 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 (_q *RefreshTokenQuery) Unique(unique bool) *RefreshTokenQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *RefreshTokenQuery) Order(o ...refreshtoken.OrderOption) *RefreshTokenQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first RefreshToken entity from the query.
|
||||
// Returns a *NotFoundError when no RefreshToken was found.
|
||||
func (_q *RefreshTokenQuery) First(ctx context.Context) (*RefreshToken, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{refreshtoken.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *RefreshTokenQuery) FirstX(ctx context.Context) *RefreshToken {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first RefreshToken ID from the query.
|
||||
// Returns a *NotFoundError when no RefreshToken ID was found.
|
||||
func (_q *RefreshTokenQuery) FirstID(ctx context.Context) (id string, err error) {
|
||||
var ids []string
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{refreshtoken.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *RefreshTokenQuery) FirstIDX(ctx context.Context) string {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single RefreshToken entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one RefreshToken entity is found.
|
||||
// Returns a *NotFoundError when no RefreshToken entities are found.
|
||||
func (_q *RefreshTokenQuery) Only(ctx context.Context) (*RefreshToken, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{refreshtoken.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{refreshtoken.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *RefreshTokenQuery) OnlyX(ctx context.Context) *RefreshToken {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only RefreshToken ID in the query.
|
||||
// Returns a *NotSingularError when more than one RefreshToken ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *RefreshTokenQuery) OnlyID(ctx context.Context) (id string, err error) {
|
||||
var ids []string
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{refreshtoken.Label}
|
||||
default:
|
||||
err = &NotSingularError{refreshtoken.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *RefreshTokenQuery) OnlyIDX(ctx context.Context) string {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of RefreshTokens.
|
||||
func (_q *RefreshTokenQuery) All(ctx context.Context) ([]*RefreshToken, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*RefreshToken, *RefreshTokenQuery]()
|
||||
return withInterceptors[[]*RefreshToken](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *RefreshTokenQuery) AllX(ctx context.Context) []*RefreshToken {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of RefreshToken IDs.
|
||||
func (_q *RefreshTokenQuery) IDs(ctx context.Context) (ids []string, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(refreshtoken.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *RefreshTokenQuery) IDsX(ctx context.Context) []string {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *RefreshTokenQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*RefreshTokenQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *RefreshTokenQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *RefreshTokenQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *RefreshTokenQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the RefreshTokenQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *RefreshTokenQuery) Clone() *RefreshTokenQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &RefreshTokenQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]refreshtoken.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.RefreshToken{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// UserID string `json:"user_id,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.RefreshToken.Query().
|
||||
// GroupBy(refreshtoken.FieldUserID).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *RefreshTokenQuery) GroupBy(field string, fields ...string) *RefreshTokenGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &RefreshTokenGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = refreshtoken.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// UserID string `json:"user_id,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.RefreshToken.Query().
|
||||
// Select(refreshtoken.FieldUserID).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *RefreshTokenQuery) Select(fields ...string) *RefreshTokenSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &RefreshTokenSelect{RefreshTokenQuery: _q}
|
||||
sbuild.label = refreshtoken.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a RefreshTokenSelect configured with the given aggregations.
|
||||
func (_q *RefreshTokenQuery) Aggregate(fns ...AggregateFunc) *RefreshTokenSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *RefreshTokenQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.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, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !refreshtoken.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *RefreshTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*RefreshToken, error) {
|
||||
var (
|
||||
nodes = []*RefreshToken{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*RefreshToken).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &RefreshToken{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *RefreshTokenQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *RefreshTokenQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(refreshtoken.Table, refreshtoken.Columns, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, refreshtoken.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != refreshtoken.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *RefreshTokenQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(refreshtoken.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = refreshtoken.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := _q.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 := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// RefreshTokenGroupBy is the group-by builder for RefreshToken entities.
|
||||
type RefreshTokenGroupBy struct {
|
||||
selector
|
||||
build *RefreshTokenQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *RefreshTokenGroupBy) Aggregate(fns ...AggregateFunc) *RefreshTokenGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *RefreshTokenGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*RefreshTokenQuery, *RefreshTokenGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *RefreshTokenGroupBy) sqlScan(ctx context.Context, root *RefreshTokenQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// RefreshTokenSelect is the builder for selecting fields of RefreshToken entities.
|
||||
type RefreshTokenSelect struct {
|
||||
*RefreshTokenQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *RefreshTokenSelect) Aggregate(fns ...AggregateFunc) *RefreshTokenSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *RefreshTokenSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*RefreshTokenQuery, *RefreshTokenSelect](ctx, _s.RefreshTokenQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *RefreshTokenSelect) sqlScan(ctx context.Context, root *RefreshTokenQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
314
internal/ent/refreshtoken_update.go
Normal file
314
internal/ent/refreshtoken_update.go
Normal file
@@ -0,0 +1,314 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/predicate"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken"
|
||||
)
|
||||
|
||||
// RefreshTokenUpdate is the builder for updating RefreshToken entities.
|
||||
type RefreshTokenUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *RefreshTokenMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the RefreshTokenUpdate builder.
|
||||
func (_u *RefreshTokenUpdate) Where(ps ...predicate.RefreshToken) *RefreshTokenUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *RefreshTokenUpdate) SetUserID(v string) *RefreshTokenUpdate {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *RefreshTokenUpdate) SetNillableUserID(v *string) *RefreshTokenUpdate {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTokenHash sets the "token_hash" field.
|
||||
func (_u *RefreshTokenUpdate) SetTokenHash(v string) *RefreshTokenUpdate {
|
||||
_u.mutation.SetTokenHash(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTokenHash sets the "token_hash" field if the given value is not nil.
|
||||
func (_u *RefreshTokenUpdate) SetNillableTokenHash(v *string) *RefreshTokenUpdate {
|
||||
if v != nil {
|
||||
_u.SetTokenHash(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetExpiresAt sets the "expires_at" field.
|
||||
func (_u *RefreshTokenUpdate) SetExpiresAt(v time.Time) *RefreshTokenUpdate {
|
||||
_u.mutation.SetExpiresAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
||||
func (_u *RefreshTokenUpdate) SetNillableExpiresAt(v *time.Time) *RefreshTokenUpdate {
|
||||
if v != nil {
|
||||
_u.SetExpiresAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the RefreshTokenMutation object of the builder.
|
||||
func (_u *RefreshTokenUpdate) Mutation() *RefreshTokenMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *RefreshTokenUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *RefreshTokenUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *RefreshTokenUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *RefreshTokenUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *RefreshTokenUpdate) check() error {
|
||||
if v, ok := _u.mutation.UserID(); ok {
|
||||
if err := refreshtoken.UserIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "RefreshToken.user_id": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.TokenHash(); ok {
|
||||
if err := refreshtoken.TokenHashValidator(v); err != nil {
|
||||
return &ValidationError{Name: "token_hash", err: fmt.Errorf(`ent: validator failed for field "RefreshToken.token_hash": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *RefreshTokenUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(refreshtoken.Table, refreshtoken.Columns, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UserID(); ok {
|
||||
_spec.SetField(refreshtoken.FieldUserID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.TokenHash(); ok {
|
||||
_spec.SetField(refreshtoken.FieldTokenHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ExpiresAt(); ok {
|
||||
_spec.SetField(refreshtoken.FieldExpiresAt, field.TypeTime, value)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{refreshtoken.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// RefreshTokenUpdateOne is the builder for updating a single RefreshToken entity.
|
||||
type RefreshTokenUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *RefreshTokenMutation
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *RefreshTokenUpdateOne) SetUserID(v string) *RefreshTokenUpdateOne {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *RefreshTokenUpdateOne) SetNillableUserID(v *string) *RefreshTokenUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTokenHash sets the "token_hash" field.
|
||||
func (_u *RefreshTokenUpdateOne) SetTokenHash(v string) *RefreshTokenUpdateOne {
|
||||
_u.mutation.SetTokenHash(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTokenHash sets the "token_hash" field if the given value is not nil.
|
||||
func (_u *RefreshTokenUpdateOne) SetNillableTokenHash(v *string) *RefreshTokenUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetTokenHash(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetExpiresAt sets the "expires_at" field.
|
||||
func (_u *RefreshTokenUpdateOne) SetExpiresAt(v time.Time) *RefreshTokenUpdateOne {
|
||||
_u.mutation.SetExpiresAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
||||
func (_u *RefreshTokenUpdateOne) SetNillableExpiresAt(v *time.Time) *RefreshTokenUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetExpiresAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the RefreshTokenMutation object of the builder.
|
||||
func (_u *RefreshTokenUpdateOne) Mutation() *RefreshTokenMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the RefreshTokenUpdate builder.
|
||||
func (_u *RefreshTokenUpdateOne) Where(ps ...predicate.RefreshToken) *RefreshTokenUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *RefreshTokenUpdateOne) Select(field string, fields ...string) *RefreshTokenUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated RefreshToken entity.
|
||||
func (_u *RefreshTokenUpdateOne) Save(ctx context.Context) (*RefreshToken, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *RefreshTokenUpdateOne) SaveX(ctx context.Context) *RefreshToken {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *RefreshTokenUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *RefreshTokenUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *RefreshTokenUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.UserID(); ok {
|
||||
if err := refreshtoken.UserIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "RefreshToken.user_id": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.TokenHash(); ok {
|
||||
if err := refreshtoken.TokenHashValidator(v); err != nil {
|
||||
return &ValidationError{Name: "token_hash", err: fmt.Errorf(`ent: validator failed for field "RefreshToken.token_hash": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *RefreshTokenUpdateOne) sqlSave(ctx context.Context) (_node *RefreshToken, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(refreshtoken.Table, refreshtoken.Columns, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "RefreshToken.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, refreshtoken.FieldID)
|
||||
for _, f := range fields {
|
||||
if !refreshtoken.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != refreshtoken.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UserID(); ok {
|
||||
_spec.SetField(refreshtoken.FieldUserID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.TokenHash(); ok {
|
||||
_spec.SetField(refreshtoken.FieldTokenHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ExpiresAt(); ok {
|
||||
_spec.SetField(refreshtoken.FieldExpiresAt, field.TypeTime, value)
|
||||
}
|
||||
_node = &RefreshToken{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{refreshtoken.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/auditlog"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/permission"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/refreshtoken"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/role"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/schema"
|
||||
"git.dcentral.systems/toolz/goplt/internal/ent/user"
|
||||
@@ -36,6 +37,20 @@ func init() {
|
||||
permissionDescName := permissionFields[1].Descriptor()
|
||||
// permission.NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
permission.NameValidator = permissionDescName.Validators[0].(func(string) error)
|
||||
refreshtokenFields := schema.RefreshToken{}.Fields()
|
||||
_ = refreshtokenFields
|
||||
// refreshtokenDescUserID is the schema descriptor for user_id field.
|
||||
refreshtokenDescUserID := refreshtokenFields[1].Descriptor()
|
||||
// refreshtoken.UserIDValidator is a validator for the "user_id" field. It is called by the builders before save.
|
||||
refreshtoken.UserIDValidator = refreshtokenDescUserID.Validators[0].(func(string) error)
|
||||
// refreshtokenDescTokenHash is the schema descriptor for token_hash field.
|
||||
refreshtokenDescTokenHash := refreshtokenFields[2].Descriptor()
|
||||
// refreshtoken.TokenHashValidator is a validator for the "token_hash" field. It is called by the builders before save.
|
||||
refreshtoken.TokenHashValidator = refreshtokenDescTokenHash.Validators[0].(func(string) error)
|
||||
// refreshtokenDescCreatedAt is the schema descriptor for created_at field.
|
||||
refreshtokenDescCreatedAt := refreshtokenFields[4].Descriptor()
|
||||
// refreshtoken.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
refreshtoken.DefaultCreatedAt = refreshtokenDescCreatedAt.Default.(func() time.Time)
|
||||
roleFields := schema.Role{}.Fields()
|
||||
_ = roleFields
|
||||
// roleDescName is the schema descriptor for name field.
|
||||
|
||||
@@ -16,6 +16,8 @@ type Tx struct {
|
||||
AuditLog *AuditLogClient
|
||||
// Permission is the client for interacting with the Permission builders.
|
||||
Permission *PermissionClient
|
||||
// RefreshToken is the client for interacting with the RefreshToken builders.
|
||||
RefreshToken *RefreshTokenClient
|
||||
// Role is the client for interacting with the Role builders.
|
||||
Role *RoleClient
|
||||
// RolePermission is the client for interacting with the RolePermission builders.
|
||||
@@ -157,6 +159,7 @@ func (tx *Tx) Client() *Client {
|
||||
func (tx *Tx) init() {
|
||||
tx.AuditLog = NewAuditLogClient(tx.config)
|
||||
tx.Permission = NewPermissionClient(tx.config)
|
||||
tx.RefreshToken = NewRefreshTokenClient(tx.config)
|
||||
tx.Role = NewRoleClient(tx.config)
|
||||
tx.RolePermission = NewRolePermissionClient(tx.config)
|
||||
tx.User = NewUserClient(tx.config)
|
||||
|
||||
Reference in New Issue
Block a user