msg_create.go 29 KB

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