wpchatroom_create.go 29 KB

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