labellog_update.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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/labellog"
  9. "wechat-api/ent/predicate"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // LabelLogUpdate is the builder for updating LabelLog entities.
  15. type LabelLogUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *LabelLogMutation
  19. }
  20. // Where appends a list predicates to the LabelLogUpdate builder.
  21. func (llu *LabelLogUpdate) Where(ps ...predicate.LabelLog) *LabelLogUpdate {
  22. llu.mutation.Where(ps...)
  23. return llu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (llu *LabelLogUpdate) SetUpdatedAt(t time.Time) *LabelLogUpdate {
  27. llu.mutation.SetUpdatedAt(t)
  28. return llu
  29. }
  30. // SetLabelName sets the "label_name" field.
  31. func (llu *LabelLogUpdate) SetLabelName(s string) *LabelLogUpdate {
  32. llu.mutation.SetLabelName(s)
  33. return llu
  34. }
  35. // SetNillableLabelName sets the "label_name" field if the given value is not nil.
  36. func (llu *LabelLogUpdate) SetNillableLabelName(s *string) *LabelLogUpdate {
  37. if s != nil {
  38. llu.SetLabelName(*s)
  39. }
  40. return llu
  41. }
  42. // SetLabelID sets the "label_id" field.
  43. func (llu *LabelLogUpdate) SetLabelID(i int) *LabelLogUpdate {
  44. llu.mutation.ResetLabelID()
  45. llu.mutation.SetLabelID(i)
  46. return llu
  47. }
  48. // SetNillableLabelID sets the "label_id" field if the given value is not nil.
  49. func (llu *LabelLogUpdate) SetNillableLabelID(i *int) *LabelLogUpdate {
  50. if i != nil {
  51. llu.SetLabelID(*i)
  52. }
  53. return llu
  54. }
  55. // AddLabelID adds i to the "label_id" field.
  56. func (llu *LabelLogUpdate) AddLabelID(i int) *LabelLogUpdate {
  57. llu.mutation.AddLabelID(i)
  58. return llu
  59. }
  60. // SetWxID sets the "wx_id" field.
  61. func (llu *LabelLogUpdate) SetWxID(s string) *LabelLogUpdate {
  62. llu.mutation.SetWxID(s)
  63. return llu
  64. }
  65. // SetNillableWxID sets the "wx_id" field if the given value is not nil.
  66. func (llu *LabelLogUpdate) SetNillableWxID(s *string) *LabelLogUpdate {
  67. if s != nil {
  68. llu.SetWxID(*s)
  69. }
  70. return llu
  71. }
  72. // SetOrganizationID sets the "organization_id" field.
  73. func (llu *LabelLogUpdate) SetOrganizationID(u uint64) *LabelLogUpdate {
  74. llu.mutation.ResetOrganizationID()
  75. llu.mutation.SetOrganizationID(u)
  76. return llu
  77. }
  78. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  79. func (llu *LabelLogUpdate) SetNillableOrganizationID(u *uint64) *LabelLogUpdate {
  80. if u != nil {
  81. llu.SetOrganizationID(*u)
  82. }
  83. return llu
  84. }
  85. // AddOrganizationID adds u to the "organization_id" field.
  86. func (llu *LabelLogUpdate) AddOrganizationID(u int64) *LabelLogUpdate {
  87. llu.mutation.AddOrganizationID(u)
  88. return llu
  89. }
  90. // ClearOrganizationID clears the value of the "organization_id" field.
  91. func (llu *LabelLogUpdate) ClearOrganizationID() *LabelLogUpdate {
  92. llu.mutation.ClearOrganizationID()
  93. return llu
  94. }
  95. // Mutation returns the LabelLogMutation object of the builder.
  96. func (llu *LabelLogUpdate) Mutation() *LabelLogMutation {
  97. return llu.mutation
  98. }
  99. // Save executes the query and returns the number of nodes affected by the update operation.
  100. func (llu *LabelLogUpdate) Save(ctx context.Context) (int, error) {
  101. llu.defaults()
  102. return withHooks(ctx, llu.sqlSave, llu.mutation, llu.hooks)
  103. }
  104. // SaveX is like Save, but panics if an error occurs.
  105. func (llu *LabelLogUpdate) SaveX(ctx context.Context) int {
  106. affected, err := llu.Save(ctx)
  107. if err != nil {
  108. panic(err)
  109. }
  110. return affected
  111. }
  112. // Exec executes the query.
  113. func (llu *LabelLogUpdate) Exec(ctx context.Context) error {
  114. _, err := llu.Save(ctx)
  115. return err
  116. }
  117. // ExecX is like Exec, but panics if an error occurs.
  118. func (llu *LabelLogUpdate) ExecX(ctx context.Context) {
  119. if err := llu.Exec(ctx); err != nil {
  120. panic(err)
  121. }
  122. }
  123. // defaults sets the default values of the builder before save.
  124. func (llu *LabelLogUpdate) defaults() {
  125. if _, ok := llu.mutation.UpdatedAt(); !ok {
  126. v := labellog.UpdateDefaultUpdatedAt()
  127. llu.mutation.SetUpdatedAt(v)
  128. }
  129. }
  130. func (llu *LabelLogUpdate) sqlSave(ctx context.Context) (n int, err error) {
  131. _spec := sqlgraph.NewUpdateSpec(labellog.Table, labellog.Columns, sqlgraph.NewFieldSpec(labellog.FieldID, field.TypeUint64))
  132. if ps := llu.mutation.predicates; len(ps) > 0 {
  133. _spec.Predicate = func(selector *sql.Selector) {
  134. for i := range ps {
  135. ps[i](selector)
  136. }
  137. }
  138. }
  139. if value, ok := llu.mutation.UpdatedAt(); ok {
  140. _spec.SetField(labellog.FieldUpdatedAt, field.TypeTime, value)
  141. }
  142. if value, ok := llu.mutation.LabelName(); ok {
  143. _spec.SetField(labellog.FieldLabelName, field.TypeString, value)
  144. }
  145. if value, ok := llu.mutation.LabelID(); ok {
  146. _spec.SetField(labellog.FieldLabelID, field.TypeInt, value)
  147. }
  148. if value, ok := llu.mutation.AddedLabelID(); ok {
  149. _spec.AddField(labellog.FieldLabelID, field.TypeInt, value)
  150. }
  151. if value, ok := llu.mutation.WxID(); ok {
  152. _spec.SetField(labellog.FieldWxID, field.TypeString, value)
  153. }
  154. if value, ok := llu.mutation.OrganizationID(); ok {
  155. _spec.SetField(labellog.FieldOrganizationID, field.TypeUint64, value)
  156. }
  157. if value, ok := llu.mutation.AddedOrganizationID(); ok {
  158. _spec.AddField(labellog.FieldOrganizationID, field.TypeUint64, value)
  159. }
  160. if llu.mutation.OrganizationIDCleared() {
  161. _spec.ClearField(labellog.FieldOrganizationID, field.TypeUint64)
  162. }
  163. if n, err = sqlgraph.UpdateNodes(ctx, llu.driver, _spec); err != nil {
  164. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  165. err = &NotFoundError{labellog.Label}
  166. } else if sqlgraph.IsConstraintError(err) {
  167. err = &ConstraintError{msg: err.Error(), wrap: err}
  168. }
  169. return 0, err
  170. }
  171. llu.mutation.done = true
  172. return n, nil
  173. }
  174. // LabelLogUpdateOne is the builder for updating a single LabelLog entity.
  175. type LabelLogUpdateOne struct {
  176. config
  177. fields []string
  178. hooks []Hook
  179. mutation *LabelLogMutation
  180. }
  181. // SetUpdatedAt sets the "updated_at" field.
  182. func (lluo *LabelLogUpdateOne) SetUpdatedAt(t time.Time) *LabelLogUpdateOne {
  183. lluo.mutation.SetUpdatedAt(t)
  184. return lluo
  185. }
  186. // SetLabelName sets the "label_name" field.
  187. func (lluo *LabelLogUpdateOne) SetLabelName(s string) *LabelLogUpdateOne {
  188. lluo.mutation.SetLabelName(s)
  189. return lluo
  190. }
  191. // SetNillableLabelName sets the "label_name" field if the given value is not nil.
  192. func (lluo *LabelLogUpdateOne) SetNillableLabelName(s *string) *LabelLogUpdateOne {
  193. if s != nil {
  194. lluo.SetLabelName(*s)
  195. }
  196. return lluo
  197. }
  198. // SetLabelID sets the "label_id" field.
  199. func (lluo *LabelLogUpdateOne) SetLabelID(i int) *LabelLogUpdateOne {
  200. lluo.mutation.ResetLabelID()
  201. lluo.mutation.SetLabelID(i)
  202. return lluo
  203. }
  204. // SetNillableLabelID sets the "label_id" field if the given value is not nil.
  205. func (lluo *LabelLogUpdateOne) SetNillableLabelID(i *int) *LabelLogUpdateOne {
  206. if i != nil {
  207. lluo.SetLabelID(*i)
  208. }
  209. return lluo
  210. }
  211. // AddLabelID adds i to the "label_id" field.
  212. func (lluo *LabelLogUpdateOne) AddLabelID(i int) *LabelLogUpdateOne {
  213. lluo.mutation.AddLabelID(i)
  214. return lluo
  215. }
  216. // SetWxID sets the "wx_id" field.
  217. func (lluo *LabelLogUpdateOne) SetWxID(s string) *LabelLogUpdateOne {
  218. lluo.mutation.SetWxID(s)
  219. return lluo
  220. }
  221. // SetNillableWxID sets the "wx_id" field if the given value is not nil.
  222. func (lluo *LabelLogUpdateOne) SetNillableWxID(s *string) *LabelLogUpdateOne {
  223. if s != nil {
  224. lluo.SetWxID(*s)
  225. }
  226. return lluo
  227. }
  228. // SetOrganizationID sets the "organization_id" field.
  229. func (lluo *LabelLogUpdateOne) SetOrganizationID(u uint64) *LabelLogUpdateOne {
  230. lluo.mutation.ResetOrganizationID()
  231. lluo.mutation.SetOrganizationID(u)
  232. return lluo
  233. }
  234. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  235. func (lluo *LabelLogUpdateOne) SetNillableOrganizationID(u *uint64) *LabelLogUpdateOne {
  236. if u != nil {
  237. lluo.SetOrganizationID(*u)
  238. }
  239. return lluo
  240. }
  241. // AddOrganizationID adds u to the "organization_id" field.
  242. func (lluo *LabelLogUpdateOne) AddOrganizationID(u int64) *LabelLogUpdateOne {
  243. lluo.mutation.AddOrganizationID(u)
  244. return lluo
  245. }
  246. // ClearOrganizationID clears the value of the "organization_id" field.
  247. func (lluo *LabelLogUpdateOne) ClearOrganizationID() *LabelLogUpdateOne {
  248. lluo.mutation.ClearOrganizationID()
  249. return lluo
  250. }
  251. // Mutation returns the LabelLogMutation object of the builder.
  252. func (lluo *LabelLogUpdateOne) Mutation() *LabelLogMutation {
  253. return lluo.mutation
  254. }
  255. // Where appends a list predicates to the LabelLogUpdate builder.
  256. func (lluo *LabelLogUpdateOne) Where(ps ...predicate.LabelLog) *LabelLogUpdateOne {
  257. lluo.mutation.Where(ps...)
  258. return lluo
  259. }
  260. // Select allows selecting one or more fields (columns) of the returned entity.
  261. // The default is selecting all fields defined in the entity schema.
  262. func (lluo *LabelLogUpdateOne) Select(field string, fields ...string) *LabelLogUpdateOne {
  263. lluo.fields = append([]string{field}, fields...)
  264. return lluo
  265. }
  266. // Save executes the query and returns the updated LabelLog entity.
  267. func (lluo *LabelLogUpdateOne) Save(ctx context.Context) (*LabelLog, error) {
  268. lluo.defaults()
  269. return withHooks(ctx, lluo.sqlSave, lluo.mutation, lluo.hooks)
  270. }
  271. // SaveX is like Save, but panics if an error occurs.
  272. func (lluo *LabelLogUpdateOne) SaveX(ctx context.Context) *LabelLog {
  273. node, err := lluo.Save(ctx)
  274. if err != nil {
  275. panic(err)
  276. }
  277. return node
  278. }
  279. // Exec executes the query on the entity.
  280. func (lluo *LabelLogUpdateOne) Exec(ctx context.Context) error {
  281. _, err := lluo.Save(ctx)
  282. return err
  283. }
  284. // ExecX is like Exec, but panics if an error occurs.
  285. func (lluo *LabelLogUpdateOne) ExecX(ctx context.Context) {
  286. if err := lluo.Exec(ctx); err != nil {
  287. panic(err)
  288. }
  289. }
  290. // defaults sets the default values of the builder before save.
  291. func (lluo *LabelLogUpdateOne) defaults() {
  292. if _, ok := lluo.mutation.UpdatedAt(); !ok {
  293. v := labellog.UpdateDefaultUpdatedAt()
  294. lluo.mutation.SetUpdatedAt(v)
  295. }
  296. }
  297. func (lluo *LabelLogUpdateOne) sqlSave(ctx context.Context) (_node *LabelLog, err error) {
  298. _spec := sqlgraph.NewUpdateSpec(labellog.Table, labellog.Columns, sqlgraph.NewFieldSpec(labellog.FieldID, field.TypeUint64))
  299. id, ok := lluo.mutation.ID()
  300. if !ok {
  301. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "LabelLog.id" for update`)}
  302. }
  303. _spec.Node.ID.Value = id
  304. if fields := lluo.fields; len(fields) > 0 {
  305. _spec.Node.Columns = make([]string, 0, len(fields))
  306. _spec.Node.Columns = append(_spec.Node.Columns, labellog.FieldID)
  307. for _, f := range fields {
  308. if !labellog.ValidColumn(f) {
  309. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  310. }
  311. if f != labellog.FieldID {
  312. _spec.Node.Columns = append(_spec.Node.Columns, f)
  313. }
  314. }
  315. }
  316. if ps := lluo.mutation.predicates; len(ps) > 0 {
  317. _spec.Predicate = func(selector *sql.Selector) {
  318. for i := range ps {
  319. ps[i](selector)
  320. }
  321. }
  322. }
  323. if value, ok := lluo.mutation.UpdatedAt(); ok {
  324. _spec.SetField(labellog.FieldUpdatedAt, field.TypeTime, value)
  325. }
  326. if value, ok := lluo.mutation.LabelName(); ok {
  327. _spec.SetField(labellog.FieldLabelName, field.TypeString, value)
  328. }
  329. if value, ok := lluo.mutation.LabelID(); ok {
  330. _spec.SetField(labellog.FieldLabelID, field.TypeInt, value)
  331. }
  332. if value, ok := lluo.mutation.AddedLabelID(); ok {
  333. _spec.AddField(labellog.FieldLabelID, field.TypeInt, value)
  334. }
  335. if value, ok := lluo.mutation.WxID(); ok {
  336. _spec.SetField(labellog.FieldWxID, field.TypeString, value)
  337. }
  338. if value, ok := lluo.mutation.OrganizationID(); ok {
  339. _spec.SetField(labellog.FieldOrganizationID, field.TypeUint64, value)
  340. }
  341. if value, ok := lluo.mutation.AddedOrganizationID(); ok {
  342. _spec.AddField(labellog.FieldOrganizationID, field.TypeUint64, value)
  343. }
  344. if lluo.mutation.OrganizationIDCleared() {
  345. _spec.ClearField(labellog.FieldOrganizationID, field.TypeUint64)
  346. }
  347. _node = &LabelLog{config: lluo.config}
  348. _spec.Assign = _node.assignValues
  349. _spec.ScanValues = _node.scanValues
  350. if err = sqlgraph.UpdateNode(ctx, lluo.driver, _spec); err != nil {
  351. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  352. err = &NotFoundError{labellog.Label}
  353. } else if sqlgraph.IsConstraintError(err) {
  354. err = &ConstraintError{msg: err.Error(), wrap: err}
  355. }
  356. return nil, err
  357. }
  358. lluo.mutation.done = true
  359. return _node, nil
  360. }