-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
telegramchatrecapsoptions_create.go
310 lines (281 loc) · 10.4 KB
/
telegramchatrecapsoptions_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"github.com/nekomeowww/insights-bot/ent/telegramchatrecapsoptions"
)
// TelegramChatRecapsOptionsCreate is the builder for creating a TelegramChatRecapsOptions entity.
type TelegramChatRecapsOptionsCreate struct {
config
mutation *TelegramChatRecapsOptionsMutation
hooks []Hook
}
// SetChatID sets the "chat_id" field.
func (tcroc *TelegramChatRecapsOptionsCreate) SetChatID(i int64) *TelegramChatRecapsOptionsCreate {
tcroc.mutation.SetChatID(i)
return tcroc
}
// SetAutoRecapSendMode sets the "auto_recap_send_mode" field.
func (tcroc *TelegramChatRecapsOptionsCreate) SetAutoRecapSendMode(i int) *TelegramChatRecapsOptionsCreate {
tcroc.mutation.SetAutoRecapSendMode(i)
return tcroc
}
// SetNillableAutoRecapSendMode sets the "auto_recap_send_mode" field if the given value is not nil.
func (tcroc *TelegramChatRecapsOptionsCreate) SetNillableAutoRecapSendMode(i *int) *TelegramChatRecapsOptionsCreate {
if i != nil {
tcroc.SetAutoRecapSendMode(*i)
}
return tcroc
}
// SetManualRecapRatePerSeconds sets the "manual_recap_rate_per_seconds" field.
func (tcroc *TelegramChatRecapsOptionsCreate) SetManualRecapRatePerSeconds(i int64) *TelegramChatRecapsOptionsCreate {
tcroc.mutation.SetManualRecapRatePerSeconds(i)
return tcroc
}
// SetNillableManualRecapRatePerSeconds sets the "manual_recap_rate_per_seconds" field if the given value is not nil.
func (tcroc *TelegramChatRecapsOptionsCreate) SetNillableManualRecapRatePerSeconds(i *int64) *TelegramChatRecapsOptionsCreate {
if i != nil {
tcroc.SetManualRecapRatePerSeconds(*i)
}
return tcroc
}
// SetCreatedAt sets the "created_at" field.
func (tcroc *TelegramChatRecapsOptionsCreate) SetCreatedAt(i int64) *TelegramChatRecapsOptionsCreate {
tcroc.mutation.SetCreatedAt(i)
return tcroc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (tcroc *TelegramChatRecapsOptionsCreate) SetNillableCreatedAt(i *int64) *TelegramChatRecapsOptionsCreate {
if i != nil {
tcroc.SetCreatedAt(*i)
}
return tcroc
}
// SetUpdatedAt sets the "updated_at" field.
func (tcroc *TelegramChatRecapsOptionsCreate) SetUpdatedAt(i int64) *TelegramChatRecapsOptionsCreate {
tcroc.mutation.SetUpdatedAt(i)
return tcroc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (tcroc *TelegramChatRecapsOptionsCreate) SetNillableUpdatedAt(i *int64) *TelegramChatRecapsOptionsCreate {
if i != nil {
tcroc.SetUpdatedAt(*i)
}
return tcroc
}
// SetID sets the "id" field.
func (tcroc *TelegramChatRecapsOptionsCreate) SetID(u uuid.UUID) *TelegramChatRecapsOptionsCreate {
tcroc.mutation.SetID(u)
return tcroc
}
// SetNillableID sets the "id" field if the given value is not nil.
func (tcroc *TelegramChatRecapsOptionsCreate) SetNillableID(u *uuid.UUID) *TelegramChatRecapsOptionsCreate {
if u != nil {
tcroc.SetID(*u)
}
return tcroc
}
// Mutation returns the TelegramChatRecapsOptionsMutation object of the builder.
func (tcroc *TelegramChatRecapsOptionsCreate) Mutation() *TelegramChatRecapsOptionsMutation {
return tcroc.mutation
}
// Save creates the TelegramChatRecapsOptions in the database.
func (tcroc *TelegramChatRecapsOptionsCreate) Save(ctx context.Context) (*TelegramChatRecapsOptions, error) {
tcroc.defaults()
return withHooks(ctx, tcroc.sqlSave, tcroc.mutation, tcroc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (tcroc *TelegramChatRecapsOptionsCreate) SaveX(ctx context.Context) *TelegramChatRecapsOptions {
v, err := tcroc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (tcroc *TelegramChatRecapsOptionsCreate) Exec(ctx context.Context) error {
_, err := tcroc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (tcroc *TelegramChatRecapsOptionsCreate) ExecX(ctx context.Context) {
if err := tcroc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (tcroc *TelegramChatRecapsOptionsCreate) defaults() {
if _, ok := tcroc.mutation.AutoRecapSendMode(); !ok {
v := telegramchatrecapsoptions.DefaultAutoRecapSendMode
tcroc.mutation.SetAutoRecapSendMode(v)
}
if _, ok := tcroc.mutation.ManualRecapRatePerSeconds(); !ok {
v := telegramchatrecapsoptions.DefaultManualRecapRatePerSeconds
tcroc.mutation.SetManualRecapRatePerSeconds(v)
}
if _, ok := tcroc.mutation.CreatedAt(); !ok {
v := telegramchatrecapsoptions.DefaultCreatedAt()
tcroc.mutation.SetCreatedAt(v)
}
if _, ok := tcroc.mutation.UpdatedAt(); !ok {
v := telegramchatrecapsoptions.DefaultUpdatedAt()
tcroc.mutation.SetUpdatedAt(v)
}
if _, ok := tcroc.mutation.ID(); !ok {
v := telegramchatrecapsoptions.DefaultID()
tcroc.mutation.SetID(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (tcroc *TelegramChatRecapsOptionsCreate) check() error {
if _, ok := tcroc.mutation.ChatID(); !ok {
return &ValidationError{Name: "chat_id", err: errors.New(`ent: missing required field "TelegramChatRecapsOptions.chat_id"`)}
}
if _, ok := tcroc.mutation.AutoRecapSendMode(); !ok {
return &ValidationError{Name: "auto_recap_send_mode", err: errors.New(`ent: missing required field "TelegramChatRecapsOptions.auto_recap_send_mode"`)}
}
if _, ok := tcroc.mutation.ManualRecapRatePerSeconds(); !ok {
return &ValidationError{Name: "manual_recap_rate_per_seconds", err: errors.New(`ent: missing required field "TelegramChatRecapsOptions.manual_recap_rate_per_seconds"`)}
}
if _, ok := tcroc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "TelegramChatRecapsOptions.created_at"`)}
}
if _, ok := tcroc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "TelegramChatRecapsOptions.updated_at"`)}
}
return nil
}
func (tcroc *TelegramChatRecapsOptionsCreate) sqlSave(ctx context.Context) (*TelegramChatRecapsOptions, error) {
if err := tcroc.check(); err != nil {
return nil, err
}
_node, _spec := tcroc.createSpec()
if err := sqlgraph.CreateNode(ctx, tcroc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != nil {
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
_node.ID = *id
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
return nil, err
}
}
tcroc.mutation.id = &_node.ID
tcroc.mutation.done = true
return _node, nil
}
func (tcroc *TelegramChatRecapsOptionsCreate) createSpec() (*TelegramChatRecapsOptions, *sqlgraph.CreateSpec) {
var (
_node = &TelegramChatRecapsOptions{config: tcroc.config}
_spec = sqlgraph.NewCreateSpec(telegramchatrecapsoptions.Table, sqlgraph.NewFieldSpec(telegramchatrecapsoptions.FieldID, field.TypeUUID))
)
_spec.Schema = tcroc.schemaConfig.TelegramChatRecapsOptions
if id, ok := tcroc.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = &id
}
if value, ok := tcroc.mutation.ChatID(); ok {
_spec.SetField(telegramchatrecapsoptions.FieldChatID, field.TypeInt64, value)
_node.ChatID = value
}
if value, ok := tcroc.mutation.AutoRecapSendMode(); ok {
_spec.SetField(telegramchatrecapsoptions.FieldAutoRecapSendMode, field.TypeInt, value)
_node.AutoRecapSendMode = value
}
if value, ok := tcroc.mutation.ManualRecapRatePerSeconds(); ok {
_spec.SetField(telegramchatrecapsoptions.FieldManualRecapRatePerSeconds, field.TypeInt64, value)
_node.ManualRecapRatePerSeconds = value
}
if value, ok := tcroc.mutation.CreatedAt(); ok {
_spec.SetField(telegramchatrecapsoptions.FieldCreatedAt, field.TypeInt64, value)
_node.CreatedAt = value
}
if value, ok := tcroc.mutation.UpdatedAt(); ok {
_spec.SetField(telegramchatrecapsoptions.FieldUpdatedAt, field.TypeInt64, value)
_node.UpdatedAt = value
}
return _node, _spec
}
// TelegramChatRecapsOptionsCreateBulk is the builder for creating many TelegramChatRecapsOptions entities in bulk.
type TelegramChatRecapsOptionsCreateBulk struct {
config
builders []*TelegramChatRecapsOptionsCreate
}
// Save creates the TelegramChatRecapsOptions entities in the database.
func (tcrocb *TelegramChatRecapsOptionsCreateBulk) Save(ctx context.Context) ([]*TelegramChatRecapsOptions, error) {
specs := make([]*sqlgraph.CreateSpec, len(tcrocb.builders))
nodes := make([]*TelegramChatRecapsOptions, len(tcrocb.builders))
mutators := make([]Mutator, len(tcrocb.builders))
for i := range tcrocb.builders {
func(i int, root context.Context) {
builder := tcrocb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*TelegramChatRecapsOptionsMutation)
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, tcrocb.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, tcrocb.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
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, tcrocb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (tcrocb *TelegramChatRecapsOptionsCreateBulk) SaveX(ctx context.Context) []*TelegramChatRecapsOptions {
v, err := tcrocb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (tcrocb *TelegramChatRecapsOptionsCreateBulk) Exec(ctx context.Context) error {
_, err := tcrocb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (tcrocb *TelegramChatRecapsOptionsCreateBulk) ExecX(ctx context.Context) {
if err := tcrocb.Exec(ctx); err != nil {
panic(err)
}
}