label_update.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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/label"
  9. "wechat-api/ent/labelrelationship"
  10. "wechat-api/ent/predicate"
  11. "entgo.io/ent/dialect/sql"
  12. "entgo.io/ent/dialect/sql/sqlgraph"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // LabelUpdate is the builder for updating Label entities.
  16. type LabelUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *LabelMutation
  20. }
  21. // Where appends a list predicates to the LabelUpdate builder.
  22. func (lu *LabelUpdate) Where(ps ...predicate.Label) *LabelUpdate {
  23. lu.mutation.Where(ps...)
  24. return lu
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (lu *LabelUpdate) SetUpdatedAt(t time.Time) *LabelUpdate {
  28. lu.mutation.SetUpdatedAt(t)
  29. return lu
  30. }
  31. // SetStatus sets the "status" field.
  32. func (lu *LabelUpdate) SetStatus(u uint8) *LabelUpdate {
  33. lu.mutation.ResetStatus()
  34. lu.mutation.SetStatus(u)
  35. return lu
  36. }
  37. // SetNillableStatus sets the "status" field if the given value is not nil.
  38. func (lu *LabelUpdate) SetNillableStatus(u *uint8) *LabelUpdate {
  39. if u != nil {
  40. lu.SetStatus(*u)
  41. }
  42. return lu
  43. }
  44. // AddStatus adds u to the "status" field.
  45. func (lu *LabelUpdate) AddStatus(u int8) *LabelUpdate {
  46. lu.mutation.AddStatus(u)
  47. return lu
  48. }
  49. // ClearStatus clears the value of the "status" field.
  50. func (lu *LabelUpdate) ClearStatus() *LabelUpdate {
  51. lu.mutation.ClearStatus()
  52. return lu
  53. }
  54. // SetDeletedAt sets the "deleted_at" field.
  55. func (lu *LabelUpdate) SetDeletedAt(t time.Time) *LabelUpdate {
  56. lu.mutation.SetDeletedAt(t)
  57. return lu
  58. }
  59. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  60. func (lu *LabelUpdate) SetNillableDeletedAt(t *time.Time) *LabelUpdate {
  61. if t != nil {
  62. lu.SetDeletedAt(*t)
  63. }
  64. return lu
  65. }
  66. // ClearDeletedAt clears the value of the "deleted_at" field.
  67. func (lu *LabelUpdate) ClearDeletedAt() *LabelUpdate {
  68. lu.mutation.ClearDeletedAt()
  69. return lu
  70. }
  71. // SetType sets the "type" field.
  72. func (lu *LabelUpdate) SetType(i int) *LabelUpdate {
  73. lu.mutation.ResetType()
  74. lu.mutation.SetType(i)
  75. return lu
  76. }
  77. // SetNillableType sets the "type" field if the given value is not nil.
  78. func (lu *LabelUpdate) SetNillableType(i *int) *LabelUpdate {
  79. if i != nil {
  80. lu.SetType(*i)
  81. }
  82. return lu
  83. }
  84. // AddType adds i to the "type" field.
  85. func (lu *LabelUpdate) AddType(i int) *LabelUpdate {
  86. lu.mutation.AddType(i)
  87. return lu
  88. }
  89. // SetName sets the "name" field.
  90. func (lu *LabelUpdate) SetName(s string) *LabelUpdate {
  91. lu.mutation.SetName(s)
  92. return lu
  93. }
  94. // SetNillableName sets the "name" field if the given value is not nil.
  95. func (lu *LabelUpdate) SetNillableName(s *string) *LabelUpdate {
  96. if s != nil {
  97. lu.SetName(*s)
  98. }
  99. return lu
  100. }
  101. // SetFrom sets the "from" field.
  102. func (lu *LabelUpdate) SetFrom(i int) *LabelUpdate {
  103. lu.mutation.ResetFrom()
  104. lu.mutation.SetFrom(i)
  105. return lu
  106. }
  107. // SetNillableFrom sets the "from" field if the given value is not nil.
  108. func (lu *LabelUpdate) SetNillableFrom(i *int) *LabelUpdate {
  109. if i != nil {
  110. lu.SetFrom(*i)
  111. }
  112. return lu
  113. }
  114. // AddFrom adds i to the "from" field.
  115. func (lu *LabelUpdate) AddFrom(i int) *LabelUpdate {
  116. lu.mutation.AddFrom(i)
  117. return lu
  118. }
  119. // SetMode sets the "mode" field.
  120. func (lu *LabelUpdate) SetMode(i int) *LabelUpdate {
  121. lu.mutation.ResetMode()
  122. lu.mutation.SetMode(i)
  123. return lu
  124. }
  125. // SetNillableMode sets the "mode" field if the given value is not nil.
  126. func (lu *LabelUpdate) SetNillableMode(i *int) *LabelUpdate {
  127. if i != nil {
  128. lu.SetMode(*i)
  129. }
  130. return lu
  131. }
  132. // AddMode adds i to the "mode" field.
  133. func (lu *LabelUpdate) AddMode(i int) *LabelUpdate {
  134. lu.mutation.AddMode(i)
  135. return lu
  136. }
  137. // SetConditions sets the "conditions" field.
  138. func (lu *LabelUpdate) SetConditions(s string) *LabelUpdate {
  139. lu.mutation.SetConditions(s)
  140. return lu
  141. }
  142. // SetNillableConditions sets the "conditions" field if the given value is not nil.
  143. func (lu *LabelUpdate) SetNillableConditions(s *string) *LabelUpdate {
  144. if s != nil {
  145. lu.SetConditions(*s)
  146. }
  147. return lu
  148. }
  149. // ClearConditions clears the value of the "conditions" field.
  150. func (lu *LabelUpdate) ClearConditions() *LabelUpdate {
  151. lu.mutation.ClearConditions()
  152. return lu
  153. }
  154. // SetOrganizationID sets the "organization_id" field.
  155. func (lu *LabelUpdate) SetOrganizationID(u uint64) *LabelUpdate {
  156. lu.mutation.ResetOrganizationID()
  157. lu.mutation.SetOrganizationID(u)
  158. return lu
  159. }
  160. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  161. func (lu *LabelUpdate) SetNillableOrganizationID(u *uint64) *LabelUpdate {
  162. if u != nil {
  163. lu.SetOrganizationID(*u)
  164. }
  165. return lu
  166. }
  167. // AddOrganizationID adds u to the "organization_id" field.
  168. func (lu *LabelUpdate) AddOrganizationID(u int64) *LabelUpdate {
  169. lu.mutation.AddOrganizationID(u)
  170. return lu
  171. }
  172. // ClearOrganizationID clears the value of the "organization_id" field.
  173. func (lu *LabelUpdate) ClearOrganizationID() *LabelUpdate {
  174. lu.mutation.ClearOrganizationID()
  175. return lu
  176. }
  177. // AddLabelRelationshipIDs adds the "label_relationships" edge to the LabelRelationship entity by IDs.
  178. func (lu *LabelUpdate) AddLabelRelationshipIDs(ids ...uint64) *LabelUpdate {
  179. lu.mutation.AddLabelRelationshipIDs(ids...)
  180. return lu
  181. }
  182. // AddLabelRelationships adds the "label_relationships" edges to the LabelRelationship entity.
  183. func (lu *LabelUpdate) AddLabelRelationships(l ...*LabelRelationship) *LabelUpdate {
  184. ids := make([]uint64, len(l))
  185. for i := range l {
  186. ids[i] = l[i].ID
  187. }
  188. return lu.AddLabelRelationshipIDs(ids...)
  189. }
  190. // Mutation returns the LabelMutation object of the builder.
  191. func (lu *LabelUpdate) Mutation() *LabelMutation {
  192. return lu.mutation
  193. }
  194. // ClearLabelRelationships clears all "label_relationships" edges to the LabelRelationship entity.
  195. func (lu *LabelUpdate) ClearLabelRelationships() *LabelUpdate {
  196. lu.mutation.ClearLabelRelationships()
  197. return lu
  198. }
  199. // RemoveLabelRelationshipIDs removes the "label_relationships" edge to LabelRelationship entities by IDs.
  200. func (lu *LabelUpdate) RemoveLabelRelationshipIDs(ids ...uint64) *LabelUpdate {
  201. lu.mutation.RemoveLabelRelationshipIDs(ids...)
  202. return lu
  203. }
  204. // RemoveLabelRelationships removes "label_relationships" edges to LabelRelationship entities.
  205. func (lu *LabelUpdate) RemoveLabelRelationships(l ...*LabelRelationship) *LabelUpdate {
  206. ids := make([]uint64, len(l))
  207. for i := range l {
  208. ids[i] = l[i].ID
  209. }
  210. return lu.RemoveLabelRelationshipIDs(ids...)
  211. }
  212. // Save executes the query and returns the number of nodes affected by the update operation.
  213. func (lu *LabelUpdate) Save(ctx context.Context) (int, error) {
  214. if err := lu.defaults(); err != nil {
  215. return 0, err
  216. }
  217. return withHooks(ctx, lu.sqlSave, lu.mutation, lu.hooks)
  218. }
  219. // SaveX is like Save, but panics if an error occurs.
  220. func (lu *LabelUpdate) SaveX(ctx context.Context) int {
  221. affected, err := lu.Save(ctx)
  222. if err != nil {
  223. panic(err)
  224. }
  225. return affected
  226. }
  227. // Exec executes the query.
  228. func (lu *LabelUpdate) Exec(ctx context.Context) error {
  229. _, err := lu.Save(ctx)
  230. return err
  231. }
  232. // ExecX is like Exec, but panics if an error occurs.
  233. func (lu *LabelUpdate) ExecX(ctx context.Context) {
  234. if err := lu.Exec(ctx); err != nil {
  235. panic(err)
  236. }
  237. }
  238. // defaults sets the default values of the builder before save.
  239. func (lu *LabelUpdate) defaults() error {
  240. if _, ok := lu.mutation.UpdatedAt(); !ok {
  241. if label.UpdateDefaultUpdatedAt == nil {
  242. return fmt.Errorf("ent: uninitialized label.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  243. }
  244. v := label.UpdateDefaultUpdatedAt()
  245. lu.mutation.SetUpdatedAt(v)
  246. }
  247. return nil
  248. }
  249. func (lu *LabelUpdate) sqlSave(ctx context.Context) (n int, err error) {
  250. _spec := sqlgraph.NewUpdateSpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUint64))
  251. if ps := lu.mutation.predicates; len(ps) > 0 {
  252. _spec.Predicate = func(selector *sql.Selector) {
  253. for i := range ps {
  254. ps[i](selector)
  255. }
  256. }
  257. }
  258. if value, ok := lu.mutation.UpdatedAt(); ok {
  259. _spec.SetField(label.FieldUpdatedAt, field.TypeTime, value)
  260. }
  261. if value, ok := lu.mutation.Status(); ok {
  262. _spec.SetField(label.FieldStatus, field.TypeUint8, value)
  263. }
  264. if value, ok := lu.mutation.AddedStatus(); ok {
  265. _spec.AddField(label.FieldStatus, field.TypeUint8, value)
  266. }
  267. if lu.mutation.StatusCleared() {
  268. _spec.ClearField(label.FieldStatus, field.TypeUint8)
  269. }
  270. if value, ok := lu.mutation.DeletedAt(); ok {
  271. _spec.SetField(label.FieldDeletedAt, field.TypeTime, value)
  272. }
  273. if lu.mutation.DeletedAtCleared() {
  274. _spec.ClearField(label.FieldDeletedAt, field.TypeTime)
  275. }
  276. if value, ok := lu.mutation.GetType(); ok {
  277. _spec.SetField(label.FieldType, field.TypeInt, value)
  278. }
  279. if value, ok := lu.mutation.AddedType(); ok {
  280. _spec.AddField(label.FieldType, field.TypeInt, value)
  281. }
  282. if value, ok := lu.mutation.Name(); ok {
  283. _spec.SetField(label.FieldName, field.TypeString, value)
  284. }
  285. if value, ok := lu.mutation.From(); ok {
  286. _spec.SetField(label.FieldFrom, field.TypeInt, value)
  287. }
  288. if value, ok := lu.mutation.AddedFrom(); ok {
  289. _spec.AddField(label.FieldFrom, field.TypeInt, value)
  290. }
  291. if value, ok := lu.mutation.Mode(); ok {
  292. _spec.SetField(label.FieldMode, field.TypeInt, value)
  293. }
  294. if value, ok := lu.mutation.AddedMode(); ok {
  295. _spec.AddField(label.FieldMode, field.TypeInt, value)
  296. }
  297. if value, ok := lu.mutation.Conditions(); ok {
  298. _spec.SetField(label.FieldConditions, field.TypeString, value)
  299. }
  300. if lu.mutation.ConditionsCleared() {
  301. _spec.ClearField(label.FieldConditions, field.TypeString)
  302. }
  303. if value, ok := lu.mutation.OrganizationID(); ok {
  304. _spec.SetField(label.FieldOrganizationID, field.TypeUint64, value)
  305. }
  306. if value, ok := lu.mutation.AddedOrganizationID(); ok {
  307. _spec.AddField(label.FieldOrganizationID, field.TypeUint64, value)
  308. }
  309. if lu.mutation.OrganizationIDCleared() {
  310. _spec.ClearField(label.FieldOrganizationID, field.TypeUint64)
  311. }
  312. if lu.mutation.LabelRelationshipsCleared() {
  313. edge := &sqlgraph.EdgeSpec{
  314. Rel: sqlgraph.O2M,
  315. Inverse: false,
  316. Table: label.LabelRelationshipsTable,
  317. Columns: []string{label.LabelRelationshipsColumn},
  318. Bidi: false,
  319. Target: &sqlgraph.EdgeTarget{
  320. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  321. },
  322. }
  323. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  324. }
  325. if nodes := lu.mutation.RemovedLabelRelationshipsIDs(); len(nodes) > 0 && !lu.mutation.LabelRelationshipsCleared() {
  326. edge := &sqlgraph.EdgeSpec{
  327. Rel: sqlgraph.O2M,
  328. Inverse: false,
  329. Table: label.LabelRelationshipsTable,
  330. Columns: []string{label.LabelRelationshipsColumn},
  331. Bidi: false,
  332. Target: &sqlgraph.EdgeTarget{
  333. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  334. },
  335. }
  336. for _, k := range nodes {
  337. edge.Target.Nodes = append(edge.Target.Nodes, k)
  338. }
  339. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  340. }
  341. if nodes := lu.mutation.LabelRelationshipsIDs(); len(nodes) > 0 {
  342. edge := &sqlgraph.EdgeSpec{
  343. Rel: sqlgraph.O2M,
  344. Inverse: false,
  345. Table: label.LabelRelationshipsTable,
  346. Columns: []string{label.LabelRelationshipsColumn},
  347. Bidi: false,
  348. Target: &sqlgraph.EdgeTarget{
  349. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  350. },
  351. }
  352. for _, k := range nodes {
  353. edge.Target.Nodes = append(edge.Target.Nodes, k)
  354. }
  355. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  356. }
  357. if n, err = sqlgraph.UpdateNodes(ctx, lu.driver, _spec); err != nil {
  358. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  359. err = &NotFoundError{label.Label}
  360. } else if sqlgraph.IsConstraintError(err) {
  361. err = &ConstraintError{msg: err.Error(), wrap: err}
  362. }
  363. return 0, err
  364. }
  365. lu.mutation.done = true
  366. return n, nil
  367. }
  368. // LabelUpdateOne is the builder for updating a single Label entity.
  369. type LabelUpdateOne struct {
  370. config
  371. fields []string
  372. hooks []Hook
  373. mutation *LabelMutation
  374. }
  375. // SetUpdatedAt sets the "updated_at" field.
  376. func (luo *LabelUpdateOne) SetUpdatedAt(t time.Time) *LabelUpdateOne {
  377. luo.mutation.SetUpdatedAt(t)
  378. return luo
  379. }
  380. // SetStatus sets the "status" field.
  381. func (luo *LabelUpdateOne) SetStatus(u uint8) *LabelUpdateOne {
  382. luo.mutation.ResetStatus()
  383. luo.mutation.SetStatus(u)
  384. return luo
  385. }
  386. // SetNillableStatus sets the "status" field if the given value is not nil.
  387. func (luo *LabelUpdateOne) SetNillableStatus(u *uint8) *LabelUpdateOne {
  388. if u != nil {
  389. luo.SetStatus(*u)
  390. }
  391. return luo
  392. }
  393. // AddStatus adds u to the "status" field.
  394. func (luo *LabelUpdateOne) AddStatus(u int8) *LabelUpdateOne {
  395. luo.mutation.AddStatus(u)
  396. return luo
  397. }
  398. // ClearStatus clears the value of the "status" field.
  399. func (luo *LabelUpdateOne) ClearStatus() *LabelUpdateOne {
  400. luo.mutation.ClearStatus()
  401. return luo
  402. }
  403. // SetDeletedAt sets the "deleted_at" field.
  404. func (luo *LabelUpdateOne) SetDeletedAt(t time.Time) *LabelUpdateOne {
  405. luo.mutation.SetDeletedAt(t)
  406. return luo
  407. }
  408. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  409. func (luo *LabelUpdateOne) SetNillableDeletedAt(t *time.Time) *LabelUpdateOne {
  410. if t != nil {
  411. luo.SetDeletedAt(*t)
  412. }
  413. return luo
  414. }
  415. // ClearDeletedAt clears the value of the "deleted_at" field.
  416. func (luo *LabelUpdateOne) ClearDeletedAt() *LabelUpdateOne {
  417. luo.mutation.ClearDeletedAt()
  418. return luo
  419. }
  420. // SetType sets the "type" field.
  421. func (luo *LabelUpdateOne) SetType(i int) *LabelUpdateOne {
  422. luo.mutation.ResetType()
  423. luo.mutation.SetType(i)
  424. return luo
  425. }
  426. // SetNillableType sets the "type" field if the given value is not nil.
  427. func (luo *LabelUpdateOne) SetNillableType(i *int) *LabelUpdateOne {
  428. if i != nil {
  429. luo.SetType(*i)
  430. }
  431. return luo
  432. }
  433. // AddType adds i to the "type" field.
  434. func (luo *LabelUpdateOne) AddType(i int) *LabelUpdateOne {
  435. luo.mutation.AddType(i)
  436. return luo
  437. }
  438. // SetName sets the "name" field.
  439. func (luo *LabelUpdateOne) SetName(s string) *LabelUpdateOne {
  440. luo.mutation.SetName(s)
  441. return luo
  442. }
  443. // SetNillableName sets the "name" field if the given value is not nil.
  444. func (luo *LabelUpdateOne) SetNillableName(s *string) *LabelUpdateOne {
  445. if s != nil {
  446. luo.SetName(*s)
  447. }
  448. return luo
  449. }
  450. // SetFrom sets the "from" field.
  451. func (luo *LabelUpdateOne) SetFrom(i int) *LabelUpdateOne {
  452. luo.mutation.ResetFrom()
  453. luo.mutation.SetFrom(i)
  454. return luo
  455. }
  456. // SetNillableFrom sets the "from" field if the given value is not nil.
  457. func (luo *LabelUpdateOne) SetNillableFrom(i *int) *LabelUpdateOne {
  458. if i != nil {
  459. luo.SetFrom(*i)
  460. }
  461. return luo
  462. }
  463. // AddFrom adds i to the "from" field.
  464. func (luo *LabelUpdateOne) AddFrom(i int) *LabelUpdateOne {
  465. luo.mutation.AddFrom(i)
  466. return luo
  467. }
  468. // SetMode sets the "mode" field.
  469. func (luo *LabelUpdateOne) SetMode(i int) *LabelUpdateOne {
  470. luo.mutation.ResetMode()
  471. luo.mutation.SetMode(i)
  472. return luo
  473. }
  474. // SetNillableMode sets the "mode" field if the given value is not nil.
  475. func (luo *LabelUpdateOne) SetNillableMode(i *int) *LabelUpdateOne {
  476. if i != nil {
  477. luo.SetMode(*i)
  478. }
  479. return luo
  480. }
  481. // AddMode adds i to the "mode" field.
  482. func (luo *LabelUpdateOne) AddMode(i int) *LabelUpdateOne {
  483. luo.mutation.AddMode(i)
  484. return luo
  485. }
  486. // SetConditions sets the "conditions" field.
  487. func (luo *LabelUpdateOne) SetConditions(s string) *LabelUpdateOne {
  488. luo.mutation.SetConditions(s)
  489. return luo
  490. }
  491. // SetNillableConditions sets the "conditions" field if the given value is not nil.
  492. func (luo *LabelUpdateOne) SetNillableConditions(s *string) *LabelUpdateOne {
  493. if s != nil {
  494. luo.SetConditions(*s)
  495. }
  496. return luo
  497. }
  498. // ClearConditions clears the value of the "conditions" field.
  499. func (luo *LabelUpdateOne) ClearConditions() *LabelUpdateOne {
  500. luo.mutation.ClearConditions()
  501. return luo
  502. }
  503. // SetOrganizationID sets the "organization_id" field.
  504. func (luo *LabelUpdateOne) SetOrganizationID(u uint64) *LabelUpdateOne {
  505. luo.mutation.ResetOrganizationID()
  506. luo.mutation.SetOrganizationID(u)
  507. return luo
  508. }
  509. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  510. func (luo *LabelUpdateOne) SetNillableOrganizationID(u *uint64) *LabelUpdateOne {
  511. if u != nil {
  512. luo.SetOrganizationID(*u)
  513. }
  514. return luo
  515. }
  516. // AddOrganizationID adds u to the "organization_id" field.
  517. func (luo *LabelUpdateOne) AddOrganizationID(u int64) *LabelUpdateOne {
  518. luo.mutation.AddOrganizationID(u)
  519. return luo
  520. }
  521. // ClearOrganizationID clears the value of the "organization_id" field.
  522. func (luo *LabelUpdateOne) ClearOrganizationID() *LabelUpdateOne {
  523. luo.mutation.ClearOrganizationID()
  524. return luo
  525. }
  526. // AddLabelRelationshipIDs adds the "label_relationships" edge to the LabelRelationship entity by IDs.
  527. func (luo *LabelUpdateOne) AddLabelRelationshipIDs(ids ...uint64) *LabelUpdateOne {
  528. luo.mutation.AddLabelRelationshipIDs(ids...)
  529. return luo
  530. }
  531. // AddLabelRelationships adds the "label_relationships" edges to the LabelRelationship entity.
  532. func (luo *LabelUpdateOne) AddLabelRelationships(l ...*LabelRelationship) *LabelUpdateOne {
  533. ids := make([]uint64, len(l))
  534. for i := range l {
  535. ids[i] = l[i].ID
  536. }
  537. return luo.AddLabelRelationshipIDs(ids...)
  538. }
  539. // Mutation returns the LabelMutation object of the builder.
  540. func (luo *LabelUpdateOne) Mutation() *LabelMutation {
  541. return luo.mutation
  542. }
  543. // ClearLabelRelationships clears all "label_relationships" edges to the LabelRelationship entity.
  544. func (luo *LabelUpdateOne) ClearLabelRelationships() *LabelUpdateOne {
  545. luo.mutation.ClearLabelRelationships()
  546. return luo
  547. }
  548. // RemoveLabelRelationshipIDs removes the "label_relationships" edge to LabelRelationship entities by IDs.
  549. func (luo *LabelUpdateOne) RemoveLabelRelationshipIDs(ids ...uint64) *LabelUpdateOne {
  550. luo.mutation.RemoveLabelRelationshipIDs(ids...)
  551. return luo
  552. }
  553. // RemoveLabelRelationships removes "label_relationships" edges to LabelRelationship entities.
  554. func (luo *LabelUpdateOne) RemoveLabelRelationships(l ...*LabelRelationship) *LabelUpdateOne {
  555. ids := make([]uint64, len(l))
  556. for i := range l {
  557. ids[i] = l[i].ID
  558. }
  559. return luo.RemoveLabelRelationshipIDs(ids...)
  560. }
  561. // Where appends a list predicates to the LabelUpdate builder.
  562. func (luo *LabelUpdateOne) Where(ps ...predicate.Label) *LabelUpdateOne {
  563. luo.mutation.Where(ps...)
  564. return luo
  565. }
  566. // Select allows selecting one or more fields (columns) of the returned entity.
  567. // The default is selecting all fields defined in the entity schema.
  568. func (luo *LabelUpdateOne) Select(field string, fields ...string) *LabelUpdateOne {
  569. luo.fields = append([]string{field}, fields...)
  570. return luo
  571. }
  572. // Save executes the query and returns the updated Label entity.
  573. func (luo *LabelUpdateOne) Save(ctx context.Context) (*Label, error) {
  574. if err := luo.defaults(); err != nil {
  575. return nil, err
  576. }
  577. return withHooks(ctx, luo.sqlSave, luo.mutation, luo.hooks)
  578. }
  579. // SaveX is like Save, but panics if an error occurs.
  580. func (luo *LabelUpdateOne) SaveX(ctx context.Context) *Label {
  581. node, err := luo.Save(ctx)
  582. if err != nil {
  583. panic(err)
  584. }
  585. return node
  586. }
  587. // Exec executes the query on the entity.
  588. func (luo *LabelUpdateOne) Exec(ctx context.Context) error {
  589. _, err := luo.Save(ctx)
  590. return err
  591. }
  592. // ExecX is like Exec, but panics if an error occurs.
  593. func (luo *LabelUpdateOne) ExecX(ctx context.Context) {
  594. if err := luo.Exec(ctx); err != nil {
  595. panic(err)
  596. }
  597. }
  598. // defaults sets the default values of the builder before save.
  599. func (luo *LabelUpdateOne) defaults() error {
  600. if _, ok := luo.mutation.UpdatedAt(); !ok {
  601. if label.UpdateDefaultUpdatedAt == nil {
  602. return fmt.Errorf("ent: uninitialized label.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  603. }
  604. v := label.UpdateDefaultUpdatedAt()
  605. luo.mutation.SetUpdatedAt(v)
  606. }
  607. return nil
  608. }
  609. func (luo *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) {
  610. _spec := sqlgraph.NewUpdateSpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUint64))
  611. id, ok := luo.mutation.ID()
  612. if !ok {
  613. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Label.id" for update`)}
  614. }
  615. _spec.Node.ID.Value = id
  616. if fields := luo.fields; len(fields) > 0 {
  617. _spec.Node.Columns = make([]string, 0, len(fields))
  618. _spec.Node.Columns = append(_spec.Node.Columns, label.FieldID)
  619. for _, f := range fields {
  620. if !label.ValidColumn(f) {
  621. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  622. }
  623. if f != label.FieldID {
  624. _spec.Node.Columns = append(_spec.Node.Columns, f)
  625. }
  626. }
  627. }
  628. if ps := luo.mutation.predicates; len(ps) > 0 {
  629. _spec.Predicate = func(selector *sql.Selector) {
  630. for i := range ps {
  631. ps[i](selector)
  632. }
  633. }
  634. }
  635. if value, ok := luo.mutation.UpdatedAt(); ok {
  636. _spec.SetField(label.FieldUpdatedAt, field.TypeTime, value)
  637. }
  638. if value, ok := luo.mutation.Status(); ok {
  639. _spec.SetField(label.FieldStatus, field.TypeUint8, value)
  640. }
  641. if value, ok := luo.mutation.AddedStatus(); ok {
  642. _spec.AddField(label.FieldStatus, field.TypeUint8, value)
  643. }
  644. if luo.mutation.StatusCleared() {
  645. _spec.ClearField(label.FieldStatus, field.TypeUint8)
  646. }
  647. if value, ok := luo.mutation.DeletedAt(); ok {
  648. _spec.SetField(label.FieldDeletedAt, field.TypeTime, value)
  649. }
  650. if luo.mutation.DeletedAtCleared() {
  651. _spec.ClearField(label.FieldDeletedAt, field.TypeTime)
  652. }
  653. if value, ok := luo.mutation.GetType(); ok {
  654. _spec.SetField(label.FieldType, field.TypeInt, value)
  655. }
  656. if value, ok := luo.mutation.AddedType(); ok {
  657. _spec.AddField(label.FieldType, field.TypeInt, value)
  658. }
  659. if value, ok := luo.mutation.Name(); ok {
  660. _spec.SetField(label.FieldName, field.TypeString, value)
  661. }
  662. if value, ok := luo.mutation.From(); ok {
  663. _spec.SetField(label.FieldFrom, field.TypeInt, value)
  664. }
  665. if value, ok := luo.mutation.AddedFrom(); ok {
  666. _spec.AddField(label.FieldFrom, field.TypeInt, value)
  667. }
  668. if value, ok := luo.mutation.Mode(); ok {
  669. _spec.SetField(label.FieldMode, field.TypeInt, value)
  670. }
  671. if value, ok := luo.mutation.AddedMode(); ok {
  672. _spec.AddField(label.FieldMode, field.TypeInt, value)
  673. }
  674. if value, ok := luo.mutation.Conditions(); ok {
  675. _spec.SetField(label.FieldConditions, field.TypeString, value)
  676. }
  677. if luo.mutation.ConditionsCleared() {
  678. _spec.ClearField(label.FieldConditions, field.TypeString)
  679. }
  680. if value, ok := luo.mutation.OrganizationID(); ok {
  681. _spec.SetField(label.FieldOrganizationID, field.TypeUint64, value)
  682. }
  683. if value, ok := luo.mutation.AddedOrganizationID(); ok {
  684. _spec.AddField(label.FieldOrganizationID, field.TypeUint64, value)
  685. }
  686. if luo.mutation.OrganizationIDCleared() {
  687. _spec.ClearField(label.FieldOrganizationID, field.TypeUint64)
  688. }
  689. if luo.mutation.LabelRelationshipsCleared() {
  690. edge := &sqlgraph.EdgeSpec{
  691. Rel: sqlgraph.O2M,
  692. Inverse: false,
  693. Table: label.LabelRelationshipsTable,
  694. Columns: []string{label.LabelRelationshipsColumn},
  695. Bidi: false,
  696. Target: &sqlgraph.EdgeTarget{
  697. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  698. },
  699. }
  700. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  701. }
  702. if nodes := luo.mutation.RemovedLabelRelationshipsIDs(); len(nodes) > 0 && !luo.mutation.LabelRelationshipsCleared() {
  703. edge := &sqlgraph.EdgeSpec{
  704. Rel: sqlgraph.O2M,
  705. Inverse: false,
  706. Table: label.LabelRelationshipsTable,
  707. Columns: []string{label.LabelRelationshipsColumn},
  708. Bidi: false,
  709. Target: &sqlgraph.EdgeTarget{
  710. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  711. },
  712. }
  713. for _, k := range nodes {
  714. edge.Target.Nodes = append(edge.Target.Nodes, k)
  715. }
  716. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  717. }
  718. if nodes := luo.mutation.LabelRelationshipsIDs(); len(nodes) > 0 {
  719. edge := &sqlgraph.EdgeSpec{
  720. Rel: sqlgraph.O2M,
  721. Inverse: false,
  722. Table: label.LabelRelationshipsTable,
  723. Columns: []string{label.LabelRelationshipsColumn},
  724. Bidi: false,
  725. Target: &sqlgraph.EdgeTarget{
  726. IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
  727. },
  728. }
  729. for _, k := range nodes {
  730. edge.Target.Nodes = append(edge.Target.Nodes, k)
  731. }
  732. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  733. }
  734. _node = &Label{config: luo.config}
  735. _spec.Assign = _node.assignValues
  736. _spec.ScanValues = _node.scanValues
  737. if err = sqlgraph.UpdateNode(ctx, luo.driver, _spec); err != nil {
  738. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  739. err = &NotFoundError{label.Label}
  740. } else if sqlgraph.IsConstraintError(err) {
  741. err = &ConstraintError{msg: err.Error(), wrap: err}
  742. }
  743. return nil, err
  744. }
  745. luo.mutation.done = true
  746. return _node, nil
  747. }