mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
241 lines
7.1 KiB
Go
241 lines
7.1 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"polaris/ent/notificationclient"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// NotificationClientCreate is the builder for creating a NotificationClient entity.
|
|
type NotificationClientCreate struct {
|
|
config
|
|
mutation *NotificationClientMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (ncc *NotificationClientCreate) SetName(s string) *NotificationClientCreate {
|
|
ncc.mutation.SetName(s)
|
|
return ncc
|
|
}
|
|
|
|
// SetService sets the "service" field.
|
|
func (ncc *NotificationClientCreate) SetService(s string) *NotificationClientCreate {
|
|
ncc.mutation.SetService(s)
|
|
return ncc
|
|
}
|
|
|
|
// SetSettings sets the "settings" field.
|
|
func (ncc *NotificationClientCreate) SetSettings(s string) *NotificationClientCreate {
|
|
ncc.mutation.SetSettings(s)
|
|
return ncc
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (ncc *NotificationClientCreate) SetEnabled(b bool) *NotificationClientCreate {
|
|
ncc.mutation.SetEnabled(b)
|
|
return ncc
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (ncc *NotificationClientCreate) SetNillableEnabled(b *bool) *NotificationClientCreate {
|
|
if b != nil {
|
|
ncc.SetEnabled(*b)
|
|
}
|
|
return ncc
|
|
}
|
|
|
|
// Mutation returns the NotificationClientMutation object of the builder.
|
|
func (ncc *NotificationClientCreate) Mutation() *NotificationClientMutation {
|
|
return ncc.mutation
|
|
}
|
|
|
|
// Save creates the NotificationClient in the database.
|
|
func (ncc *NotificationClientCreate) Save(ctx context.Context) (*NotificationClient, error) {
|
|
ncc.defaults()
|
|
return withHooks(ctx, ncc.sqlSave, ncc.mutation, ncc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (ncc *NotificationClientCreate) SaveX(ctx context.Context) *NotificationClient {
|
|
v, err := ncc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (ncc *NotificationClientCreate) Exec(ctx context.Context) error {
|
|
_, err := ncc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (ncc *NotificationClientCreate) ExecX(ctx context.Context) {
|
|
if err := ncc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (ncc *NotificationClientCreate) defaults() {
|
|
if _, ok := ncc.mutation.Enabled(); !ok {
|
|
v := notificationclient.DefaultEnabled
|
|
ncc.mutation.SetEnabled(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (ncc *NotificationClientCreate) check() error {
|
|
if _, ok := ncc.mutation.Name(); !ok {
|
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "NotificationClient.name"`)}
|
|
}
|
|
if _, ok := ncc.mutation.Service(); !ok {
|
|
return &ValidationError{Name: "service", err: errors.New(`ent: missing required field "NotificationClient.service"`)}
|
|
}
|
|
if _, ok := ncc.mutation.Settings(); !ok {
|
|
return &ValidationError{Name: "settings", err: errors.New(`ent: missing required field "NotificationClient.settings"`)}
|
|
}
|
|
if _, ok := ncc.mutation.Enabled(); !ok {
|
|
return &ValidationError{Name: "enabled", err: errors.New(`ent: missing required field "NotificationClient.enabled"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (ncc *NotificationClientCreate) sqlSave(ctx context.Context) (*NotificationClient, error) {
|
|
if err := ncc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := ncc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, ncc.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)
|
|
ncc.mutation.id = &_node.ID
|
|
ncc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (ncc *NotificationClientCreate) createSpec() (*NotificationClient, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &NotificationClient{config: ncc.config}
|
|
_spec = sqlgraph.NewCreateSpec(notificationclient.Table, sqlgraph.NewFieldSpec(notificationclient.FieldID, field.TypeInt))
|
|
)
|
|
if value, ok := ncc.mutation.Name(); ok {
|
|
_spec.SetField(notificationclient.FieldName, field.TypeString, value)
|
|
_node.Name = value
|
|
}
|
|
if value, ok := ncc.mutation.Service(); ok {
|
|
_spec.SetField(notificationclient.FieldService, field.TypeString, value)
|
|
_node.Service = value
|
|
}
|
|
if value, ok := ncc.mutation.Settings(); ok {
|
|
_spec.SetField(notificationclient.FieldSettings, field.TypeString, value)
|
|
_node.Settings = value
|
|
}
|
|
if value, ok := ncc.mutation.Enabled(); ok {
|
|
_spec.SetField(notificationclient.FieldEnabled, field.TypeBool, value)
|
|
_node.Enabled = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// NotificationClientCreateBulk is the builder for creating many NotificationClient entities in bulk.
|
|
type NotificationClientCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*NotificationClientCreate
|
|
}
|
|
|
|
// Save creates the NotificationClient entities in the database.
|
|
func (nccb *NotificationClientCreateBulk) Save(ctx context.Context) ([]*NotificationClient, error) {
|
|
if nccb.err != nil {
|
|
return nil, nccb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(nccb.builders))
|
|
nodes := make([]*NotificationClient, len(nccb.builders))
|
|
mutators := make([]Mutator, len(nccb.builders))
|
|
for i := range nccb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := nccb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*NotificationClientMutation)
|
|
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, nccb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, nccb.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, nccb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (nccb *NotificationClientCreateBulk) SaveX(ctx context.Context) []*NotificationClient {
|
|
v, err := nccb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (nccb *NotificationClientCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := nccb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (nccb *NotificationClientCreateBulk) ExecX(ctx context.Context) {
|
|
if err := nccb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|