mirror of
https://github.com/Fishwaldo/mouthpiece.git
synced 2025-03-16 03:51:22 +00:00
919 lines
26 KiB
Go
919 lines
26 KiB
Go
/*
|
|
MIT License
|
|
|
|
Copyright (c) 2021 Justin Hammond
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
*/
|
|
|
|
// Code generated by entc, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbapp"
|
|
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbfilter"
|
|
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbgroup"
|
|
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbtransportrecipients"
|
|
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbuser"
|
|
"github.com/Fishwaldo/mouthpiece/pkg/ent/tenant"
|
|
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
|
)
|
|
|
|
// DbGroupCreate is the builder for creating a DbGroup entity.
|
|
type DbGroupCreate struct {
|
|
config
|
|
mutation *DbGroupMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetTenantID sets the "tenant_id" field.
|
|
func (dgc *DbGroupCreate) SetTenantID(i int) *DbGroupCreate {
|
|
dgc.mutation.SetTenantID(i)
|
|
return dgc
|
|
}
|
|
|
|
// SetAppData sets the "AppData" field.
|
|
func (dgc *DbGroupCreate) SetAppData(id interfaces.AppData) *DbGroupCreate {
|
|
dgc.mutation.SetAppData(id)
|
|
return dgc
|
|
}
|
|
|
|
// SetNillableAppData sets the "AppData" field if the given value is not nil.
|
|
func (dgc *DbGroupCreate) SetNillableAppData(id *interfaces.AppData) *DbGroupCreate {
|
|
if id != nil {
|
|
dgc.SetAppData(*id)
|
|
}
|
|
return dgc
|
|
}
|
|
|
|
// SetName sets the "Name" field.
|
|
func (dgc *DbGroupCreate) SetName(s string) *DbGroupCreate {
|
|
dgc.mutation.SetName(s)
|
|
return dgc
|
|
}
|
|
|
|
// SetDescription sets the "Description" field.
|
|
func (dgc *DbGroupCreate) SetDescription(s string) *DbGroupCreate {
|
|
dgc.mutation.SetDescription(s)
|
|
return dgc
|
|
}
|
|
|
|
// SetNillableDescription sets the "Description" field if the given value is not nil.
|
|
func (dgc *DbGroupCreate) SetNillableDescription(s *string) *DbGroupCreate {
|
|
if s != nil {
|
|
dgc.SetDescription(*s)
|
|
}
|
|
return dgc
|
|
}
|
|
|
|
// SetTenant sets the "tenant" edge to the Tenant entity.
|
|
func (dgc *DbGroupCreate) SetTenant(t *Tenant) *DbGroupCreate {
|
|
return dgc.SetTenantID(t.ID)
|
|
}
|
|
|
|
// AddTransportRecipientIDs adds the "TransportRecipients" edge to the DbTransportRecipients entity by IDs.
|
|
func (dgc *DbGroupCreate) AddTransportRecipientIDs(ids ...int) *DbGroupCreate {
|
|
dgc.mutation.AddTransportRecipientIDs(ids...)
|
|
return dgc
|
|
}
|
|
|
|
// AddTransportRecipients adds the "TransportRecipients" edges to the DbTransportRecipients entity.
|
|
func (dgc *DbGroupCreate) AddTransportRecipients(d ...*DbTransportRecipients) *DbGroupCreate {
|
|
ids := make([]int, len(d))
|
|
for i := range d {
|
|
ids[i] = d[i].ID
|
|
}
|
|
return dgc.AddTransportRecipientIDs(ids...)
|
|
}
|
|
|
|
// AddUserIDs adds the "users" edge to the DbUser entity by IDs.
|
|
func (dgc *DbGroupCreate) AddUserIDs(ids ...int) *DbGroupCreate {
|
|
dgc.mutation.AddUserIDs(ids...)
|
|
return dgc
|
|
}
|
|
|
|
// AddUsers adds the "users" edges to the DbUser entity.
|
|
func (dgc *DbGroupCreate) AddUsers(d ...*DbUser) *DbGroupCreate {
|
|
ids := make([]int, len(d))
|
|
for i := range d {
|
|
ids[i] = d[i].ID
|
|
}
|
|
return dgc.AddUserIDs(ids...)
|
|
}
|
|
|
|
// AddFilterIDs adds the "filters" edge to the DbFilter entity by IDs.
|
|
func (dgc *DbGroupCreate) AddFilterIDs(ids ...int) *DbGroupCreate {
|
|
dgc.mutation.AddFilterIDs(ids...)
|
|
return dgc
|
|
}
|
|
|
|
// AddFilters adds the "filters" edges to the DbFilter entity.
|
|
func (dgc *DbGroupCreate) AddFilters(d ...*DbFilter) *DbGroupCreate {
|
|
ids := make([]int, len(d))
|
|
for i := range d {
|
|
ids[i] = d[i].ID
|
|
}
|
|
return dgc.AddFilterIDs(ids...)
|
|
}
|
|
|
|
// AddAppIDs adds the "apps" edge to the DbApp entity by IDs.
|
|
func (dgc *DbGroupCreate) AddAppIDs(ids ...int) *DbGroupCreate {
|
|
dgc.mutation.AddAppIDs(ids...)
|
|
return dgc
|
|
}
|
|
|
|
// AddApps adds the "apps" edges to the DbApp entity.
|
|
func (dgc *DbGroupCreate) AddApps(d ...*DbApp) *DbGroupCreate {
|
|
ids := make([]int, len(d))
|
|
for i := range d {
|
|
ids[i] = d[i].ID
|
|
}
|
|
return dgc.AddAppIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the DbGroupMutation object of the builder.
|
|
func (dgc *DbGroupCreate) Mutation() *DbGroupMutation {
|
|
return dgc.mutation
|
|
}
|
|
|
|
// Save creates the DbGroup in the database.
|
|
func (dgc *DbGroupCreate) Save(ctx context.Context) (*DbGroup, error) {
|
|
var (
|
|
err error
|
|
node *DbGroup
|
|
)
|
|
if len(dgc.hooks) == 0 {
|
|
if err = dgc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
node, err = dgc.sqlSave(ctx)
|
|
} else {
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*DbGroupMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err = dgc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
dgc.mutation = mutation
|
|
if node, err = dgc.sqlSave(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &node.ID
|
|
mutation.done = true
|
|
return node, err
|
|
})
|
|
for i := len(dgc.hooks) - 1; i >= 0; i-- {
|
|
if dgc.hooks[i] == nil {
|
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
}
|
|
mut = dgc.hooks[i](mut)
|
|
}
|
|
v, err := mut.Mutate(ctx, dgc.mutation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
nv, ok := v.(*DbGroup)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected node type %T returned from DbGroupMutation", v)
|
|
}
|
|
node = nv
|
|
}
|
|
return node, err
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (dgc *DbGroupCreate) SaveX(ctx context.Context) *DbGroup {
|
|
v, err := dgc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (dgc *DbGroupCreate) Exec(ctx context.Context) error {
|
|
_, err := dgc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (dgc *DbGroupCreate) ExecX(ctx context.Context) {
|
|
if err := dgc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (dgc *DbGroupCreate) check() error {
|
|
if _, ok := dgc.mutation.TenantID(); !ok {
|
|
return &ValidationError{Name: "tenant_id", err: errors.New(`ent: missing required field "DbGroup.tenant_id"`)}
|
|
}
|
|
if _, ok := dgc.mutation.Name(); !ok {
|
|
return &ValidationError{Name: "Name", err: errors.New(`ent: missing required field "DbGroup.Name"`)}
|
|
}
|
|
if v, ok := dgc.mutation.Name(); ok {
|
|
if err := dbgroup.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "Name", err: fmt.Errorf(`ent: validator failed for field "DbGroup.Name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := dgc.mutation.TenantID(); !ok {
|
|
return &ValidationError{Name: "tenant", err: errors.New(`ent: missing required edge "DbGroup.tenant"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (dgc *DbGroupCreate) sqlSave(ctx context.Context) (*DbGroup, error) {
|
|
_node, _spec := dgc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, dgc.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 = int(id)
|
|
return _node, nil
|
|
}
|
|
|
|
func (dgc *DbGroupCreate) createSpec() (*DbGroup, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &DbGroup{config: dgc.config}
|
|
_spec = &sqlgraph.CreateSpec{
|
|
Table: dbgroup.Table,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: dbgroup.FieldID,
|
|
},
|
|
}
|
|
)
|
|
_spec.OnConflict = dgc.conflict
|
|
if value, ok := dgc.mutation.AppData(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: value,
|
|
Column: dbgroup.FieldAppData,
|
|
})
|
|
_node.AppData = value
|
|
}
|
|
if value, ok := dgc.mutation.Name(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: dbgroup.FieldName,
|
|
})
|
|
_node.Name = value
|
|
}
|
|
if value, ok := dgc.mutation.Description(); ok {
|
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: value,
|
|
Column: dbgroup.FieldDescription,
|
|
})
|
|
_node.Description = value
|
|
}
|
|
if nodes := dgc.mutation.TenantIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: false,
|
|
Table: dbgroup.TenantTable,
|
|
Columns: []string{dbgroup.TenantColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: tenant.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.TenantID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := dgc.mutation.TransportRecipientsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: dbgroup.TransportRecipientsTable,
|
|
Columns: []string{dbgroup.TransportRecipientsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: dbtransportrecipients.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := dgc.mutation.UsersIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: dbgroup.UsersTable,
|
|
Columns: dbgroup.UsersPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: dbuser.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := dgc.mutation.FiltersIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: dbgroup.FiltersTable,
|
|
Columns: dbgroup.FiltersPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: dbfilter.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := dgc.mutation.AppsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: true,
|
|
Table: dbgroup.AppsTable,
|
|
Columns: dbgroup.AppsPrimaryKey,
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: dbapp.FieldID,
|
|
},
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_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.DbGroup.Create().
|
|
// SetTenantID(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.DbGroupUpsert) {
|
|
// SetTenantID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (dgc *DbGroupCreate) OnConflict(opts ...sql.ConflictOption) *DbGroupUpsertOne {
|
|
dgc.conflict = opts
|
|
return &DbGroupUpsertOne{
|
|
create: dgc,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.DbGroup.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (dgc *DbGroupCreate) OnConflictColumns(columns ...string) *DbGroupUpsertOne {
|
|
dgc.conflict = append(dgc.conflict, sql.ConflictColumns(columns...))
|
|
return &DbGroupUpsertOne{
|
|
create: dgc,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// DbGroupUpsertOne is the builder for "upsert"-ing
|
|
// one DbGroup node.
|
|
DbGroupUpsertOne struct {
|
|
create *DbGroupCreate
|
|
}
|
|
|
|
// DbGroupUpsert is the "OnConflict" setter.
|
|
DbGroupUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetTenantID sets the "tenant_id" field.
|
|
func (u *DbGroupUpsert) SetTenantID(v int) *DbGroupUpsert {
|
|
u.Set(dbgroup.FieldTenantID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateTenantID sets the "tenant_id" field to the value that was provided on create.
|
|
func (u *DbGroupUpsert) UpdateTenantID() *DbGroupUpsert {
|
|
u.SetExcluded(dbgroup.FieldTenantID)
|
|
return u
|
|
}
|
|
|
|
// SetAppData sets the "AppData" field.
|
|
func (u *DbGroupUpsert) SetAppData(v interfaces.AppData) *DbGroupUpsert {
|
|
u.Set(dbgroup.FieldAppData, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateAppData sets the "AppData" field to the value that was provided on create.
|
|
func (u *DbGroupUpsert) UpdateAppData() *DbGroupUpsert {
|
|
u.SetExcluded(dbgroup.FieldAppData)
|
|
return u
|
|
}
|
|
|
|
// ClearAppData clears the value of the "AppData" field.
|
|
func (u *DbGroupUpsert) ClearAppData() *DbGroupUpsert {
|
|
u.SetNull(dbgroup.FieldAppData)
|
|
return u
|
|
}
|
|
|
|
// SetName sets the "Name" field.
|
|
func (u *DbGroupUpsert) SetName(v string) *DbGroupUpsert {
|
|
u.Set(dbgroup.FieldName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateName sets the "Name" field to the value that was provided on create.
|
|
func (u *DbGroupUpsert) UpdateName() *DbGroupUpsert {
|
|
u.SetExcluded(dbgroup.FieldName)
|
|
return u
|
|
}
|
|
|
|
// SetDescription sets the "Description" field.
|
|
func (u *DbGroupUpsert) SetDescription(v string) *DbGroupUpsert {
|
|
u.Set(dbgroup.FieldDescription, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDescription sets the "Description" field to the value that was provided on create.
|
|
func (u *DbGroupUpsert) UpdateDescription() *DbGroupUpsert {
|
|
u.SetExcluded(dbgroup.FieldDescription)
|
|
return u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "Description" field.
|
|
func (u *DbGroupUpsert) ClearDescription() *DbGroupUpsert {
|
|
u.SetNull(dbgroup.FieldDescription)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.DbGroup.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *DbGroupUpsertOne) UpdateNewValues() *DbGroupUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.DbGroup.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *DbGroupUpsertOne) Ignore() *DbGroupUpsertOne {
|
|
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 *DbGroupUpsertOne) DoNothing() *DbGroupUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the DbGroupCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *DbGroupUpsertOne) Update(set func(*DbGroupUpsert)) *DbGroupUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&DbGroupUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetTenantID sets the "tenant_id" field.
|
|
func (u *DbGroupUpsertOne) SetTenantID(v int) *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.SetTenantID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTenantID sets the "tenant_id" field to the value that was provided on create.
|
|
func (u *DbGroupUpsertOne) UpdateTenantID() *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.UpdateTenantID()
|
|
})
|
|
}
|
|
|
|
// SetAppData sets the "AppData" field.
|
|
func (u *DbGroupUpsertOne) SetAppData(v interfaces.AppData) *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.SetAppData(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAppData sets the "AppData" field to the value that was provided on create.
|
|
func (u *DbGroupUpsertOne) UpdateAppData() *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.UpdateAppData()
|
|
})
|
|
}
|
|
|
|
// ClearAppData clears the value of the "AppData" field.
|
|
func (u *DbGroupUpsertOne) ClearAppData() *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.ClearAppData()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "Name" field.
|
|
func (u *DbGroupUpsertOne) SetName(v string) *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "Name" field to the value that was provided on create.
|
|
func (u *DbGroupUpsertOne) UpdateName() *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetDescription sets the "Description" field.
|
|
func (u *DbGroupUpsertOne) SetDescription(v string) *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.SetDescription(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDescription sets the "Description" field to the value that was provided on create.
|
|
func (u *DbGroupUpsertOne) UpdateDescription() *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.UpdateDescription()
|
|
})
|
|
}
|
|
|
|
// ClearDescription clears the value of the "Description" field.
|
|
func (u *DbGroupUpsertOne) ClearDescription() *DbGroupUpsertOne {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.ClearDescription()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *DbGroupUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for DbGroupCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *DbGroupUpsertOne) 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 *DbGroupUpsertOne) ID(ctx context.Context) (id int, 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 *DbGroupUpsertOne) IDX(ctx context.Context) int {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
func (dgc *DbGroupCreate) SetDbGroupFromStruct(input *DbGroup) *DbGroupCreate {
|
|
|
|
dgc.SetTenantID(input.TenantID)
|
|
|
|
dgc.SetAppData(input.AppData)
|
|
|
|
dgc.SetName(input.Name)
|
|
|
|
dgc.SetDescription(input.Description)
|
|
|
|
return dgc
|
|
}
|
|
|
|
// DbGroupCreateBulk is the builder for creating many DbGroup entities in bulk.
|
|
type DbGroupCreateBulk struct {
|
|
config
|
|
builders []*DbGroupCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the DbGroup entities in the database.
|
|
func (dgcb *DbGroupCreateBulk) Save(ctx context.Context) ([]*DbGroup, error) {
|
|
specs := make([]*sqlgraph.CreateSpec, len(dgcb.builders))
|
|
nodes := make([]*DbGroup, len(dgcb.builders))
|
|
mutators := make([]Mutator, len(dgcb.builders))
|
|
for i := range dgcb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := dgcb.builders[i]
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*DbGroupMutation)
|
|
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, dgcb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = dgcb.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, dgcb.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 = int(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, dgcb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (dgcb *DbGroupCreateBulk) SaveX(ctx context.Context) []*DbGroup {
|
|
v, err := dgcb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (dgcb *DbGroupCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := dgcb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (dgcb *DbGroupCreateBulk) ExecX(ctx context.Context) {
|
|
if err := dgcb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.DbGroup.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.DbGroupUpsert) {
|
|
// SetTenantID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (dgcb *DbGroupCreateBulk) OnConflict(opts ...sql.ConflictOption) *DbGroupUpsertBulk {
|
|
dgcb.conflict = opts
|
|
return &DbGroupUpsertBulk{
|
|
create: dgcb,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.DbGroup.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (dgcb *DbGroupCreateBulk) OnConflictColumns(columns ...string) *DbGroupUpsertBulk {
|
|
dgcb.conflict = append(dgcb.conflict, sql.ConflictColumns(columns...))
|
|
return &DbGroupUpsertBulk{
|
|
create: dgcb,
|
|
}
|
|
}
|
|
|
|
// DbGroupUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of DbGroup nodes.
|
|
type DbGroupUpsertBulk struct {
|
|
create *DbGroupCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.DbGroup.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *DbGroupUpsertBulk) UpdateNewValues() *DbGroupUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.DbGroup.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *DbGroupUpsertBulk) Ignore() *DbGroupUpsertBulk {
|
|
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 *DbGroupUpsertBulk) DoNothing() *DbGroupUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the DbGroupCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *DbGroupUpsertBulk) Update(set func(*DbGroupUpsert)) *DbGroupUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&DbGroupUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetTenantID sets the "tenant_id" field.
|
|
func (u *DbGroupUpsertBulk) SetTenantID(v int) *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.SetTenantID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTenantID sets the "tenant_id" field to the value that was provided on create.
|
|
func (u *DbGroupUpsertBulk) UpdateTenantID() *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.UpdateTenantID()
|
|
})
|
|
}
|
|
|
|
// SetAppData sets the "AppData" field.
|
|
func (u *DbGroupUpsertBulk) SetAppData(v interfaces.AppData) *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.SetAppData(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAppData sets the "AppData" field to the value that was provided on create.
|
|
func (u *DbGroupUpsertBulk) UpdateAppData() *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.UpdateAppData()
|
|
})
|
|
}
|
|
|
|
// ClearAppData clears the value of the "AppData" field.
|
|
func (u *DbGroupUpsertBulk) ClearAppData() *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.ClearAppData()
|
|
})
|
|
}
|
|
|
|
// SetName sets the "Name" field.
|
|
func (u *DbGroupUpsertBulk) SetName(v string) *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.SetName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateName sets the "Name" field to the value that was provided on create.
|
|
func (u *DbGroupUpsertBulk) UpdateName() *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.UpdateName()
|
|
})
|
|
}
|
|
|
|
// SetDescription sets the "Description" field.
|
|
func (u *DbGroupUpsertBulk) SetDescription(v string) *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.SetDescription(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDescription sets the "Description" field to the value that was provided on create.
|
|
func (u *DbGroupUpsertBulk) UpdateDescription() *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.UpdateDescription()
|
|
})
|
|
}
|
|
|
|
// ClearDescription clears the value of the "Description" field.
|
|
func (u *DbGroupUpsertBulk) ClearDescription() *DbGroupUpsertBulk {
|
|
return u.Update(func(s *DbGroupUpsert) {
|
|
s.ClearDescription()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *DbGroupUpsertBulk) Exec(ctx context.Context) error {
|
|
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 DbGroupCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for DbGroupCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *DbGroupUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|