1042 lines
30 KiB
Go
1042 lines
30 KiB
Go
// ENT数据库文件,请勿编辑。
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"likedream-goframe/internal/ent/syscard"
|
|
"likedream-goframe/internal/ent/sysuser"
|
|
"likedream-goframe/internal/framework/ent2"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
// SysCardCreate is the builder for creating a SysCard entity.
|
|
type SysCardCreate struct {
|
|
config
|
|
mutation *SysCardMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetCreateTime sets the "create_time" field.
|
|
func (_c *SysCardCreate) SetCreateTime(v *ent2.CustomTime) *SysCardCreate {
|
|
_c.mutation.SetCreateTime(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (_c *SysCardCreate) SetUpdateTime(v *ent2.CustomTime) *SysCardCreate {
|
|
_c.mutation.SetUpdateTime(v)
|
|
return _c
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (_c *SysCardCreate) SetContent(v string) *SysCardCreate {
|
|
_c.mutation.SetContent(v)
|
|
return _c
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_c *SysCardCreate) SetStatus(v syscard.Status) *SysCardCreate {
|
|
_c.mutation.SetStatus(v)
|
|
return _c
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (_c *SysCardCreate) SetValue(v uint64) *SysCardCreate {
|
|
_c.mutation.SetValue(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCreatorID sets the "creator_id" field.
|
|
func (_c *SysCardCreate) SetCreatorID(v int64) *SysCardCreate {
|
|
_c.mutation.SetCreatorID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUsedID sets the "used_id" field.
|
|
func (_c *SysCardCreate) SetUsedID(v int64) *SysCardCreate {
|
|
_c.mutation.SetUsedID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUsedID sets the "used_id" field if the given value is not nil.
|
|
func (_c *SysCardCreate) SetNillableUsedID(v *int64) *SysCardCreate {
|
|
if v != nil {
|
|
_c.SetUsedID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCashUserID sets the "cash_user_id" field.
|
|
func (_c *SysCardCreate) SetCashUserID(v int64) *SysCardCreate {
|
|
_c.mutation.SetCashUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCashUserID sets the "cash_user_id" field if the given value is not nil.
|
|
func (_c *SysCardCreate) SetNillableCashUserID(v *int64) *SysCardCreate {
|
|
if v != nil {
|
|
_c.SetCashUserID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCashValue sets the "cash_value" field.
|
|
func (_c *SysCardCreate) SetCashValue(v decimal.Decimal) *SysCardCreate {
|
|
_c.mutation.SetCashValue(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCashValue sets the "cash_value" field if the given value is not nil.
|
|
func (_c *SysCardCreate) SetNillableCashValue(v *decimal.Decimal) *SysCardCreate {
|
|
if v != nil {
|
|
_c.SetCashValue(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreator sets the "creator" edge to the SysUser entity.
|
|
func (_c *SysCardCreate) SetCreator(v *SysUser) *SysCardCreate {
|
|
return _c.SetCreatorID(v.ID)
|
|
}
|
|
|
|
// SetUserID sets the "user" edge to the SysUser entity by ID.
|
|
func (_c *SysCardCreate) SetUserID(id int64) *SysCardCreate {
|
|
_c.mutation.SetUserID(id)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUserID sets the "user" edge to the SysUser entity by ID if the given value is not nil.
|
|
func (_c *SysCardCreate) SetNillableUserID(id *int64) *SysCardCreate {
|
|
if id != nil {
|
|
_c = _c.SetUserID(*id)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the SysUser entity.
|
|
func (_c *SysCardCreate) SetUser(v *SysUser) *SysCardCreate {
|
|
return _c.SetUserID(v.ID)
|
|
}
|
|
|
|
// SetCashUser sets the "cash_user" edge to the SysUser entity.
|
|
func (_c *SysCardCreate) SetCashUser(v *SysUser) *SysCardCreate {
|
|
return _c.SetCashUserID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the SysCardMutation object of the builder.
|
|
func (_c *SysCardCreate) Mutation() *SysCardMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the SysCard in the database.
|
|
func (_c *SysCardCreate) Save(ctx context.Context) (*SysCard, error) {
|
|
if err := _c.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *SysCardCreate) SaveX(ctx context.Context) *SysCard {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SysCardCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SysCardCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_c *SysCardCreate) defaults() error {
|
|
if _, ok := _c.mutation.CreateTime(); !ok {
|
|
if syscard.DefaultCreateTime == nil {
|
|
return fmt.Errorf("ent: uninitialized syscard.DefaultCreateTime (forgotten import ent/runtime?)")
|
|
}
|
|
v := syscard.DefaultCreateTime()
|
|
_c.mutation.SetCreateTime(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdateTime(); !ok {
|
|
if syscard.DefaultUpdateTime == nil {
|
|
return fmt.Errorf("ent: uninitialized syscard.DefaultUpdateTime (forgotten import ent/runtime?)")
|
|
}
|
|
v := syscard.DefaultUpdateTime()
|
|
_c.mutation.SetUpdateTime(v)
|
|
}
|
|
if _, ok := _c.mutation.CashValue(); !ok {
|
|
if syscard.DefaultCashValue == nil {
|
|
return fmt.Errorf("ent: uninitialized syscard.DefaultCashValue (forgotten import ent/runtime?)")
|
|
}
|
|
v := syscard.DefaultCashValue()
|
|
_c.mutation.SetCashValue(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *SysCardCreate) check() error {
|
|
if _, ok := _c.mutation.CreateTime(); !ok {
|
|
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "SysCard.create_time"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdateTime(); !ok {
|
|
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "SysCard.update_time"`)}
|
|
}
|
|
if _, ok := _c.mutation.Content(); !ok {
|
|
return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "SysCard.content"`)}
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "SysCard.status"`)}
|
|
}
|
|
if v, ok := _c.mutation.Status(); ok {
|
|
if err := syscard.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "SysCard.status": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Value(); !ok {
|
|
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "SysCard.value"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatorID(); !ok {
|
|
return &ValidationError{Name: "creator_id", err: errors.New(`ent: missing required field "SysCard.creator_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.CashValue(); !ok {
|
|
return &ValidationError{Name: "cash_value", err: errors.New(`ent: missing required field "SysCard.cash_value"`)}
|
|
}
|
|
if len(_c.mutation.CreatorIDs()) == 0 {
|
|
return &ValidationError{Name: "creator", err: errors.New(`ent: missing required edge "SysCard.creator"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *SysCardCreate) sqlSave(ctx context.Context) (*SysCard, error) {
|
|
if err := _c.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := _c.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int64(id)
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *SysCardCreate) createSpec() (*SysCard, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &SysCard{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(syscard.Table, sqlgraph.NewFieldSpec(syscard.FieldID, field.TypeInt64))
|
|
)
|
|
_spec.Schema = _c.schemaConfig.SysCard
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.CreateTime(); ok {
|
|
_spec.SetField(syscard.FieldCreateTime, field.TypeString, value)
|
|
_node.CreateTime = value
|
|
}
|
|
if value, ok := _c.mutation.UpdateTime(); ok {
|
|
_spec.SetField(syscard.FieldUpdateTime, field.TypeString, value)
|
|
_node.UpdateTime = value
|
|
}
|
|
if value, ok := _c.mutation.Content(); ok {
|
|
_spec.SetField(syscard.FieldContent, field.TypeString, value)
|
|
_node.Content = value
|
|
}
|
|
if value, ok := _c.mutation.Status(); ok {
|
|
_spec.SetField(syscard.FieldStatus, field.TypeEnum, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := _c.mutation.Value(); ok {
|
|
_spec.SetField(syscard.FieldValue, field.TypeUint64, value)
|
|
_node.Value = value
|
|
}
|
|
if value, ok := _c.mutation.CashValue(); ok {
|
|
_spec.SetField(syscard.FieldCashValue, field.TypeString, value)
|
|
_node.CashValue = value
|
|
}
|
|
if nodes := _c.mutation.CreatorIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: syscard.CreatorTable,
|
|
Columns: []string{syscard.CreatorColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
edge.Schema = _c.schemaConfig.SysCard
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.CreatorID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: syscard.UserTable,
|
|
Columns: []string{syscard.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
edge.Schema = _c.schemaConfig.SysCard
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.UsedID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.CashUserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: syscard.CashUserTable,
|
|
Columns: []string{syscard.CashUserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
edge.Schema = _c.schemaConfig.SysCard
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.CashUserID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.SysCard.Create().
|
|
// SetCreateTime(v).
|
|
// OnConflict(
|
|
// // Update the row with the new values
|
|
// // the was proposed for insertion.
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// // Override some of the fields with custom
|
|
// // update values.
|
|
// Update(func(u *ent.SysCardUpsert) {
|
|
// SetCreateTime(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *SysCardCreate) OnConflict(opts ...sql.ConflictOption) *SysCardUpsertOne {
|
|
_c.conflict = opts
|
|
return &SysCardUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.SysCard.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *SysCardCreate) OnConflictColumns(columns ...string) *SysCardUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &SysCardUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// SysCardUpsertOne is the builder for "upsert"-ing
|
|
// one SysCard node.
|
|
SysCardUpsertOne struct {
|
|
create *SysCardCreate
|
|
}
|
|
|
|
// SysCardUpsert is the "OnConflict" setter.
|
|
SysCardUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *SysCardUpsert) SetUpdateTime(v *ent2.CustomTime) *SysCardUpsert {
|
|
u.Set(syscard.FieldUpdateTime, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *SysCardUpsert) UpdateUpdateTime() *SysCardUpsert {
|
|
u.SetExcluded(syscard.FieldUpdateTime)
|
|
return u
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (u *SysCardUpsert) SetContent(v string) *SysCardUpsert {
|
|
u.Set(syscard.FieldContent, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateContent sets the "content" field to the value that was provided on create.
|
|
func (u *SysCardUpsert) UpdateContent() *SysCardUpsert {
|
|
u.SetExcluded(syscard.FieldContent)
|
|
return u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (u *SysCardUpsert) SetStatus(v syscard.Status) *SysCardUpsert {
|
|
u.Set(syscard.FieldStatus, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateStatus sets the "status" field to the value that was provided on create.
|
|
func (u *SysCardUpsert) UpdateStatus() *SysCardUpsert {
|
|
u.SetExcluded(syscard.FieldStatus)
|
|
return u
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (u *SysCardUpsert) SetValue(v uint64) *SysCardUpsert {
|
|
u.Set(syscard.FieldValue, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateValue sets the "value" field to the value that was provided on create.
|
|
func (u *SysCardUpsert) UpdateValue() *SysCardUpsert {
|
|
u.SetExcluded(syscard.FieldValue)
|
|
return u
|
|
}
|
|
|
|
// AddValue adds v to the "value" field.
|
|
func (u *SysCardUpsert) AddValue(v uint64) *SysCardUpsert {
|
|
u.Add(syscard.FieldValue, v)
|
|
return u
|
|
}
|
|
|
|
// SetCreatorID sets the "creator_id" field.
|
|
func (u *SysCardUpsert) SetCreatorID(v int64) *SysCardUpsert {
|
|
u.Set(syscard.FieldCreatorID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatorID sets the "creator_id" field to the value that was provided on create.
|
|
func (u *SysCardUpsert) UpdateCreatorID() *SysCardUpsert {
|
|
u.SetExcluded(syscard.FieldCreatorID)
|
|
return u
|
|
}
|
|
|
|
// SetUsedID sets the "used_id" field.
|
|
func (u *SysCardUpsert) SetUsedID(v int64) *SysCardUpsert {
|
|
u.Set(syscard.FieldUsedID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUsedID sets the "used_id" field to the value that was provided on create.
|
|
func (u *SysCardUpsert) UpdateUsedID() *SysCardUpsert {
|
|
u.SetExcluded(syscard.FieldUsedID)
|
|
return u
|
|
}
|
|
|
|
// ClearUsedID clears the value of the "used_id" field.
|
|
func (u *SysCardUpsert) ClearUsedID() *SysCardUpsert {
|
|
u.SetNull(syscard.FieldUsedID)
|
|
return u
|
|
}
|
|
|
|
// SetCashUserID sets the "cash_user_id" field.
|
|
func (u *SysCardUpsert) SetCashUserID(v int64) *SysCardUpsert {
|
|
u.Set(syscard.FieldCashUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCashUserID sets the "cash_user_id" field to the value that was provided on create.
|
|
func (u *SysCardUpsert) UpdateCashUserID() *SysCardUpsert {
|
|
u.SetExcluded(syscard.FieldCashUserID)
|
|
return u
|
|
}
|
|
|
|
// ClearCashUserID clears the value of the "cash_user_id" field.
|
|
func (u *SysCardUpsert) ClearCashUserID() *SysCardUpsert {
|
|
u.SetNull(syscard.FieldCashUserID)
|
|
return u
|
|
}
|
|
|
|
// SetCashValue sets the "cash_value" field.
|
|
func (u *SysCardUpsert) SetCashValue(v decimal.Decimal) *SysCardUpsert {
|
|
u.Set(syscard.FieldCashValue, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCashValue sets the "cash_value" field to the value that was provided on create.
|
|
func (u *SysCardUpsert) UpdateCashValue() *SysCardUpsert {
|
|
u.SetExcluded(syscard.FieldCashValue)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SysCard.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *SysCardUpsertOne) UpdateNewValues() *SysCardUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
|
if _, exists := u.create.mutation.CreateTime(); exists {
|
|
s.SetIgnore(syscard.FieldCreateTime)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SysCard.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *SysCardUpsertOne) Ignore() *SysCardUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
|
return u
|
|
}
|
|
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
|
// Supported only by SQLite and PostgreSQL.
|
|
func (u *SysCardUpsertOne) DoNothing() *SysCardUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the SysCardCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *SysCardUpsertOne) Update(set func(*SysCardUpsert)) *SysCardUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&SysCardUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *SysCardUpsertOne) SetUpdateTime(v *ent2.CustomTime) *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetUpdateTime(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *SysCardUpsertOne) UpdateUpdateTime() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateUpdateTime()
|
|
})
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (u *SysCardUpsertOne) SetContent(v string) *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetContent(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContent sets the "content" field to the value that was provided on create.
|
|
func (u *SysCardUpsertOne) UpdateContent() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateContent()
|
|
})
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (u *SysCardUpsertOne) SetStatus(v syscard.Status) *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetStatus(v)
|
|
})
|
|
}
|
|
|
|
// UpdateStatus sets the "status" field to the value that was provided on create.
|
|
func (u *SysCardUpsertOne) UpdateStatus() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateStatus()
|
|
})
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (u *SysCardUpsertOne) SetValue(v uint64) *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetValue(v)
|
|
})
|
|
}
|
|
|
|
// AddValue adds v to the "value" field.
|
|
func (u *SysCardUpsertOne) AddValue(v uint64) *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.AddValue(v)
|
|
})
|
|
}
|
|
|
|
// UpdateValue sets the "value" field to the value that was provided on create.
|
|
func (u *SysCardUpsertOne) UpdateValue() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateValue()
|
|
})
|
|
}
|
|
|
|
// SetCreatorID sets the "creator_id" field.
|
|
func (u *SysCardUpsertOne) SetCreatorID(v int64) *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetCreatorID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatorID sets the "creator_id" field to the value that was provided on create.
|
|
func (u *SysCardUpsertOne) UpdateCreatorID() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateCreatorID()
|
|
})
|
|
}
|
|
|
|
// SetUsedID sets the "used_id" field.
|
|
func (u *SysCardUpsertOne) SetUsedID(v int64) *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetUsedID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUsedID sets the "used_id" field to the value that was provided on create.
|
|
func (u *SysCardUpsertOne) UpdateUsedID() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateUsedID()
|
|
})
|
|
}
|
|
|
|
// ClearUsedID clears the value of the "used_id" field.
|
|
func (u *SysCardUpsertOne) ClearUsedID() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.ClearUsedID()
|
|
})
|
|
}
|
|
|
|
// SetCashUserID sets the "cash_user_id" field.
|
|
func (u *SysCardUpsertOne) SetCashUserID(v int64) *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetCashUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCashUserID sets the "cash_user_id" field to the value that was provided on create.
|
|
func (u *SysCardUpsertOne) UpdateCashUserID() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateCashUserID()
|
|
})
|
|
}
|
|
|
|
// ClearCashUserID clears the value of the "cash_user_id" field.
|
|
func (u *SysCardUpsertOne) ClearCashUserID() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.ClearCashUserID()
|
|
})
|
|
}
|
|
|
|
// SetCashValue sets the "cash_value" field.
|
|
func (u *SysCardUpsertOne) SetCashValue(v decimal.Decimal) *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetCashValue(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCashValue sets the "cash_value" field to the value that was provided on create.
|
|
func (u *SysCardUpsertOne) UpdateCashValue() *SysCardUpsertOne {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateCashValue()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *SysCardUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for SysCardCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *SysCardUpsertOne) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
|
func (u *SysCardUpsertOne) ID(ctx context.Context) (id int64, err error) {
|
|
node, err := u.create.Save(ctx)
|
|
if err != nil {
|
|
return id, err
|
|
}
|
|
return node.ID, nil
|
|
}
|
|
|
|
// IDX is like ID, but panics if an error occurs.
|
|
func (u *SysCardUpsertOne) IDX(ctx context.Context) int64 {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// SysCardCreateBulk is the builder for creating many SysCard entities in bulk.
|
|
type SysCardCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*SysCardCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the SysCard entities in the database.
|
|
func (_c *SysCardCreateBulk) Save(ctx context.Context) ([]*SysCard, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*SysCard, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*SysCardMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
var err error
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = _c.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
if specs[i].ID.Value != nil {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int64(id)
|
|
}
|
|
mutation.done = true
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_c *SysCardCreateBulk) SaveX(ctx context.Context) []*SysCard {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SysCardCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SysCardCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.SysCard.CreateBulk(builders...).
|
|
// OnConflict(
|
|
// // Update the row with the new values
|
|
// // the was proposed for insertion.
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// // Override some of the fields with custom
|
|
// // update values.
|
|
// Update(func(u *ent.SysCardUpsert) {
|
|
// SetCreateTime(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *SysCardCreateBulk) OnConflict(opts ...sql.ConflictOption) *SysCardUpsertBulk {
|
|
_c.conflict = opts
|
|
return &SysCardUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.SysCard.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *SysCardCreateBulk) OnConflictColumns(columns ...string) *SysCardUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &SysCardUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// SysCardUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of SysCard nodes.
|
|
type SysCardUpsertBulk struct {
|
|
create *SysCardCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.SysCard.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *SysCardUpsertBulk) UpdateNewValues() *SysCardUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
|
for _, b := range u.create.builders {
|
|
if _, exists := b.mutation.CreateTime(); exists {
|
|
s.SetIgnore(syscard.FieldCreateTime)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SysCard.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *SysCardUpsertBulk) Ignore() *SysCardUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
|
return u
|
|
}
|
|
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
|
// Supported only by SQLite and PostgreSQL.
|
|
func (u *SysCardUpsertBulk) DoNothing() *SysCardUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the SysCardCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *SysCardUpsertBulk) Update(set func(*SysCardUpsert)) *SysCardUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&SysCardUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *SysCardUpsertBulk) SetUpdateTime(v *ent2.CustomTime) *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetUpdateTime(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *SysCardUpsertBulk) UpdateUpdateTime() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateUpdateTime()
|
|
})
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (u *SysCardUpsertBulk) SetContent(v string) *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetContent(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContent sets the "content" field to the value that was provided on create.
|
|
func (u *SysCardUpsertBulk) UpdateContent() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateContent()
|
|
})
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (u *SysCardUpsertBulk) SetStatus(v syscard.Status) *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetStatus(v)
|
|
})
|
|
}
|
|
|
|
// UpdateStatus sets the "status" field to the value that was provided on create.
|
|
func (u *SysCardUpsertBulk) UpdateStatus() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateStatus()
|
|
})
|
|
}
|
|
|
|
// SetValue sets the "value" field.
|
|
func (u *SysCardUpsertBulk) SetValue(v uint64) *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetValue(v)
|
|
})
|
|
}
|
|
|
|
// AddValue adds v to the "value" field.
|
|
func (u *SysCardUpsertBulk) AddValue(v uint64) *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.AddValue(v)
|
|
})
|
|
}
|
|
|
|
// UpdateValue sets the "value" field to the value that was provided on create.
|
|
func (u *SysCardUpsertBulk) UpdateValue() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateValue()
|
|
})
|
|
}
|
|
|
|
// SetCreatorID sets the "creator_id" field.
|
|
func (u *SysCardUpsertBulk) SetCreatorID(v int64) *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetCreatorID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatorID sets the "creator_id" field to the value that was provided on create.
|
|
func (u *SysCardUpsertBulk) UpdateCreatorID() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateCreatorID()
|
|
})
|
|
}
|
|
|
|
// SetUsedID sets the "used_id" field.
|
|
func (u *SysCardUpsertBulk) SetUsedID(v int64) *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetUsedID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUsedID sets the "used_id" field to the value that was provided on create.
|
|
func (u *SysCardUpsertBulk) UpdateUsedID() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateUsedID()
|
|
})
|
|
}
|
|
|
|
// ClearUsedID clears the value of the "used_id" field.
|
|
func (u *SysCardUpsertBulk) ClearUsedID() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.ClearUsedID()
|
|
})
|
|
}
|
|
|
|
// SetCashUserID sets the "cash_user_id" field.
|
|
func (u *SysCardUpsertBulk) SetCashUserID(v int64) *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetCashUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCashUserID sets the "cash_user_id" field to the value that was provided on create.
|
|
func (u *SysCardUpsertBulk) UpdateCashUserID() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateCashUserID()
|
|
})
|
|
}
|
|
|
|
// ClearCashUserID clears the value of the "cash_user_id" field.
|
|
func (u *SysCardUpsertBulk) ClearCashUserID() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.ClearCashUserID()
|
|
})
|
|
}
|
|
|
|
// SetCashValue sets the "cash_value" field.
|
|
func (u *SysCardUpsertBulk) SetCashValue(v decimal.Decimal) *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.SetCashValue(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCashValue sets the "cash_value" field to the value that was provided on create.
|
|
func (u *SysCardUpsertBulk) UpdateCashValue() *SysCardUpsertBulk {
|
|
return u.Update(func(s *SysCardUpsert) {
|
|
s.UpdateCashValue()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *SysCardUpsertBulk) Exec(ctx context.Context) error {
|
|
if u.create.err != nil {
|
|
return u.create.err
|
|
}
|
|
for i, b := range u.create.builders {
|
|
if len(b.conflict) != 0 {
|
|
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SysCardCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for SysCardCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *SysCardUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|