mutation.go 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "time"
  6. "code.osinet.fr/fgm/entdemo/ent/car"
  7. "code.osinet.fr/fgm/entdemo/ent/group"
  8. "code.osinet.fr/fgm/entdemo/ent/user"
  9. "github.com/facebookincubator/ent"
  10. )
  11. const (
  12. // Operation types.
  13. OpCreate = ent.OpCreate
  14. OpDelete = ent.OpDelete
  15. OpDeleteOne = ent.OpDeleteOne
  16. OpUpdate = ent.OpUpdate
  17. OpUpdateOne = ent.OpUpdateOne
  18. // Node types.
  19. TypeCar = "Car"
  20. TypeGroup = "Group"
  21. TypeUser = "User"
  22. )
  23. // CarMutation represents an operation that mutate the Cars
  24. // nodes in the graph.
  25. type CarMutation struct {
  26. config
  27. op Op
  28. typ string
  29. id *int
  30. model *string
  31. registered_at *time.Time
  32. clearedFields map[string]struct{}
  33. owner *int
  34. clearedowner bool
  35. }
  36. var _ ent.Mutation = (*CarMutation)(nil)
  37. // newCarMutation creates new mutation for $n.Name.
  38. func newCarMutation(c config, op Op) *CarMutation {
  39. return &CarMutation{
  40. config: c,
  41. op: op,
  42. typ: TypeCar,
  43. clearedFields: make(map[string]struct{}),
  44. }
  45. }
  46. // Client returns a new `ent.Client` from the mutation. If the mutation was
  47. // executed in a transaction (ent.Tx), a transactional client is returned.
  48. func (m CarMutation) Client() *Client {
  49. client := &Client{config: m.config}
  50. client.init()
  51. return client
  52. }
  53. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  54. // it returns an error otherwise.
  55. func (m CarMutation) Tx() (*Tx, error) {
  56. if _, ok := m.driver.(*txDriver); !ok {
  57. return nil, fmt.Errorf("ent: mutation is not running in a transaction")
  58. }
  59. tx := &Tx{config: m.config}
  60. tx.init()
  61. return tx, nil
  62. }
  63. // ID returns the id value in the mutation. Note that, the id
  64. // is available only if it was provided to the builder.
  65. func (m *CarMutation) ID() (id int, exists bool) {
  66. if m.id == nil {
  67. return
  68. }
  69. return *m.id, true
  70. }
  71. // SetModel sets the model field.
  72. func (m *CarMutation) SetModel(s string) {
  73. m.model = &s
  74. }
  75. // Model returns the model value in the mutation.
  76. func (m *CarMutation) Model() (r string, exists bool) {
  77. v := m.model
  78. if v == nil {
  79. return
  80. }
  81. return *v, true
  82. }
  83. // ResetModel reset all changes of the model field.
  84. func (m *CarMutation) ResetModel() {
  85. m.model = nil
  86. }
  87. // SetRegisteredAt sets the registered_at field.
  88. func (m *CarMutation) SetRegisteredAt(t time.Time) {
  89. m.registered_at = &t
  90. }
  91. // RegisteredAt returns the registered_at value in the mutation.
  92. func (m *CarMutation) RegisteredAt() (r time.Time, exists bool) {
  93. v := m.registered_at
  94. if v == nil {
  95. return
  96. }
  97. return *v, true
  98. }
  99. // ResetRegisteredAt reset all changes of the registered_at field.
  100. func (m *CarMutation) ResetRegisteredAt() {
  101. m.registered_at = nil
  102. }
  103. // SetOwnerID sets the owner edge to User by id.
  104. func (m *CarMutation) SetOwnerID(id int) {
  105. m.owner = &id
  106. }
  107. // ClearOwner clears the owner edge to User.
  108. func (m *CarMutation) ClearOwner() {
  109. m.clearedowner = true
  110. }
  111. // OwnerCleared returns if the edge owner was cleared.
  112. func (m *CarMutation) OwnerCleared() bool {
  113. return m.clearedowner
  114. }
  115. // OwnerID returns the owner id in the mutation.
  116. func (m *CarMutation) OwnerID() (id int, exists bool) {
  117. if m.owner != nil {
  118. return *m.owner, true
  119. }
  120. return
  121. }
  122. // OwnerIDs returns the owner ids in the mutation.
  123. // Note that ids always returns len(ids) <= 1 for unique edges, and you should use
  124. // OwnerID instead. It exists only for internal usage by the builders.
  125. func (m *CarMutation) OwnerIDs() (ids []int) {
  126. if id := m.owner; id != nil {
  127. ids = append(ids, *id)
  128. }
  129. return
  130. }
  131. // ResetOwner reset all changes of the owner edge.
  132. func (m *CarMutation) ResetOwner() {
  133. m.owner = nil
  134. m.clearedowner = false
  135. }
  136. // Op returns the operation name.
  137. func (m *CarMutation) Op() Op {
  138. return m.op
  139. }
  140. // Type returns the node type of this mutation (Car).
  141. func (m *CarMutation) Type() string {
  142. return m.typ
  143. }
  144. // Fields returns all fields that were changed during
  145. // this mutation. Note that, in order to get all numeric
  146. // fields that were in/decremented, call AddedFields().
  147. func (m *CarMutation) Fields() []string {
  148. fields := make([]string, 0, 2)
  149. if m.model != nil {
  150. fields = append(fields, car.FieldModel)
  151. }
  152. if m.registered_at != nil {
  153. fields = append(fields, car.FieldRegisteredAt)
  154. }
  155. return fields
  156. }
  157. // Field returns the value of a field with the given name.
  158. // The second boolean value indicates that this field was
  159. // not set, or was not define in the schema.
  160. func (m *CarMutation) Field(name string) (ent.Value, bool) {
  161. switch name {
  162. case car.FieldModel:
  163. return m.Model()
  164. case car.FieldRegisteredAt:
  165. return m.RegisteredAt()
  166. }
  167. return nil, false
  168. }
  169. // SetField sets the value for the given name. It returns an
  170. // error if the field is not defined in the schema, or if the
  171. // type mismatch the field type.
  172. func (m *CarMutation) SetField(name string, value ent.Value) error {
  173. switch name {
  174. case car.FieldModel:
  175. v, ok := value.(string)
  176. if !ok {
  177. return fmt.Errorf("unexpected type %T for field %s", value, name)
  178. }
  179. m.SetModel(v)
  180. return nil
  181. case car.FieldRegisteredAt:
  182. v, ok := value.(time.Time)
  183. if !ok {
  184. return fmt.Errorf("unexpected type %T for field %s", value, name)
  185. }
  186. m.SetRegisteredAt(v)
  187. return nil
  188. }
  189. return fmt.Errorf("unknown Car field %s", name)
  190. }
  191. // AddedFields returns all numeric fields that were incremented
  192. // or decremented during this mutation.
  193. func (m *CarMutation) AddedFields() []string {
  194. return nil
  195. }
  196. // AddedField returns the numeric value that was in/decremented
  197. // from a field with the given name. The second value indicates
  198. // that this field was not set, or was not define in the schema.
  199. func (m *CarMutation) AddedField(name string) (ent.Value, bool) {
  200. return nil, false
  201. }
  202. // AddField adds the value for the given name. It returns an
  203. // error if the field is not defined in the schema, or if the
  204. // type mismatch the field type.
  205. func (m *CarMutation) AddField(name string, value ent.Value) error {
  206. switch name {
  207. }
  208. return fmt.Errorf("unknown Car numeric field %s", name)
  209. }
  210. // ClearedFields returns all nullable fields that were cleared
  211. // during this mutation.
  212. func (m *CarMutation) ClearedFields() []string {
  213. return nil
  214. }
  215. // FieldCleared returns a boolean indicates if this field was
  216. // cleared in this mutation.
  217. func (m *CarMutation) FieldCleared(name string) bool {
  218. _, ok := m.clearedFields[name]
  219. return ok
  220. }
  221. // ClearField clears the value for the given name. It returns an
  222. // error if the field is not defined in the schema.
  223. func (m *CarMutation) ClearField(name string) error {
  224. return fmt.Errorf("unknown Car nullable field %s", name)
  225. }
  226. // ResetField resets all changes in the mutation regarding the
  227. // given field name. It returns an error if the field is not
  228. // defined in the schema.
  229. func (m *CarMutation) ResetField(name string) error {
  230. switch name {
  231. case car.FieldModel:
  232. m.ResetModel()
  233. return nil
  234. case car.FieldRegisteredAt:
  235. m.ResetRegisteredAt()
  236. return nil
  237. }
  238. return fmt.Errorf("unknown Car field %s", name)
  239. }
  240. // AddedEdges returns all edge names that were set/added in this
  241. // mutation.
  242. func (m *CarMutation) AddedEdges() []string {
  243. edges := make([]string, 0, 1)
  244. if m.owner != nil {
  245. edges = append(edges, car.EdgeOwner)
  246. }
  247. return edges
  248. }
  249. // AddedIDs returns all ids (to other nodes) that were added for
  250. // the given edge name.
  251. func (m *CarMutation) AddedIDs(name string) []ent.Value {
  252. switch name {
  253. case car.EdgeOwner:
  254. if id := m.owner; id != nil {
  255. return []ent.Value{*id}
  256. }
  257. }
  258. return nil
  259. }
  260. // RemovedEdges returns all edge names that were removed in this
  261. // mutation.
  262. func (m *CarMutation) RemovedEdges() []string {
  263. edges := make([]string, 0, 1)
  264. return edges
  265. }
  266. // RemovedIDs returns all ids (to other nodes) that were removed for
  267. // the given edge name.
  268. func (m *CarMutation) RemovedIDs(name string) []ent.Value {
  269. switch name {
  270. }
  271. return nil
  272. }
  273. // ClearedEdges returns all edge names that were cleared in this
  274. // mutation.
  275. func (m *CarMutation) ClearedEdges() []string {
  276. edges := make([]string, 0, 1)
  277. if m.clearedowner {
  278. edges = append(edges, car.EdgeOwner)
  279. }
  280. return edges
  281. }
  282. // EdgeCleared returns a boolean indicates if this edge was
  283. // cleared in this mutation.
  284. func (m *CarMutation) EdgeCleared(name string) bool {
  285. switch name {
  286. case car.EdgeOwner:
  287. return m.clearedowner
  288. }
  289. return false
  290. }
  291. // ClearEdge clears the value for the given name. It returns an
  292. // error if the edge name is not defined in the schema.
  293. func (m *CarMutation) ClearEdge(name string) error {
  294. switch name {
  295. case car.EdgeOwner:
  296. m.ClearOwner()
  297. return nil
  298. }
  299. return fmt.Errorf("unknown Car unique edge %s", name)
  300. }
  301. // ResetEdge resets all changes in the mutation regarding the
  302. // given edge name. It returns an error if the edge is not
  303. // defined in the schema.
  304. func (m *CarMutation) ResetEdge(name string) error {
  305. switch name {
  306. case car.EdgeOwner:
  307. m.ResetOwner()
  308. return nil
  309. }
  310. return fmt.Errorf("unknown Car edge %s", name)
  311. }
  312. // GroupMutation represents an operation that mutate the Groups
  313. // nodes in the graph.
  314. type GroupMutation struct {
  315. config
  316. op Op
  317. typ string
  318. id *int
  319. name *string
  320. clearedFields map[string]struct{}
  321. users map[int]struct{}
  322. removedusers map[int]struct{}
  323. }
  324. var _ ent.Mutation = (*GroupMutation)(nil)
  325. // newGroupMutation creates new mutation for $n.Name.
  326. func newGroupMutation(c config, op Op) *GroupMutation {
  327. return &GroupMutation{
  328. config: c,
  329. op: op,
  330. typ: TypeGroup,
  331. clearedFields: make(map[string]struct{}),
  332. }
  333. }
  334. // Client returns a new `ent.Client` from the mutation. If the mutation was
  335. // executed in a transaction (ent.Tx), a transactional client is returned.
  336. func (m GroupMutation) Client() *Client {
  337. client := &Client{config: m.config}
  338. client.init()
  339. return client
  340. }
  341. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  342. // it returns an error otherwise.
  343. func (m GroupMutation) Tx() (*Tx, error) {
  344. if _, ok := m.driver.(*txDriver); !ok {
  345. return nil, fmt.Errorf("ent: mutation is not running in a transaction")
  346. }
  347. tx := &Tx{config: m.config}
  348. tx.init()
  349. return tx, nil
  350. }
  351. // ID returns the id value in the mutation. Note that, the id
  352. // is available only if it was provided to the builder.
  353. func (m *GroupMutation) ID() (id int, exists bool) {
  354. if m.id == nil {
  355. return
  356. }
  357. return *m.id, true
  358. }
  359. // SetName sets the name field.
  360. func (m *GroupMutation) SetName(s string) {
  361. m.name = &s
  362. }
  363. // Name returns the name value in the mutation.
  364. func (m *GroupMutation) Name() (r string, exists bool) {
  365. v := m.name
  366. if v == nil {
  367. return
  368. }
  369. return *v, true
  370. }
  371. // ResetName reset all changes of the name field.
  372. func (m *GroupMutation) ResetName() {
  373. m.name = nil
  374. }
  375. // AddUserIDs adds the users edge to User by ids.
  376. func (m *GroupMutation) AddUserIDs(ids ...int) {
  377. if m.users == nil {
  378. m.users = make(map[int]struct{})
  379. }
  380. for i := range ids {
  381. m.users[ids[i]] = struct{}{}
  382. }
  383. }
  384. // RemoveUserIDs removes the users edge to User by ids.
  385. func (m *GroupMutation) RemoveUserIDs(ids ...int) {
  386. if m.removedusers == nil {
  387. m.removedusers = make(map[int]struct{})
  388. }
  389. for i := range ids {
  390. m.removedusers[ids[i]] = struct{}{}
  391. }
  392. }
  393. // RemovedUsers returns the removed ids of users.
  394. func (m *GroupMutation) RemovedUsersIDs() (ids []int) {
  395. for id := range m.removedusers {
  396. ids = append(ids, id)
  397. }
  398. return
  399. }
  400. // UsersIDs returns the users ids in the mutation.
  401. func (m *GroupMutation) UsersIDs() (ids []int) {
  402. for id := range m.users {
  403. ids = append(ids, id)
  404. }
  405. return
  406. }
  407. // ResetUsers reset all changes of the users edge.
  408. func (m *GroupMutation) ResetUsers() {
  409. m.users = nil
  410. m.removedusers = nil
  411. }
  412. // Op returns the operation name.
  413. func (m *GroupMutation) Op() Op {
  414. return m.op
  415. }
  416. // Type returns the node type of this mutation (Group).
  417. func (m *GroupMutation) Type() string {
  418. return m.typ
  419. }
  420. // Fields returns all fields that were changed during
  421. // this mutation. Note that, in order to get all numeric
  422. // fields that were in/decremented, call AddedFields().
  423. func (m *GroupMutation) Fields() []string {
  424. fields := make([]string, 0, 1)
  425. if m.name != nil {
  426. fields = append(fields, group.FieldName)
  427. }
  428. return fields
  429. }
  430. // Field returns the value of a field with the given name.
  431. // The second boolean value indicates that this field was
  432. // not set, or was not define in the schema.
  433. func (m *GroupMutation) Field(name string) (ent.Value, bool) {
  434. switch name {
  435. case group.FieldName:
  436. return m.Name()
  437. }
  438. return nil, false
  439. }
  440. // SetField sets the value for the given name. It returns an
  441. // error if the field is not defined in the schema, or if the
  442. // type mismatch the field type.
  443. func (m *GroupMutation) SetField(name string, value ent.Value) error {
  444. switch name {
  445. case group.FieldName:
  446. v, ok := value.(string)
  447. if !ok {
  448. return fmt.Errorf("unexpected type %T for field %s", value, name)
  449. }
  450. m.SetName(v)
  451. return nil
  452. }
  453. return fmt.Errorf("unknown Group field %s", name)
  454. }
  455. // AddedFields returns all numeric fields that were incremented
  456. // or decremented during this mutation.
  457. func (m *GroupMutation) AddedFields() []string {
  458. return nil
  459. }
  460. // AddedField returns the numeric value that was in/decremented
  461. // from a field with the given name. The second value indicates
  462. // that this field was not set, or was not define in the schema.
  463. func (m *GroupMutation) AddedField(name string) (ent.Value, bool) {
  464. return nil, false
  465. }
  466. // AddField adds the value for the given name. It returns an
  467. // error if the field is not defined in the schema, or if the
  468. // type mismatch the field type.
  469. func (m *GroupMutation) AddField(name string, value ent.Value) error {
  470. switch name {
  471. }
  472. return fmt.Errorf("unknown Group numeric field %s", name)
  473. }
  474. // ClearedFields returns all nullable fields that were cleared
  475. // during this mutation.
  476. func (m *GroupMutation) ClearedFields() []string {
  477. return nil
  478. }
  479. // FieldCleared returns a boolean indicates if this field was
  480. // cleared in this mutation.
  481. func (m *GroupMutation) FieldCleared(name string) bool {
  482. _, ok := m.clearedFields[name]
  483. return ok
  484. }
  485. // ClearField clears the value for the given name. It returns an
  486. // error if the field is not defined in the schema.
  487. func (m *GroupMutation) ClearField(name string) error {
  488. return fmt.Errorf("unknown Group nullable field %s", name)
  489. }
  490. // ResetField resets all changes in the mutation regarding the
  491. // given field name. It returns an error if the field is not
  492. // defined in the schema.
  493. func (m *GroupMutation) ResetField(name string) error {
  494. switch name {
  495. case group.FieldName:
  496. m.ResetName()
  497. return nil
  498. }
  499. return fmt.Errorf("unknown Group field %s", name)
  500. }
  501. // AddedEdges returns all edge names that were set/added in this
  502. // mutation.
  503. func (m *GroupMutation) AddedEdges() []string {
  504. edges := make([]string, 0, 1)
  505. if m.users != nil {
  506. edges = append(edges, group.EdgeUsers)
  507. }
  508. return edges
  509. }
  510. // AddedIDs returns all ids (to other nodes) that were added for
  511. // the given edge name.
  512. func (m *GroupMutation) AddedIDs(name string) []ent.Value {
  513. switch name {
  514. case group.EdgeUsers:
  515. ids := make([]ent.Value, 0, len(m.users))
  516. for id := range m.users {
  517. ids = append(ids, id)
  518. }
  519. return ids
  520. }
  521. return nil
  522. }
  523. // RemovedEdges returns all edge names that were removed in this
  524. // mutation.
  525. func (m *GroupMutation) RemovedEdges() []string {
  526. edges := make([]string, 0, 1)
  527. if m.removedusers != nil {
  528. edges = append(edges, group.EdgeUsers)
  529. }
  530. return edges
  531. }
  532. // RemovedIDs returns all ids (to other nodes) that were removed for
  533. // the given edge name.
  534. func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
  535. switch name {
  536. case group.EdgeUsers:
  537. ids := make([]ent.Value, 0, len(m.removedusers))
  538. for id := range m.removedusers {
  539. ids = append(ids, id)
  540. }
  541. return ids
  542. }
  543. return nil
  544. }
  545. // ClearedEdges returns all edge names that were cleared in this
  546. // mutation.
  547. func (m *GroupMutation) ClearedEdges() []string {
  548. edges := make([]string, 0, 1)
  549. return edges
  550. }
  551. // EdgeCleared returns a boolean indicates if this edge was
  552. // cleared in this mutation.
  553. func (m *GroupMutation) EdgeCleared(name string) bool {
  554. switch name {
  555. }
  556. return false
  557. }
  558. // ClearEdge clears the value for the given name. It returns an
  559. // error if the edge name is not defined in the schema.
  560. func (m *GroupMutation) ClearEdge(name string) error {
  561. switch name {
  562. }
  563. return fmt.Errorf("unknown Group unique edge %s", name)
  564. }
  565. // ResetEdge resets all changes in the mutation regarding the
  566. // given edge name. It returns an error if the edge is not
  567. // defined in the schema.
  568. func (m *GroupMutation) ResetEdge(name string) error {
  569. switch name {
  570. case group.EdgeUsers:
  571. m.ResetUsers()
  572. return nil
  573. }
  574. return fmt.Errorf("unknown Group edge %s", name)
  575. }
  576. // UserMutation represents an operation that mutate the Users
  577. // nodes in the graph.
  578. type UserMutation struct {
  579. config
  580. op Op
  581. typ string
  582. id *int
  583. age *int
  584. addage *int
  585. name *string
  586. clearedFields map[string]struct{}
  587. cars map[int]struct{}
  588. removedcars map[int]struct{}
  589. groups map[int]struct{}
  590. removedgroups map[int]struct{}
  591. }
  592. var _ ent.Mutation = (*UserMutation)(nil)
  593. // newUserMutation creates new mutation for $n.Name.
  594. func newUserMutation(c config, op Op) *UserMutation {
  595. return &UserMutation{
  596. config: c,
  597. op: op,
  598. typ: TypeUser,
  599. clearedFields: make(map[string]struct{}),
  600. }
  601. }
  602. // Client returns a new `ent.Client` from the mutation. If the mutation was
  603. // executed in a transaction (ent.Tx), a transactional client is returned.
  604. func (m UserMutation) Client() *Client {
  605. client := &Client{config: m.config}
  606. client.init()
  607. return client
  608. }
  609. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  610. // it returns an error otherwise.
  611. func (m UserMutation) Tx() (*Tx, error) {
  612. if _, ok := m.driver.(*txDriver); !ok {
  613. return nil, fmt.Errorf("ent: mutation is not running in a transaction")
  614. }
  615. tx := &Tx{config: m.config}
  616. tx.init()
  617. return tx, nil
  618. }
  619. // ID returns the id value in the mutation. Note that, the id
  620. // is available only if it was provided to the builder.
  621. func (m *UserMutation) ID() (id int, exists bool) {
  622. if m.id == nil {
  623. return
  624. }
  625. return *m.id, true
  626. }
  627. // SetAge sets the age field.
  628. func (m *UserMutation) SetAge(i int) {
  629. m.age = &i
  630. m.addage = nil
  631. }
  632. // Age returns the age value in the mutation.
  633. func (m *UserMutation) Age() (r int, exists bool) {
  634. v := m.age
  635. if v == nil {
  636. return
  637. }
  638. return *v, true
  639. }
  640. // AddAge adds i to age.
  641. func (m *UserMutation) AddAge(i int) {
  642. if m.addage != nil {
  643. *m.addage += i
  644. } else {
  645. m.addage = &i
  646. }
  647. }
  648. // AddedAge returns the value that was added to the age field in this mutation.
  649. func (m *UserMutation) AddedAge() (r int, exists bool) {
  650. v := m.addage
  651. if v == nil {
  652. return
  653. }
  654. return *v, true
  655. }
  656. // ResetAge reset all changes of the age field.
  657. func (m *UserMutation) ResetAge() {
  658. m.age = nil
  659. m.addage = nil
  660. }
  661. // SetName sets the name field.
  662. func (m *UserMutation) SetName(s string) {
  663. m.name = &s
  664. }
  665. // Name returns the name value in the mutation.
  666. func (m *UserMutation) Name() (r string, exists bool) {
  667. v := m.name
  668. if v == nil {
  669. return
  670. }
  671. return *v, true
  672. }
  673. // ResetName reset all changes of the name field.
  674. func (m *UserMutation) ResetName() {
  675. m.name = nil
  676. }
  677. // AddCarIDs adds the cars edge to Car by ids.
  678. func (m *UserMutation) AddCarIDs(ids ...int) {
  679. if m.cars == nil {
  680. m.cars = make(map[int]struct{})
  681. }
  682. for i := range ids {
  683. m.cars[ids[i]] = struct{}{}
  684. }
  685. }
  686. // RemoveCarIDs removes the cars edge to Car by ids.
  687. func (m *UserMutation) RemoveCarIDs(ids ...int) {
  688. if m.removedcars == nil {
  689. m.removedcars = make(map[int]struct{})
  690. }
  691. for i := range ids {
  692. m.removedcars[ids[i]] = struct{}{}
  693. }
  694. }
  695. // RemovedCars returns the removed ids of cars.
  696. func (m *UserMutation) RemovedCarsIDs() (ids []int) {
  697. for id := range m.removedcars {
  698. ids = append(ids, id)
  699. }
  700. return
  701. }
  702. // CarsIDs returns the cars ids in the mutation.
  703. func (m *UserMutation) CarsIDs() (ids []int) {
  704. for id := range m.cars {
  705. ids = append(ids, id)
  706. }
  707. return
  708. }
  709. // ResetCars reset all changes of the cars edge.
  710. func (m *UserMutation) ResetCars() {
  711. m.cars = nil
  712. m.removedcars = nil
  713. }
  714. // AddGroupIDs adds the groups edge to Group by ids.
  715. func (m *UserMutation) AddGroupIDs(ids ...int) {
  716. if m.groups == nil {
  717. m.groups = make(map[int]struct{})
  718. }
  719. for i := range ids {
  720. m.groups[ids[i]] = struct{}{}
  721. }
  722. }
  723. // RemoveGroupIDs removes the groups edge to Group by ids.
  724. func (m *UserMutation) RemoveGroupIDs(ids ...int) {
  725. if m.removedgroups == nil {
  726. m.removedgroups = make(map[int]struct{})
  727. }
  728. for i := range ids {
  729. m.removedgroups[ids[i]] = struct{}{}
  730. }
  731. }
  732. // RemovedGroups returns the removed ids of groups.
  733. func (m *UserMutation) RemovedGroupsIDs() (ids []int) {
  734. for id := range m.removedgroups {
  735. ids = append(ids, id)
  736. }
  737. return
  738. }
  739. // GroupsIDs returns the groups ids in the mutation.
  740. func (m *UserMutation) GroupsIDs() (ids []int) {
  741. for id := range m.groups {
  742. ids = append(ids, id)
  743. }
  744. return
  745. }
  746. // ResetGroups reset all changes of the groups edge.
  747. func (m *UserMutation) ResetGroups() {
  748. m.groups = nil
  749. m.removedgroups = nil
  750. }
  751. // Op returns the operation name.
  752. func (m *UserMutation) Op() Op {
  753. return m.op
  754. }
  755. // Type returns the node type of this mutation (User).
  756. func (m *UserMutation) Type() string {
  757. return m.typ
  758. }
  759. // Fields returns all fields that were changed during
  760. // this mutation. Note that, in order to get all numeric
  761. // fields that were in/decremented, call AddedFields().
  762. func (m *UserMutation) Fields() []string {
  763. fields := make([]string, 0, 2)
  764. if m.age != nil {
  765. fields = append(fields, user.FieldAge)
  766. }
  767. if m.name != nil {
  768. fields = append(fields, user.FieldName)
  769. }
  770. return fields
  771. }
  772. // Field returns the value of a field with the given name.
  773. // The second boolean value indicates that this field was
  774. // not set, or was not define in the schema.
  775. func (m *UserMutation) Field(name string) (ent.Value, bool) {
  776. switch name {
  777. case user.FieldAge:
  778. return m.Age()
  779. case user.FieldName:
  780. return m.Name()
  781. }
  782. return nil, false
  783. }
  784. // SetField sets the value for the given name. It returns an
  785. // error if the field is not defined in the schema, or if the
  786. // type mismatch the field type.
  787. func (m *UserMutation) SetField(name string, value ent.Value) error {
  788. switch name {
  789. case user.FieldAge:
  790. v, ok := value.(int)
  791. if !ok {
  792. return fmt.Errorf("unexpected type %T for field %s", value, name)
  793. }
  794. m.SetAge(v)
  795. return nil
  796. case user.FieldName:
  797. v, ok := value.(string)
  798. if !ok {
  799. return fmt.Errorf("unexpected type %T for field %s", value, name)
  800. }
  801. m.SetName(v)
  802. return nil
  803. }
  804. return fmt.Errorf("unknown User field %s", name)
  805. }
  806. // AddedFields returns all numeric fields that were incremented
  807. // or decremented during this mutation.
  808. func (m *UserMutation) AddedFields() []string {
  809. var fields []string
  810. if m.addage != nil {
  811. fields = append(fields, user.FieldAge)
  812. }
  813. return fields
  814. }
  815. // AddedField returns the numeric value that was in/decremented
  816. // from a field with the given name. The second value indicates
  817. // that this field was not set, or was not define in the schema.
  818. func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
  819. switch name {
  820. case user.FieldAge:
  821. return m.AddedAge()
  822. }
  823. return nil, false
  824. }
  825. // AddField adds the value for the given name. It returns an
  826. // error if the field is not defined in the schema, or if the
  827. // type mismatch the field type.
  828. func (m *UserMutation) AddField(name string, value ent.Value) error {
  829. switch name {
  830. case user.FieldAge:
  831. v, ok := value.(int)
  832. if !ok {
  833. return fmt.Errorf("unexpected type %T for field %s", value, name)
  834. }
  835. m.AddAge(v)
  836. return nil
  837. }
  838. return fmt.Errorf("unknown User numeric field %s", name)
  839. }
  840. // ClearedFields returns all nullable fields that were cleared
  841. // during this mutation.
  842. func (m *UserMutation) ClearedFields() []string {
  843. return nil
  844. }
  845. // FieldCleared returns a boolean indicates if this field was
  846. // cleared in this mutation.
  847. func (m *UserMutation) FieldCleared(name string) bool {
  848. _, ok := m.clearedFields[name]
  849. return ok
  850. }
  851. // ClearField clears the value for the given name. It returns an
  852. // error if the field is not defined in the schema.
  853. func (m *UserMutation) ClearField(name string) error {
  854. return fmt.Errorf("unknown User nullable field %s", name)
  855. }
  856. // ResetField resets all changes in the mutation regarding the
  857. // given field name. It returns an error if the field is not
  858. // defined in the schema.
  859. func (m *UserMutation) ResetField(name string) error {
  860. switch name {
  861. case user.FieldAge:
  862. m.ResetAge()
  863. return nil
  864. case user.FieldName:
  865. m.ResetName()
  866. return nil
  867. }
  868. return fmt.Errorf("unknown User field %s", name)
  869. }
  870. // AddedEdges returns all edge names that were set/added in this
  871. // mutation.
  872. func (m *UserMutation) AddedEdges() []string {
  873. edges := make([]string, 0, 2)
  874. if m.cars != nil {
  875. edges = append(edges, user.EdgeCars)
  876. }
  877. if m.groups != nil {
  878. edges = append(edges, user.EdgeGroups)
  879. }
  880. return edges
  881. }
  882. // AddedIDs returns all ids (to other nodes) that were added for
  883. // the given edge name.
  884. func (m *UserMutation) AddedIDs(name string) []ent.Value {
  885. switch name {
  886. case user.EdgeCars:
  887. ids := make([]ent.Value, 0, len(m.cars))
  888. for id := range m.cars {
  889. ids = append(ids, id)
  890. }
  891. return ids
  892. case user.EdgeGroups:
  893. ids := make([]ent.Value, 0, len(m.groups))
  894. for id := range m.groups {
  895. ids = append(ids, id)
  896. }
  897. return ids
  898. }
  899. return nil
  900. }
  901. // RemovedEdges returns all edge names that were removed in this
  902. // mutation.
  903. func (m *UserMutation) RemovedEdges() []string {
  904. edges := make([]string, 0, 2)
  905. if m.removedcars != nil {
  906. edges = append(edges, user.EdgeCars)
  907. }
  908. if m.removedgroups != nil {
  909. edges = append(edges, user.EdgeGroups)
  910. }
  911. return edges
  912. }
  913. // RemovedIDs returns all ids (to other nodes) that were removed for
  914. // the given edge name.
  915. func (m *UserMutation) RemovedIDs(name string) []ent.Value {
  916. switch name {
  917. case user.EdgeCars:
  918. ids := make([]ent.Value, 0, len(m.removedcars))
  919. for id := range m.removedcars {
  920. ids = append(ids, id)
  921. }
  922. return ids
  923. case user.EdgeGroups:
  924. ids := make([]ent.Value, 0, len(m.removedgroups))
  925. for id := range m.removedgroups {
  926. ids = append(ids, id)
  927. }
  928. return ids
  929. }
  930. return nil
  931. }
  932. // ClearedEdges returns all edge names that were cleared in this
  933. // mutation.
  934. func (m *UserMutation) ClearedEdges() []string {
  935. edges := make([]string, 0, 2)
  936. return edges
  937. }
  938. // EdgeCleared returns a boolean indicates if this edge was
  939. // cleared in this mutation.
  940. func (m *UserMutation) EdgeCleared(name string) bool {
  941. switch name {
  942. }
  943. return false
  944. }
  945. // ClearEdge clears the value for the given name. It returns an
  946. // error if the edge name is not defined in the schema.
  947. func (m *UserMutation) ClearEdge(name string) error {
  948. switch name {
  949. }
  950. return fmt.Errorf("unknown User unique edge %s", name)
  951. }
  952. // ResetEdge resets all changes in the mutation regarding the
  953. // given edge name. It returns an error if the edge is not
  954. // defined in the schema.
  955. func (m *UserMutation) ResetEdge(name string) error {
  956. switch name {
  957. case user.EdgeCars:
  958. m.ResetCars()
  959. return nil
  960. case user.EdgeGroups:
  961. m.ResetGroups()
  962. return nil
  963. }
  964. return fmt.Errorf("unknown User edge %s", name)
  965. }