employeeconfig_update.go 14 KB

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