label_update.go 23 KB

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