label_update.go 22 KB

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