labeltagging_update.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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/labeltagging"
  9. "wechat-api/ent/predicate"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/dialect/sql/sqljson"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // LabelTaggingUpdate is the builder for updating LabelTagging entities.
  16. type LabelTaggingUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *LabelTaggingMutation
  20. }
  21. // Where appends a list predicates to the LabelTaggingUpdate builder.
  22. func (ltu *LabelTaggingUpdate) Where(ps ...predicate.LabelTagging) *LabelTaggingUpdate {
  23. ltu.mutation.Where(ps...)
  24. return ltu
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (ltu *LabelTaggingUpdate) SetUpdatedAt(t time.Time) *LabelTaggingUpdate {
  28. ltu.mutation.SetUpdatedAt(t)
  29. return ltu
  30. }
  31. // SetStatus sets the "status" field.
  32. func (ltu *LabelTaggingUpdate) SetStatus(u uint8) *LabelTaggingUpdate {
  33. ltu.mutation.ResetStatus()
  34. ltu.mutation.SetStatus(u)
  35. return ltu
  36. }
  37. // SetNillableStatus sets the "status" field if the given value is not nil.
  38. func (ltu *LabelTaggingUpdate) SetNillableStatus(u *uint8) *LabelTaggingUpdate {
  39. if u != nil {
  40. ltu.SetStatus(*u)
  41. }
  42. return ltu
  43. }
  44. // AddStatus adds u to the "status" field.
  45. func (ltu *LabelTaggingUpdate) AddStatus(u int8) *LabelTaggingUpdate {
  46. ltu.mutation.AddStatus(u)
  47. return ltu
  48. }
  49. // ClearStatus clears the value of the "status" field.
  50. func (ltu *LabelTaggingUpdate) ClearStatus() *LabelTaggingUpdate {
  51. ltu.mutation.ClearStatus()
  52. return ltu
  53. }
  54. // SetDeletedAt sets the "deleted_at" field.
  55. func (ltu *LabelTaggingUpdate) SetDeletedAt(t time.Time) *LabelTaggingUpdate {
  56. ltu.mutation.SetDeletedAt(t)
  57. return ltu
  58. }
  59. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  60. func (ltu *LabelTaggingUpdate) SetNillableDeletedAt(t *time.Time) *LabelTaggingUpdate {
  61. if t != nil {
  62. ltu.SetDeletedAt(*t)
  63. }
  64. return ltu
  65. }
  66. // ClearDeletedAt clears the value of the "deleted_at" field.
  67. func (ltu *LabelTaggingUpdate) ClearDeletedAt() *LabelTaggingUpdate {
  68. ltu.mutation.ClearDeletedAt()
  69. return ltu
  70. }
  71. // SetOrganizationID sets the "organization_id" field.
  72. func (ltu *LabelTaggingUpdate) SetOrganizationID(u uint64) *LabelTaggingUpdate {
  73. ltu.mutation.ResetOrganizationID()
  74. ltu.mutation.SetOrganizationID(u)
  75. return ltu
  76. }
  77. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  78. func (ltu *LabelTaggingUpdate) SetNillableOrganizationID(u *uint64) *LabelTaggingUpdate {
  79. if u != nil {
  80. ltu.SetOrganizationID(*u)
  81. }
  82. return ltu
  83. }
  84. // AddOrganizationID adds u to the "organization_id" field.
  85. func (ltu *LabelTaggingUpdate) AddOrganizationID(u int64) *LabelTaggingUpdate {
  86. ltu.mutation.AddOrganizationID(u)
  87. return ltu
  88. }
  89. // ClearOrganizationID clears the value of the "organization_id" field.
  90. func (ltu *LabelTaggingUpdate) ClearOrganizationID() *LabelTaggingUpdate {
  91. ltu.mutation.ClearOrganizationID()
  92. return ltu
  93. }
  94. // SetType sets the "type" field.
  95. func (ltu *LabelTaggingUpdate) SetType(i int) *LabelTaggingUpdate {
  96. ltu.mutation.ResetType()
  97. ltu.mutation.SetType(i)
  98. return ltu
  99. }
  100. // SetNillableType sets the "type" field if the given value is not nil.
  101. func (ltu *LabelTaggingUpdate) SetNillableType(i *int) *LabelTaggingUpdate {
  102. if i != nil {
  103. ltu.SetType(*i)
  104. }
  105. return ltu
  106. }
  107. // AddType adds i to the "type" field.
  108. func (ltu *LabelTaggingUpdate) AddType(i int) *LabelTaggingUpdate {
  109. ltu.mutation.AddType(i)
  110. return ltu
  111. }
  112. // SetConditions sets the "conditions" field.
  113. func (ltu *LabelTaggingUpdate) SetConditions(s []string) *LabelTaggingUpdate {
  114. ltu.mutation.SetConditions(s)
  115. return ltu
  116. }
  117. // AppendConditions appends s to the "conditions" field.
  118. func (ltu *LabelTaggingUpdate) AppendConditions(s []string) *LabelTaggingUpdate {
  119. ltu.mutation.AppendConditions(s)
  120. return ltu
  121. }
  122. // ClearConditions clears the value of the "conditions" field.
  123. func (ltu *LabelTaggingUpdate) ClearConditions() *LabelTaggingUpdate {
  124. ltu.mutation.ClearConditions()
  125. return ltu
  126. }
  127. // SetActionLabelAdd sets the "action_label_add" field.
  128. func (ltu *LabelTaggingUpdate) SetActionLabelAdd(u []uint64) *LabelTaggingUpdate {
  129. ltu.mutation.SetActionLabelAdd(u)
  130. return ltu
  131. }
  132. // AppendActionLabelAdd appends u to the "action_label_add" field.
  133. func (ltu *LabelTaggingUpdate) AppendActionLabelAdd(u []uint64) *LabelTaggingUpdate {
  134. ltu.mutation.AppendActionLabelAdd(u)
  135. return ltu
  136. }
  137. // ClearActionLabelAdd clears the value of the "action_label_add" field.
  138. func (ltu *LabelTaggingUpdate) ClearActionLabelAdd() *LabelTaggingUpdate {
  139. ltu.mutation.ClearActionLabelAdd()
  140. return ltu
  141. }
  142. // SetActionLabelDel sets the "action_label_del" field.
  143. func (ltu *LabelTaggingUpdate) SetActionLabelDel(u []uint64) *LabelTaggingUpdate {
  144. ltu.mutation.SetActionLabelDel(u)
  145. return ltu
  146. }
  147. // AppendActionLabelDel appends u to the "action_label_del" field.
  148. func (ltu *LabelTaggingUpdate) AppendActionLabelDel(u []uint64) *LabelTaggingUpdate {
  149. ltu.mutation.AppendActionLabelDel(u)
  150. return ltu
  151. }
  152. // ClearActionLabelDel clears the value of the "action_label_del" field.
  153. func (ltu *LabelTaggingUpdate) ClearActionLabelDel() *LabelTaggingUpdate {
  154. ltu.mutation.ClearActionLabelDel()
  155. return ltu
  156. }
  157. // Mutation returns the LabelTaggingMutation object of the builder.
  158. func (ltu *LabelTaggingUpdate) Mutation() *LabelTaggingMutation {
  159. return ltu.mutation
  160. }
  161. // Save executes the query and returns the number of nodes affected by the update operation.
  162. func (ltu *LabelTaggingUpdate) Save(ctx context.Context) (int, error) {
  163. if err := ltu.defaults(); err != nil {
  164. return 0, err
  165. }
  166. return withHooks(ctx, ltu.sqlSave, ltu.mutation, ltu.hooks)
  167. }
  168. // SaveX is like Save, but panics if an error occurs.
  169. func (ltu *LabelTaggingUpdate) SaveX(ctx context.Context) int {
  170. affected, err := ltu.Save(ctx)
  171. if err != nil {
  172. panic(err)
  173. }
  174. return affected
  175. }
  176. // Exec executes the query.
  177. func (ltu *LabelTaggingUpdate) Exec(ctx context.Context) error {
  178. _, err := ltu.Save(ctx)
  179. return err
  180. }
  181. // ExecX is like Exec, but panics if an error occurs.
  182. func (ltu *LabelTaggingUpdate) ExecX(ctx context.Context) {
  183. if err := ltu.Exec(ctx); err != nil {
  184. panic(err)
  185. }
  186. }
  187. // defaults sets the default values of the builder before save.
  188. func (ltu *LabelTaggingUpdate) defaults() error {
  189. if _, ok := ltu.mutation.UpdatedAt(); !ok {
  190. if labeltagging.UpdateDefaultUpdatedAt == nil {
  191. return fmt.Errorf("ent: uninitialized labeltagging.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  192. }
  193. v := labeltagging.UpdateDefaultUpdatedAt()
  194. ltu.mutation.SetUpdatedAt(v)
  195. }
  196. return nil
  197. }
  198. func (ltu *LabelTaggingUpdate) sqlSave(ctx context.Context) (n int, err error) {
  199. _spec := sqlgraph.NewUpdateSpec(labeltagging.Table, labeltagging.Columns, sqlgraph.NewFieldSpec(labeltagging.FieldID, field.TypeUint64))
  200. if ps := ltu.mutation.predicates; len(ps) > 0 {
  201. _spec.Predicate = func(selector *sql.Selector) {
  202. for i := range ps {
  203. ps[i](selector)
  204. }
  205. }
  206. }
  207. if value, ok := ltu.mutation.UpdatedAt(); ok {
  208. _spec.SetField(labeltagging.FieldUpdatedAt, field.TypeTime, value)
  209. }
  210. if value, ok := ltu.mutation.Status(); ok {
  211. _spec.SetField(labeltagging.FieldStatus, field.TypeUint8, value)
  212. }
  213. if value, ok := ltu.mutation.AddedStatus(); ok {
  214. _spec.AddField(labeltagging.FieldStatus, field.TypeUint8, value)
  215. }
  216. if ltu.mutation.StatusCleared() {
  217. _spec.ClearField(labeltagging.FieldStatus, field.TypeUint8)
  218. }
  219. if value, ok := ltu.mutation.DeletedAt(); ok {
  220. _spec.SetField(labeltagging.FieldDeletedAt, field.TypeTime, value)
  221. }
  222. if ltu.mutation.DeletedAtCleared() {
  223. _spec.ClearField(labeltagging.FieldDeletedAt, field.TypeTime)
  224. }
  225. if value, ok := ltu.mutation.OrganizationID(); ok {
  226. _spec.SetField(labeltagging.FieldOrganizationID, field.TypeUint64, value)
  227. }
  228. if value, ok := ltu.mutation.AddedOrganizationID(); ok {
  229. _spec.AddField(labeltagging.FieldOrganizationID, field.TypeUint64, value)
  230. }
  231. if ltu.mutation.OrganizationIDCleared() {
  232. _spec.ClearField(labeltagging.FieldOrganizationID, field.TypeUint64)
  233. }
  234. if value, ok := ltu.mutation.GetType(); ok {
  235. _spec.SetField(labeltagging.FieldType, field.TypeInt, value)
  236. }
  237. if value, ok := ltu.mutation.AddedType(); ok {
  238. _spec.AddField(labeltagging.FieldType, field.TypeInt, value)
  239. }
  240. if value, ok := ltu.mutation.Conditions(); ok {
  241. _spec.SetField(labeltagging.FieldConditions, field.TypeJSON, value)
  242. }
  243. if value, ok := ltu.mutation.AppendedConditions(); ok {
  244. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  245. sqljson.Append(u, labeltagging.FieldConditions, value)
  246. })
  247. }
  248. if ltu.mutation.ConditionsCleared() {
  249. _spec.ClearField(labeltagging.FieldConditions, field.TypeJSON)
  250. }
  251. if value, ok := ltu.mutation.ActionLabelAdd(); ok {
  252. _spec.SetField(labeltagging.FieldActionLabelAdd, field.TypeJSON, value)
  253. }
  254. if value, ok := ltu.mutation.AppendedActionLabelAdd(); ok {
  255. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  256. sqljson.Append(u, labeltagging.FieldActionLabelAdd, value)
  257. })
  258. }
  259. if ltu.mutation.ActionLabelAddCleared() {
  260. _spec.ClearField(labeltagging.FieldActionLabelAdd, field.TypeJSON)
  261. }
  262. if value, ok := ltu.mutation.ActionLabelDel(); ok {
  263. _spec.SetField(labeltagging.FieldActionLabelDel, field.TypeJSON, value)
  264. }
  265. if value, ok := ltu.mutation.AppendedActionLabelDel(); ok {
  266. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  267. sqljson.Append(u, labeltagging.FieldActionLabelDel, value)
  268. })
  269. }
  270. if ltu.mutation.ActionLabelDelCleared() {
  271. _spec.ClearField(labeltagging.FieldActionLabelDel, field.TypeJSON)
  272. }
  273. if n, err = sqlgraph.UpdateNodes(ctx, ltu.driver, _spec); err != nil {
  274. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  275. err = &NotFoundError{labeltagging.Label}
  276. } else if sqlgraph.IsConstraintError(err) {
  277. err = &ConstraintError{msg: err.Error(), wrap: err}
  278. }
  279. return 0, err
  280. }
  281. ltu.mutation.done = true
  282. return n, nil
  283. }
  284. // LabelTaggingUpdateOne is the builder for updating a single LabelTagging entity.
  285. type LabelTaggingUpdateOne struct {
  286. config
  287. fields []string
  288. hooks []Hook
  289. mutation *LabelTaggingMutation
  290. }
  291. // SetUpdatedAt sets the "updated_at" field.
  292. func (ltuo *LabelTaggingUpdateOne) SetUpdatedAt(t time.Time) *LabelTaggingUpdateOne {
  293. ltuo.mutation.SetUpdatedAt(t)
  294. return ltuo
  295. }
  296. // SetStatus sets the "status" field.
  297. func (ltuo *LabelTaggingUpdateOne) SetStatus(u uint8) *LabelTaggingUpdateOne {
  298. ltuo.mutation.ResetStatus()
  299. ltuo.mutation.SetStatus(u)
  300. return ltuo
  301. }
  302. // SetNillableStatus sets the "status" field if the given value is not nil.
  303. func (ltuo *LabelTaggingUpdateOne) SetNillableStatus(u *uint8) *LabelTaggingUpdateOne {
  304. if u != nil {
  305. ltuo.SetStatus(*u)
  306. }
  307. return ltuo
  308. }
  309. // AddStatus adds u to the "status" field.
  310. func (ltuo *LabelTaggingUpdateOne) AddStatus(u int8) *LabelTaggingUpdateOne {
  311. ltuo.mutation.AddStatus(u)
  312. return ltuo
  313. }
  314. // ClearStatus clears the value of the "status" field.
  315. func (ltuo *LabelTaggingUpdateOne) ClearStatus() *LabelTaggingUpdateOne {
  316. ltuo.mutation.ClearStatus()
  317. return ltuo
  318. }
  319. // SetDeletedAt sets the "deleted_at" field.
  320. func (ltuo *LabelTaggingUpdateOne) SetDeletedAt(t time.Time) *LabelTaggingUpdateOne {
  321. ltuo.mutation.SetDeletedAt(t)
  322. return ltuo
  323. }
  324. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  325. func (ltuo *LabelTaggingUpdateOne) SetNillableDeletedAt(t *time.Time) *LabelTaggingUpdateOne {
  326. if t != nil {
  327. ltuo.SetDeletedAt(*t)
  328. }
  329. return ltuo
  330. }
  331. // ClearDeletedAt clears the value of the "deleted_at" field.
  332. func (ltuo *LabelTaggingUpdateOne) ClearDeletedAt() *LabelTaggingUpdateOne {
  333. ltuo.mutation.ClearDeletedAt()
  334. return ltuo
  335. }
  336. // SetOrganizationID sets the "organization_id" field.
  337. func (ltuo *LabelTaggingUpdateOne) SetOrganizationID(u uint64) *LabelTaggingUpdateOne {
  338. ltuo.mutation.ResetOrganizationID()
  339. ltuo.mutation.SetOrganizationID(u)
  340. return ltuo
  341. }
  342. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  343. func (ltuo *LabelTaggingUpdateOne) SetNillableOrganizationID(u *uint64) *LabelTaggingUpdateOne {
  344. if u != nil {
  345. ltuo.SetOrganizationID(*u)
  346. }
  347. return ltuo
  348. }
  349. // AddOrganizationID adds u to the "organization_id" field.
  350. func (ltuo *LabelTaggingUpdateOne) AddOrganizationID(u int64) *LabelTaggingUpdateOne {
  351. ltuo.mutation.AddOrganizationID(u)
  352. return ltuo
  353. }
  354. // ClearOrganizationID clears the value of the "organization_id" field.
  355. func (ltuo *LabelTaggingUpdateOne) ClearOrganizationID() *LabelTaggingUpdateOne {
  356. ltuo.mutation.ClearOrganizationID()
  357. return ltuo
  358. }
  359. // SetType sets the "type" field.
  360. func (ltuo *LabelTaggingUpdateOne) SetType(i int) *LabelTaggingUpdateOne {
  361. ltuo.mutation.ResetType()
  362. ltuo.mutation.SetType(i)
  363. return ltuo
  364. }
  365. // SetNillableType sets the "type" field if the given value is not nil.
  366. func (ltuo *LabelTaggingUpdateOne) SetNillableType(i *int) *LabelTaggingUpdateOne {
  367. if i != nil {
  368. ltuo.SetType(*i)
  369. }
  370. return ltuo
  371. }
  372. // AddType adds i to the "type" field.
  373. func (ltuo *LabelTaggingUpdateOne) AddType(i int) *LabelTaggingUpdateOne {
  374. ltuo.mutation.AddType(i)
  375. return ltuo
  376. }
  377. // SetConditions sets the "conditions" field.
  378. func (ltuo *LabelTaggingUpdateOne) SetConditions(s []string) *LabelTaggingUpdateOne {
  379. ltuo.mutation.SetConditions(s)
  380. return ltuo
  381. }
  382. // AppendConditions appends s to the "conditions" field.
  383. func (ltuo *LabelTaggingUpdateOne) AppendConditions(s []string) *LabelTaggingUpdateOne {
  384. ltuo.mutation.AppendConditions(s)
  385. return ltuo
  386. }
  387. // ClearConditions clears the value of the "conditions" field.
  388. func (ltuo *LabelTaggingUpdateOne) ClearConditions() *LabelTaggingUpdateOne {
  389. ltuo.mutation.ClearConditions()
  390. return ltuo
  391. }
  392. // SetActionLabelAdd sets the "action_label_add" field.
  393. func (ltuo *LabelTaggingUpdateOne) SetActionLabelAdd(u []uint64) *LabelTaggingUpdateOne {
  394. ltuo.mutation.SetActionLabelAdd(u)
  395. return ltuo
  396. }
  397. // AppendActionLabelAdd appends u to the "action_label_add" field.
  398. func (ltuo *LabelTaggingUpdateOne) AppendActionLabelAdd(u []uint64) *LabelTaggingUpdateOne {
  399. ltuo.mutation.AppendActionLabelAdd(u)
  400. return ltuo
  401. }
  402. // ClearActionLabelAdd clears the value of the "action_label_add" field.
  403. func (ltuo *LabelTaggingUpdateOne) ClearActionLabelAdd() *LabelTaggingUpdateOne {
  404. ltuo.mutation.ClearActionLabelAdd()
  405. return ltuo
  406. }
  407. // SetActionLabelDel sets the "action_label_del" field.
  408. func (ltuo *LabelTaggingUpdateOne) SetActionLabelDel(u []uint64) *LabelTaggingUpdateOne {
  409. ltuo.mutation.SetActionLabelDel(u)
  410. return ltuo
  411. }
  412. // AppendActionLabelDel appends u to the "action_label_del" field.
  413. func (ltuo *LabelTaggingUpdateOne) AppendActionLabelDel(u []uint64) *LabelTaggingUpdateOne {
  414. ltuo.mutation.AppendActionLabelDel(u)
  415. return ltuo
  416. }
  417. // ClearActionLabelDel clears the value of the "action_label_del" field.
  418. func (ltuo *LabelTaggingUpdateOne) ClearActionLabelDel() *LabelTaggingUpdateOne {
  419. ltuo.mutation.ClearActionLabelDel()
  420. return ltuo
  421. }
  422. // Mutation returns the LabelTaggingMutation object of the builder.
  423. func (ltuo *LabelTaggingUpdateOne) Mutation() *LabelTaggingMutation {
  424. return ltuo.mutation
  425. }
  426. // Where appends a list predicates to the LabelTaggingUpdate builder.
  427. func (ltuo *LabelTaggingUpdateOne) Where(ps ...predicate.LabelTagging) *LabelTaggingUpdateOne {
  428. ltuo.mutation.Where(ps...)
  429. return ltuo
  430. }
  431. // Select allows selecting one or more fields (columns) of the returned entity.
  432. // The default is selecting all fields defined in the entity schema.
  433. func (ltuo *LabelTaggingUpdateOne) Select(field string, fields ...string) *LabelTaggingUpdateOne {
  434. ltuo.fields = append([]string{field}, fields...)
  435. return ltuo
  436. }
  437. // Save executes the query and returns the updated LabelTagging entity.
  438. func (ltuo *LabelTaggingUpdateOne) Save(ctx context.Context) (*LabelTagging, error) {
  439. if err := ltuo.defaults(); err != nil {
  440. return nil, err
  441. }
  442. return withHooks(ctx, ltuo.sqlSave, ltuo.mutation, ltuo.hooks)
  443. }
  444. // SaveX is like Save, but panics if an error occurs.
  445. func (ltuo *LabelTaggingUpdateOne) SaveX(ctx context.Context) *LabelTagging {
  446. node, err := ltuo.Save(ctx)
  447. if err != nil {
  448. panic(err)
  449. }
  450. return node
  451. }
  452. // Exec executes the query on the entity.
  453. func (ltuo *LabelTaggingUpdateOne) Exec(ctx context.Context) error {
  454. _, err := ltuo.Save(ctx)
  455. return err
  456. }
  457. // ExecX is like Exec, but panics if an error occurs.
  458. func (ltuo *LabelTaggingUpdateOne) ExecX(ctx context.Context) {
  459. if err := ltuo.Exec(ctx); err != nil {
  460. panic(err)
  461. }
  462. }
  463. // defaults sets the default values of the builder before save.
  464. func (ltuo *LabelTaggingUpdateOne) defaults() error {
  465. if _, ok := ltuo.mutation.UpdatedAt(); !ok {
  466. if labeltagging.UpdateDefaultUpdatedAt == nil {
  467. return fmt.Errorf("ent: uninitialized labeltagging.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  468. }
  469. v := labeltagging.UpdateDefaultUpdatedAt()
  470. ltuo.mutation.SetUpdatedAt(v)
  471. }
  472. return nil
  473. }
  474. func (ltuo *LabelTaggingUpdateOne) sqlSave(ctx context.Context) (_node *LabelTagging, err error) {
  475. _spec := sqlgraph.NewUpdateSpec(labeltagging.Table, labeltagging.Columns, sqlgraph.NewFieldSpec(labeltagging.FieldID, field.TypeUint64))
  476. id, ok := ltuo.mutation.ID()
  477. if !ok {
  478. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "LabelTagging.id" for update`)}
  479. }
  480. _spec.Node.ID.Value = id
  481. if fields := ltuo.fields; len(fields) > 0 {
  482. _spec.Node.Columns = make([]string, 0, len(fields))
  483. _spec.Node.Columns = append(_spec.Node.Columns, labeltagging.FieldID)
  484. for _, f := range fields {
  485. if !labeltagging.ValidColumn(f) {
  486. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  487. }
  488. if f != labeltagging.FieldID {
  489. _spec.Node.Columns = append(_spec.Node.Columns, f)
  490. }
  491. }
  492. }
  493. if ps := ltuo.mutation.predicates; len(ps) > 0 {
  494. _spec.Predicate = func(selector *sql.Selector) {
  495. for i := range ps {
  496. ps[i](selector)
  497. }
  498. }
  499. }
  500. if value, ok := ltuo.mutation.UpdatedAt(); ok {
  501. _spec.SetField(labeltagging.FieldUpdatedAt, field.TypeTime, value)
  502. }
  503. if value, ok := ltuo.mutation.Status(); ok {
  504. _spec.SetField(labeltagging.FieldStatus, field.TypeUint8, value)
  505. }
  506. if value, ok := ltuo.mutation.AddedStatus(); ok {
  507. _spec.AddField(labeltagging.FieldStatus, field.TypeUint8, value)
  508. }
  509. if ltuo.mutation.StatusCleared() {
  510. _spec.ClearField(labeltagging.FieldStatus, field.TypeUint8)
  511. }
  512. if value, ok := ltuo.mutation.DeletedAt(); ok {
  513. _spec.SetField(labeltagging.FieldDeletedAt, field.TypeTime, value)
  514. }
  515. if ltuo.mutation.DeletedAtCleared() {
  516. _spec.ClearField(labeltagging.FieldDeletedAt, field.TypeTime)
  517. }
  518. if value, ok := ltuo.mutation.OrganizationID(); ok {
  519. _spec.SetField(labeltagging.FieldOrganizationID, field.TypeUint64, value)
  520. }
  521. if value, ok := ltuo.mutation.AddedOrganizationID(); ok {
  522. _spec.AddField(labeltagging.FieldOrganizationID, field.TypeUint64, value)
  523. }
  524. if ltuo.mutation.OrganizationIDCleared() {
  525. _spec.ClearField(labeltagging.FieldOrganizationID, field.TypeUint64)
  526. }
  527. if value, ok := ltuo.mutation.GetType(); ok {
  528. _spec.SetField(labeltagging.FieldType, field.TypeInt, value)
  529. }
  530. if value, ok := ltuo.mutation.AddedType(); ok {
  531. _spec.AddField(labeltagging.FieldType, field.TypeInt, value)
  532. }
  533. if value, ok := ltuo.mutation.Conditions(); ok {
  534. _spec.SetField(labeltagging.FieldConditions, field.TypeJSON, value)
  535. }
  536. if value, ok := ltuo.mutation.AppendedConditions(); ok {
  537. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  538. sqljson.Append(u, labeltagging.FieldConditions, value)
  539. })
  540. }
  541. if ltuo.mutation.ConditionsCleared() {
  542. _spec.ClearField(labeltagging.FieldConditions, field.TypeJSON)
  543. }
  544. if value, ok := ltuo.mutation.ActionLabelAdd(); ok {
  545. _spec.SetField(labeltagging.FieldActionLabelAdd, field.TypeJSON, value)
  546. }
  547. if value, ok := ltuo.mutation.AppendedActionLabelAdd(); ok {
  548. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  549. sqljson.Append(u, labeltagging.FieldActionLabelAdd, value)
  550. })
  551. }
  552. if ltuo.mutation.ActionLabelAddCleared() {
  553. _spec.ClearField(labeltagging.FieldActionLabelAdd, field.TypeJSON)
  554. }
  555. if value, ok := ltuo.mutation.ActionLabelDel(); ok {
  556. _spec.SetField(labeltagging.FieldActionLabelDel, field.TypeJSON, value)
  557. }
  558. if value, ok := ltuo.mutation.AppendedActionLabelDel(); ok {
  559. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  560. sqljson.Append(u, labeltagging.FieldActionLabelDel, value)
  561. })
  562. }
  563. if ltuo.mutation.ActionLabelDelCleared() {
  564. _spec.ClearField(labeltagging.FieldActionLabelDel, field.TypeJSON)
  565. }
  566. _node = &LabelTagging{config: ltuo.config}
  567. _spec.Assign = _node.assignValues
  568. _spec.ScanValues = _node.scanValues
  569. if err = sqlgraph.UpdateNode(ctx, ltuo.driver, _spec); err != nil {
  570. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  571. err = &NotFoundError{labeltagging.Label}
  572. } else if sqlgraph.IsConstraintError(err) {
  573. err = &ConstraintError{msg: err.Error(), wrap: err}
  574. }
  575. return nil, err
  576. }
  577. ltuo.mutation.done = true
  578. return _node, nil
  579. }