852 lines
27 KiB
Go
852 lines
27 KiB
Go
// ENT数据库文件,请勿编辑。
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"likedream-goframe/internal/ent/sysbalancerecord"
|
|
"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"
|
|
)
|
|
|
|
// SysBalanceRecordCreate is the builder for creating a SysBalanceRecord entity.
|
|
type SysBalanceRecordCreate struct {
|
|
config
|
|
mutation *SysBalanceRecordMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetCreateTime sets the "create_time" field.
|
|
func (_c *SysBalanceRecordCreate) SetCreateTime(v *ent2.CustomTime) *SysBalanceRecordCreate {
|
|
_c.mutation.SetCreateTime(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (_c *SysBalanceRecordCreate) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordCreate {
|
|
_c.mutation.SetUpdateTime(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *SysBalanceRecordCreate) SetUserID(v int64) *SysBalanceRecordCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_c *SysBalanceRecordCreate) SetType(v sysbalancerecord.Type) *SysBalanceRecordCreate {
|
|
_c.mutation.SetType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetAmount sets the "amount" field.
|
|
func (_c *SysBalanceRecordCreate) SetAmount(v decimal.Decimal) *SysBalanceRecordCreate {
|
|
_c.mutation.SetAmount(v)
|
|
return _c
|
|
}
|
|
|
|
// SetReason sets the "reason" field.
|
|
func (_c *SysBalanceRecordCreate) SetReason(v string) *SysBalanceRecordCreate {
|
|
_c.mutation.SetReason(v)
|
|
return _c
|
|
}
|
|
|
|
// SetBalanceBefore sets the "balance_before" field.
|
|
func (_c *SysBalanceRecordCreate) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordCreate {
|
|
_c.mutation.SetBalanceBefore(v)
|
|
return _c
|
|
}
|
|
|
|
// SetBalanceAfter sets the "balance_after" field.
|
|
func (_c *SysBalanceRecordCreate) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordCreate {
|
|
_c.mutation.SetBalanceAfter(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the SysUser entity.
|
|
func (_c *SysBalanceRecordCreate) SetUser(v *SysUser) *SysBalanceRecordCreate {
|
|
return _c.SetUserID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the SysBalanceRecordMutation object of the builder.
|
|
func (_c *SysBalanceRecordCreate) Mutation() *SysBalanceRecordMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the SysBalanceRecord in the database.
|
|
func (_c *SysBalanceRecordCreate) Save(ctx context.Context) (*SysBalanceRecord, 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 *SysBalanceRecordCreate) SaveX(ctx context.Context) *SysBalanceRecord {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SysBalanceRecordCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SysBalanceRecordCreate) 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 *SysBalanceRecordCreate) defaults() error {
|
|
if _, ok := _c.mutation.CreateTime(); !ok {
|
|
if sysbalancerecord.DefaultCreateTime == nil {
|
|
return fmt.Errorf("ent: uninitialized sysbalancerecord.DefaultCreateTime (forgotten import ent/runtime?)")
|
|
}
|
|
v := sysbalancerecord.DefaultCreateTime()
|
|
_c.mutation.SetCreateTime(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdateTime(); !ok {
|
|
if sysbalancerecord.DefaultUpdateTime == nil {
|
|
return fmt.Errorf("ent: uninitialized sysbalancerecord.DefaultUpdateTime (forgotten import ent/runtime?)")
|
|
}
|
|
v := sysbalancerecord.DefaultUpdateTime()
|
|
_c.mutation.SetUpdateTime(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *SysBalanceRecordCreate) check() error {
|
|
if _, ok := _c.mutation.CreateTime(); !ok {
|
|
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "SysBalanceRecord.create_time"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdateTime(); !ok {
|
|
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "SysBalanceRecord.update_time"`)}
|
|
}
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "SysBalanceRecord.user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.GetType(); !ok {
|
|
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "SysBalanceRecord.type"`)}
|
|
}
|
|
if v, ok := _c.mutation.GetType(); ok {
|
|
if err := sysbalancerecord.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "SysBalanceRecord.type": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Amount(); !ok {
|
|
return &ValidationError{Name: "amount", err: errors.New(`ent: missing required field "SysBalanceRecord.amount"`)}
|
|
}
|
|
if _, ok := _c.mutation.Reason(); !ok {
|
|
return &ValidationError{Name: "reason", err: errors.New(`ent: missing required field "SysBalanceRecord.reason"`)}
|
|
}
|
|
if _, ok := _c.mutation.BalanceBefore(); !ok {
|
|
return &ValidationError{Name: "balance_before", err: errors.New(`ent: missing required field "SysBalanceRecord.balance_before"`)}
|
|
}
|
|
if _, ok := _c.mutation.BalanceAfter(); !ok {
|
|
return &ValidationError{Name: "balance_after", err: errors.New(`ent: missing required field "SysBalanceRecord.balance_after"`)}
|
|
}
|
|
if len(_c.mutation.UserIDs()) == 0 {
|
|
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "SysBalanceRecord.user"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *SysBalanceRecordCreate) sqlSave(ctx context.Context) (*SysBalanceRecord, 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 *SysBalanceRecordCreate) createSpec() (*SysBalanceRecord, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &SysBalanceRecord{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(sysbalancerecord.Table, sqlgraph.NewFieldSpec(sysbalancerecord.FieldID, field.TypeInt64))
|
|
)
|
|
_spec.Schema = _c.schemaConfig.SysBalanceRecord
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.CreateTime(); ok {
|
|
_spec.SetField(sysbalancerecord.FieldCreateTime, field.TypeString, value)
|
|
_node.CreateTime = value
|
|
}
|
|
if value, ok := _c.mutation.UpdateTime(); ok {
|
|
_spec.SetField(sysbalancerecord.FieldUpdateTime, field.TypeString, value)
|
|
_node.UpdateTime = value
|
|
}
|
|
if value, ok := _c.mutation.GetType(); ok {
|
|
_spec.SetField(sysbalancerecord.FieldType, field.TypeEnum, value)
|
|
_node.Type = value
|
|
}
|
|
if value, ok := _c.mutation.Amount(); ok {
|
|
_spec.SetField(sysbalancerecord.FieldAmount, field.TypeString, value)
|
|
_node.Amount = value
|
|
}
|
|
if value, ok := _c.mutation.Reason(); ok {
|
|
_spec.SetField(sysbalancerecord.FieldReason, field.TypeString, value)
|
|
_node.Reason = value
|
|
}
|
|
if value, ok := _c.mutation.BalanceBefore(); ok {
|
|
_spec.SetField(sysbalancerecord.FieldBalanceBefore, field.TypeString, value)
|
|
_node.BalanceBefore = value
|
|
}
|
|
if value, ok := _c.mutation.BalanceAfter(); ok {
|
|
_spec.SetField(sysbalancerecord.FieldBalanceAfter, field.TypeString, value)
|
|
_node.BalanceAfter = value
|
|
}
|
|
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: sysbalancerecord.UserTable,
|
|
Columns: []string{sysbalancerecord.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
edge.Schema = _c.schemaConfig.SysBalanceRecord
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.UserID = 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.SysBalanceRecord.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.SysBalanceRecordUpsert) {
|
|
// SetCreateTime(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *SysBalanceRecordCreate) OnConflict(opts ...sql.ConflictOption) *SysBalanceRecordUpsertOne {
|
|
_c.conflict = opts
|
|
return &SysBalanceRecordUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.SysBalanceRecord.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *SysBalanceRecordCreate) OnConflictColumns(columns ...string) *SysBalanceRecordUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &SysBalanceRecordUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// SysBalanceRecordUpsertOne is the builder for "upsert"-ing
|
|
// one SysBalanceRecord node.
|
|
SysBalanceRecordUpsertOne struct {
|
|
create *SysBalanceRecordCreate
|
|
}
|
|
|
|
// SysBalanceRecordUpsert is the "OnConflict" setter.
|
|
SysBalanceRecordUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *SysBalanceRecordUpsert) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpsert {
|
|
u.Set(sysbalancerecord.FieldUpdateTime, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsert) UpdateUpdateTime() *SysBalanceRecordUpsert {
|
|
u.SetExcluded(sysbalancerecord.FieldUpdateTime)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *SysBalanceRecordUpsert) SetUserID(v int64) *SysBalanceRecordUpsert {
|
|
u.Set(sysbalancerecord.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsert) UpdateUserID() *SysBalanceRecordUpsert {
|
|
u.SetExcluded(sysbalancerecord.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (u *SysBalanceRecordUpsert) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpsert {
|
|
u.Set(sysbalancerecord.FieldType, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateType sets the "type" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsert) UpdateType() *SysBalanceRecordUpsert {
|
|
u.SetExcluded(sysbalancerecord.FieldType)
|
|
return u
|
|
}
|
|
|
|
// SetAmount sets the "amount" field.
|
|
func (u *SysBalanceRecordUpsert) SetAmount(v decimal.Decimal) *SysBalanceRecordUpsert {
|
|
u.Set(sysbalancerecord.FieldAmount, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateAmount sets the "amount" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsert) UpdateAmount() *SysBalanceRecordUpsert {
|
|
u.SetExcluded(sysbalancerecord.FieldAmount)
|
|
return u
|
|
}
|
|
|
|
// SetReason sets the "reason" field.
|
|
func (u *SysBalanceRecordUpsert) SetReason(v string) *SysBalanceRecordUpsert {
|
|
u.Set(sysbalancerecord.FieldReason, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateReason sets the "reason" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsert) UpdateReason() *SysBalanceRecordUpsert {
|
|
u.SetExcluded(sysbalancerecord.FieldReason)
|
|
return u
|
|
}
|
|
|
|
// SetBalanceBefore sets the "balance_before" field.
|
|
func (u *SysBalanceRecordUpsert) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpsert {
|
|
u.Set(sysbalancerecord.FieldBalanceBefore, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateBalanceBefore sets the "balance_before" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsert) UpdateBalanceBefore() *SysBalanceRecordUpsert {
|
|
u.SetExcluded(sysbalancerecord.FieldBalanceBefore)
|
|
return u
|
|
}
|
|
|
|
// SetBalanceAfter sets the "balance_after" field.
|
|
func (u *SysBalanceRecordUpsert) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpsert {
|
|
u.Set(sysbalancerecord.FieldBalanceAfter, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateBalanceAfter sets the "balance_after" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsert) UpdateBalanceAfter() *SysBalanceRecordUpsert {
|
|
u.SetExcluded(sysbalancerecord.FieldBalanceAfter)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SysBalanceRecord.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *SysBalanceRecordUpsertOne) UpdateNewValues() *SysBalanceRecordUpsertOne {
|
|
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(sysbalancerecord.FieldCreateTime)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SysBalanceRecord.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *SysBalanceRecordUpsertOne) Ignore() *SysBalanceRecordUpsertOne {
|
|
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 *SysBalanceRecordUpsertOne) DoNothing() *SysBalanceRecordUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the SysBalanceRecordCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *SysBalanceRecordUpsertOne) Update(set func(*SysBalanceRecordUpsert)) *SysBalanceRecordUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&SysBalanceRecordUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *SysBalanceRecordUpsertOne) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetUpdateTime(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertOne) UpdateUpdateTime() *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateUpdateTime()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *SysBalanceRecordUpsertOne) SetUserID(v int64) *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertOne) UpdateUserID() *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (u *SysBalanceRecordUpsertOne) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateType sets the "type" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertOne) UpdateType() *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateType()
|
|
})
|
|
}
|
|
|
|
// SetAmount sets the "amount" field.
|
|
func (u *SysBalanceRecordUpsertOne) SetAmount(v decimal.Decimal) *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetAmount(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAmount sets the "amount" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertOne) UpdateAmount() *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateAmount()
|
|
})
|
|
}
|
|
|
|
// SetReason sets the "reason" field.
|
|
func (u *SysBalanceRecordUpsertOne) SetReason(v string) *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetReason(v)
|
|
})
|
|
}
|
|
|
|
// UpdateReason sets the "reason" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertOne) UpdateReason() *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateReason()
|
|
})
|
|
}
|
|
|
|
// SetBalanceBefore sets the "balance_before" field.
|
|
func (u *SysBalanceRecordUpsertOne) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetBalanceBefore(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBalanceBefore sets the "balance_before" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertOne) UpdateBalanceBefore() *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateBalanceBefore()
|
|
})
|
|
}
|
|
|
|
// SetBalanceAfter sets the "balance_after" field.
|
|
func (u *SysBalanceRecordUpsertOne) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetBalanceAfter(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBalanceAfter sets the "balance_after" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertOne) UpdateBalanceAfter() *SysBalanceRecordUpsertOne {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateBalanceAfter()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *SysBalanceRecordUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for SysBalanceRecordCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *SysBalanceRecordUpsertOne) 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 *SysBalanceRecordUpsertOne) 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 *SysBalanceRecordUpsertOne) IDX(ctx context.Context) int64 {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// SysBalanceRecordCreateBulk is the builder for creating many SysBalanceRecord entities in bulk.
|
|
type SysBalanceRecordCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*SysBalanceRecordCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the SysBalanceRecord entities in the database.
|
|
func (_c *SysBalanceRecordCreateBulk) Save(ctx context.Context) ([]*SysBalanceRecord, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*SysBalanceRecord, 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.(*SysBalanceRecordMutation)
|
|
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 *SysBalanceRecordCreateBulk) SaveX(ctx context.Context) []*SysBalanceRecord {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SysBalanceRecordCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SysBalanceRecordCreateBulk) 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.SysBalanceRecord.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.SysBalanceRecordUpsert) {
|
|
// SetCreateTime(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *SysBalanceRecordCreateBulk) OnConflict(opts ...sql.ConflictOption) *SysBalanceRecordUpsertBulk {
|
|
_c.conflict = opts
|
|
return &SysBalanceRecordUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.SysBalanceRecord.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *SysBalanceRecordCreateBulk) OnConflictColumns(columns ...string) *SysBalanceRecordUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &SysBalanceRecordUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// SysBalanceRecordUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of SysBalanceRecord nodes.
|
|
type SysBalanceRecordUpsertBulk struct {
|
|
create *SysBalanceRecordCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.SysBalanceRecord.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *SysBalanceRecordUpsertBulk) UpdateNewValues() *SysBalanceRecordUpsertBulk {
|
|
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(sysbalancerecord.FieldCreateTime)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SysBalanceRecord.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *SysBalanceRecordUpsertBulk) Ignore() *SysBalanceRecordUpsertBulk {
|
|
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 *SysBalanceRecordUpsertBulk) DoNothing() *SysBalanceRecordUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the SysBalanceRecordCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *SysBalanceRecordUpsertBulk) Update(set func(*SysBalanceRecordUpsert)) *SysBalanceRecordUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&SysBalanceRecordUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *SysBalanceRecordUpsertBulk) SetUpdateTime(v *ent2.CustomTime) *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetUpdateTime(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertBulk) UpdateUpdateTime() *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateUpdateTime()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *SysBalanceRecordUpsertBulk) SetUserID(v int64) *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertBulk) UpdateUserID() *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (u *SysBalanceRecordUpsertBulk) SetType(v sysbalancerecord.Type) *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateType sets the "type" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertBulk) UpdateType() *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateType()
|
|
})
|
|
}
|
|
|
|
// SetAmount sets the "amount" field.
|
|
func (u *SysBalanceRecordUpsertBulk) SetAmount(v decimal.Decimal) *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetAmount(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAmount sets the "amount" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertBulk) UpdateAmount() *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateAmount()
|
|
})
|
|
}
|
|
|
|
// SetReason sets the "reason" field.
|
|
func (u *SysBalanceRecordUpsertBulk) SetReason(v string) *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetReason(v)
|
|
})
|
|
}
|
|
|
|
// UpdateReason sets the "reason" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertBulk) UpdateReason() *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateReason()
|
|
})
|
|
}
|
|
|
|
// SetBalanceBefore sets the "balance_before" field.
|
|
func (u *SysBalanceRecordUpsertBulk) SetBalanceBefore(v decimal.Decimal) *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetBalanceBefore(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBalanceBefore sets the "balance_before" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertBulk) UpdateBalanceBefore() *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateBalanceBefore()
|
|
})
|
|
}
|
|
|
|
// SetBalanceAfter sets the "balance_after" field.
|
|
func (u *SysBalanceRecordUpsertBulk) SetBalanceAfter(v decimal.Decimal) *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.SetBalanceAfter(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBalanceAfter sets the "balance_after" field to the value that was provided on create.
|
|
func (u *SysBalanceRecordUpsertBulk) UpdateBalanceAfter() *SysBalanceRecordUpsertBulk {
|
|
return u.Update(func(s *SysBalanceRecordUpsert) {
|
|
s.UpdateBalanceAfter()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *SysBalanceRecordUpsertBulk) 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 SysBalanceRecordCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for SysBalanceRecordCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *SysBalanceRecordUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|