msg_create.go 29 KB

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