init: create project
This commit is contained in:
395
server/ent/client.go
Normal file
395
server/ent/client.go
Normal file
@@ -0,0 +1,395 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/kallydev/privacy/ent/migrate"
|
||||
|
||||
"github.com/kallydev/privacy/ent/jdmodel"
|
||||
"github.com/kallydev/privacy/ent/qqmodel"
|
||||
"github.com/kallydev/privacy/ent/sfmodel"
|
||||
|
||||
"github.com/facebook/ent/dialect"
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Client is the client that holds all ent builders.
|
||||
type Client struct {
|
||||
config
|
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema
|
||||
// JDModel is the client for interacting with the JDModel builders.
|
||||
JDModel *JDModelClient
|
||||
// QQModel is the client for interacting with the QQModel builders.
|
||||
QQModel *QQModelClient
|
||||
// SFModel is the client for interacting with the SFModel builders.
|
||||
SFModel *SFModelClient
|
||||
}
|
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
func NewClient(opts ...Option) *Client {
|
||||
cfg := config{log: log.Println, hooks: &hooks{}}
|
||||
cfg.options(opts...)
|
||||
client := &Client{config: cfg}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.JDModel = NewJDModelClient(c.config)
|
||||
c.QQModel = NewQQModelClient(c.config)
|
||||
c.SFModel = NewSFModelClient(c.config)
|
||||
}
|
||||
|
||||
// Open opens a database/sql.DB specified by the driver name and
|
||||
// the data source name, and returns a new client attached to it.
|
||||
// Optional parameters can be added for configuring the client.
|
||||
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||
switch driverName {
|
||||
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||
drv, err := sql.Open(driverName, dataSourceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewClient(append(options, Driver(drv))...), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||
}
|
||||
}
|
||||
|
||||
// Tx returns a new transactional client. The provided context
|
||||
// is used until the transaction is committed or rolled back.
|
||||
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
if _, ok := c.driver.(*txDriver); ok {
|
||||
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
|
||||
}
|
||||
tx, err := newTx(ctx, c.driver)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ent: starting a transaction: %v", err)
|
||||
}
|
||||
cfg := config{driver: tx, log: c.log, debug: c.debug, hooks: c.hooks}
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
JDModel: NewJDModelClient(cfg),
|
||||
QQModel: NewQQModelClient(cfg),
|
||||
SFModel: NewSFModelClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BeginTx returns a transactional client with options.
|
||||
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||
if _, ok := c.driver.(*txDriver); ok {
|
||||
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
|
||||
}
|
||||
tx, err := c.driver.(*sql.Driver).BeginTx(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ent: starting a transaction: %v", err)
|
||||
}
|
||||
cfg := config{driver: &txDriver{tx: tx, drv: c.driver}, log: c.log, debug: c.debug, hooks: c.hooks}
|
||||
return &Tx{
|
||||
config: cfg,
|
||||
JDModel: NewJDModelClient(cfg),
|
||||
QQModel: NewQQModelClient(cfg),
|
||||
SFModel: NewSFModelClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// JDModel.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
//
|
||||
func (c *Client) Debug() *Client {
|
||||
if c.debug {
|
||||
return c
|
||||
}
|
||||
cfg := config{driver: dialect.Debug(c.driver, c.log), log: c.log, debug: true, hooks: c.hooks}
|
||||
client := &Client{config: cfg}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Close closes the database connection and prevents new queries from starting.
|
||||
func (c *Client) Close() error {
|
||||
return c.driver.Close()
|
||||
}
|
||||
|
||||
// Use adds the mutation hooks to all the entity clients.
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
c.JDModel.Use(hooks...)
|
||||
c.QQModel.Use(hooks...)
|
||||
c.SFModel.Use(hooks...)
|
||||
}
|
||||
|
||||
// JDModelClient is a client for the JDModel schema.
|
||||
type JDModelClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewJDModelClient returns a client for the JDModel from the given config.
|
||||
func NewJDModelClient(c config) *JDModelClient {
|
||||
return &JDModelClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `jdmodel.Hooks(f(g(h())))`.
|
||||
func (c *JDModelClient) Use(hooks ...Hook) {
|
||||
c.hooks.JDModel = append(c.hooks.JDModel, hooks...)
|
||||
}
|
||||
|
||||
// Create returns a create builder for JDModel.
|
||||
func (c *JDModelClient) Create() *JDModelCreate {
|
||||
mutation := newJDModelMutation(c.config, OpCreate)
|
||||
return &JDModelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// BulkCreate returns a builder for creating a bulk of JDModel entities.
|
||||
func (c *JDModelClient) CreateBulk(builders ...*JDModelCreate) *JDModelCreateBulk {
|
||||
return &JDModelCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for JDModel.
|
||||
func (c *JDModelClient) Update() *JDModelUpdate {
|
||||
mutation := newJDModelMutation(c.config, OpUpdate)
|
||||
return &JDModelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *JDModelClient) UpdateOne(jm *JDModel) *JDModelUpdateOne {
|
||||
mutation := newJDModelMutation(c.config, OpUpdateOne, withJDModel(jm))
|
||||
return &JDModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *JDModelClient) UpdateOneID(id int) *JDModelUpdateOne {
|
||||
mutation := newJDModelMutation(c.config, OpUpdateOne, withJDModelID(id))
|
||||
return &JDModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for JDModel.
|
||||
func (c *JDModelClient) Delete() *JDModelDelete {
|
||||
mutation := newJDModelMutation(c.config, OpDelete)
|
||||
return &JDModelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *JDModelClient) DeleteOne(jm *JDModel) *JDModelDeleteOne {
|
||||
return c.DeleteOneID(jm.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *JDModelClient) DeleteOneID(id int) *JDModelDeleteOne {
|
||||
builder := c.Delete().Where(jdmodel.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &JDModelDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for JDModel.
|
||||
func (c *JDModelClient) Query() *JDModelQuery {
|
||||
return &JDModelQuery{config: c.config}
|
||||
}
|
||||
|
||||
// Get returns a JDModel entity by its id.
|
||||
func (c *JDModelClient) Get(ctx context.Context, id int) (*JDModel, error) {
|
||||
return c.Query().Where(jdmodel.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *JDModelClient) GetX(ctx context.Context, id int) *JDModel {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *JDModelClient) Hooks() []Hook {
|
||||
return c.hooks.JDModel
|
||||
}
|
||||
|
||||
// QQModelClient is a client for the QQModel schema.
|
||||
type QQModelClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewQQModelClient returns a client for the QQModel from the given config.
|
||||
func NewQQModelClient(c config) *QQModelClient {
|
||||
return &QQModelClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `qqmodel.Hooks(f(g(h())))`.
|
||||
func (c *QQModelClient) Use(hooks ...Hook) {
|
||||
c.hooks.QQModel = append(c.hooks.QQModel, hooks...)
|
||||
}
|
||||
|
||||
// Create returns a create builder for QQModel.
|
||||
func (c *QQModelClient) Create() *QQModelCreate {
|
||||
mutation := newQQModelMutation(c.config, OpCreate)
|
||||
return &QQModelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// BulkCreate returns a builder for creating a bulk of QQModel entities.
|
||||
func (c *QQModelClient) CreateBulk(builders ...*QQModelCreate) *QQModelCreateBulk {
|
||||
return &QQModelCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for QQModel.
|
||||
func (c *QQModelClient) Update() *QQModelUpdate {
|
||||
mutation := newQQModelMutation(c.config, OpUpdate)
|
||||
return &QQModelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *QQModelClient) UpdateOne(qm *QQModel) *QQModelUpdateOne {
|
||||
mutation := newQQModelMutation(c.config, OpUpdateOne, withQQModel(qm))
|
||||
return &QQModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *QQModelClient) UpdateOneID(id int) *QQModelUpdateOne {
|
||||
mutation := newQQModelMutation(c.config, OpUpdateOne, withQQModelID(id))
|
||||
return &QQModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for QQModel.
|
||||
func (c *QQModelClient) Delete() *QQModelDelete {
|
||||
mutation := newQQModelMutation(c.config, OpDelete)
|
||||
return &QQModelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *QQModelClient) DeleteOne(qm *QQModel) *QQModelDeleteOne {
|
||||
return c.DeleteOneID(qm.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *QQModelClient) DeleteOneID(id int) *QQModelDeleteOne {
|
||||
builder := c.Delete().Where(qqmodel.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &QQModelDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for QQModel.
|
||||
func (c *QQModelClient) Query() *QQModelQuery {
|
||||
return &QQModelQuery{config: c.config}
|
||||
}
|
||||
|
||||
// Get returns a QQModel entity by its id.
|
||||
func (c *QQModelClient) Get(ctx context.Context, id int) (*QQModel, error) {
|
||||
return c.Query().Where(qqmodel.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *QQModelClient) GetX(ctx context.Context, id int) *QQModel {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *QQModelClient) Hooks() []Hook {
|
||||
return c.hooks.QQModel
|
||||
}
|
||||
|
||||
// SFModelClient is a client for the SFModel schema.
|
||||
type SFModelClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSFModelClient returns a client for the SFModel from the given config.
|
||||
func NewSFModelClient(c config) *SFModelClient {
|
||||
return &SFModelClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `sfmodel.Hooks(f(g(h())))`.
|
||||
func (c *SFModelClient) Use(hooks ...Hook) {
|
||||
c.hooks.SFModel = append(c.hooks.SFModel, hooks...)
|
||||
}
|
||||
|
||||
// Create returns a create builder for SFModel.
|
||||
func (c *SFModelClient) Create() *SFModelCreate {
|
||||
mutation := newSFModelMutation(c.config, OpCreate)
|
||||
return &SFModelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// BulkCreate returns a builder for creating a bulk of SFModel entities.
|
||||
func (c *SFModelClient) CreateBulk(builders ...*SFModelCreate) *SFModelCreateBulk {
|
||||
return &SFModelCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for SFModel.
|
||||
func (c *SFModelClient) Update() *SFModelUpdate {
|
||||
mutation := newSFModelMutation(c.config, OpUpdate)
|
||||
return &SFModelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SFModelClient) UpdateOne(sm *SFModel) *SFModelUpdateOne {
|
||||
mutation := newSFModelMutation(c.config, OpUpdateOne, withSFModel(sm))
|
||||
return &SFModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SFModelClient) UpdateOneID(id int) *SFModelUpdateOne {
|
||||
mutation := newSFModelMutation(c.config, OpUpdateOne, withSFModelID(id))
|
||||
return &SFModelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for SFModel.
|
||||
func (c *SFModelClient) Delete() *SFModelDelete {
|
||||
mutation := newSFModelMutation(c.config, OpDelete)
|
||||
return &SFModelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *SFModelClient) DeleteOne(sm *SFModel) *SFModelDeleteOne {
|
||||
return c.DeleteOneID(sm.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *SFModelClient) DeleteOneID(id int) *SFModelDeleteOne {
|
||||
builder := c.Delete().Where(sfmodel.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SFModelDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for SFModel.
|
||||
func (c *SFModelClient) Query() *SFModelQuery {
|
||||
return &SFModelQuery{config: c.config}
|
||||
}
|
||||
|
||||
// Get returns a SFModel entity by its id.
|
||||
func (c *SFModelClient) Get(ctx context.Context, id int) (*SFModel, error) {
|
||||
return c.Query().Where(sfmodel.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SFModelClient) GetX(ctx context.Context, id int) *SFModel {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SFModelClient) Hooks() []Hook {
|
||||
return c.hooks.SFModel
|
||||
}
|
61
server/ent/config.go
Normal file
61
server/ent/config.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/dialect"
|
||||
)
|
||||
|
||||
// Option function to configure the client.
|
||||
type Option func(*config)
|
||||
|
||||
// Config is the configuration for the client and its builder.
|
||||
type config struct {
|
||||
// driver used for executing database requests.
|
||||
driver dialect.Driver
|
||||
// debug enable a debug logging.
|
||||
debug bool
|
||||
// log used for logging on debug mode.
|
||||
log func(...interface{})
|
||||
// hooks to execute on mutations.
|
||||
hooks *hooks
|
||||
}
|
||||
|
||||
// hooks per client, for fast access.
|
||||
type hooks struct {
|
||||
JDModel []ent.Hook
|
||||
QQModel []ent.Hook
|
||||
SFModel []ent.Hook
|
||||
}
|
||||
|
||||
// Options applies the options on the config object.
|
||||
func (c *config) options(opts ...Option) {
|
||||
for _, opt := range opts {
|
||||
opt(c)
|
||||
}
|
||||
if c.debug {
|
||||
c.driver = dialect.Debug(c.driver, c.log)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug enables debug logging on the ent.Driver.
|
||||
func Debug() Option {
|
||||
return func(c *config) {
|
||||
c.debug = true
|
||||
}
|
||||
}
|
||||
|
||||
// Log sets the logging function for debug mode.
|
||||
func Log(fn func(...interface{})) Option {
|
||||
return func(c *config) {
|
||||
c.log = fn
|
||||
}
|
||||
}
|
||||
|
||||
// Driver configures the client driver.
|
||||
func Driver(driver dialect.Driver) Option {
|
||||
return func(c *config) {
|
||||
c.driver = driver
|
||||
}
|
||||
}
|
33
server/ent/context.go
Normal file
33
server/ent/context.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type clientCtxKey struct{}
|
||||
|
||||
// FromContext returns the Client stored in a context, or nil if there isn't one.
|
||||
func FromContext(ctx context.Context) *Client {
|
||||
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewContext returns a new context with the given Client attached.
|
||||
func NewContext(parent context.Context, c *Client) context.Context {
|
||||
return context.WithValue(parent, clientCtxKey{}, c)
|
||||
}
|
||||
|
||||
type txCtxKey struct{}
|
||||
|
||||
// TxFromContext returns the Tx stored in a context, or nil if there isn't one.
|
||||
func TxFromContext(ctx context.Context) *Tx {
|
||||
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||
return tx
|
||||
}
|
||||
|
||||
// NewTxContext returns a new context with the given Client attached.
|
||||
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||
return context.WithValue(parent, txCtxKey{}, tx)
|
||||
}
|
270
server/ent/ent.go
Normal file
270
server/ent/ent.go
Normal file
@@ -0,0 +1,270 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/dialect"
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// ent aliases to avoid import conflict in user's code.
|
||||
type (
|
||||
Op = ent.Op
|
||||
Hook = ent.Hook
|
||||
Value = ent.Value
|
||||
Query = ent.Query
|
||||
Policy = ent.Policy
|
||||
Mutator = ent.Mutator
|
||||
Mutation = ent.Mutation
|
||||
MutateFunc = ent.MutateFunc
|
||||
)
|
||||
|
||||
// OrderFunc applies an ordering on the sql selector.
|
||||
type OrderFunc func(*sql.Selector, func(string) bool)
|
||||
|
||||
// Asc applies the given fields in ASC order.
|
||||
func Asc(fields ...string) OrderFunc {
|
||||
return func(s *sql.Selector, check func(string) bool) {
|
||||
for _, f := range fields {
|
||||
if check(f) {
|
||||
s.OrderBy(sql.Asc(f))
|
||||
} else {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("invalid field %q for ordering", f)})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Desc applies the given fields in DESC order.
|
||||
func Desc(fields ...string) OrderFunc {
|
||||
return func(s *sql.Selector, check func(string) bool) {
|
||||
for _, f := range fields {
|
||||
if check(f) {
|
||||
s.OrderBy(sql.Desc(f))
|
||||
} else {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("invalid field %q for ordering", f)})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||
type AggregateFunc func(*sql.Selector, func(string) bool) string
|
||||
|
||||
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||
//
|
||||
// GroupBy(field1, field2).
|
||||
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||
return func(s *sql.Selector, check func(string) bool) string {
|
||||
return sql.As(fn(s, check), end)
|
||||
}
|
||||
}
|
||||
|
||||
// Count applies the "count" aggregation function on each group.
|
||||
func Count() AggregateFunc {
|
||||
return func(s *sql.Selector, _ func(string) bool) string {
|
||||
return sql.Count("*")
|
||||
}
|
||||
}
|
||||
|
||||
// Max applies the "max" aggregation function on the given field of each group.
|
||||
func Max(field string) AggregateFunc {
|
||||
return func(s *sql.Selector, check func(string) bool) string {
|
||||
if !check(field) {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)})
|
||||
return ""
|
||||
}
|
||||
return sql.Max(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||
func Mean(field string) AggregateFunc {
|
||||
return func(s *sql.Selector, check func(string) bool) string {
|
||||
if !check(field) {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)})
|
||||
return ""
|
||||
}
|
||||
return sql.Avg(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Min applies the "min" aggregation function on the given field of each group.
|
||||
func Min(field string) AggregateFunc {
|
||||
return func(s *sql.Selector, check func(string) bool) string {
|
||||
if !check(field) {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)})
|
||||
return ""
|
||||
}
|
||||
return sql.Min(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||
func Sum(field string) AggregateFunc {
|
||||
return func(s *sql.Selector, check func(string) bool) string {
|
||||
if !check(field) {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)})
|
||||
return ""
|
||||
}
|
||||
return sql.Sum(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// ValidationError returns when validating a field fails.
|
||||
type ValidationError struct {
|
||||
Name string // Field or edge name.
|
||||
err error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *ValidationError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ValidationError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
// IsValidationError returns a boolean indicating whether the error is a validaton error.
|
||||
func IsValidationError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ValidationError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||
type NotFoundError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotFoundError) Error() string {
|
||||
return "ent: " + e.label + " not found"
|
||||
}
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// MaskNotFound masks not found error.
|
||||
func MaskNotFound(err error) error {
|
||||
if IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||
type NotSingularError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotSingularError) Error() string {
|
||||
return "ent: " + e.label + " not singular"
|
||||
}
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||
type NotLoadedError struct {
|
||||
edge string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotLoadedError) Error() string {
|
||||
return "ent: " + e.edge + " edge was not loaded"
|
||||
}
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ConstraintError) Error() string {
|
||||
return "ent: constraint failed: " + e.msg
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
var (
|
||||
msg = err.Error()
|
||||
// error format per dialect.
|
||||
errors = [...]string{
|
||||
"Error 1062", // MySQL 1062 error (ER_DUP_ENTRY).
|
||||
"UNIQUE constraint failed", // SQLite.
|
||||
"duplicate key value violates unique constraint", // PostgreSQL.
|
||||
}
|
||||
)
|
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok {
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
for i := range errors {
|
||||
if strings.Contains(msg, errors[i]) {
|
||||
return &ConstraintError{msg, err}, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// rollback calls to tx.Rollback and wraps the given error with the rollback error if occurred.
|
||||
func rollback(tx dialect.Tx, err error) error {
|
||||
if rerr := tx.Rollback(); rerr != nil {
|
||||
err = fmt.Errorf("%s: %v", err.Error(), rerr)
|
||||
}
|
||||
if err, ok := isSQLConstraintError(err); ok {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
78
server/ent/enttest/enttest.go
Normal file
78
server/ent/enttest/enttest.go
Normal file
@@ -0,0 +1,78 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package enttest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/kallydev/privacy/ent"
|
||||
// required by schema hooks.
|
||||
_ "github.com/kallydev/privacy/ent/runtime"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql/schema"
|
||||
)
|
||||
|
||||
type (
|
||||
// TestingT is the interface that is shared between
|
||||
// testing.T and testing.B and used by enttest.
|
||||
TestingT interface {
|
||||
FailNow()
|
||||
Error(...interface{})
|
||||
}
|
||||
|
||||
// Option configures client creation.
|
||||
Option func(*options)
|
||||
|
||||
options struct {
|
||||
opts []ent.Option
|
||||
migrateOpts []schema.MigrateOption
|
||||
}
|
||||
)
|
||||
|
||||
// WithOptions forwards options to client creation.
|
||||
func WithOptions(opts ...ent.Option) Option {
|
||||
return func(o *options) {
|
||||
o.opts = append(o.opts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// WithMigrateOptions forwards options to auto migration.
|
||||
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||
return func(o *options) {
|
||||
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func newOptions(opts []Option) *options {
|
||||
o := &options{}
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// Open calls ent.Open and auto-run migration.
|
||||
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
|
||||
o := newOptions(opts)
|
||||
c, err := ent.Open(driverName, dataSourceName, o.opts...)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// NewClient calls ent.NewClient and auto-run migration.
|
||||
func NewClient(t TestingT, opts ...Option) *ent.Client {
|
||||
o := newOptions(opts)
|
||||
c := ent.NewClient(o.opts...)
|
||||
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
return c
|
||||
}
|
3
server/ent/generate.go
Normal file
3
server/ent/generate.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package ent
|
||||
|
||||
//go:generate go run github.com/facebook/ent/cmd/entc generate ./schema
|
230
server/ent/hook/hook.go
Normal file
230
server/ent/hook/hook.go
Normal file
@@ -0,0 +1,230 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/kallydev/privacy/ent"
|
||||
)
|
||||
|
||||
// The JDModelFunc type is an adapter to allow the use of ordinary
|
||||
// function as JDModel mutator.
|
||||
type JDModelFunc func(context.Context, *ent.JDModelMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f JDModelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
mv, ok := m.(*ent.JDModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.JDModelMutation", m)
|
||||
}
|
||||
return f(ctx, mv)
|
||||
}
|
||||
|
||||
// The QQModelFunc type is an adapter to allow the use of ordinary
|
||||
// function as QQModel mutator.
|
||||
type QQModelFunc func(context.Context, *ent.QQModelMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f QQModelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
mv, ok := m.(*ent.QQModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.QQModelMutation", m)
|
||||
}
|
||||
return f(ctx, mv)
|
||||
}
|
||||
|
||||
// The SFModelFunc type is an adapter to allow the use of ordinary
|
||||
// function as SFModel mutator.
|
||||
type SFModelFunc func(context.Context, *ent.SFModelMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f SFModelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
mv, ok := m.(*ent.SFModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SFModelMutation", m)
|
||||
}
|
||||
return f(ctx, mv)
|
||||
}
|
||||
|
||||
// Condition is a hook condition function.
|
||||
type Condition func(context.Context, ent.Mutation) bool
|
||||
|
||||
// And groups conditions with the AND operator.
|
||||
func And(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m ent.Mutation) bool {
|
||||
if !first(ctx, m) || !second(ctx, m) {
|
||||
return false
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if !cond(ctx, m) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Or groups conditions with the OR operator.
|
||||
func Or(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m ent.Mutation) bool {
|
||||
if first(ctx, m) || second(ctx, m) {
|
||||
return true
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if cond(ctx, m) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Not negates a given condition.
|
||||
func Not(cond Condition) Condition {
|
||||
return func(ctx context.Context, m ent.Mutation) bool {
|
||||
return !cond(ctx, m)
|
||||
}
|
||||
}
|
||||
|
||||
// HasOp is a condition testing mutation operation.
|
||||
func HasOp(op ent.Op) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
return m.Op().Is(op)
|
||||
}
|
||||
}
|
||||
|
||||
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||
func HasAddedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||
func HasClearedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasFields is a condition validating `.Field` on fields.
|
||||
func HasFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m ent.Mutation) bool {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// If executes the given hook under condition.
|
||||
//
|
||||
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||
//
|
||||
func If(hk ent.Hook, cond Condition) ent.Hook {
|
||||
return func(next ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if cond(ctx, m) {
|
||||
return hk(next).Mutate(ctx, m)
|
||||
}
|
||||
return next.Mutate(ctx, m)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// On executes the given hook only for the given operation.
|
||||
//
|
||||
// hook.On(Log, ent.Delete|ent.Create)
|
||||
//
|
||||
func On(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, HasOp(op))
|
||||
}
|
||||
|
||||
// Unless skips the given hook only for the given operation.
|
||||
//
|
||||
// hook.Unless(Log, ent.Update|ent.UpdateOne)
|
||||
//
|
||||
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
// return []ent.Hook{
|
||||
// Reject(ent.Delete|ent.Update),
|
||||
// }
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook {
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
// Chain acts as a list of hooks and is effectively immutable.
|
||||
// Once created, it will always hold the same set of hooks in the same order.
|
||||
type Chain struct {
|
||||
hooks []ent.Hook
|
||||
}
|
||||
|
||||
// NewChain creates a new chain of hooks.
|
||||
func NewChain(hooks ...ent.Hook) Chain {
|
||||
return Chain{append([]ent.Hook(nil), hooks...)}
|
||||
}
|
||||
|
||||
// Hook chains the list of hooks and returns the final hook.
|
||||
func (c Chain) Hook() ent.Hook {
|
||||
return func(mutator ent.Mutator) ent.Mutator {
|
||||
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||
mutator = c.hooks[i](mutator)
|
||||
}
|
||||
return mutator
|
||||
}
|
||||
}
|
||||
|
||||
// Append extends a chain, adding the specified hook
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Append(hooks ...ent.Hook) Chain {
|
||||
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
|
||||
newHooks = append(newHooks, c.hooks...)
|
||||
newHooks = append(newHooks, hooks...)
|
||||
return Chain{newHooks}
|
||||
}
|
||||
|
||||
// Extend extends a chain, adding the specified chain
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Extend(chain Chain) Chain {
|
||||
return c.Append(chain.hooks...)
|
||||
}
|
136
server/ent/jdmodel.go
Normal file
136
server/ent/jdmodel.go
Normal file
@@ -0,0 +1,136 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/kallydev/privacy/ent/jdmodel"
|
||||
)
|
||||
|
||||
// JDModel is the model entity for the JDModel schema.
|
||||
type JDModel struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Nickname holds the value of the "nickname" field.
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
// Password holds the value of the "password" field.
|
||||
Password string `json:"password,omitempty"`
|
||||
// Email holds the value of the "email" field.
|
||||
Email string `json:"email,omitempty"`
|
||||
// IDNumber holds the value of the "id_number" field.
|
||||
IDNumber string `json:"id_number,omitempty"`
|
||||
// PhoneNumber holds the value of the "phone_number" field.
|
||||
PhoneNumber int64 `json:"phone_number,omitempty"`
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*JDModel) scanValues() []interface{} {
|
||||
return []interface{}{
|
||||
&sql.NullInt64{}, // id
|
||||
&sql.NullString{}, // name
|
||||
&sql.NullString{}, // nickname
|
||||
&sql.NullString{}, // password
|
||||
&sql.NullString{}, // email
|
||||
&sql.NullString{}, // id_number
|
||||
&sql.NullInt64{}, // phone_number
|
||||
}
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the JDModel fields.
|
||||
func (jm *JDModel) assignValues(values ...interface{}) error {
|
||||
if m, n := len(values), len(jdmodel.Columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
value, ok := values[0].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
jm.ID = int(value.Int64)
|
||||
values = values[1:]
|
||||
if value, ok := values[0].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[0])
|
||||
} else if value.Valid {
|
||||
jm.Name = value.String
|
||||
}
|
||||
if value, ok := values[1].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field nickname", values[1])
|
||||
} else if value.Valid {
|
||||
jm.Nickname = value.String
|
||||
}
|
||||
if value, ok := values[2].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field password", values[2])
|
||||
} else if value.Valid {
|
||||
jm.Password = value.String
|
||||
}
|
||||
if value, ok := values[3].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field email", values[3])
|
||||
} else if value.Valid {
|
||||
jm.Email = value.String
|
||||
}
|
||||
if value, ok := values[4].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id_number", values[4])
|
||||
} else if value.Valid {
|
||||
jm.IDNumber = value.String
|
||||
}
|
||||
if value, ok := values[5].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field phone_number", values[5])
|
||||
} else if value.Valid {
|
||||
jm.PhoneNumber = value.Int64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this JDModel.
|
||||
// Note that, you need to call JDModel.Unwrap() before calling this method, if this JDModel
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (jm *JDModel) Update() *JDModelUpdateOne {
|
||||
return (&JDModelClient{config: jm.config}).UpdateOne(jm)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
|
||||
// so that all next queries will be executed through the driver which created the transaction.
|
||||
func (jm *JDModel) Unwrap() *JDModel {
|
||||
tx, ok := jm.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: JDModel is not a transactional entity")
|
||||
}
|
||||
jm.config.driver = tx.drv
|
||||
return jm
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (jm *JDModel) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("JDModel(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", jm.ID))
|
||||
builder.WriteString(", name=")
|
||||
builder.WriteString(jm.Name)
|
||||
builder.WriteString(", nickname=")
|
||||
builder.WriteString(jm.Nickname)
|
||||
builder.WriteString(", password=")
|
||||
builder.WriteString(jm.Password)
|
||||
builder.WriteString(", email=")
|
||||
builder.WriteString(jm.Email)
|
||||
builder.WriteString(", id_number=")
|
||||
builder.WriteString(jm.IDNumber)
|
||||
builder.WriteString(", phone_number=")
|
||||
builder.WriteString(fmt.Sprintf("%v", jm.PhoneNumber))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// JDModels is a parsable slice of JDModel.
|
||||
type JDModels []*JDModel
|
||||
|
||||
func (jm JDModels) config(cfg config) {
|
||||
for _i := range jm {
|
||||
jm[_i].config = cfg
|
||||
}
|
||||
}
|
46
server/ent/jdmodel/jdmodel.go
Normal file
46
server/ent/jdmodel/jdmodel.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package jdmodel
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the jdmodel type in the database.
|
||||
Label = "jd_model"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldNickname holds the string denoting the nickname field in the database.
|
||||
FieldNickname = "nickname"
|
||||
// FieldPassword holds the string denoting the password field in the database.
|
||||
FieldPassword = "password"
|
||||
// FieldEmail holds the string denoting the email field in the database.
|
||||
FieldEmail = "email"
|
||||
// FieldIDNumber holds the string denoting the id_number field in the database.
|
||||
FieldIDNumber = "id_number"
|
||||
// FieldPhoneNumber holds the string denoting the phone_number field in the database.
|
||||
FieldPhoneNumber = "phone_number"
|
||||
|
||||
// Table holds the table name of the jdmodel in the database.
|
||||
Table = "jd"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for jdmodel fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
FieldNickname,
|
||||
FieldPassword,
|
||||
FieldEmail,
|
||||
FieldIDNumber,
|
||||
FieldPhoneNumber,
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
796
server/ent/jdmodel/where.go
Normal file
796
server/ent/jdmodel/where.go
Normal file
@@ -0,0 +1,796 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package jdmodel
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their identifier.
|
||||
func ID(id int) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// Nickname applies equality check predicate on the "nickname" field. It's identical to NicknameEQ.
|
||||
func Nickname(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
|
||||
func Password(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// Email applies equality check predicate on the "email" field. It's identical to EmailEQ.
|
||||
func Email(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumber applies equality check predicate on the "id_number" field. It's identical to IDNumberEQ.
|
||||
func IDNumber(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumber applies equality check predicate on the "phone_number" field. It's identical to PhoneNumberEQ.
|
||||
func PhoneNumber(v int64) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldName), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldName), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameEQ applies the EQ predicate on the "nickname" field.
|
||||
func NicknameEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameNEQ applies the NEQ predicate on the "nickname" field.
|
||||
func NicknameNEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameIn applies the In predicate on the "nickname" field.
|
||||
func NicknameIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldNickname), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameNotIn applies the NotIn predicate on the "nickname" field.
|
||||
func NicknameNotIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldNickname), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameGT applies the GT predicate on the "nickname" field.
|
||||
func NicknameGT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameGTE applies the GTE predicate on the "nickname" field.
|
||||
func NicknameGTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameLT applies the LT predicate on the "nickname" field.
|
||||
func NicknameLT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameLTE applies the LTE predicate on the "nickname" field.
|
||||
func NicknameLTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameContains applies the Contains predicate on the "nickname" field.
|
||||
func NicknameContains(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameHasPrefix applies the HasPrefix predicate on the "nickname" field.
|
||||
func NicknameHasPrefix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameHasSuffix applies the HasSuffix predicate on the "nickname" field.
|
||||
func NicknameHasSuffix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameEqualFold applies the EqualFold predicate on the "nickname" field.
|
||||
func NicknameEqualFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NicknameContainsFold applies the ContainsFold predicate on the "nickname" field.
|
||||
func NicknameContainsFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldNickname), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordEQ applies the EQ predicate on the "password" field.
|
||||
func PasswordEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordNEQ applies the NEQ predicate on the "password" field.
|
||||
func PasswordNEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordIn applies the In predicate on the "password" field.
|
||||
func PasswordIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldPassword), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordNotIn applies the NotIn predicate on the "password" field.
|
||||
func PasswordNotIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldPassword), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordGT applies the GT predicate on the "password" field.
|
||||
func PasswordGT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordGTE applies the GTE predicate on the "password" field.
|
||||
func PasswordGTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordLT applies the LT predicate on the "password" field.
|
||||
func PasswordLT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordLTE applies the LTE predicate on the "password" field.
|
||||
func PasswordLTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordContains applies the Contains predicate on the "password" field.
|
||||
func PasswordContains(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
|
||||
func PasswordHasPrefix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
|
||||
func PasswordHasSuffix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
|
||||
func PasswordEqualFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
|
||||
func PasswordContainsFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldPassword), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailEQ applies the EQ predicate on the "email" field.
|
||||
func EmailEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailNEQ applies the NEQ predicate on the "email" field.
|
||||
func EmailNEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailIn applies the In predicate on the "email" field.
|
||||
func EmailIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldEmail), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailNotIn applies the NotIn predicate on the "email" field.
|
||||
func EmailNotIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldEmail), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailGT applies the GT predicate on the "email" field.
|
||||
func EmailGT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailGTE applies the GTE predicate on the "email" field.
|
||||
func EmailGTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailLT applies the LT predicate on the "email" field.
|
||||
func EmailLT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailLTE applies the LTE predicate on the "email" field.
|
||||
func EmailLTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailContains applies the Contains predicate on the "email" field.
|
||||
func EmailContains(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailHasPrefix applies the HasPrefix predicate on the "email" field.
|
||||
func EmailHasPrefix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailHasSuffix applies the HasSuffix predicate on the "email" field.
|
||||
func EmailHasSuffix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailEqualFold applies the EqualFold predicate on the "email" field.
|
||||
func EmailEqualFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// EmailContainsFold applies the ContainsFold predicate on the "email" field.
|
||||
func EmailContainsFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldEmail), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberEQ applies the EQ predicate on the "id_number" field.
|
||||
func IDNumberEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberNEQ applies the NEQ predicate on the "id_number" field.
|
||||
func IDNumberNEQ(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberIn applies the In predicate on the "id_number" field.
|
||||
func IDNumberIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldIDNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberNotIn applies the NotIn predicate on the "id_number" field.
|
||||
func IDNumberNotIn(vs ...string) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldIDNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberGT applies the GT predicate on the "id_number" field.
|
||||
func IDNumberGT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberGTE applies the GTE predicate on the "id_number" field.
|
||||
func IDNumberGTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberLT applies the LT predicate on the "id_number" field.
|
||||
func IDNumberLT(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberLTE applies the LTE predicate on the "id_number" field.
|
||||
func IDNumberLTE(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberContains applies the Contains predicate on the "id_number" field.
|
||||
func IDNumberContains(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberHasPrefix applies the HasPrefix predicate on the "id_number" field.
|
||||
func IDNumberHasPrefix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberHasSuffix applies the HasSuffix predicate on the "id_number" field.
|
||||
func IDNumberHasSuffix(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberEqualFold applies the EqualFold predicate on the "id_number" field.
|
||||
func IDNumberEqualFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNumberContainsFold applies the ContainsFold predicate on the "id_number" field.
|
||||
func IDNumberContainsFold(v string) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldIDNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberEQ applies the EQ predicate on the "phone_number" field.
|
||||
func PhoneNumberEQ(v int64) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberNEQ applies the NEQ predicate on the "phone_number" field.
|
||||
func PhoneNumberNEQ(v int64) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberIn applies the In predicate on the "phone_number" field.
|
||||
func PhoneNumberIn(vs ...int64) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldPhoneNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberNotIn applies the NotIn predicate on the "phone_number" field.
|
||||
func PhoneNumberNotIn(vs ...int64) predicate.JDModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldPhoneNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberGT applies the GT predicate on the "phone_number" field.
|
||||
func PhoneNumberGT(v int64) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberGTE applies the GTE predicate on the "phone_number" field.
|
||||
func PhoneNumberGTE(v int64) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberLT applies the LT predicate on the "phone_number" field.
|
||||
func PhoneNumberLT(v int64) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberLTE applies the LTE predicate on the "phone_number" field.
|
||||
func PhoneNumberLTE(v int64) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// And groups list of predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.JDModel) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Or groups list of predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.JDModel) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.JDModel) predicate.JDModel {
|
||||
return predicate.JDModel(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
269
server/ent/jdmodel_create.go
Normal file
269
server/ent/jdmodel_create.go
Normal file
@@ -0,0 +1,269 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/jdmodel"
|
||||
)
|
||||
|
||||
// JDModelCreate is the builder for creating a JDModel entity.
|
||||
type JDModelCreate struct {
|
||||
config
|
||||
mutation *JDModelMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the name field.
|
||||
func (jmc *JDModelCreate) SetName(s string) *JDModelCreate {
|
||||
jmc.mutation.SetName(s)
|
||||
return jmc
|
||||
}
|
||||
|
||||
// SetNickname sets the nickname field.
|
||||
func (jmc *JDModelCreate) SetNickname(s string) *JDModelCreate {
|
||||
jmc.mutation.SetNickname(s)
|
||||
return jmc
|
||||
}
|
||||
|
||||
// SetPassword sets the password field.
|
||||
func (jmc *JDModelCreate) SetPassword(s string) *JDModelCreate {
|
||||
jmc.mutation.SetPassword(s)
|
||||
return jmc
|
||||
}
|
||||
|
||||
// SetEmail sets the email field.
|
||||
func (jmc *JDModelCreate) SetEmail(s string) *JDModelCreate {
|
||||
jmc.mutation.SetEmail(s)
|
||||
return jmc
|
||||
}
|
||||
|
||||
// SetIDNumber sets the id_number field.
|
||||
func (jmc *JDModelCreate) SetIDNumber(s string) *JDModelCreate {
|
||||
jmc.mutation.SetIDNumber(s)
|
||||
return jmc
|
||||
}
|
||||
|
||||
// SetPhoneNumber sets the phone_number field.
|
||||
func (jmc *JDModelCreate) SetPhoneNumber(i int64) *JDModelCreate {
|
||||
jmc.mutation.SetPhoneNumber(i)
|
||||
return jmc
|
||||
}
|
||||
|
||||
// Mutation returns the JDModelMutation object of the builder.
|
||||
func (jmc *JDModelCreate) Mutation() *JDModelMutation {
|
||||
return jmc.mutation
|
||||
}
|
||||
|
||||
// Save creates the JDModel in the database.
|
||||
func (jmc *JDModelCreate) Save(ctx context.Context) (*JDModel, error) {
|
||||
var (
|
||||
err error
|
||||
node *JDModel
|
||||
)
|
||||
if len(jmc.hooks) == 0 {
|
||||
if err = jmc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = jmc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*JDModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = jmc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jmc.mutation = mutation
|
||||
node, err = jmc.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(jmc.hooks) - 1; i >= 0; i-- {
|
||||
mut = jmc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, jmc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (jmc *JDModelCreate) SaveX(ctx context.Context) *JDModel {
|
||||
v, err := jmc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (jmc *JDModelCreate) check() error {
|
||||
if _, ok := jmc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New("ent: missing required field \"name\"")}
|
||||
}
|
||||
if _, ok := jmc.mutation.Nickname(); !ok {
|
||||
return &ValidationError{Name: "nickname", err: errors.New("ent: missing required field \"nickname\"")}
|
||||
}
|
||||
if _, ok := jmc.mutation.Password(); !ok {
|
||||
return &ValidationError{Name: "password", err: errors.New("ent: missing required field \"password\"")}
|
||||
}
|
||||
if _, ok := jmc.mutation.Email(); !ok {
|
||||
return &ValidationError{Name: "email", err: errors.New("ent: missing required field \"email\"")}
|
||||
}
|
||||
if _, ok := jmc.mutation.IDNumber(); !ok {
|
||||
return &ValidationError{Name: "id_number", err: errors.New("ent: missing required field \"id_number\"")}
|
||||
}
|
||||
if _, ok := jmc.mutation.PhoneNumber(); !ok {
|
||||
return &ValidationError{Name: "phone_number", err: errors.New("ent: missing required field \"phone_number\"")}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (jmc *JDModelCreate) sqlSave(ctx context.Context) (*JDModel, error) {
|
||||
_node, _spec := jmc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, jmc.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (jmc *JDModelCreate) createSpec() (*JDModel, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &JDModel{config: jmc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: jdmodel.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: jdmodel.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := jmc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldName,
|
||||
})
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := jmc.mutation.Nickname(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldNickname,
|
||||
})
|
||||
_node.Nickname = value
|
||||
}
|
||||
if value, ok := jmc.mutation.Password(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldPassword,
|
||||
})
|
||||
_node.Password = value
|
||||
}
|
||||
if value, ok := jmc.mutation.Email(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldEmail,
|
||||
})
|
||||
_node.Email = value
|
||||
}
|
||||
if value, ok := jmc.mutation.IDNumber(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldIDNumber,
|
||||
})
|
||||
_node.IDNumber = value
|
||||
}
|
||||
if value, ok := jmc.mutation.PhoneNumber(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldPhoneNumber,
|
||||
})
|
||||
_node.PhoneNumber = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// JDModelCreateBulk is the builder for creating a bulk of JDModel entities.
|
||||
type JDModelCreateBulk struct {
|
||||
config
|
||||
builders []*JDModelCreate
|
||||
}
|
||||
|
||||
// Save creates the JDModel entities in the database.
|
||||
func (jmcb *JDModelCreateBulk) Save(ctx context.Context) ([]*JDModel, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(jmcb.builders))
|
||||
nodes := make([]*JDModel, len(jmcb.builders))
|
||||
mutators := make([]Mutator, len(jmcb.builders))
|
||||
for i := range jmcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := jmcb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*JDModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, jmcb.builders[i+1].mutation)
|
||||
} else {
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, jmcb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
}
|
||||
}
|
||||
mutation.done = true
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
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, jmcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (jmcb *JDModelCreateBulk) SaveX(ctx context.Context) []*JDModel {
|
||||
v, err := jmcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
108
server/ent/jdmodel_delete.go
Normal file
108
server/ent/jdmodel_delete.go
Normal file
@@ -0,0 +1,108 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/jdmodel"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
)
|
||||
|
||||
// JDModelDelete is the builder for deleting a JDModel entity.
|
||||
type JDModelDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *JDModelMutation
|
||||
}
|
||||
|
||||
// Where adds a new predicate to the delete builder.
|
||||
func (jmd *JDModelDelete) Where(ps ...predicate.JDModel) *JDModelDelete {
|
||||
jmd.mutation.predicates = append(jmd.mutation.predicates, ps...)
|
||||
return jmd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (jmd *JDModelDelete) Exec(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(jmd.hooks) == 0 {
|
||||
affected, err = jmd.sqlExec(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*JDModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
jmd.mutation = mutation
|
||||
affected, err = jmd.sqlExec(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(jmd.hooks) - 1; i >= 0; i-- {
|
||||
mut = jmd.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, jmd.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (jmd *JDModelDelete) ExecX(ctx context.Context) int {
|
||||
n, err := jmd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (jmd *JDModelDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: jdmodel.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: jdmodel.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := jmd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlgraph.DeleteNodes(ctx, jmd.driver, _spec)
|
||||
}
|
||||
|
||||
// JDModelDeleteOne is the builder for deleting a single JDModel entity.
|
||||
type JDModelDeleteOne struct {
|
||||
jmd *JDModelDelete
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (jmdo *JDModelDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := jmdo.jmd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (jmdo *JDModelDeleteOne) ExecX(ctx context.Context) {
|
||||
jmdo.jmd.ExecX(ctx)
|
||||
}
|
883
server/ent/jdmodel_query.go
Normal file
883
server/ent/jdmodel_query.go
Normal file
@@ -0,0 +1,883 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/jdmodel"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
)
|
||||
|
||||
// JDModelQuery is the builder for querying JDModel entities.
|
||||
type JDModelQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
order []OrderFunc
|
||||
unique []string
|
||||
predicates []predicate.JDModel
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (jmq *JDModelQuery) Where(ps ...predicate.JDModel) *JDModelQuery {
|
||||
jmq.predicates = append(jmq.predicates, ps...)
|
||||
return jmq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
func (jmq *JDModelQuery) Limit(limit int) *JDModelQuery {
|
||||
jmq.limit = &limit
|
||||
return jmq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
func (jmq *JDModelQuery) Offset(offset int) *JDModelQuery {
|
||||
jmq.offset = &offset
|
||||
return jmq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (jmq *JDModelQuery) Order(o ...OrderFunc) *JDModelQuery {
|
||||
jmq.order = append(jmq.order, o...)
|
||||
return jmq
|
||||
}
|
||||
|
||||
// First returns the first JDModel entity in the query. Returns *NotFoundError when no jdmodel was found.
|
||||
func (jmq *JDModelQuery) First(ctx context.Context) (*JDModel, error) {
|
||||
nodes, err := jmq.Limit(1).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{jdmodel.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (jmq *JDModelQuery) FirstX(ctx context.Context) *JDModel {
|
||||
node, err := jmq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first JDModel id in the query. Returns *NotFoundError when no id was found.
|
||||
func (jmq *JDModelQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = jmq.Limit(1).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (jmq *JDModelQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := jmq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns the only JDModel entity in the query, returns an error if not exactly one entity was returned.
|
||||
func (jmq *JDModelQuery) Only(ctx context.Context) (*JDModel, error) {
|
||||
nodes, err := jmq.Limit(2).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{jdmodel.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (jmq *JDModelQuery) OnlyX(ctx context.Context) *JDModel {
|
||||
node, err := jmq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID returns the only JDModel id in the query, returns an error if not exactly one id was returned.
|
||||
func (jmq *JDModelQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = jmq.Limit(2).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
err = &NotSingularError{jdmodel.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (jmq *JDModelQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := jmq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of JDModels.
|
||||
func (jmq *JDModelQuery) All(ctx context.Context) ([]*JDModel, error) {
|
||||
if err := jmq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return jmq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (jmq *JDModelQuery) AllX(ctx context.Context) []*JDModel {
|
||||
nodes, err := jmq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of JDModel ids.
|
||||
func (jmq *JDModelQuery) IDs(ctx context.Context) ([]int, error) {
|
||||
var ids []int
|
||||
if err := jmq.Select(jdmodel.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (jmq *JDModelQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := jmq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (jmq *JDModelQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := jmq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return jmq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (jmq *JDModelQuery) CountX(ctx context.Context) int {
|
||||
count, err := jmq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (jmq *JDModelQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := jmq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return jmq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (jmq *JDModelQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := jmq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the query builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (jmq *JDModelQuery) Clone() *JDModelQuery {
|
||||
if jmq == nil {
|
||||
return nil
|
||||
}
|
||||
return &JDModelQuery{
|
||||
config: jmq.config,
|
||||
limit: jmq.limit,
|
||||
offset: jmq.offset,
|
||||
order: append([]OrderFunc{}, jmq.order...),
|
||||
unique: append([]string{}, jmq.unique...),
|
||||
predicates: append([]predicate.JDModel{}, jmq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: jmq.sql.Clone(),
|
||||
path: jmq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy 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 {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.JDModel.Query().
|
||||
// GroupBy(jdmodel.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (jmq *JDModelQuery) GroupBy(field string, fields ...string) *JDModelGroupBy {
|
||||
group := &JDModelGroupBy{config: jmq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := jmq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return jmq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
// Select one or more fields from the given query.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.JDModel.Query().
|
||||
// Select(jdmodel.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (jmq *JDModelQuery) Select(field string, fields ...string) *JDModelSelect {
|
||||
selector := &JDModelSelect{config: jmq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := jmq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return jmq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (jmq *JDModelQuery) prepareQuery(ctx context.Context) error {
|
||||
if jmq.path != nil {
|
||||
prev, err := jmq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jmq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (jmq *JDModelQuery) sqlAll(ctx context.Context) ([]*JDModel, error) {
|
||||
var (
|
||||
nodes = []*JDModel{}
|
||||
_spec = jmq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func() []interface{} {
|
||||
node := &JDModel{config: jmq.config}
|
||||
nodes = append(nodes, node)
|
||||
values := node.scanValues()
|
||||
return values
|
||||
}
|
||||
_spec.Assign = func(values ...interface{}) error {
|
||||
if len(nodes) == 0 {
|
||||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
return node.assignValues(values...)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, jmq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (jmq *JDModelQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := jmq.querySpec()
|
||||
return sqlgraph.CountNodes(ctx, jmq.driver, _spec)
|
||||
}
|
||||
|
||||
func (jmq *JDModelQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
n, err := jmq.sqlCount(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("ent: check existence: %v", err)
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (jmq *JDModelQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: jdmodel.Table,
|
||||
Columns: jdmodel.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: jdmodel.FieldID,
|
||||
},
|
||||
},
|
||||
From: jmq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if ps := jmq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := jmq.limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := jmq.offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := jmq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector, jdmodel.ValidColumn)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (jmq *JDModelQuery) sqlQuery() *sql.Selector {
|
||||
builder := sql.Dialect(jmq.driver.Dialect())
|
||||
t1 := builder.Table(jdmodel.Table)
|
||||
selector := builder.Select(t1.Columns(jdmodel.Columns...)...).From(t1)
|
||||
if jmq.sql != nil {
|
||||
selector = jmq.sql
|
||||
selector.Select(selector.Columns(jdmodel.Columns...)...)
|
||||
}
|
||||
for _, p := range jmq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range jmq.order {
|
||||
p(selector, jdmodel.ValidColumn)
|
||||
}
|
||||
if offset := jmq.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 := jmq.limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// JDModelGroupBy is the builder for group-by JDModel entities.
|
||||
type JDModelGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (jmgb *JDModelGroupBy) Aggregate(fns ...AggregateFunc) *JDModelGroupBy {
|
||||
jmgb.fns = append(jmgb.fns, fns...)
|
||||
return jmgb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (jmgb *JDModelGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := jmgb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jmgb.sql = query
|
||||
return jmgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (jmgb *JDModelGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := jmgb.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field.
|
||||
func (jmgb *JDModelGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(jmgb.fields) > 1 {
|
||||
return nil, errors.New("ent: JDModelGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := jmgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (jmgb *JDModelGroupBy) StringsX(ctx context.Context) []string {
|
||||
v, err := jmgb.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from group-by. It is only allowed when querying group-by with one field.
|
||||
func (jmgb *JDModelGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = jmgb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: JDModelGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (jmgb *JDModelGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := jmgb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
|
||||
func (jmgb *JDModelGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(jmgb.fields) > 1 {
|
||||
return nil, errors.New("ent: JDModelGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := jmgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (jmgb *JDModelGroupBy) IntsX(ctx context.Context) []int {
|
||||
v, err := jmgb.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from group-by. It is only allowed when querying group-by with one field.
|
||||
func (jmgb *JDModelGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = jmgb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: JDModelGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (jmgb *JDModelGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := jmgb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
|
||||
func (jmgb *JDModelGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(jmgb.fields) > 1 {
|
||||
return nil, errors.New("ent: JDModelGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := jmgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (jmgb *JDModelGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := jmgb.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field.
|
||||
func (jmgb *JDModelGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = jmgb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: JDModelGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (jmgb *JDModelGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := jmgb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
|
||||
func (jmgb *JDModelGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(jmgb.fields) > 1 {
|
||||
return nil, errors.New("ent: JDModelGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := jmgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (jmgb *JDModelGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
v, err := jmgb.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field.
|
||||
func (jmgb *JDModelGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = jmgb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: JDModelGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (jmgb *JDModelGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := jmgb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (jmgb *JDModelGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
for _, f := range jmgb.fields {
|
||||
if !jdmodel.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||
}
|
||||
}
|
||||
selector := jmgb.sqlQuery()
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := jmgb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (jmgb *JDModelGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := jmgb.sql
|
||||
columns := make([]string, 0, len(jmgb.fields)+len(jmgb.fns))
|
||||
columns = append(columns, jmgb.fields...)
|
||||
for _, fn := range jmgb.fns {
|
||||
columns = append(columns, fn(selector, jdmodel.ValidColumn))
|
||||
}
|
||||
return selector.Select(columns...).GroupBy(jmgb.fields...)
|
||||
}
|
||||
|
||||
// JDModelSelect is the builder for select fields of JDModel entities.
|
||||
type JDModelSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (jms *JDModelSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := jms.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jms.sql = query
|
||||
return jms.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (jms *JDModelSelect) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := jms.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from selector. It is only allowed when selecting one field.
|
||||
func (jms *JDModelSelect) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(jms.fields) > 1 {
|
||||
return nil, errors.New("ent: JDModelSelect.Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := jms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (jms *JDModelSelect) StringsX(ctx context.Context) []string {
|
||||
v, err := jms.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (jms *JDModelSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = jms.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: JDModelSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (jms *JDModelSelect) StringX(ctx context.Context) string {
|
||||
v, err := jms.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from selector. It is only allowed when selecting one field.
|
||||
func (jms *JDModelSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(jms.fields) > 1 {
|
||||
return nil, errors.New("ent: JDModelSelect.Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := jms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (jms *JDModelSelect) IntsX(ctx context.Context) []int {
|
||||
v, err := jms.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (jms *JDModelSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = jms.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: JDModelSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (jms *JDModelSelect) IntX(ctx context.Context) int {
|
||||
v, err := jms.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from selector. It is only allowed when selecting one field.
|
||||
func (jms *JDModelSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(jms.fields) > 1 {
|
||||
return nil, errors.New("ent: JDModelSelect.Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := jms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (jms *JDModelSelect) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := jms.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (jms *JDModelSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = jms.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: JDModelSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (jms *JDModelSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := jms.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from selector. It is only allowed when selecting one field.
|
||||
func (jms *JDModelSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(jms.fields) > 1 {
|
||||
return nil, errors.New("ent: JDModelSelect.Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := jms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (jms *JDModelSelect) BoolsX(ctx context.Context) []bool {
|
||||
v, err := jms.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (jms *JDModelSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = jms.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: JDModelSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (jms *JDModelSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := jms.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (jms *JDModelSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
for _, f := range jms.fields {
|
||||
if !jdmodel.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for selection", f)}
|
||||
}
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := jms.sqlQuery().Query()
|
||||
if err := jms.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (jms *JDModelSelect) sqlQuery() sql.Querier {
|
||||
selector := jms.sql
|
||||
selector.Select(selector.Columns(jms.fields...)...)
|
||||
return selector
|
||||
}
|
389
server/ent/jdmodel_update.go
Normal file
389
server/ent/jdmodel_update.go
Normal file
@@ -0,0 +1,389 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/jdmodel"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
)
|
||||
|
||||
// JDModelUpdate is the builder for updating JDModel entities.
|
||||
type JDModelUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *JDModelMutation
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (jmu *JDModelUpdate) Where(ps ...predicate.JDModel) *JDModelUpdate {
|
||||
jmu.mutation.predicates = append(jmu.mutation.predicates, ps...)
|
||||
return jmu
|
||||
}
|
||||
|
||||
// SetName sets the name field.
|
||||
func (jmu *JDModelUpdate) SetName(s string) *JDModelUpdate {
|
||||
jmu.mutation.SetName(s)
|
||||
return jmu
|
||||
}
|
||||
|
||||
// SetNickname sets the nickname field.
|
||||
func (jmu *JDModelUpdate) SetNickname(s string) *JDModelUpdate {
|
||||
jmu.mutation.SetNickname(s)
|
||||
return jmu
|
||||
}
|
||||
|
||||
// SetPassword sets the password field.
|
||||
func (jmu *JDModelUpdate) SetPassword(s string) *JDModelUpdate {
|
||||
jmu.mutation.SetPassword(s)
|
||||
return jmu
|
||||
}
|
||||
|
||||
// SetEmail sets the email field.
|
||||
func (jmu *JDModelUpdate) SetEmail(s string) *JDModelUpdate {
|
||||
jmu.mutation.SetEmail(s)
|
||||
return jmu
|
||||
}
|
||||
|
||||
// SetIDNumber sets the id_number field.
|
||||
func (jmu *JDModelUpdate) SetIDNumber(s string) *JDModelUpdate {
|
||||
jmu.mutation.SetIDNumber(s)
|
||||
return jmu
|
||||
}
|
||||
|
||||
// SetPhoneNumber sets the phone_number field.
|
||||
func (jmu *JDModelUpdate) SetPhoneNumber(i int64) *JDModelUpdate {
|
||||
jmu.mutation.ResetPhoneNumber()
|
||||
jmu.mutation.SetPhoneNumber(i)
|
||||
return jmu
|
||||
}
|
||||
|
||||
// AddPhoneNumber adds i to phone_number.
|
||||
func (jmu *JDModelUpdate) AddPhoneNumber(i int64) *JDModelUpdate {
|
||||
jmu.mutation.AddPhoneNumber(i)
|
||||
return jmu
|
||||
}
|
||||
|
||||
// Mutation returns the JDModelMutation object of the builder.
|
||||
func (jmu *JDModelUpdate) Mutation() *JDModelMutation {
|
||||
return jmu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
||||
func (jmu *JDModelUpdate) Save(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(jmu.hooks) == 0 {
|
||||
affected, err = jmu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*JDModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
jmu.mutation = mutation
|
||||
affected, err = jmu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(jmu.hooks) - 1; i >= 0; i-- {
|
||||
mut = jmu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, jmu.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (jmu *JDModelUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := jmu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (jmu *JDModelUpdate) Exec(ctx context.Context) error {
|
||||
_, err := jmu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (jmu *JDModelUpdate) ExecX(ctx context.Context) {
|
||||
if err := jmu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (jmu *JDModelUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: jdmodel.Table,
|
||||
Columns: jdmodel.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: jdmodel.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := jmu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := jmu.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldName,
|
||||
})
|
||||
}
|
||||
if value, ok := jmu.mutation.Nickname(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldNickname,
|
||||
})
|
||||
}
|
||||
if value, ok := jmu.mutation.Password(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldPassword,
|
||||
})
|
||||
}
|
||||
if value, ok := jmu.mutation.Email(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldEmail,
|
||||
})
|
||||
}
|
||||
if value, ok := jmu.mutation.IDNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldIDNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := jmu.mutation.PhoneNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := jmu.mutation.AddedPhoneNumber(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, jmu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// JDModelUpdateOne is the builder for updating a single JDModel entity.
|
||||
type JDModelUpdateOne struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *JDModelMutation
|
||||
}
|
||||
|
||||
// SetName sets the name field.
|
||||
func (jmuo *JDModelUpdateOne) SetName(s string) *JDModelUpdateOne {
|
||||
jmuo.mutation.SetName(s)
|
||||
return jmuo
|
||||
}
|
||||
|
||||
// SetNickname sets the nickname field.
|
||||
func (jmuo *JDModelUpdateOne) SetNickname(s string) *JDModelUpdateOne {
|
||||
jmuo.mutation.SetNickname(s)
|
||||
return jmuo
|
||||
}
|
||||
|
||||
// SetPassword sets the password field.
|
||||
func (jmuo *JDModelUpdateOne) SetPassword(s string) *JDModelUpdateOne {
|
||||
jmuo.mutation.SetPassword(s)
|
||||
return jmuo
|
||||
}
|
||||
|
||||
// SetEmail sets the email field.
|
||||
func (jmuo *JDModelUpdateOne) SetEmail(s string) *JDModelUpdateOne {
|
||||
jmuo.mutation.SetEmail(s)
|
||||
return jmuo
|
||||
}
|
||||
|
||||
// SetIDNumber sets the id_number field.
|
||||
func (jmuo *JDModelUpdateOne) SetIDNumber(s string) *JDModelUpdateOne {
|
||||
jmuo.mutation.SetIDNumber(s)
|
||||
return jmuo
|
||||
}
|
||||
|
||||
// SetPhoneNumber sets the phone_number field.
|
||||
func (jmuo *JDModelUpdateOne) SetPhoneNumber(i int64) *JDModelUpdateOne {
|
||||
jmuo.mutation.ResetPhoneNumber()
|
||||
jmuo.mutation.SetPhoneNumber(i)
|
||||
return jmuo
|
||||
}
|
||||
|
||||
// AddPhoneNumber adds i to phone_number.
|
||||
func (jmuo *JDModelUpdateOne) AddPhoneNumber(i int64) *JDModelUpdateOne {
|
||||
jmuo.mutation.AddPhoneNumber(i)
|
||||
return jmuo
|
||||
}
|
||||
|
||||
// Mutation returns the JDModelMutation object of the builder.
|
||||
func (jmuo *JDModelUpdateOne) Mutation() *JDModelMutation {
|
||||
return jmuo.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated entity.
|
||||
func (jmuo *JDModelUpdateOne) Save(ctx context.Context) (*JDModel, error) {
|
||||
var (
|
||||
err error
|
||||
node *JDModel
|
||||
)
|
||||
if len(jmuo.hooks) == 0 {
|
||||
node, err = jmuo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*JDModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
jmuo.mutation = mutation
|
||||
node, err = jmuo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(jmuo.hooks) - 1; i >= 0; i-- {
|
||||
mut = jmuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, jmuo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (jmuo *JDModelUpdateOne) SaveX(ctx context.Context) *JDModel {
|
||||
node, err := jmuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (jmuo *JDModelUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := jmuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (jmuo *JDModelUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := jmuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (jmuo *JDModelUpdateOne) sqlSave(ctx context.Context) (_node *JDModel, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: jdmodel.Table,
|
||||
Columns: jdmodel.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: jdmodel.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := jmuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing JDModel.ID for update")}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if value, ok := jmuo.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldName,
|
||||
})
|
||||
}
|
||||
if value, ok := jmuo.mutation.Nickname(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldNickname,
|
||||
})
|
||||
}
|
||||
if value, ok := jmuo.mutation.Password(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldPassword,
|
||||
})
|
||||
}
|
||||
if value, ok := jmuo.mutation.Email(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldEmail,
|
||||
})
|
||||
}
|
||||
if value, ok := jmuo.mutation.IDNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldIDNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := jmuo.mutation.PhoneNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := jmuo.mutation.AddedPhoneNumber(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: jdmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
_node = &JDModel{config: jmuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues()
|
||||
if err = sqlgraph.UpdateNode(ctx, jmuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{jdmodel.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return _node, nil
|
||||
}
|
72
server/ent/migrate/migrate.go
Normal file
72
server/ent/migrate/migrate.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/facebook/ent/dialect"
|
||||
"github.com/facebook/ent/dialect/sql/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||
// for the ids of each entity (table).
|
||||
// Note that this option cannot be applied on tables that already exist.
|
||||
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||
// WithDropColumn sets the drop column option to the migration.
|
||||
// If this option is enabled, ent migration will drop old columns
|
||||
// that were used for both fields and edges. This defaults to false.
|
||||
WithDropColumn = schema.WithDropColumn
|
||||
// WithDropIndex sets the drop index option to the migration.
|
||||
// If this option is enabled, ent migration will drop old indexes
|
||||
// that were defined in the schema. This defaults to false.
|
||||
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||
// and therefore, it's recommended to enable this option to get more
|
||||
// flexibility in the schema changes.
|
||||
WithDropIndex = schema.WithDropIndex
|
||||
// WithFixture sets the foreign-key renaming option to the migration when upgrading
|
||||
// ent from v0.1.0 (issue-#285). Defaults to false.
|
||||
WithFixture = schema.WithFixture
|
||||
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||
WithForeignKeys = schema.WithForeignKeys
|
||||
)
|
||||
|
||||
// Schema is the API for creating, migrating and dropping a schema.
|
||||
type Schema struct {
|
||||
drv dialect.Driver
|
||||
universalID bool
|
||||
}
|
||||
|
||||
// NewSchema creates a new schema client.
|
||||
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||
|
||||
// Create creates all schema resources.
|
||||
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %v", err)
|
||||
}
|
||||
return migrate.Create(ctx, Tables...)
|
||||
}
|
||||
|
||||
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||
//
|
||||
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
//
|
||||
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||
drv := &schema.WriteDriver{
|
||||
Writer: w,
|
||||
Driver: s.drv,
|
||||
}
|
||||
migrate, err := schema.NewMigrate(drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %v", err)
|
||||
}
|
||||
return migrate.Create(ctx, Tables...)
|
||||
}
|
64
server/ent/migrate/schema.go
Normal file
64
server/ent/migrate/schema.go
Normal file
@@ -0,0 +1,64 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent/dialect/sql/schema"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// JdColumns holds the columns for the "jd" table.
|
||||
JdColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "nickname", Type: field.TypeString},
|
||||
{Name: "password", Type: field.TypeString},
|
||||
{Name: "email", Type: field.TypeString},
|
||||
{Name: "id_number", Type: field.TypeString},
|
||||
{Name: "phone_number", Type: field.TypeInt64},
|
||||
}
|
||||
// JdTable holds the schema information for the "jd" table.
|
||||
JdTable = &schema.Table{
|
||||
Name: "jd",
|
||||
Columns: JdColumns,
|
||||
PrimaryKey: []*schema.Column{JdColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{},
|
||||
}
|
||||
// QqColumns holds the columns for the "qq" table.
|
||||
QqColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "qq_number", Type: field.TypeInt64},
|
||||
{Name: "phone_number", Type: field.TypeInt64},
|
||||
}
|
||||
// QqTable holds the schema information for the "qq" table.
|
||||
QqTable = &schema.Table{
|
||||
Name: "qq",
|
||||
Columns: QqColumns,
|
||||
PrimaryKey: []*schema.Column{QqColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{},
|
||||
}
|
||||
// SfColumns holds the columns for the "sf" table.
|
||||
SfColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "phone_number", Type: field.TypeInt64},
|
||||
{Name: "address", Type: field.TypeString},
|
||||
}
|
||||
// SfTable holds the schema information for the "sf" table.
|
||||
SfTable = &schema.Table{
|
||||
Name: "sf",
|
||||
Columns: SfColumns,
|
||||
PrimaryKey: []*schema.Column{SfColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
JdTable,
|
||||
QqTable,
|
||||
SfTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
}
|
1493
server/ent/mutation.go
Normal file
1493
server/ent/mutation.go
Normal file
File diff suppressed because it is too large
Load Diff
16
server/ent/predicate/predicate.go
Normal file
16
server/ent/predicate/predicate.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package predicate
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// JDModel is the predicate function for jdmodel builders.
|
||||
type JDModel func(*sql.Selector)
|
||||
|
||||
// QQModel is the predicate function for qqmodel builders.
|
||||
type QQModel func(*sql.Selector)
|
||||
|
||||
// SFModel is the predicate function for sfmodel builders.
|
||||
type SFModel func(*sql.Selector)
|
96
server/ent/qqmodel.go
Normal file
96
server/ent/qqmodel.go
Normal file
@@ -0,0 +1,96 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/kallydev/privacy/ent/qqmodel"
|
||||
)
|
||||
|
||||
// QQModel is the model entity for the QQModel schema.
|
||||
type QQModel struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// QqNumber holds the value of the "qq_number" field.
|
||||
QqNumber int64 `json:"qq_number,omitempty"`
|
||||
// PhoneNumber holds the value of the "phone_number" field.
|
||||
PhoneNumber int64 `json:"phone_number,omitempty"`
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*QQModel) scanValues() []interface{} {
|
||||
return []interface{}{
|
||||
&sql.NullInt64{}, // id
|
||||
&sql.NullInt64{}, // qq_number
|
||||
&sql.NullInt64{}, // phone_number
|
||||
}
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the QQModel fields.
|
||||
func (qm *QQModel) assignValues(values ...interface{}) error {
|
||||
if m, n := len(values), len(qqmodel.Columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
value, ok := values[0].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
qm.ID = int(value.Int64)
|
||||
values = values[1:]
|
||||
if value, ok := values[0].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field qq_number", values[0])
|
||||
} else if value.Valid {
|
||||
qm.QqNumber = value.Int64
|
||||
}
|
||||
if value, ok := values[1].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field phone_number", values[1])
|
||||
} else if value.Valid {
|
||||
qm.PhoneNumber = value.Int64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this QQModel.
|
||||
// Note that, you need to call QQModel.Unwrap() before calling this method, if this QQModel
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (qm *QQModel) Update() *QQModelUpdateOne {
|
||||
return (&QQModelClient{config: qm.config}).UpdateOne(qm)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
|
||||
// so that all next queries will be executed through the driver which created the transaction.
|
||||
func (qm *QQModel) Unwrap() *QQModel {
|
||||
tx, ok := qm.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: QQModel is not a transactional entity")
|
||||
}
|
||||
qm.config.driver = tx.drv
|
||||
return qm
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (qm *QQModel) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("QQModel(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", qm.ID))
|
||||
builder.WriteString(", qq_number=")
|
||||
builder.WriteString(fmt.Sprintf("%v", qm.QqNumber))
|
||||
builder.WriteString(", phone_number=")
|
||||
builder.WriteString(fmt.Sprintf("%v", qm.PhoneNumber))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// QQModels is a parsable slice of QQModel.
|
||||
type QQModels []*QQModel
|
||||
|
||||
func (qm QQModels) config(cfg config) {
|
||||
for _i := range qm {
|
||||
qm[_i].config = cfg
|
||||
}
|
||||
}
|
34
server/ent/qqmodel/qqmodel.go
Normal file
34
server/ent/qqmodel/qqmodel.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package qqmodel
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the qqmodel type in the database.
|
||||
Label = "qq_model"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldQqNumber holds the string denoting the qq_number field in the database.
|
||||
FieldQqNumber = "qq_number"
|
||||
// FieldPhoneNumber holds the string denoting the phone_number field in the database.
|
||||
FieldPhoneNumber = "phone_number"
|
||||
|
||||
// Table holds the table name of the qqmodel in the database.
|
||||
Table = "qq"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for qqmodel fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldQqNumber,
|
||||
FieldPhoneNumber,
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
289
server/ent/qqmodel/where.go
Normal file
289
server/ent/qqmodel/where.go
Normal file
@@ -0,0 +1,289 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package qqmodel
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their identifier.
|
||||
func ID(id int) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// QqNumber applies equality check predicate on the "qq_number" field. It's identical to QqNumberEQ.
|
||||
func QqNumber(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldQqNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumber applies equality check predicate on the "phone_number" field. It's identical to PhoneNumberEQ.
|
||||
func PhoneNumber(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QqNumberEQ applies the EQ predicate on the "qq_number" field.
|
||||
func QqNumberEQ(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldQqNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QqNumberNEQ applies the NEQ predicate on the "qq_number" field.
|
||||
func QqNumberNEQ(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldQqNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QqNumberIn applies the In predicate on the "qq_number" field.
|
||||
func QqNumberIn(vs ...int64) predicate.QQModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldQqNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// QqNumberNotIn applies the NotIn predicate on the "qq_number" field.
|
||||
func QqNumberNotIn(vs ...int64) predicate.QQModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldQqNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// QqNumberGT applies the GT predicate on the "qq_number" field.
|
||||
func QqNumberGT(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldQqNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QqNumberGTE applies the GTE predicate on the "qq_number" field.
|
||||
func QqNumberGTE(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldQqNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QqNumberLT applies the LT predicate on the "qq_number" field.
|
||||
func QqNumberLT(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldQqNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// QqNumberLTE applies the LTE predicate on the "qq_number" field.
|
||||
func QqNumberLTE(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldQqNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberEQ applies the EQ predicate on the "phone_number" field.
|
||||
func PhoneNumberEQ(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberNEQ applies the NEQ predicate on the "phone_number" field.
|
||||
func PhoneNumberNEQ(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberIn applies the In predicate on the "phone_number" field.
|
||||
func PhoneNumberIn(vs ...int64) predicate.QQModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldPhoneNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberNotIn applies the NotIn predicate on the "phone_number" field.
|
||||
func PhoneNumberNotIn(vs ...int64) predicate.QQModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldPhoneNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberGT applies the GT predicate on the "phone_number" field.
|
||||
func PhoneNumberGT(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberGTE applies the GTE predicate on the "phone_number" field.
|
||||
func PhoneNumberGTE(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberLT applies the LT predicate on the "phone_number" field.
|
||||
func PhoneNumberLT(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberLTE applies the LTE predicate on the "phone_number" field.
|
||||
func PhoneNumberLTE(v int64) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// And groups list of predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.QQModel) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Or groups list of predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.QQModel) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.QQModel) predicate.QQModel {
|
||||
return predicate.QQModel(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
201
server/ent/qqmodel_create.go
Normal file
201
server/ent/qqmodel_create.go
Normal file
@@ -0,0 +1,201 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/qqmodel"
|
||||
)
|
||||
|
||||
// QQModelCreate is the builder for creating a QQModel entity.
|
||||
type QQModelCreate struct {
|
||||
config
|
||||
mutation *QQModelMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetQqNumber sets the qq_number field.
|
||||
func (qmc *QQModelCreate) SetQqNumber(i int64) *QQModelCreate {
|
||||
qmc.mutation.SetQqNumber(i)
|
||||
return qmc
|
||||
}
|
||||
|
||||
// SetPhoneNumber sets the phone_number field.
|
||||
func (qmc *QQModelCreate) SetPhoneNumber(i int64) *QQModelCreate {
|
||||
qmc.mutation.SetPhoneNumber(i)
|
||||
return qmc
|
||||
}
|
||||
|
||||
// Mutation returns the QQModelMutation object of the builder.
|
||||
func (qmc *QQModelCreate) Mutation() *QQModelMutation {
|
||||
return qmc.mutation
|
||||
}
|
||||
|
||||
// Save creates the QQModel in the database.
|
||||
func (qmc *QQModelCreate) Save(ctx context.Context) (*QQModel, error) {
|
||||
var (
|
||||
err error
|
||||
node *QQModel
|
||||
)
|
||||
if len(qmc.hooks) == 0 {
|
||||
if err = qmc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = qmc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*QQModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = qmc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qmc.mutation = mutation
|
||||
node, err = qmc.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(qmc.hooks) - 1; i >= 0; i-- {
|
||||
mut = qmc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, qmc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (qmc *QQModelCreate) SaveX(ctx context.Context) *QQModel {
|
||||
v, err := qmc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (qmc *QQModelCreate) check() error {
|
||||
if _, ok := qmc.mutation.QqNumber(); !ok {
|
||||
return &ValidationError{Name: "qq_number", err: errors.New("ent: missing required field \"qq_number\"")}
|
||||
}
|
||||
if _, ok := qmc.mutation.PhoneNumber(); !ok {
|
||||
return &ValidationError{Name: "phone_number", err: errors.New("ent: missing required field \"phone_number\"")}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qmc *QQModelCreate) sqlSave(ctx context.Context) (*QQModel, error) {
|
||||
_node, _spec := qmc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, qmc.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (qmc *QQModelCreate) createSpec() (*QQModel, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &QQModel{config: qmc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: qqmodel.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: qqmodel.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := qmc.mutation.QqNumber(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldQqNumber,
|
||||
})
|
||||
_node.QqNumber = value
|
||||
}
|
||||
if value, ok := qmc.mutation.PhoneNumber(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldPhoneNumber,
|
||||
})
|
||||
_node.PhoneNumber = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// QQModelCreateBulk is the builder for creating a bulk of QQModel entities.
|
||||
type QQModelCreateBulk struct {
|
||||
config
|
||||
builders []*QQModelCreate
|
||||
}
|
||||
|
||||
// Save creates the QQModel entities in the database.
|
||||
func (qmcb *QQModelCreateBulk) Save(ctx context.Context) ([]*QQModel, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(qmcb.builders))
|
||||
nodes := make([]*QQModel, len(qmcb.builders))
|
||||
mutators := make([]Mutator, len(qmcb.builders))
|
||||
for i := range qmcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := qmcb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*QQModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, qmcb.builders[i+1].mutation)
|
||||
} else {
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, qmcb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
}
|
||||
}
|
||||
mutation.done = true
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
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, qmcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (qmcb *QQModelCreateBulk) SaveX(ctx context.Context) []*QQModel {
|
||||
v, err := qmcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
108
server/ent/qqmodel_delete.go
Normal file
108
server/ent/qqmodel_delete.go
Normal file
@@ -0,0 +1,108 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
"github.com/kallydev/privacy/ent/qqmodel"
|
||||
)
|
||||
|
||||
// QQModelDelete is the builder for deleting a QQModel entity.
|
||||
type QQModelDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *QQModelMutation
|
||||
}
|
||||
|
||||
// Where adds a new predicate to the delete builder.
|
||||
func (qmd *QQModelDelete) Where(ps ...predicate.QQModel) *QQModelDelete {
|
||||
qmd.mutation.predicates = append(qmd.mutation.predicates, ps...)
|
||||
return qmd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (qmd *QQModelDelete) Exec(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(qmd.hooks) == 0 {
|
||||
affected, err = qmd.sqlExec(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*QQModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
qmd.mutation = mutation
|
||||
affected, err = qmd.sqlExec(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(qmd.hooks) - 1; i >= 0; i-- {
|
||||
mut = qmd.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, qmd.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (qmd *QQModelDelete) ExecX(ctx context.Context) int {
|
||||
n, err := qmd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (qmd *QQModelDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: qqmodel.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: qqmodel.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := qmd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlgraph.DeleteNodes(ctx, qmd.driver, _spec)
|
||||
}
|
||||
|
||||
// QQModelDeleteOne is the builder for deleting a single QQModel entity.
|
||||
type QQModelDeleteOne struct {
|
||||
qmd *QQModelDelete
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (qmdo *QQModelDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := qmdo.qmd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (qmdo *QQModelDeleteOne) ExecX(ctx context.Context) {
|
||||
qmdo.qmd.ExecX(ctx)
|
||||
}
|
883
server/ent/qqmodel_query.go
Normal file
883
server/ent/qqmodel_query.go
Normal file
@@ -0,0 +1,883 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
"github.com/kallydev/privacy/ent/qqmodel"
|
||||
)
|
||||
|
||||
// QQModelQuery is the builder for querying QQModel entities.
|
||||
type QQModelQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
order []OrderFunc
|
||||
unique []string
|
||||
predicates []predicate.QQModel
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (qmq *QQModelQuery) Where(ps ...predicate.QQModel) *QQModelQuery {
|
||||
qmq.predicates = append(qmq.predicates, ps...)
|
||||
return qmq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
func (qmq *QQModelQuery) Limit(limit int) *QQModelQuery {
|
||||
qmq.limit = &limit
|
||||
return qmq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
func (qmq *QQModelQuery) Offset(offset int) *QQModelQuery {
|
||||
qmq.offset = &offset
|
||||
return qmq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (qmq *QQModelQuery) Order(o ...OrderFunc) *QQModelQuery {
|
||||
qmq.order = append(qmq.order, o...)
|
||||
return qmq
|
||||
}
|
||||
|
||||
// First returns the first QQModel entity in the query. Returns *NotFoundError when no qqmodel was found.
|
||||
func (qmq *QQModelQuery) First(ctx context.Context) (*QQModel, error) {
|
||||
nodes, err := qmq.Limit(1).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{qqmodel.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (qmq *QQModelQuery) FirstX(ctx context.Context) *QQModel {
|
||||
node, err := qmq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first QQModel id in the query. Returns *NotFoundError when no id was found.
|
||||
func (qmq *QQModelQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = qmq.Limit(1).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (qmq *QQModelQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := qmq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns the only QQModel entity in the query, returns an error if not exactly one entity was returned.
|
||||
func (qmq *QQModelQuery) Only(ctx context.Context) (*QQModel, error) {
|
||||
nodes, err := qmq.Limit(2).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{qqmodel.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (qmq *QQModelQuery) OnlyX(ctx context.Context) *QQModel {
|
||||
node, err := qmq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID returns the only QQModel id in the query, returns an error if not exactly one id was returned.
|
||||
func (qmq *QQModelQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = qmq.Limit(2).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
err = &NotSingularError{qqmodel.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (qmq *QQModelQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := qmq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of QQModels.
|
||||
func (qmq *QQModelQuery) All(ctx context.Context) ([]*QQModel, error) {
|
||||
if err := qmq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return qmq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (qmq *QQModelQuery) AllX(ctx context.Context) []*QQModel {
|
||||
nodes, err := qmq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of QQModel ids.
|
||||
func (qmq *QQModelQuery) IDs(ctx context.Context) ([]int, error) {
|
||||
var ids []int
|
||||
if err := qmq.Select(qqmodel.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (qmq *QQModelQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := qmq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (qmq *QQModelQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := qmq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return qmq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (qmq *QQModelQuery) CountX(ctx context.Context) int {
|
||||
count, err := qmq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (qmq *QQModelQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := qmq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return qmq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (qmq *QQModelQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := qmq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the query builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (qmq *QQModelQuery) Clone() *QQModelQuery {
|
||||
if qmq == nil {
|
||||
return nil
|
||||
}
|
||||
return &QQModelQuery{
|
||||
config: qmq.config,
|
||||
limit: qmq.limit,
|
||||
offset: qmq.offset,
|
||||
order: append([]OrderFunc{}, qmq.order...),
|
||||
unique: append([]string{}, qmq.unique...),
|
||||
predicates: append([]predicate.QQModel{}, qmq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: qmq.sql.Clone(),
|
||||
path: qmq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy 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 {
|
||||
// QqNumber int64 `json:"qq_number,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.QQModel.Query().
|
||||
// GroupBy(qqmodel.FieldQqNumber).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (qmq *QQModelQuery) GroupBy(field string, fields ...string) *QQModelGroupBy {
|
||||
group := &QQModelGroupBy{config: qmq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := qmq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return qmq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
// Select one or more fields from the given query.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// QqNumber int64 `json:"qq_number,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.QQModel.Query().
|
||||
// Select(qqmodel.FieldQqNumber).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (qmq *QQModelQuery) Select(field string, fields ...string) *QQModelSelect {
|
||||
selector := &QQModelSelect{config: qmq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := qmq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return qmq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (qmq *QQModelQuery) prepareQuery(ctx context.Context) error {
|
||||
if qmq.path != nil {
|
||||
prev, err := qmq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qmq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qmq *QQModelQuery) sqlAll(ctx context.Context) ([]*QQModel, error) {
|
||||
var (
|
||||
nodes = []*QQModel{}
|
||||
_spec = qmq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func() []interface{} {
|
||||
node := &QQModel{config: qmq.config}
|
||||
nodes = append(nodes, node)
|
||||
values := node.scanValues()
|
||||
return values
|
||||
}
|
||||
_spec.Assign = func(values ...interface{}) error {
|
||||
if len(nodes) == 0 {
|
||||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
return node.assignValues(values...)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, qmq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (qmq *QQModelQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := qmq.querySpec()
|
||||
return sqlgraph.CountNodes(ctx, qmq.driver, _spec)
|
||||
}
|
||||
|
||||
func (qmq *QQModelQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
n, err := qmq.sqlCount(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("ent: check existence: %v", err)
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (qmq *QQModelQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: qqmodel.Table,
|
||||
Columns: qqmodel.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: qqmodel.FieldID,
|
||||
},
|
||||
},
|
||||
From: qmq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if ps := qmq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := qmq.limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := qmq.offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := qmq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector, qqmodel.ValidColumn)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (qmq *QQModelQuery) sqlQuery() *sql.Selector {
|
||||
builder := sql.Dialect(qmq.driver.Dialect())
|
||||
t1 := builder.Table(qqmodel.Table)
|
||||
selector := builder.Select(t1.Columns(qqmodel.Columns...)...).From(t1)
|
||||
if qmq.sql != nil {
|
||||
selector = qmq.sql
|
||||
selector.Select(selector.Columns(qqmodel.Columns...)...)
|
||||
}
|
||||
for _, p := range qmq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range qmq.order {
|
||||
p(selector, qqmodel.ValidColumn)
|
||||
}
|
||||
if offset := qmq.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 := qmq.limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// QQModelGroupBy is the builder for group-by QQModel entities.
|
||||
type QQModelGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (qmgb *QQModelGroupBy) Aggregate(fns ...AggregateFunc) *QQModelGroupBy {
|
||||
qmgb.fns = append(qmgb.fns, fns...)
|
||||
return qmgb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (qmgb *QQModelGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := qmgb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qmgb.sql = query
|
||||
return qmgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (qmgb *QQModelGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := qmgb.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field.
|
||||
func (qmgb *QQModelGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(qmgb.fields) > 1 {
|
||||
return nil, errors.New("ent: QQModelGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := qmgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (qmgb *QQModelGroupBy) StringsX(ctx context.Context) []string {
|
||||
v, err := qmgb.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from group-by. It is only allowed when querying group-by with one field.
|
||||
func (qmgb *QQModelGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = qmgb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: QQModelGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (qmgb *QQModelGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := qmgb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
|
||||
func (qmgb *QQModelGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(qmgb.fields) > 1 {
|
||||
return nil, errors.New("ent: QQModelGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := qmgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (qmgb *QQModelGroupBy) IntsX(ctx context.Context) []int {
|
||||
v, err := qmgb.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from group-by. It is only allowed when querying group-by with one field.
|
||||
func (qmgb *QQModelGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = qmgb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: QQModelGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (qmgb *QQModelGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := qmgb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
|
||||
func (qmgb *QQModelGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(qmgb.fields) > 1 {
|
||||
return nil, errors.New("ent: QQModelGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := qmgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (qmgb *QQModelGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := qmgb.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field.
|
||||
func (qmgb *QQModelGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = qmgb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: QQModelGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (qmgb *QQModelGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := qmgb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
|
||||
func (qmgb *QQModelGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(qmgb.fields) > 1 {
|
||||
return nil, errors.New("ent: QQModelGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := qmgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (qmgb *QQModelGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
v, err := qmgb.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field.
|
||||
func (qmgb *QQModelGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = qmgb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: QQModelGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (qmgb *QQModelGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := qmgb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (qmgb *QQModelGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
for _, f := range qmgb.fields {
|
||||
if !qqmodel.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||
}
|
||||
}
|
||||
selector := qmgb.sqlQuery()
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := qmgb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (qmgb *QQModelGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := qmgb.sql
|
||||
columns := make([]string, 0, len(qmgb.fields)+len(qmgb.fns))
|
||||
columns = append(columns, qmgb.fields...)
|
||||
for _, fn := range qmgb.fns {
|
||||
columns = append(columns, fn(selector, qqmodel.ValidColumn))
|
||||
}
|
||||
return selector.Select(columns...).GroupBy(qmgb.fields...)
|
||||
}
|
||||
|
||||
// QQModelSelect is the builder for select fields of QQModel entities.
|
||||
type QQModelSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (qms *QQModelSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := qms.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qms.sql = query
|
||||
return qms.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (qms *QQModelSelect) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := qms.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from selector. It is only allowed when selecting one field.
|
||||
func (qms *QQModelSelect) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(qms.fields) > 1 {
|
||||
return nil, errors.New("ent: QQModelSelect.Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := qms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (qms *QQModelSelect) StringsX(ctx context.Context) []string {
|
||||
v, err := qms.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (qms *QQModelSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = qms.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: QQModelSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (qms *QQModelSelect) StringX(ctx context.Context) string {
|
||||
v, err := qms.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from selector. It is only allowed when selecting one field.
|
||||
func (qms *QQModelSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(qms.fields) > 1 {
|
||||
return nil, errors.New("ent: QQModelSelect.Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := qms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (qms *QQModelSelect) IntsX(ctx context.Context) []int {
|
||||
v, err := qms.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (qms *QQModelSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = qms.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: QQModelSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (qms *QQModelSelect) IntX(ctx context.Context) int {
|
||||
v, err := qms.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from selector. It is only allowed when selecting one field.
|
||||
func (qms *QQModelSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(qms.fields) > 1 {
|
||||
return nil, errors.New("ent: QQModelSelect.Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := qms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (qms *QQModelSelect) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := qms.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (qms *QQModelSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = qms.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: QQModelSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (qms *QQModelSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := qms.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from selector. It is only allowed when selecting one field.
|
||||
func (qms *QQModelSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(qms.fields) > 1 {
|
||||
return nil, errors.New("ent: QQModelSelect.Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := qms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (qms *QQModelSelect) BoolsX(ctx context.Context) []bool {
|
||||
v, err := qms.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (qms *QQModelSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = qms.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: QQModelSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (qms *QQModelSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := qms.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (qms *QQModelSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
for _, f := range qms.fields {
|
||||
if !qqmodel.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for selection", f)}
|
||||
}
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := qms.sqlQuery().Query()
|
||||
if err := qms.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (qms *QQModelSelect) sqlQuery() sql.Querier {
|
||||
selector := qms.sql
|
||||
selector.Select(selector.Columns(qms.fields...)...)
|
||||
return selector
|
||||
}
|
313
server/ent/qqmodel_update.go
Normal file
313
server/ent/qqmodel_update.go
Normal file
@@ -0,0 +1,313 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
"github.com/kallydev/privacy/ent/qqmodel"
|
||||
)
|
||||
|
||||
// QQModelUpdate is the builder for updating QQModel entities.
|
||||
type QQModelUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *QQModelMutation
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (qmu *QQModelUpdate) Where(ps ...predicate.QQModel) *QQModelUpdate {
|
||||
qmu.mutation.predicates = append(qmu.mutation.predicates, ps...)
|
||||
return qmu
|
||||
}
|
||||
|
||||
// SetQqNumber sets the qq_number field.
|
||||
func (qmu *QQModelUpdate) SetQqNumber(i int64) *QQModelUpdate {
|
||||
qmu.mutation.ResetQqNumber()
|
||||
qmu.mutation.SetQqNumber(i)
|
||||
return qmu
|
||||
}
|
||||
|
||||
// AddQqNumber adds i to qq_number.
|
||||
func (qmu *QQModelUpdate) AddQqNumber(i int64) *QQModelUpdate {
|
||||
qmu.mutation.AddQqNumber(i)
|
||||
return qmu
|
||||
}
|
||||
|
||||
// SetPhoneNumber sets the phone_number field.
|
||||
func (qmu *QQModelUpdate) SetPhoneNumber(i int64) *QQModelUpdate {
|
||||
qmu.mutation.ResetPhoneNumber()
|
||||
qmu.mutation.SetPhoneNumber(i)
|
||||
return qmu
|
||||
}
|
||||
|
||||
// AddPhoneNumber adds i to phone_number.
|
||||
func (qmu *QQModelUpdate) AddPhoneNumber(i int64) *QQModelUpdate {
|
||||
qmu.mutation.AddPhoneNumber(i)
|
||||
return qmu
|
||||
}
|
||||
|
||||
// Mutation returns the QQModelMutation object of the builder.
|
||||
func (qmu *QQModelUpdate) Mutation() *QQModelMutation {
|
||||
return qmu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
||||
func (qmu *QQModelUpdate) Save(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(qmu.hooks) == 0 {
|
||||
affected, err = qmu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*QQModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
qmu.mutation = mutation
|
||||
affected, err = qmu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(qmu.hooks) - 1; i >= 0; i-- {
|
||||
mut = qmu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, qmu.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (qmu *QQModelUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := qmu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (qmu *QQModelUpdate) Exec(ctx context.Context) error {
|
||||
_, err := qmu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (qmu *QQModelUpdate) ExecX(ctx context.Context) {
|
||||
if err := qmu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (qmu *QQModelUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: qqmodel.Table,
|
||||
Columns: qqmodel.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: qqmodel.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := qmu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := qmu.mutation.QqNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldQqNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := qmu.mutation.AddedQqNumber(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldQqNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := qmu.mutation.PhoneNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := qmu.mutation.AddedPhoneNumber(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, qmu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// QQModelUpdateOne is the builder for updating a single QQModel entity.
|
||||
type QQModelUpdateOne struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *QQModelMutation
|
||||
}
|
||||
|
||||
// SetQqNumber sets the qq_number field.
|
||||
func (qmuo *QQModelUpdateOne) SetQqNumber(i int64) *QQModelUpdateOne {
|
||||
qmuo.mutation.ResetQqNumber()
|
||||
qmuo.mutation.SetQqNumber(i)
|
||||
return qmuo
|
||||
}
|
||||
|
||||
// AddQqNumber adds i to qq_number.
|
||||
func (qmuo *QQModelUpdateOne) AddQqNumber(i int64) *QQModelUpdateOne {
|
||||
qmuo.mutation.AddQqNumber(i)
|
||||
return qmuo
|
||||
}
|
||||
|
||||
// SetPhoneNumber sets the phone_number field.
|
||||
func (qmuo *QQModelUpdateOne) SetPhoneNumber(i int64) *QQModelUpdateOne {
|
||||
qmuo.mutation.ResetPhoneNumber()
|
||||
qmuo.mutation.SetPhoneNumber(i)
|
||||
return qmuo
|
||||
}
|
||||
|
||||
// AddPhoneNumber adds i to phone_number.
|
||||
func (qmuo *QQModelUpdateOne) AddPhoneNumber(i int64) *QQModelUpdateOne {
|
||||
qmuo.mutation.AddPhoneNumber(i)
|
||||
return qmuo
|
||||
}
|
||||
|
||||
// Mutation returns the QQModelMutation object of the builder.
|
||||
func (qmuo *QQModelUpdateOne) Mutation() *QQModelMutation {
|
||||
return qmuo.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated entity.
|
||||
func (qmuo *QQModelUpdateOne) Save(ctx context.Context) (*QQModel, error) {
|
||||
var (
|
||||
err error
|
||||
node *QQModel
|
||||
)
|
||||
if len(qmuo.hooks) == 0 {
|
||||
node, err = qmuo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*QQModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
qmuo.mutation = mutation
|
||||
node, err = qmuo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(qmuo.hooks) - 1; i >= 0; i-- {
|
||||
mut = qmuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, qmuo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (qmuo *QQModelUpdateOne) SaveX(ctx context.Context) *QQModel {
|
||||
node, err := qmuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (qmuo *QQModelUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := qmuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (qmuo *QQModelUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := qmuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (qmuo *QQModelUpdateOne) sqlSave(ctx context.Context) (_node *QQModel, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: qqmodel.Table,
|
||||
Columns: qqmodel.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: qqmodel.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := qmuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing QQModel.ID for update")}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if value, ok := qmuo.mutation.QqNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldQqNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := qmuo.mutation.AddedQqNumber(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldQqNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := qmuo.mutation.PhoneNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := qmuo.mutation.AddedPhoneNumber(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: qqmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
_node = &QQModel{config: qmuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues()
|
||||
if err = sqlgraph.UpdateNode(ctx, qmuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{qqmodel.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return _node, nil
|
||||
}
|
9
server/ent/runtime.go
Normal file
9
server/ent/runtime.go
Normal file
@@ -0,0 +1,9 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
// The init function reads all schema descriptors with runtime code
|
||||
// (default values, validators, hooks and policies) and stitches it
|
||||
// to their package variables.
|
||||
func init() {
|
||||
}
|
10
server/ent/runtime/runtime.go
Normal file
10
server/ent/runtime/runtime.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package runtime
|
||||
|
||||
// The schema-stitching logic is generated in github.com/kallydev/privacy/ent/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.5.0" // Version of ent codegen.
|
||||
Sum = "h1:NlDQDxJi1X6+20CCjRQgu8UqvRhQNm5ocPBCQYdxC/8=" // Sum of ent codegen.
|
||||
)
|
37
server/ent/schema/jdmodel.go
Normal file
37
server/ent/schema/jdmodel.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/dialect/entsql"
|
||||
"github.com/facebook/ent/schema"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
)
|
||||
|
||||
// JDModel holds the schema definition for the JDModel entity.
|
||||
type JDModel struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Annotations of the JDModel.
|
||||
func (JDModel) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{Table: "jd"},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the JDModel.
|
||||
func (JDModel) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name"),
|
||||
field.String("nickname"),
|
||||
field.String("password"),
|
||||
field.String("email"),
|
||||
field.String("id_number"),
|
||||
field.Int64("phone_number"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the JDModel.
|
||||
func (JDModel) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
33
server/ent/schema/qqmodel.go
Normal file
33
server/ent/schema/qqmodel.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/dialect/entsql"
|
||||
"github.com/facebook/ent/schema"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
)
|
||||
|
||||
// QQModel holds the schema definition for the QQModel entity.
|
||||
type QQModel struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Annotations of the QQModel.
|
||||
func (QQModel) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{Table: "qq"},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the QQModel.
|
||||
func (QQModel) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int64("qq_number"),
|
||||
field.Int64("phone_number"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the QQModel.
|
||||
func (QQModel) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
34
server/ent/schema/sfmodel.go
Normal file
34
server/ent/schema/sfmodel.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/dialect/entsql"
|
||||
"github.com/facebook/ent/schema"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
)
|
||||
|
||||
// SFModel holds the schema definition for the SFModel entity.
|
||||
type SFModel struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Annotations of the SFModel.
|
||||
func (SFModel) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{Table: "sf"},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the SFModel.
|
||||
func (SFModel) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name"),
|
||||
field.Int64("phone_number"),
|
||||
field.String("address"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the SFModel.
|
||||
func (SFModel) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
106
server/ent/sfmodel.go
Normal file
106
server/ent/sfmodel.go
Normal file
@@ -0,0 +1,106 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/kallydev/privacy/ent/sfmodel"
|
||||
)
|
||||
|
||||
// SFModel is the model entity for the SFModel schema.
|
||||
type SFModel struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// PhoneNumber holds the value of the "phone_number" field.
|
||||
PhoneNumber int64 `json:"phone_number,omitempty"`
|
||||
// Address holds the value of the "address" field.
|
||||
Address string `json:"address,omitempty"`
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*SFModel) scanValues() []interface{} {
|
||||
return []interface{}{
|
||||
&sql.NullInt64{}, // id
|
||||
&sql.NullString{}, // name
|
||||
&sql.NullInt64{}, // phone_number
|
||||
&sql.NullString{}, // address
|
||||
}
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the SFModel fields.
|
||||
func (sm *SFModel) assignValues(values ...interface{}) error {
|
||||
if m, n := len(values), len(sfmodel.Columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
value, ok := values[0].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
sm.ID = int(value.Int64)
|
||||
values = values[1:]
|
||||
if value, ok := values[0].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[0])
|
||||
} else if value.Valid {
|
||||
sm.Name = value.String
|
||||
}
|
||||
if value, ok := values[1].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field phone_number", values[1])
|
||||
} else if value.Valid {
|
||||
sm.PhoneNumber = value.Int64
|
||||
}
|
||||
if value, ok := values[2].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field address", values[2])
|
||||
} else if value.Valid {
|
||||
sm.Address = value.String
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this SFModel.
|
||||
// Note that, you need to call SFModel.Unwrap() before calling this method, if this SFModel
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (sm *SFModel) Update() *SFModelUpdateOne {
|
||||
return (&SFModelClient{config: sm.config}).UpdateOne(sm)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
|
||||
// so that all next queries will be executed through the driver which created the transaction.
|
||||
func (sm *SFModel) Unwrap() *SFModel {
|
||||
tx, ok := sm.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: SFModel is not a transactional entity")
|
||||
}
|
||||
sm.config.driver = tx.drv
|
||||
return sm
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (sm *SFModel) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("SFModel(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", sm.ID))
|
||||
builder.WriteString(", name=")
|
||||
builder.WriteString(sm.Name)
|
||||
builder.WriteString(", phone_number=")
|
||||
builder.WriteString(fmt.Sprintf("%v", sm.PhoneNumber))
|
||||
builder.WriteString(", address=")
|
||||
builder.WriteString(sm.Address)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// SFModels is a parsable slice of SFModel.
|
||||
type SFModels []*SFModel
|
||||
|
||||
func (sm SFModels) config(cfg config) {
|
||||
for _i := range sm {
|
||||
sm[_i].config = cfg
|
||||
}
|
||||
}
|
37
server/ent/sfmodel/sfmodel.go
Normal file
37
server/ent/sfmodel/sfmodel.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package sfmodel
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the sfmodel type in the database.
|
||||
Label = "sf_model"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldPhoneNumber holds the string denoting the phone_number field in the database.
|
||||
FieldPhoneNumber = "phone_number"
|
||||
// FieldAddress holds the string denoting the address field in the database.
|
||||
FieldAddress = "address"
|
||||
|
||||
// Table holds the table name of the sfmodel in the database.
|
||||
Table = "sf"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for sfmodel fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
FieldPhoneNumber,
|
||||
FieldAddress,
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
442
server/ent/sfmodel/where.go
Normal file
442
server/ent/sfmodel/where.go
Normal file
@@ -0,0 +1,442 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package sfmodel
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their identifier.
|
||||
func ID(id int) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumber applies equality check predicate on the "phone_number" field. It's identical to PhoneNumberEQ.
|
||||
func PhoneNumber(v int64) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// Address applies equality check predicate on the "address" field. It's identical to AddressEQ.
|
||||
func Address(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.SFModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldName), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.SFModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldName), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldName), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberEQ applies the EQ predicate on the "phone_number" field.
|
||||
func PhoneNumberEQ(v int64) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberNEQ applies the NEQ predicate on the "phone_number" field.
|
||||
func PhoneNumberNEQ(v int64) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberIn applies the In predicate on the "phone_number" field.
|
||||
func PhoneNumberIn(vs ...int64) predicate.SFModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldPhoneNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberNotIn applies the NotIn predicate on the "phone_number" field.
|
||||
func PhoneNumberNotIn(vs ...int64) predicate.SFModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldPhoneNumber), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberGT applies the GT predicate on the "phone_number" field.
|
||||
func PhoneNumberGT(v int64) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberGTE applies the GTE predicate on the "phone_number" field.
|
||||
func PhoneNumberGTE(v int64) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberLT applies the LT predicate on the "phone_number" field.
|
||||
func PhoneNumberLT(v int64) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// PhoneNumberLTE applies the LTE predicate on the "phone_number" field.
|
||||
func PhoneNumberLTE(v int64) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldPhoneNumber), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressEQ applies the EQ predicate on the "address" field.
|
||||
func AddressEQ(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressNEQ applies the NEQ predicate on the "address" field.
|
||||
func AddressNEQ(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressIn applies the In predicate on the "address" field.
|
||||
func AddressIn(vs ...string) predicate.SFModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldAddress), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressNotIn applies the NotIn predicate on the "address" field.
|
||||
func AddressNotIn(vs ...string) predicate.SFModel {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldAddress), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressGT applies the GT predicate on the "address" field.
|
||||
func AddressGT(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressGTE applies the GTE predicate on the "address" field.
|
||||
func AddressGTE(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressLT applies the LT predicate on the "address" field.
|
||||
func AddressLT(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressLTE applies the LTE predicate on the "address" field.
|
||||
func AddressLTE(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressContains applies the Contains predicate on the "address" field.
|
||||
func AddressContains(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressHasPrefix applies the HasPrefix predicate on the "address" field.
|
||||
func AddressHasPrefix(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressHasSuffix applies the HasSuffix predicate on the "address" field.
|
||||
func AddressHasSuffix(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressEqualFold applies the EqualFold predicate on the "address" field.
|
||||
func AddressEqualFold(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AddressContainsFold applies the ContainsFold predicate on the "address" field.
|
||||
func AddressContainsFold(v string) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldAddress), v))
|
||||
})
|
||||
}
|
||||
|
||||
// And groups list of predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.SFModel) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Or groups list of predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.SFModel) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.SFModel) predicate.SFModel {
|
||||
return predicate.SFModel(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
218
server/ent/sfmodel_create.go
Normal file
218
server/ent/sfmodel_create.go
Normal file
@@ -0,0 +1,218 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/sfmodel"
|
||||
)
|
||||
|
||||
// SFModelCreate is the builder for creating a SFModel entity.
|
||||
type SFModelCreate struct {
|
||||
config
|
||||
mutation *SFModelMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the name field.
|
||||
func (smc *SFModelCreate) SetName(s string) *SFModelCreate {
|
||||
smc.mutation.SetName(s)
|
||||
return smc
|
||||
}
|
||||
|
||||
// SetPhoneNumber sets the phone_number field.
|
||||
func (smc *SFModelCreate) SetPhoneNumber(i int64) *SFModelCreate {
|
||||
smc.mutation.SetPhoneNumber(i)
|
||||
return smc
|
||||
}
|
||||
|
||||
// SetAddress sets the address field.
|
||||
func (smc *SFModelCreate) SetAddress(s string) *SFModelCreate {
|
||||
smc.mutation.SetAddress(s)
|
||||
return smc
|
||||
}
|
||||
|
||||
// Mutation returns the SFModelMutation object of the builder.
|
||||
func (smc *SFModelCreate) Mutation() *SFModelMutation {
|
||||
return smc.mutation
|
||||
}
|
||||
|
||||
// Save creates the SFModel in the database.
|
||||
func (smc *SFModelCreate) Save(ctx context.Context) (*SFModel, error) {
|
||||
var (
|
||||
err error
|
||||
node *SFModel
|
||||
)
|
||||
if len(smc.hooks) == 0 {
|
||||
if err = smc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = smc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SFModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = smc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
smc.mutation = mutation
|
||||
node, err = smc.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(smc.hooks) - 1; i >= 0; i-- {
|
||||
mut = smc.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, smc.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (smc *SFModelCreate) SaveX(ctx context.Context) *SFModel {
|
||||
v, err := smc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (smc *SFModelCreate) check() error {
|
||||
if _, ok := smc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New("ent: missing required field \"name\"")}
|
||||
}
|
||||
if _, ok := smc.mutation.PhoneNumber(); !ok {
|
||||
return &ValidationError{Name: "phone_number", err: errors.New("ent: missing required field \"phone_number\"")}
|
||||
}
|
||||
if _, ok := smc.mutation.Address(); !ok {
|
||||
return &ValidationError{Name: "address", err: errors.New("ent: missing required field \"address\"")}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (smc *SFModelCreate) sqlSave(ctx context.Context) (*SFModel, error) {
|
||||
_node, _spec := smc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, smc.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (smc *SFModelCreate) createSpec() (*SFModel, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &SFModel{config: smc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: sfmodel.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: sfmodel.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := smc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldName,
|
||||
})
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := smc.mutation.PhoneNumber(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldPhoneNumber,
|
||||
})
|
||||
_node.PhoneNumber = value
|
||||
}
|
||||
if value, ok := smc.mutation.Address(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldAddress,
|
||||
})
|
||||
_node.Address = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// SFModelCreateBulk is the builder for creating a bulk of SFModel entities.
|
||||
type SFModelCreateBulk struct {
|
||||
config
|
||||
builders []*SFModelCreate
|
||||
}
|
||||
|
||||
// Save creates the SFModel entities in the database.
|
||||
func (smcb *SFModelCreateBulk) Save(ctx context.Context) ([]*SFModel, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(smcb.builders))
|
||||
nodes := make([]*SFModel, len(smcb.builders))
|
||||
mutators := make([]Mutator, len(smcb.builders))
|
||||
for i := range smcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := smcb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SFModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, smcb.builders[i+1].mutation)
|
||||
} else {
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, smcb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
}
|
||||
}
|
||||
mutation.done = true
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
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, smcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (smcb *SFModelCreateBulk) SaveX(ctx context.Context) []*SFModel {
|
||||
v, err := smcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
108
server/ent/sfmodel_delete.go
Normal file
108
server/ent/sfmodel_delete.go
Normal file
@@ -0,0 +1,108 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
"github.com/kallydev/privacy/ent/sfmodel"
|
||||
)
|
||||
|
||||
// SFModelDelete is the builder for deleting a SFModel entity.
|
||||
type SFModelDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SFModelMutation
|
||||
}
|
||||
|
||||
// Where adds a new predicate to the delete builder.
|
||||
func (smd *SFModelDelete) Where(ps ...predicate.SFModel) *SFModelDelete {
|
||||
smd.mutation.predicates = append(smd.mutation.predicates, ps...)
|
||||
return smd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (smd *SFModelDelete) Exec(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(smd.hooks) == 0 {
|
||||
affected, err = smd.sqlExec(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SFModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
smd.mutation = mutation
|
||||
affected, err = smd.sqlExec(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(smd.hooks) - 1; i >= 0; i-- {
|
||||
mut = smd.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, smd.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (smd *SFModelDelete) ExecX(ctx context.Context) int {
|
||||
n, err := smd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (smd *SFModelDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: sfmodel.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: sfmodel.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := smd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlgraph.DeleteNodes(ctx, smd.driver, _spec)
|
||||
}
|
||||
|
||||
// SFModelDeleteOne is the builder for deleting a single SFModel entity.
|
||||
type SFModelDeleteOne struct {
|
||||
smd *SFModelDelete
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (smdo *SFModelDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := smdo.smd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (smdo *SFModelDeleteOne) ExecX(ctx context.Context) {
|
||||
smdo.smd.ExecX(ctx)
|
||||
}
|
883
server/ent/sfmodel_query.go
Normal file
883
server/ent/sfmodel_query.go
Normal file
@@ -0,0 +1,883 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
"github.com/kallydev/privacy/ent/sfmodel"
|
||||
)
|
||||
|
||||
// SFModelQuery is the builder for querying SFModel entities.
|
||||
type SFModelQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
order []OrderFunc
|
||||
unique []string
|
||||
predicates []predicate.SFModel
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (smq *SFModelQuery) Where(ps ...predicate.SFModel) *SFModelQuery {
|
||||
smq.predicates = append(smq.predicates, ps...)
|
||||
return smq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
func (smq *SFModelQuery) Limit(limit int) *SFModelQuery {
|
||||
smq.limit = &limit
|
||||
return smq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
func (smq *SFModelQuery) Offset(offset int) *SFModelQuery {
|
||||
smq.offset = &offset
|
||||
return smq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (smq *SFModelQuery) Order(o ...OrderFunc) *SFModelQuery {
|
||||
smq.order = append(smq.order, o...)
|
||||
return smq
|
||||
}
|
||||
|
||||
// First returns the first SFModel entity in the query. Returns *NotFoundError when no sfmodel was found.
|
||||
func (smq *SFModelQuery) First(ctx context.Context) (*SFModel, error) {
|
||||
nodes, err := smq.Limit(1).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{sfmodel.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (smq *SFModelQuery) FirstX(ctx context.Context) *SFModel {
|
||||
node, err := smq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first SFModel id in the query. Returns *NotFoundError when no id was found.
|
||||
func (smq *SFModelQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = smq.Limit(1).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (smq *SFModelQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := smq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns the only SFModel entity in the query, returns an error if not exactly one entity was returned.
|
||||
func (smq *SFModelQuery) Only(ctx context.Context) (*SFModel, error) {
|
||||
nodes, err := smq.Limit(2).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{sfmodel.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (smq *SFModelQuery) OnlyX(ctx context.Context) *SFModel {
|
||||
node, err := smq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID returns the only SFModel id in the query, returns an error if not exactly one id was returned.
|
||||
func (smq *SFModelQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = smq.Limit(2).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
err = &NotSingularError{sfmodel.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (smq *SFModelQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := smq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of SFModels.
|
||||
func (smq *SFModelQuery) All(ctx context.Context) ([]*SFModel, error) {
|
||||
if err := smq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return smq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (smq *SFModelQuery) AllX(ctx context.Context) []*SFModel {
|
||||
nodes, err := smq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of SFModel ids.
|
||||
func (smq *SFModelQuery) IDs(ctx context.Context) ([]int, error) {
|
||||
var ids []int
|
||||
if err := smq.Select(sfmodel.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (smq *SFModelQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := smq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (smq *SFModelQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := smq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return smq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (smq *SFModelQuery) CountX(ctx context.Context) int {
|
||||
count, err := smq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (smq *SFModelQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := smq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return smq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (smq *SFModelQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := smq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the query builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (smq *SFModelQuery) Clone() *SFModelQuery {
|
||||
if smq == nil {
|
||||
return nil
|
||||
}
|
||||
return &SFModelQuery{
|
||||
config: smq.config,
|
||||
limit: smq.limit,
|
||||
offset: smq.offset,
|
||||
order: append([]OrderFunc{}, smq.order...),
|
||||
unique: append([]string{}, smq.unique...),
|
||||
predicates: append([]predicate.SFModel{}, smq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: smq.sql.Clone(),
|
||||
path: smq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy 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 {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.SFModel.Query().
|
||||
// GroupBy(sfmodel.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (smq *SFModelQuery) GroupBy(field string, fields ...string) *SFModelGroupBy {
|
||||
group := &SFModelGroupBy{config: smq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := smq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return smq.sqlQuery(), nil
|
||||
}
|
||||
return group
|
||||
}
|
||||
|
||||
// Select one or more fields from the given query.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.SFModel.Query().
|
||||
// Select(sfmodel.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (smq *SFModelQuery) Select(field string, fields ...string) *SFModelSelect {
|
||||
selector := &SFModelSelect{config: smq.config}
|
||||
selector.fields = append([]string{field}, fields...)
|
||||
selector.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := smq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return smq.sqlQuery(), nil
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
func (smq *SFModelQuery) prepareQuery(ctx context.Context) error {
|
||||
if smq.path != nil {
|
||||
prev, err := smq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
smq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (smq *SFModelQuery) sqlAll(ctx context.Context) ([]*SFModel, error) {
|
||||
var (
|
||||
nodes = []*SFModel{}
|
||||
_spec = smq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func() []interface{} {
|
||||
node := &SFModel{config: smq.config}
|
||||
nodes = append(nodes, node)
|
||||
values := node.scanValues()
|
||||
return values
|
||||
}
|
||||
_spec.Assign = func(values ...interface{}) error {
|
||||
if len(nodes) == 0 {
|
||||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
return node.assignValues(values...)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, smq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (smq *SFModelQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := smq.querySpec()
|
||||
return sqlgraph.CountNodes(ctx, smq.driver, _spec)
|
||||
}
|
||||
|
||||
func (smq *SFModelQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
n, err := smq.sqlCount(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("ent: check existence: %v", err)
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (smq *SFModelQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: sfmodel.Table,
|
||||
Columns: sfmodel.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: sfmodel.FieldID,
|
||||
},
|
||||
},
|
||||
From: smq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if ps := smq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := smq.limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := smq.offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := smq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector, sfmodel.ValidColumn)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (smq *SFModelQuery) sqlQuery() *sql.Selector {
|
||||
builder := sql.Dialect(smq.driver.Dialect())
|
||||
t1 := builder.Table(sfmodel.Table)
|
||||
selector := builder.Select(t1.Columns(sfmodel.Columns...)...).From(t1)
|
||||
if smq.sql != nil {
|
||||
selector = smq.sql
|
||||
selector.Select(selector.Columns(sfmodel.Columns...)...)
|
||||
}
|
||||
for _, p := range smq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range smq.order {
|
||||
p(selector, sfmodel.ValidColumn)
|
||||
}
|
||||
if offset := smq.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 := smq.limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// SFModelGroupBy is the builder for group-by SFModel entities.
|
||||
type SFModelGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (smgb *SFModelGroupBy) Aggregate(fns ...AggregateFunc) *SFModelGroupBy {
|
||||
smgb.fns = append(smgb.fns, fns...)
|
||||
return smgb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scan the result into the given value.
|
||||
func (smgb *SFModelGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := smgb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
smgb.sql = query
|
||||
return smgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (smgb *SFModelGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := smgb.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field.
|
||||
func (smgb *SFModelGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(smgb.fields) > 1 {
|
||||
return nil, errors.New("ent: SFModelGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := smgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (smgb *SFModelGroupBy) StringsX(ctx context.Context) []string {
|
||||
v, err := smgb.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from group-by. It is only allowed when querying group-by with one field.
|
||||
func (smgb *SFModelGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = smgb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SFModelGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (smgb *SFModelGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := smgb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
|
||||
func (smgb *SFModelGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(smgb.fields) > 1 {
|
||||
return nil, errors.New("ent: SFModelGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := smgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (smgb *SFModelGroupBy) IntsX(ctx context.Context) []int {
|
||||
v, err := smgb.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from group-by. It is only allowed when querying group-by with one field.
|
||||
func (smgb *SFModelGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = smgb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SFModelGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (smgb *SFModelGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := smgb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
|
||||
func (smgb *SFModelGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(smgb.fields) > 1 {
|
||||
return nil, errors.New("ent: SFModelGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := smgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (smgb *SFModelGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := smgb.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field.
|
||||
func (smgb *SFModelGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = smgb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SFModelGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (smgb *SFModelGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := smgb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
|
||||
func (smgb *SFModelGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(smgb.fields) > 1 {
|
||||
return nil, errors.New("ent: SFModelGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := smgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (smgb *SFModelGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
v, err := smgb.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field.
|
||||
func (smgb *SFModelGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = smgb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SFModelGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (smgb *SFModelGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := smgb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (smgb *SFModelGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
for _, f := range smgb.fields {
|
||||
if !sfmodel.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||
}
|
||||
}
|
||||
selector := smgb.sqlQuery()
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := smgb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (smgb *SFModelGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := smgb.sql
|
||||
columns := make([]string, 0, len(smgb.fields)+len(smgb.fns))
|
||||
columns = append(columns, smgb.fields...)
|
||||
for _, fn := range smgb.fns {
|
||||
columns = append(columns, fn(selector, sfmodel.ValidColumn))
|
||||
}
|
||||
return selector.Select(columns...).GroupBy(smgb.fields...)
|
||||
}
|
||||
|
||||
// SFModelSelect is the builder for select fields of SFModel entities.
|
||||
type SFModelSelect struct {
|
||||
config
|
||||
fields []string
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scan the result into the given value.
|
||||
func (sms *SFModelSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
query, err := sms.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sms.sql = query
|
||||
return sms.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (sms *SFModelSelect) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := sms.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from selector. It is only allowed when selecting one field.
|
||||
func (sms *SFModelSelect) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(sms.fields) > 1 {
|
||||
return nil, errors.New("ent: SFModelSelect.Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := sms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (sms *SFModelSelect) StringsX(ctx context.Context) []string {
|
||||
v, err := sms.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (sms *SFModelSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = sms.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SFModelSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (sms *SFModelSelect) StringX(ctx context.Context) string {
|
||||
v, err := sms.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from selector. It is only allowed when selecting one field.
|
||||
func (sms *SFModelSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(sms.fields) > 1 {
|
||||
return nil, errors.New("ent: SFModelSelect.Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := sms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (sms *SFModelSelect) IntsX(ctx context.Context) []int {
|
||||
v, err := sms.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (sms *SFModelSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = sms.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SFModelSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (sms *SFModelSelect) IntX(ctx context.Context) int {
|
||||
v, err := sms.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from selector. It is only allowed when selecting one field.
|
||||
func (sms *SFModelSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(sms.fields) > 1 {
|
||||
return nil, errors.New("ent: SFModelSelect.Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := sms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (sms *SFModelSelect) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := sms.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (sms *SFModelSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = sms.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SFModelSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (sms *SFModelSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := sms.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from selector. It is only allowed when selecting one field.
|
||||
func (sms *SFModelSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(sms.fields) > 1 {
|
||||
return nil, errors.New("ent: SFModelSelect.Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := sms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (sms *SFModelSelect) BoolsX(ctx context.Context) []bool {
|
||||
v, err := sms.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (sms *SFModelSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = sms.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: SFModelSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (sms *SFModelSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := sms.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (sms *SFModelSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
for _, f := range sms.fields {
|
||||
if !sfmodel.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for selection", f)}
|
||||
}
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := sms.sqlQuery().Query()
|
||||
if err := sms.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (sms *SFModelSelect) sqlQuery() sql.Querier {
|
||||
selector := sms.sql
|
||||
selector.Select(selector.Columns(sms.fields...)...)
|
||||
return selector
|
||||
}
|
311
server/ent/sfmodel_update.go
Normal file
311
server/ent/sfmodel_update.go
Normal file
@@ -0,0 +1,311 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebook/ent/dialect/sql"
|
||||
"github.com/facebook/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/kallydev/privacy/ent/predicate"
|
||||
"github.com/kallydev/privacy/ent/sfmodel"
|
||||
)
|
||||
|
||||
// SFModelUpdate is the builder for updating SFModel entities.
|
||||
type SFModelUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SFModelMutation
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the builder.
|
||||
func (smu *SFModelUpdate) Where(ps ...predicate.SFModel) *SFModelUpdate {
|
||||
smu.mutation.predicates = append(smu.mutation.predicates, ps...)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetName sets the name field.
|
||||
func (smu *SFModelUpdate) SetName(s string) *SFModelUpdate {
|
||||
smu.mutation.SetName(s)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetPhoneNumber sets the phone_number field.
|
||||
func (smu *SFModelUpdate) SetPhoneNumber(i int64) *SFModelUpdate {
|
||||
smu.mutation.ResetPhoneNumber()
|
||||
smu.mutation.SetPhoneNumber(i)
|
||||
return smu
|
||||
}
|
||||
|
||||
// AddPhoneNumber adds i to phone_number.
|
||||
func (smu *SFModelUpdate) AddPhoneNumber(i int64) *SFModelUpdate {
|
||||
smu.mutation.AddPhoneNumber(i)
|
||||
return smu
|
||||
}
|
||||
|
||||
// SetAddress sets the address field.
|
||||
func (smu *SFModelUpdate) SetAddress(s string) *SFModelUpdate {
|
||||
smu.mutation.SetAddress(s)
|
||||
return smu
|
||||
}
|
||||
|
||||
// Mutation returns the SFModelMutation object of the builder.
|
||||
func (smu *SFModelUpdate) Mutation() *SFModelMutation {
|
||||
return smu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
||||
func (smu *SFModelUpdate) Save(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(smu.hooks) == 0 {
|
||||
affected, err = smu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SFModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
smu.mutation = mutation
|
||||
affected, err = smu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(smu.hooks) - 1; i >= 0; i-- {
|
||||
mut = smu.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, smu.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (smu *SFModelUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := smu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (smu *SFModelUpdate) Exec(ctx context.Context) error {
|
||||
_, err := smu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (smu *SFModelUpdate) ExecX(ctx context.Context) {
|
||||
if err := smu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (smu *SFModelUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: sfmodel.Table,
|
||||
Columns: sfmodel.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: sfmodel.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := smu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := smu.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldName,
|
||||
})
|
||||
}
|
||||
if value, ok := smu.mutation.PhoneNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := smu.mutation.AddedPhoneNumber(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := smu.mutation.Address(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldAddress,
|
||||
})
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, smu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// SFModelUpdateOne is the builder for updating a single SFModel entity.
|
||||
type SFModelUpdateOne struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SFModelMutation
|
||||
}
|
||||
|
||||
// SetName sets the name field.
|
||||
func (smuo *SFModelUpdateOne) SetName(s string) *SFModelUpdateOne {
|
||||
smuo.mutation.SetName(s)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetPhoneNumber sets the phone_number field.
|
||||
func (smuo *SFModelUpdateOne) SetPhoneNumber(i int64) *SFModelUpdateOne {
|
||||
smuo.mutation.ResetPhoneNumber()
|
||||
smuo.mutation.SetPhoneNumber(i)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// AddPhoneNumber adds i to phone_number.
|
||||
func (smuo *SFModelUpdateOne) AddPhoneNumber(i int64) *SFModelUpdateOne {
|
||||
smuo.mutation.AddPhoneNumber(i)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// SetAddress sets the address field.
|
||||
func (smuo *SFModelUpdateOne) SetAddress(s string) *SFModelUpdateOne {
|
||||
smuo.mutation.SetAddress(s)
|
||||
return smuo
|
||||
}
|
||||
|
||||
// Mutation returns the SFModelMutation object of the builder.
|
||||
func (smuo *SFModelUpdateOne) Mutation() *SFModelMutation {
|
||||
return smuo.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated entity.
|
||||
func (smuo *SFModelUpdateOne) Save(ctx context.Context) (*SFModel, error) {
|
||||
var (
|
||||
err error
|
||||
node *SFModel
|
||||
)
|
||||
if len(smuo.hooks) == 0 {
|
||||
node, err = smuo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SFModelMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
smuo.mutation = mutation
|
||||
node, err = smuo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(smuo.hooks) - 1; i >= 0; i-- {
|
||||
mut = smuo.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, smuo.mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (smuo *SFModelUpdateOne) SaveX(ctx context.Context) *SFModel {
|
||||
node, err := smuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (smuo *SFModelUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := smuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (smuo *SFModelUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := smuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (smuo *SFModelUpdateOne) sqlSave(ctx context.Context) (_node *SFModel, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: sfmodel.Table,
|
||||
Columns: sfmodel.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: sfmodel.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := smuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing SFModel.ID for update")}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if value, ok := smuo.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldName,
|
||||
})
|
||||
}
|
||||
if value, ok := smuo.mutation.PhoneNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := smuo.mutation.AddedPhoneNumber(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt64,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldPhoneNumber,
|
||||
})
|
||||
}
|
||||
if value, ok := smuo.mutation.Address(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: sfmodel.FieldAddress,
|
||||
})
|
||||
}
|
||||
_node = &SFModel{config: smuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues()
|
||||
if err = sqlgraph.UpdateNode(ctx, smuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{sfmodel.Label}
|
||||
} else if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return _node, nil
|
||||
}
|
216
server/ent/tx.go
Normal file
216
server/ent/tx.go
Normal file
@@ -0,0 +1,216 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/facebook/ent/dialect"
|
||||
)
|
||||
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// JDModel is the client for interacting with the JDModel builders.
|
||||
JDModel *JDModelClient
|
||||
// QQModel is the client for interacting with the QQModel builders.
|
||||
QQModel *QQModelClient
|
||||
// SFModel is the client for interacting with the SFModel builders.
|
||||
SFModel *SFModelClient
|
||||
|
||||
// lazily loaded.
|
||||
client *Client
|
||||
clientOnce sync.Once
|
||||
|
||||
// completion callbacks.
|
||||
mu sync.Mutex
|
||||
onCommit []CommitHook
|
||||
onRollback []RollbackHook
|
||||
|
||||
// ctx lives for the life of the transaction. It is
|
||||
// the same context used by the underlying connection.
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
type (
|
||||
// Committer is the interface that wraps the Committer method.
|
||||
Committer interface {
|
||||
Commit(context.Context, *Tx) error
|
||||
}
|
||||
|
||||
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Committer. If f is a function with the appropriate
|
||||
// signature, CommitFunc(f) is a Committer that calls f.
|
||||
CommitFunc func(context.Context, *Tx) error
|
||||
|
||||
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||
// and returns a Committer. For example:
|
||||
//
|
||||
// hook := func(next ent.Committer) ent.Committer {
|
||||
// return ent.CommitFunc(func(context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Commit(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
CommitHook func(Committer) Committer
|
||||
)
|
||||
|
||||
// Commit calls f(ctx, m).
|
||||
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||
return f(ctx, tx)
|
||||
}
|
||||
|
||||
// Commit commits the transaction.
|
||||
func (tx *Tx) Commit() error {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Commit()
|
||||
})
|
||||
tx.mu.Lock()
|
||||
hooks := append([]CommitHook(nil), tx.onCommit...)
|
||||
tx.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
return fn.Commit(tx.ctx, tx)
|
||||
}
|
||||
|
||||
// OnCommit adds a hook to call on commit.
|
||||
func (tx *Tx) OnCommit(f CommitHook) {
|
||||
tx.mu.Lock()
|
||||
defer tx.mu.Unlock()
|
||||
tx.onCommit = append(tx.onCommit, f)
|
||||
}
|
||||
|
||||
type (
|
||||
// Rollbacker is the interface that wraps the Rollbacker method.
|
||||
Rollbacker interface {
|
||||
Rollback(context.Context, *Tx) error
|
||||
}
|
||||
|
||||
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Rollbacker. If f is a function with the appropriate
|
||||
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||
RollbackFunc func(context.Context, *Tx) error
|
||||
|
||||
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||
// and returns a Rollbacker. For example:
|
||||
//
|
||||
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||
// return ent.RollbackFunc(func(context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Rollback(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
RollbackHook func(Rollbacker) Rollbacker
|
||||
)
|
||||
|
||||
// Rollback calls f(ctx, m).
|
||||
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||
return f(ctx, tx)
|
||||
}
|
||||
|
||||
// Rollback rollbacks the transaction.
|
||||
func (tx *Tx) Rollback() error {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Rollback()
|
||||
})
|
||||
tx.mu.Lock()
|
||||
hooks := append([]RollbackHook(nil), tx.onRollback...)
|
||||
tx.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
return fn.Rollback(tx.ctx, tx)
|
||||
}
|
||||
|
||||
// OnRollback adds a hook to call on rollback.
|
||||
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||
tx.mu.Lock()
|
||||
defer tx.mu.Unlock()
|
||||
tx.onRollback = append(tx.onRollback, f)
|
||||
}
|
||||
|
||||
// Client returns a Client that binds to current transaction.
|
||||
func (tx *Tx) Client() *Client {
|
||||
tx.clientOnce.Do(func() {
|
||||
tx.client = &Client{config: tx.config}
|
||||
tx.client.init()
|
||||
})
|
||||
return tx.client
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.JDModel = NewJDModelClient(tx.config)
|
||||
tx.QQModel = NewQQModelClient(tx.config)
|
||||
tx.SFModel = NewSFModelClient(tx.config)
|
||||
}
|
||||
|
||||
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||
// The idea is to support transactions without adding any extra code to the builders.
|
||||
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||
// of them in order to commit or rollback the transaction.
|
||||
//
|
||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||
// applies a query, for example: JDModel.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
type txDriver struct {
|
||||
// the driver we started the transaction from.
|
||||
drv dialect.Driver
|
||||
// tx is the underlying transaction.
|
||||
tx dialect.Tx
|
||||
}
|
||||
|
||||
// newTx creates a new transactional driver.
|
||||
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
|
||||
tx, err := drv.Tx(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &txDriver{tx: tx, drv: drv}, nil
|
||||
}
|
||||
|
||||
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||
// from the internal builders. Should be called only by the internal builders.
|
||||
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
|
||||
|
||||
// Dialect returns the dialect of the driver we started the transaction from.
|
||||
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
|
||||
|
||||
// Close is a nop close.
|
||||
func (*txDriver) Close() error { return nil }
|
||||
|
||||
// Commit is a nop commit for the internal builders.
|
||||
// User must call `Tx.Commit` in order to commit the transaction.
|
||||
func (*txDriver) Commit() error { return nil }
|
||||
|
||||
// Rollback is a nop rollback for the internal builders.
|
||||
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||
func (*txDriver) Rollback() error { return nil }
|
||||
|
||||
// Exec calls tx.Exec.
|
||||
func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error {
|
||||
return tx.tx.Exec(ctx, query, args, v)
|
||||
}
|
||||
|
||||
// Query calls tx.Query.
|
||||
func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error {
|
||||
return tx.tx.Query(ctx, query, args, v)
|
||||
}
|
||||
|
||||
var _ dialect.Driver = (*txDriver)(nil)
|
Reference in New Issue
Block a user