chatrecords_create.go 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/chatrecords"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // ChatRecordsCreate is the builder for creating a ChatRecords entity.
  14. type ChatRecordsCreate struct {
  15. config
  16. mutation *ChatRecordsMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetCreatedAt sets the "created_at" field.
  21. func (crc *ChatRecordsCreate) SetCreatedAt(t time.Time) *ChatRecordsCreate {
  22. crc.mutation.SetCreatedAt(t)
  23. return crc
  24. }
  25. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  26. func (crc *ChatRecordsCreate) SetNillableCreatedAt(t *time.Time) *ChatRecordsCreate {
  27. if t != nil {
  28. crc.SetCreatedAt(*t)
  29. }
  30. return crc
  31. }
  32. // SetUpdatedAt sets the "updated_at" field.
  33. func (crc *ChatRecordsCreate) SetUpdatedAt(t time.Time) *ChatRecordsCreate {
  34. crc.mutation.SetUpdatedAt(t)
  35. return crc
  36. }
  37. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  38. func (crc *ChatRecordsCreate) SetNillableUpdatedAt(t *time.Time) *ChatRecordsCreate {
  39. if t != nil {
  40. crc.SetUpdatedAt(*t)
  41. }
  42. return crc
  43. }
  44. // SetDeletedAt sets the "deleted_at" field.
  45. func (crc *ChatRecordsCreate) SetDeletedAt(t time.Time) *ChatRecordsCreate {
  46. crc.mutation.SetDeletedAt(t)
  47. return crc
  48. }
  49. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  50. func (crc *ChatRecordsCreate) SetNillableDeletedAt(t *time.Time) *ChatRecordsCreate {
  51. if t != nil {
  52. crc.SetDeletedAt(*t)
  53. }
  54. return crc
  55. }
  56. // SetContent sets the "content" field.
  57. func (crc *ChatRecordsCreate) SetContent(s string) *ChatRecordsCreate {
  58. crc.mutation.SetContent(s)
  59. return crc
  60. }
  61. // SetNillableContent sets the "content" field if the given value is not nil.
  62. func (crc *ChatRecordsCreate) SetNillableContent(s *string) *ChatRecordsCreate {
  63. if s != nil {
  64. crc.SetContent(*s)
  65. }
  66. return crc
  67. }
  68. // SetContentType sets the "content_type" field.
  69. func (crc *ChatRecordsCreate) SetContentType(u uint8) *ChatRecordsCreate {
  70. crc.mutation.SetContentType(u)
  71. return crc
  72. }
  73. // SetNillableContentType sets the "content_type" field if the given value is not nil.
  74. func (crc *ChatRecordsCreate) SetNillableContentType(u *uint8) *ChatRecordsCreate {
  75. if u != nil {
  76. crc.SetContentType(*u)
  77. }
  78. return crc
  79. }
  80. // SetSessionID sets the "session_id" field.
  81. func (crc *ChatRecordsCreate) SetSessionID(u uint64) *ChatRecordsCreate {
  82. crc.mutation.SetSessionID(u)
  83. return crc
  84. }
  85. // SetNillableSessionID sets the "session_id" field if the given value is not nil.
  86. func (crc *ChatRecordsCreate) SetNillableSessionID(u *uint64) *ChatRecordsCreate {
  87. if u != nil {
  88. crc.SetSessionID(*u)
  89. }
  90. return crc
  91. }
  92. // SetUserID sets the "user_id" field.
  93. func (crc *ChatRecordsCreate) SetUserID(u uint64) *ChatRecordsCreate {
  94. crc.mutation.SetUserID(u)
  95. return crc
  96. }
  97. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  98. func (crc *ChatRecordsCreate) SetNillableUserID(u *uint64) *ChatRecordsCreate {
  99. if u != nil {
  100. crc.SetUserID(*u)
  101. }
  102. return crc
  103. }
  104. // SetBotID sets the "bot_id" field.
  105. func (crc *ChatRecordsCreate) SetBotID(u uint64) *ChatRecordsCreate {
  106. crc.mutation.SetBotID(u)
  107. return crc
  108. }
  109. // SetNillableBotID sets the "bot_id" field if the given value is not nil.
  110. func (crc *ChatRecordsCreate) SetNillableBotID(u *uint64) *ChatRecordsCreate {
  111. if u != nil {
  112. crc.SetBotID(*u)
  113. }
  114. return crc
  115. }
  116. // SetBotType sets the "bot_type" field.
  117. func (crc *ChatRecordsCreate) SetBotType(u uint8) *ChatRecordsCreate {
  118. crc.mutation.SetBotType(u)
  119. return crc
  120. }
  121. // SetNillableBotType sets the "bot_type" field if the given value is not nil.
  122. func (crc *ChatRecordsCreate) SetNillableBotType(u *uint8) *ChatRecordsCreate {
  123. if u != nil {
  124. crc.SetBotType(*u)
  125. }
  126. return crc
  127. }
  128. // SetID sets the "id" field.
  129. func (crc *ChatRecordsCreate) SetID(u uint64) *ChatRecordsCreate {
  130. crc.mutation.SetID(u)
  131. return crc
  132. }
  133. // Mutation returns the ChatRecordsMutation object of the builder.
  134. func (crc *ChatRecordsCreate) Mutation() *ChatRecordsMutation {
  135. return crc.mutation
  136. }
  137. // Save creates the ChatRecords in the database.
  138. func (crc *ChatRecordsCreate) Save(ctx context.Context) (*ChatRecords, error) {
  139. if err := crc.defaults(); err != nil {
  140. return nil, err
  141. }
  142. return withHooks(ctx, crc.sqlSave, crc.mutation, crc.hooks)
  143. }
  144. // SaveX calls Save and panics if Save returns an error.
  145. func (crc *ChatRecordsCreate) SaveX(ctx context.Context) *ChatRecords {
  146. v, err := crc.Save(ctx)
  147. if err != nil {
  148. panic(err)
  149. }
  150. return v
  151. }
  152. // Exec executes the query.
  153. func (crc *ChatRecordsCreate) Exec(ctx context.Context) error {
  154. _, err := crc.Save(ctx)
  155. return err
  156. }
  157. // ExecX is like Exec, but panics if an error occurs.
  158. func (crc *ChatRecordsCreate) ExecX(ctx context.Context) {
  159. if err := crc.Exec(ctx); err != nil {
  160. panic(err)
  161. }
  162. }
  163. // defaults sets the default values of the builder before save.
  164. func (crc *ChatRecordsCreate) defaults() error {
  165. if _, ok := crc.mutation.CreatedAt(); !ok {
  166. if chatrecords.DefaultCreatedAt == nil {
  167. return fmt.Errorf("ent: uninitialized chatrecords.DefaultCreatedAt (forgotten import ent/runtime?)")
  168. }
  169. v := chatrecords.DefaultCreatedAt()
  170. crc.mutation.SetCreatedAt(v)
  171. }
  172. if _, ok := crc.mutation.UpdatedAt(); !ok {
  173. if chatrecords.DefaultUpdatedAt == nil {
  174. return fmt.Errorf("ent: uninitialized chatrecords.DefaultUpdatedAt (forgotten import ent/runtime?)")
  175. }
  176. v := chatrecords.DefaultUpdatedAt()
  177. crc.mutation.SetUpdatedAt(v)
  178. }
  179. if _, ok := crc.mutation.Content(); !ok {
  180. v := chatrecords.DefaultContent
  181. crc.mutation.SetContent(v)
  182. }
  183. if _, ok := crc.mutation.ContentType(); !ok {
  184. v := chatrecords.DefaultContentType
  185. crc.mutation.SetContentType(v)
  186. }
  187. if _, ok := crc.mutation.SessionID(); !ok {
  188. v := chatrecords.DefaultSessionID
  189. crc.mutation.SetSessionID(v)
  190. }
  191. if _, ok := crc.mutation.UserID(); !ok {
  192. v := chatrecords.DefaultUserID
  193. crc.mutation.SetUserID(v)
  194. }
  195. if _, ok := crc.mutation.BotID(); !ok {
  196. v := chatrecords.DefaultBotID
  197. crc.mutation.SetBotID(v)
  198. }
  199. if _, ok := crc.mutation.BotType(); !ok {
  200. v := chatrecords.DefaultBotType
  201. crc.mutation.SetBotType(v)
  202. }
  203. return nil
  204. }
  205. // check runs all checks and user-defined validators on the builder.
  206. func (crc *ChatRecordsCreate) check() error {
  207. if _, ok := crc.mutation.CreatedAt(); !ok {
  208. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "ChatRecords.created_at"`)}
  209. }
  210. if _, ok := crc.mutation.UpdatedAt(); !ok {
  211. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "ChatRecords.updated_at"`)}
  212. }
  213. if _, ok := crc.mutation.Content(); !ok {
  214. return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "ChatRecords.content"`)}
  215. }
  216. if _, ok := crc.mutation.ContentType(); !ok {
  217. return &ValidationError{Name: "content_type", err: errors.New(`ent: missing required field "ChatRecords.content_type"`)}
  218. }
  219. if _, ok := crc.mutation.SessionID(); !ok {
  220. return &ValidationError{Name: "session_id", err: errors.New(`ent: missing required field "ChatRecords.session_id"`)}
  221. }
  222. if _, ok := crc.mutation.UserID(); !ok {
  223. return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "ChatRecords.user_id"`)}
  224. }
  225. if _, ok := crc.mutation.BotID(); !ok {
  226. return &ValidationError{Name: "bot_id", err: errors.New(`ent: missing required field "ChatRecords.bot_id"`)}
  227. }
  228. if _, ok := crc.mutation.BotType(); !ok {
  229. return &ValidationError{Name: "bot_type", err: errors.New(`ent: missing required field "ChatRecords.bot_type"`)}
  230. }
  231. return nil
  232. }
  233. func (crc *ChatRecordsCreate) sqlSave(ctx context.Context) (*ChatRecords, error) {
  234. if err := crc.check(); err != nil {
  235. return nil, err
  236. }
  237. _node, _spec := crc.createSpec()
  238. if err := sqlgraph.CreateNode(ctx, crc.driver, _spec); err != nil {
  239. if sqlgraph.IsConstraintError(err) {
  240. err = &ConstraintError{msg: err.Error(), wrap: err}
  241. }
  242. return nil, err
  243. }
  244. if _spec.ID.Value != _node.ID {
  245. id := _spec.ID.Value.(int64)
  246. _node.ID = uint64(id)
  247. }
  248. crc.mutation.id = &_node.ID
  249. crc.mutation.done = true
  250. return _node, nil
  251. }
  252. func (crc *ChatRecordsCreate) createSpec() (*ChatRecords, *sqlgraph.CreateSpec) {
  253. var (
  254. _node = &ChatRecords{config: crc.config}
  255. _spec = sqlgraph.NewCreateSpec(chatrecords.Table, sqlgraph.NewFieldSpec(chatrecords.FieldID, field.TypeUint64))
  256. )
  257. _spec.OnConflict = crc.conflict
  258. if id, ok := crc.mutation.ID(); ok {
  259. _node.ID = id
  260. _spec.ID.Value = id
  261. }
  262. if value, ok := crc.mutation.CreatedAt(); ok {
  263. _spec.SetField(chatrecords.FieldCreatedAt, field.TypeTime, value)
  264. _node.CreatedAt = value
  265. }
  266. if value, ok := crc.mutation.UpdatedAt(); ok {
  267. _spec.SetField(chatrecords.FieldUpdatedAt, field.TypeTime, value)
  268. _node.UpdatedAt = value
  269. }
  270. if value, ok := crc.mutation.DeletedAt(); ok {
  271. _spec.SetField(chatrecords.FieldDeletedAt, field.TypeTime, value)
  272. _node.DeletedAt = value
  273. }
  274. if value, ok := crc.mutation.Content(); ok {
  275. _spec.SetField(chatrecords.FieldContent, field.TypeString, value)
  276. _node.Content = value
  277. }
  278. if value, ok := crc.mutation.ContentType(); ok {
  279. _spec.SetField(chatrecords.FieldContentType, field.TypeUint8, value)
  280. _node.ContentType = value
  281. }
  282. if value, ok := crc.mutation.SessionID(); ok {
  283. _spec.SetField(chatrecords.FieldSessionID, field.TypeUint64, value)
  284. _node.SessionID = value
  285. }
  286. if value, ok := crc.mutation.UserID(); ok {
  287. _spec.SetField(chatrecords.FieldUserID, field.TypeUint64, value)
  288. _node.UserID = value
  289. }
  290. if value, ok := crc.mutation.BotID(); ok {
  291. _spec.SetField(chatrecords.FieldBotID, field.TypeUint64, value)
  292. _node.BotID = value
  293. }
  294. if value, ok := crc.mutation.BotType(); ok {
  295. _spec.SetField(chatrecords.FieldBotType, field.TypeUint8, value)
  296. _node.BotType = value
  297. }
  298. return _node, _spec
  299. }
  300. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  301. // of the `INSERT` statement. For example:
  302. //
  303. // client.ChatRecords.Create().
  304. // SetCreatedAt(v).
  305. // OnConflict(
  306. // // Update the row with the new values
  307. // // the was proposed for insertion.
  308. // sql.ResolveWithNewValues(),
  309. // ).
  310. // // Override some of the fields with custom
  311. // // update values.
  312. // Update(func(u *ent.ChatRecordsUpsert) {
  313. // SetCreatedAt(v+v).
  314. // }).
  315. // Exec(ctx)
  316. func (crc *ChatRecordsCreate) OnConflict(opts ...sql.ConflictOption) *ChatRecordsUpsertOne {
  317. crc.conflict = opts
  318. return &ChatRecordsUpsertOne{
  319. create: crc,
  320. }
  321. }
  322. // OnConflictColumns calls `OnConflict` and configures the columns
  323. // as conflict target. Using this option is equivalent to using:
  324. //
  325. // client.ChatRecords.Create().
  326. // OnConflict(sql.ConflictColumns(columns...)).
  327. // Exec(ctx)
  328. func (crc *ChatRecordsCreate) OnConflictColumns(columns ...string) *ChatRecordsUpsertOne {
  329. crc.conflict = append(crc.conflict, sql.ConflictColumns(columns...))
  330. return &ChatRecordsUpsertOne{
  331. create: crc,
  332. }
  333. }
  334. type (
  335. // ChatRecordsUpsertOne is the builder for "upsert"-ing
  336. // one ChatRecords node.
  337. ChatRecordsUpsertOne struct {
  338. create *ChatRecordsCreate
  339. }
  340. // ChatRecordsUpsert is the "OnConflict" setter.
  341. ChatRecordsUpsert struct {
  342. *sql.UpdateSet
  343. }
  344. )
  345. // SetUpdatedAt sets the "updated_at" field.
  346. func (u *ChatRecordsUpsert) SetUpdatedAt(v time.Time) *ChatRecordsUpsert {
  347. u.Set(chatrecords.FieldUpdatedAt, v)
  348. return u
  349. }
  350. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  351. func (u *ChatRecordsUpsert) UpdateUpdatedAt() *ChatRecordsUpsert {
  352. u.SetExcluded(chatrecords.FieldUpdatedAt)
  353. return u
  354. }
  355. // SetDeletedAt sets the "deleted_at" field.
  356. func (u *ChatRecordsUpsert) SetDeletedAt(v time.Time) *ChatRecordsUpsert {
  357. u.Set(chatrecords.FieldDeletedAt, v)
  358. return u
  359. }
  360. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  361. func (u *ChatRecordsUpsert) UpdateDeletedAt() *ChatRecordsUpsert {
  362. u.SetExcluded(chatrecords.FieldDeletedAt)
  363. return u
  364. }
  365. // ClearDeletedAt clears the value of the "deleted_at" field.
  366. func (u *ChatRecordsUpsert) ClearDeletedAt() *ChatRecordsUpsert {
  367. u.SetNull(chatrecords.FieldDeletedAt)
  368. return u
  369. }
  370. // SetContent sets the "content" field.
  371. func (u *ChatRecordsUpsert) SetContent(v string) *ChatRecordsUpsert {
  372. u.Set(chatrecords.FieldContent, v)
  373. return u
  374. }
  375. // UpdateContent sets the "content" field to the value that was provided on create.
  376. func (u *ChatRecordsUpsert) UpdateContent() *ChatRecordsUpsert {
  377. u.SetExcluded(chatrecords.FieldContent)
  378. return u
  379. }
  380. // SetContentType sets the "content_type" field.
  381. func (u *ChatRecordsUpsert) SetContentType(v uint8) *ChatRecordsUpsert {
  382. u.Set(chatrecords.FieldContentType, v)
  383. return u
  384. }
  385. // UpdateContentType sets the "content_type" field to the value that was provided on create.
  386. func (u *ChatRecordsUpsert) UpdateContentType() *ChatRecordsUpsert {
  387. u.SetExcluded(chatrecords.FieldContentType)
  388. return u
  389. }
  390. // AddContentType adds v to the "content_type" field.
  391. func (u *ChatRecordsUpsert) AddContentType(v uint8) *ChatRecordsUpsert {
  392. u.Add(chatrecords.FieldContentType, v)
  393. return u
  394. }
  395. // SetSessionID sets the "session_id" field.
  396. func (u *ChatRecordsUpsert) SetSessionID(v uint64) *ChatRecordsUpsert {
  397. u.Set(chatrecords.FieldSessionID, v)
  398. return u
  399. }
  400. // UpdateSessionID sets the "session_id" field to the value that was provided on create.
  401. func (u *ChatRecordsUpsert) UpdateSessionID() *ChatRecordsUpsert {
  402. u.SetExcluded(chatrecords.FieldSessionID)
  403. return u
  404. }
  405. // AddSessionID adds v to the "session_id" field.
  406. func (u *ChatRecordsUpsert) AddSessionID(v uint64) *ChatRecordsUpsert {
  407. u.Add(chatrecords.FieldSessionID, v)
  408. return u
  409. }
  410. // SetUserID sets the "user_id" field.
  411. func (u *ChatRecordsUpsert) SetUserID(v uint64) *ChatRecordsUpsert {
  412. u.Set(chatrecords.FieldUserID, v)
  413. return u
  414. }
  415. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  416. func (u *ChatRecordsUpsert) UpdateUserID() *ChatRecordsUpsert {
  417. u.SetExcluded(chatrecords.FieldUserID)
  418. return u
  419. }
  420. // AddUserID adds v to the "user_id" field.
  421. func (u *ChatRecordsUpsert) AddUserID(v uint64) *ChatRecordsUpsert {
  422. u.Add(chatrecords.FieldUserID, v)
  423. return u
  424. }
  425. // SetBotID sets the "bot_id" field.
  426. func (u *ChatRecordsUpsert) SetBotID(v uint64) *ChatRecordsUpsert {
  427. u.Set(chatrecords.FieldBotID, v)
  428. return u
  429. }
  430. // UpdateBotID sets the "bot_id" field to the value that was provided on create.
  431. func (u *ChatRecordsUpsert) UpdateBotID() *ChatRecordsUpsert {
  432. u.SetExcluded(chatrecords.FieldBotID)
  433. return u
  434. }
  435. // AddBotID adds v to the "bot_id" field.
  436. func (u *ChatRecordsUpsert) AddBotID(v uint64) *ChatRecordsUpsert {
  437. u.Add(chatrecords.FieldBotID, v)
  438. return u
  439. }
  440. // SetBotType sets the "bot_type" field.
  441. func (u *ChatRecordsUpsert) SetBotType(v uint8) *ChatRecordsUpsert {
  442. u.Set(chatrecords.FieldBotType, v)
  443. return u
  444. }
  445. // UpdateBotType sets the "bot_type" field to the value that was provided on create.
  446. func (u *ChatRecordsUpsert) UpdateBotType() *ChatRecordsUpsert {
  447. u.SetExcluded(chatrecords.FieldBotType)
  448. return u
  449. }
  450. // AddBotType adds v to the "bot_type" field.
  451. func (u *ChatRecordsUpsert) AddBotType(v uint8) *ChatRecordsUpsert {
  452. u.Add(chatrecords.FieldBotType, v)
  453. return u
  454. }
  455. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  456. // Using this option is equivalent to using:
  457. //
  458. // client.ChatRecords.Create().
  459. // OnConflict(
  460. // sql.ResolveWithNewValues(),
  461. // sql.ResolveWith(func(u *sql.UpdateSet) {
  462. // u.SetIgnore(chatrecords.FieldID)
  463. // }),
  464. // ).
  465. // Exec(ctx)
  466. func (u *ChatRecordsUpsertOne) UpdateNewValues() *ChatRecordsUpsertOne {
  467. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  468. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  469. if _, exists := u.create.mutation.ID(); exists {
  470. s.SetIgnore(chatrecords.FieldID)
  471. }
  472. if _, exists := u.create.mutation.CreatedAt(); exists {
  473. s.SetIgnore(chatrecords.FieldCreatedAt)
  474. }
  475. }))
  476. return u
  477. }
  478. // Ignore sets each column to itself in case of conflict.
  479. // Using this option is equivalent to using:
  480. //
  481. // client.ChatRecords.Create().
  482. // OnConflict(sql.ResolveWithIgnore()).
  483. // Exec(ctx)
  484. func (u *ChatRecordsUpsertOne) Ignore() *ChatRecordsUpsertOne {
  485. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  486. return u
  487. }
  488. // DoNothing configures the conflict_action to `DO NOTHING`.
  489. // Supported only by SQLite and PostgreSQL.
  490. func (u *ChatRecordsUpsertOne) DoNothing() *ChatRecordsUpsertOne {
  491. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  492. return u
  493. }
  494. // Update allows overriding fields `UPDATE` values. See the ChatRecordsCreate.OnConflict
  495. // documentation for more info.
  496. func (u *ChatRecordsUpsertOne) Update(set func(*ChatRecordsUpsert)) *ChatRecordsUpsertOne {
  497. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  498. set(&ChatRecordsUpsert{UpdateSet: update})
  499. }))
  500. return u
  501. }
  502. // SetUpdatedAt sets the "updated_at" field.
  503. func (u *ChatRecordsUpsertOne) SetUpdatedAt(v time.Time) *ChatRecordsUpsertOne {
  504. return u.Update(func(s *ChatRecordsUpsert) {
  505. s.SetUpdatedAt(v)
  506. })
  507. }
  508. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  509. func (u *ChatRecordsUpsertOne) UpdateUpdatedAt() *ChatRecordsUpsertOne {
  510. return u.Update(func(s *ChatRecordsUpsert) {
  511. s.UpdateUpdatedAt()
  512. })
  513. }
  514. // SetDeletedAt sets the "deleted_at" field.
  515. func (u *ChatRecordsUpsertOne) SetDeletedAt(v time.Time) *ChatRecordsUpsertOne {
  516. return u.Update(func(s *ChatRecordsUpsert) {
  517. s.SetDeletedAt(v)
  518. })
  519. }
  520. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  521. func (u *ChatRecordsUpsertOne) UpdateDeletedAt() *ChatRecordsUpsertOne {
  522. return u.Update(func(s *ChatRecordsUpsert) {
  523. s.UpdateDeletedAt()
  524. })
  525. }
  526. // ClearDeletedAt clears the value of the "deleted_at" field.
  527. func (u *ChatRecordsUpsertOne) ClearDeletedAt() *ChatRecordsUpsertOne {
  528. return u.Update(func(s *ChatRecordsUpsert) {
  529. s.ClearDeletedAt()
  530. })
  531. }
  532. // SetContent sets the "content" field.
  533. func (u *ChatRecordsUpsertOne) SetContent(v string) *ChatRecordsUpsertOne {
  534. return u.Update(func(s *ChatRecordsUpsert) {
  535. s.SetContent(v)
  536. })
  537. }
  538. // UpdateContent sets the "content" field to the value that was provided on create.
  539. func (u *ChatRecordsUpsertOne) UpdateContent() *ChatRecordsUpsertOne {
  540. return u.Update(func(s *ChatRecordsUpsert) {
  541. s.UpdateContent()
  542. })
  543. }
  544. // SetContentType sets the "content_type" field.
  545. func (u *ChatRecordsUpsertOne) SetContentType(v uint8) *ChatRecordsUpsertOne {
  546. return u.Update(func(s *ChatRecordsUpsert) {
  547. s.SetContentType(v)
  548. })
  549. }
  550. // AddContentType adds v to the "content_type" field.
  551. func (u *ChatRecordsUpsertOne) AddContentType(v uint8) *ChatRecordsUpsertOne {
  552. return u.Update(func(s *ChatRecordsUpsert) {
  553. s.AddContentType(v)
  554. })
  555. }
  556. // UpdateContentType sets the "content_type" field to the value that was provided on create.
  557. func (u *ChatRecordsUpsertOne) UpdateContentType() *ChatRecordsUpsertOne {
  558. return u.Update(func(s *ChatRecordsUpsert) {
  559. s.UpdateContentType()
  560. })
  561. }
  562. // SetSessionID sets the "session_id" field.
  563. func (u *ChatRecordsUpsertOne) SetSessionID(v uint64) *ChatRecordsUpsertOne {
  564. return u.Update(func(s *ChatRecordsUpsert) {
  565. s.SetSessionID(v)
  566. })
  567. }
  568. // AddSessionID adds v to the "session_id" field.
  569. func (u *ChatRecordsUpsertOne) AddSessionID(v uint64) *ChatRecordsUpsertOne {
  570. return u.Update(func(s *ChatRecordsUpsert) {
  571. s.AddSessionID(v)
  572. })
  573. }
  574. // UpdateSessionID sets the "session_id" field to the value that was provided on create.
  575. func (u *ChatRecordsUpsertOne) UpdateSessionID() *ChatRecordsUpsertOne {
  576. return u.Update(func(s *ChatRecordsUpsert) {
  577. s.UpdateSessionID()
  578. })
  579. }
  580. // SetUserID sets the "user_id" field.
  581. func (u *ChatRecordsUpsertOne) SetUserID(v uint64) *ChatRecordsUpsertOne {
  582. return u.Update(func(s *ChatRecordsUpsert) {
  583. s.SetUserID(v)
  584. })
  585. }
  586. // AddUserID adds v to the "user_id" field.
  587. func (u *ChatRecordsUpsertOne) AddUserID(v uint64) *ChatRecordsUpsertOne {
  588. return u.Update(func(s *ChatRecordsUpsert) {
  589. s.AddUserID(v)
  590. })
  591. }
  592. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  593. func (u *ChatRecordsUpsertOne) UpdateUserID() *ChatRecordsUpsertOne {
  594. return u.Update(func(s *ChatRecordsUpsert) {
  595. s.UpdateUserID()
  596. })
  597. }
  598. // SetBotID sets the "bot_id" field.
  599. func (u *ChatRecordsUpsertOne) SetBotID(v uint64) *ChatRecordsUpsertOne {
  600. return u.Update(func(s *ChatRecordsUpsert) {
  601. s.SetBotID(v)
  602. })
  603. }
  604. // AddBotID adds v to the "bot_id" field.
  605. func (u *ChatRecordsUpsertOne) AddBotID(v uint64) *ChatRecordsUpsertOne {
  606. return u.Update(func(s *ChatRecordsUpsert) {
  607. s.AddBotID(v)
  608. })
  609. }
  610. // UpdateBotID sets the "bot_id" field to the value that was provided on create.
  611. func (u *ChatRecordsUpsertOne) UpdateBotID() *ChatRecordsUpsertOne {
  612. return u.Update(func(s *ChatRecordsUpsert) {
  613. s.UpdateBotID()
  614. })
  615. }
  616. // SetBotType sets the "bot_type" field.
  617. func (u *ChatRecordsUpsertOne) SetBotType(v uint8) *ChatRecordsUpsertOne {
  618. return u.Update(func(s *ChatRecordsUpsert) {
  619. s.SetBotType(v)
  620. })
  621. }
  622. // AddBotType adds v to the "bot_type" field.
  623. func (u *ChatRecordsUpsertOne) AddBotType(v uint8) *ChatRecordsUpsertOne {
  624. return u.Update(func(s *ChatRecordsUpsert) {
  625. s.AddBotType(v)
  626. })
  627. }
  628. // UpdateBotType sets the "bot_type" field to the value that was provided on create.
  629. func (u *ChatRecordsUpsertOne) UpdateBotType() *ChatRecordsUpsertOne {
  630. return u.Update(func(s *ChatRecordsUpsert) {
  631. s.UpdateBotType()
  632. })
  633. }
  634. // Exec executes the query.
  635. func (u *ChatRecordsUpsertOne) Exec(ctx context.Context) error {
  636. if len(u.create.conflict) == 0 {
  637. return errors.New("ent: missing options for ChatRecordsCreate.OnConflict")
  638. }
  639. return u.create.Exec(ctx)
  640. }
  641. // ExecX is like Exec, but panics if an error occurs.
  642. func (u *ChatRecordsUpsertOne) ExecX(ctx context.Context) {
  643. if err := u.create.Exec(ctx); err != nil {
  644. panic(err)
  645. }
  646. }
  647. // Exec executes the UPSERT query and returns the inserted/updated ID.
  648. func (u *ChatRecordsUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  649. node, err := u.create.Save(ctx)
  650. if err != nil {
  651. return id, err
  652. }
  653. return node.ID, nil
  654. }
  655. // IDX is like ID, but panics if an error occurs.
  656. func (u *ChatRecordsUpsertOne) IDX(ctx context.Context) uint64 {
  657. id, err := u.ID(ctx)
  658. if err != nil {
  659. panic(err)
  660. }
  661. return id
  662. }
  663. // ChatRecordsCreateBulk is the builder for creating many ChatRecords entities in bulk.
  664. type ChatRecordsCreateBulk struct {
  665. config
  666. err error
  667. builders []*ChatRecordsCreate
  668. conflict []sql.ConflictOption
  669. }
  670. // Save creates the ChatRecords entities in the database.
  671. func (crcb *ChatRecordsCreateBulk) Save(ctx context.Context) ([]*ChatRecords, error) {
  672. if crcb.err != nil {
  673. return nil, crcb.err
  674. }
  675. specs := make([]*sqlgraph.CreateSpec, len(crcb.builders))
  676. nodes := make([]*ChatRecords, len(crcb.builders))
  677. mutators := make([]Mutator, len(crcb.builders))
  678. for i := range crcb.builders {
  679. func(i int, root context.Context) {
  680. builder := crcb.builders[i]
  681. builder.defaults()
  682. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  683. mutation, ok := m.(*ChatRecordsMutation)
  684. if !ok {
  685. return nil, fmt.Errorf("unexpected mutation type %T", m)
  686. }
  687. if err := builder.check(); err != nil {
  688. return nil, err
  689. }
  690. builder.mutation = mutation
  691. var err error
  692. nodes[i], specs[i] = builder.createSpec()
  693. if i < len(mutators)-1 {
  694. _, err = mutators[i+1].Mutate(root, crcb.builders[i+1].mutation)
  695. } else {
  696. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  697. spec.OnConflict = crcb.conflict
  698. // Invoke the actual operation on the latest mutation in the chain.
  699. if err = sqlgraph.BatchCreate(ctx, crcb.driver, spec); err != nil {
  700. if sqlgraph.IsConstraintError(err) {
  701. err = &ConstraintError{msg: err.Error(), wrap: err}
  702. }
  703. }
  704. }
  705. if err != nil {
  706. return nil, err
  707. }
  708. mutation.id = &nodes[i].ID
  709. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  710. id := specs[i].ID.Value.(int64)
  711. nodes[i].ID = uint64(id)
  712. }
  713. mutation.done = true
  714. return nodes[i], nil
  715. })
  716. for i := len(builder.hooks) - 1; i >= 0; i-- {
  717. mut = builder.hooks[i](mut)
  718. }
  719. mutators[i] = mut
  720. }(i, ctx)
  721. }
  722. if len(mutators) > 0 {
  723. if _, err := mutators[0].Mutate(ctx, crcb.builders[0].mutation); err != nil {
  724. return nil, err
  725. }
  726. }
  727. return nodes, nil
  728. }
  729. // SaveX is like Save, but panics if an error occurs.
  730. func (crcb *ChatRecordsCreateBulk) SaveX(ctx context.Context) []*ChatRecords {
  731. v, err := crcb.Save(ctx)
  732. if err != nil {
  733. panic(err)
  734. }
  735. return v
  736. }
  737. // Exec executes the query.
  738. func (crcb *ChatRecordsCreateBulk) Exec(ctx context.Context) error {
  739. _, err := crcb.Save(ctx)
  740. return err
  741. }
  742. // ExecX is like Exec, but panics if an error occurs.
  743. func (crcb *ChatRecordsCreateBulk) ExecX(ctx context.Context) {
  744. if err := crcb.Exec(ctx); err != nil {
  745. panic(err)
  746. }
  747. }
  748. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  749. // of the `INSERT` statement. For example:
  750. //
  751. // client.ChatRecords.CreateBulk(builders...).
  752. // OnConflict(
  753. // // Update the row with the new values
  754. // // the was proposed for insertion.
  755. // sql.ResolveWithNewValues(),
  756. // ).
  757. // // Override some of the fields with custom
  758. // // update values.
  759. // Update(func(u *ent.ChatRecordsUpsert) {
  760. // SetCreatedAt(v+v).
  761. // }).
  762. // Exec(ctx)
  763. func (crcb *ChatRecordsCreateBulk) OnConflict(opts ...sql.ConflictOption) *ChatRecordsUpsertBulk {
  764. crcb.conflict = opts
  765. return &ChatRecordsUpsertBulk{
  766. create: crcb,
  767. }
  768. }
  769. // OnConflictColumns calls `OnConflict` and configures the columns
  770. // as conflict target. Using this option is equivalent to using:
  771. //
  772. // client.ChatRecords.Create().
  773. // OnConflict(sql.ConflictColumns(columns...)).
  774. // Exec(ctx)
  775. func (crcb *ChatRecordsCreateBulk) OnConflictColumns(columns ...string) *ChatRecordsUpsertBulk {
  776. crcb.conflict = append(crcb.conflict, sql.ConflictColumns(columns...))
  777. return &ChatRecordsUpsertBulk{
  778. create: crcb,
  779. }
  780. }
  781. // ChatRecordsUpsertBulk is the builder for "upsert"-ing
  782. // a bulk of ChatRecords nodes.
  783. type ChatRecordsUpsertBulk struct {
  784. create *ChatRecordsCreateBulk
  785. }
  786. // UpdateNewValues updates the mutable fields using the new values that
  787. // were set on create. Using this option is equivalent to using:
  788. //
  789. // client.ChatRecords.Create().
  790. // OnConflict(
  791. // sql.ResolveWithNewValues(),
  792. // sql.ResolveWith(func(u *sql.UpdateSet) {
  793. // u.SetIgnore(chatrecords.FieldID)
  794. // }),
  795. // ).
  796. // Exec(ctx)
  797. func (u *ChatRecordsUpsertBulk) UpdateNewValues() *ChatRecordsUpsertBulk {
  798. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  799. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  800. for _, b := range u.create.builders {
  801. if _, exists := b.mutation.ID(); exists {
  802. s.SetIgnore(chatrecords.FieldID)
  803. }
  804. if _, exists := b.mutation.CreatedAt(); exists {
  805. s.SetIgnore(chatrecords.FieldCreatedAt)
  806. }
  807. }
  808. }))
  809. return u
  810. }
  811. // Ignore sets each column to itself in case of conflict.
  812. // Using this option is equivalent to using:
  813. //
  814. // client.ChatRecords.Create().
  815. // OnConflict(sql.ResolveWithIgnore()).
  816. // Exec(ctx)
  817. func (u *ChatRecordsUpsertBulk) Ignore() *ChatRecordsUpsertBulk {
  818. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  819. return u
  820. }
  821. // DoNothing configures the conflict_action to `DO NOTHING`.
  822. // Supported only by SQLite and PostgreSQL.
  823. func (u *ChatRecordsUpsertBulk) DoNothing() *ChatRecordsUpsertBulk {
  824. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  825. return u
  826. }
  827. // Update allows overriding fields `UPDATE` values. See the ChatRecordsCreateBulk.OnConflict
  828. // documentation for more info.
  829. func (u *ChatRecordsUpsertBulk) Update(set func(*ChatRecordsUpsert)) *ChatRecordsUpsertBulk {
  830. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  831. set(&ChatRecordsUpsert{UpdateSet: update})
  832. }))
  833. return u
  834. }
  835. // SetUpdatedAt sets the "updated_at" field.
  836. func (u *ChatRecordsUpsertBulk) SetUpdatedAt(v time.Time) *ChatRecordsUpsertBulk {
  837. return u.Update(func(s *ChatRecordsUpsert) {
  838. s.SetUpdatedAt(v)
  839. })
  840. }
  841. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  842. func (u *ChatRecordsUpsertBulk) UpdateUpdatedAt() *ChatRecordsUpsertBulk {
  843. return u.Update(func(s *ChatRecordsUpsert) {
  844. s.UpdateUpdatedAt()
  845. })
  846. }
  847. // SetDeletedAt sets the "deleted_at" field.
  848. func (u *ChatRecordsUpsertBulk) SetDeletedAt(v time.Time) *ChatRecordsUpsertBulk {
  849. return u.Update(func(s *ChatRecordsUpsert) {
  850. s.SetDeletedAt(v)
  851. })
  852. }
  853. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  854. func (u *ChatRecordsUpsertBulk) UpdateDeletedAt() *ChatRecordsUpsertBulk {
  855. return u.Update(func(s *ChatRecordsUpsert) {
  856. s.UpdateDeletedAt()
  857. })
  858. }
  859. // ClearDeletedAt clears the value of the "deleted_at" field.
  860. func (u *ChatRecordsUpsertBulk) ClearDeletedAt() *ChatRecordsUpsertBulk {
  861. return u.Update(func(s *ChatRecordsUpsert) {
  862. s.ClearDeletedAt()
  863. })
  864. }
  865. // SetContent sets the "content" field.
  866. func (u *ChatRecordsUpsertBulk) SetContent(v string) *ChatRecordsUpsertBulk {
  867. return u.Update(func(s *ChatRecordsUpsert) {
  868. s.SetContent(v)
  869. })
  870. }
  871. // UpdateContent sets the "content" field to the value that was provided on create.
  872. func (u *ChatRecordsUpsertBulk) UpdateContent() *ChatRecordsUpsertBulk {
  873. return u.Update(func(s *ChatRecordsUpsert) {
  874. s.UpdateContent()
  875. })
  876. }
  877. // SetContentType sets the "content_type" field.
  878. func (u *ChatRecordsUpsertBulk) SetContentType(v uint8) *ChatRecordsUpsertBulk {
  879. return u.Update(func(s *ChatRecordsUpsert) {
  880. s.SetContentType(v)
  881. })
  882. }
  883. // AddContentType adds v to the "content_type" field.
  884. func (u *ChatRecordsUpsertBulk) AddContentType(v uint8) *ChatRecordsUpsertBulk {
  885. return u.Update(func(s *ChatRecordsUpsert) {
  886. s.AddContentType(v)
  887. })
  888. }
  889. // UpdateContentType sets the "content_type" field to the value that was provided on create.
  890. func (u *ChatRecordsUpsertBulk) UpdateContentType() *ChatRecordsUpsertBulk {
  891. return u.Update(func(s *ChatRecordsUpsert) {
  892. s.UpdateContentType()
  893. })
  894. }
  895. // SetSessionID sets the "session_id" field.
  896. func (u *ChatRecordsUpsertBulk) SetSessionID(v uint64) *ChatRecordsUpsertBulk {
  897. return u.Update(func(s *ChatRecordsUpsert) {
  898. s.SetSessionID(v)
  899. })
  900. }
  901. // AddSessionID adds v to the "session_id" field.
  902. func (u *ChatRecordsUpsertBulk) AddSessionID(v uint64) *ChatRecordsUpsertBulk {
  903. return u.Update(func(s *ChatRecordsUpsert) {
  904. s.AddSessionID(v)
  905. })
  906. }
  907. // UpdateSessionID sets the "session_id" field to the value that was provided on create.
  908. func (u *ChatRecordsUpsertBulk) UpdateSessionID() *ChatRecordsUpsertBulk {
  909. return u.Update(func(s *ChatRecordsUpsert) {
  910. s.UpdateSessionID()
  911. })
  912. }
  913. // SetUserID sets the "user_id" field.
  914. func (u *ChatRecordsUpsertBulk) SetUserID(v uint64) *ChatRecordsUpsertBulk {
  915. return u.Update(func(s *ChatRecordsUpsert) {
  916. s.SetUserID(v)
  917. })
  918. }
  919. // AddUserID adds v to the "user_id" field.
  920. func (u *ChatRecordsUpsertBulk) AddUserID(v uint64) *ChatRecordsUpsertBulk {
  921. return u.Update(func(s *ChatRecordsUpsert) {
  922. s.AddUserID(v)
  923. })
  924. }
  925. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  926. func (u *ChatRecordsUpsertBulk) UpdateUserID() *ChatRecordsUpsertBulk {
  927. return u.Update(func(s *ChatRecordsUpsert) {
  928. s.UpdateUserID()
  929. })
  930. }
  931. // SetBotID sets the "bot_id" field.
  932. func (u *ChatRecordsUpsertBulk) SetBotID(v uint64) *ChatRecordsUpsertBulk {
  933. return u.Update(func(s *ChatRecordsUpsert) {
  934. s.SetBotID(v)
  935. })
  936. }
  937. // AddBotID adds v to the "bot_id" field.
  938. func (u *ChatRecordsUpsertBulk) AddBotID(v uint64) *ChatRecordsUpsertBulk {
  939. return u.Update(func(s *ChatRecordsUpsert) {
  940. s.AddBotID(v)
  941. })
  942. }
  943. // UpdateBotID sets the "bot_id" field to the value that was provided on create.
  944. func (u *ChatRecordsUpsertBulk) UpdateBotID() *ChatRecordsUpsertBulk {
  945. return u.Update(func(s *ChatRecordsUpsert) {
  946. s.UpdateBotID()
  947. })
  948. }
  949. // SetBotType sets the "bot_type" field.
  950. func (u *ChatRecordsUpsertBulk) SetBotType(v uint8) *ChatRecordsUpsertBulk {
  951. return u.Update(func(s *ChatRecordsUpsert) {
  952. s.SetBotType(v)
  953. })
  954. }
  955. // AddBotType adds v to the "bot_type" field.
  956. func (u *ChatRecordsUpsertBulk) AddBotType(v uint8) *ChatRecordsUpsertBulk {
  957. return u.Update(func(s *ChatRecordsUpsert) {
  958. s.AddBotType(v)
  959. })
  960. }
  961. // UpdateBotType sets the "bot_type" field to the value that was provided on create.
  962. func (u *ChatRecordsUpsertBulk) UpdateBotType() *ChatRecordsUpsertBulk {
  963. return u.Update(func(s *ChatRecordsUpsert) {
  964. s.UpdateBotType()
  965. })
  966. }
  967. // Exec executes the query.
  968. func (u *ChatRecordsUpsertBulk) Exec(ctx context.Context) error {
  969. if u.create.err != nil {
  970. return u.create.err
  971. }
  972. for i, b := range u.create.builders {
  973. if len(b.conflict) != 0 {
  974. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ChatRecordsCreateBulk instead", i)
  975. }
  976. }
  977. if len(u.create.conflict) == 0 {
  978. return errors.New("ent: missing options for ChatRecordsCreateBulk.OnConflict")
  979. }
  980. return u.create.Exec(ctx)
  981. }
  982. // ExecX is like Exec, but panics if an error occurs.
  983. func (u *ChatRecordsUpsertBulk) ExecX(ctx context.Context) {
  984. if err := u.create.Exec(ctx); err != nil {
  985. panic(err)
  986. }
  987. }