mutation.go 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "sync"
  8. "time"
  9. "code.osinet.fr/fgm/go__ent_demo/ent/car"
  10. "code.osinet.fr/fgm/go__ent_demo/ent/group"
  11. "code.osinet.fr/fgm/go__ent_demo/ent/predicate"
  12. "code.osinet.fr/fgm/go__ent_demo/ent/user"
  13. "entgo.io/ent"
  14. )
  15. const (
  16. // Operation types.
  17. OpCreate = ent.OpCreate
  18. OpDelete = ent.OpDelete
  19. OpDeleteOne = ent.OpDeleteOne
  20. OpUpdate = ent.OpUpdate
  21. OpUpdateOne = ent.OpUpdateOne
  22. // Node types.
  23. TypeCar = "Car"
  24. TypeGroup = "Group"
  25. TypeUser = "User"
  26. )
  27. // CarMutation represents an operation that mutates the Car nodes in the graph.
  28. type CarMutation struct {
  29. config
  30. op Op
  31. typ string
  32. id *int
  33. model *string
  34. registered_at *time.Time
  35. clearedFields map[string]struct{}
  36. owner *int
  37. clearedowner bool
  38. done bool
  39. oldValue func(context.Context) (*Car, error)
  40. predicates []predicate.Car
  41. }
  42. var _ ent.Mutation = (*CarMutation)(nil)
  43. // carOption allows management of the mutation configuration using functional options.
  44. type carOption func(*CarMutation)
  45. // newCarMutation creates new mutation for the Car entity.
  46. func newCarMutation(c config, op Op, opts ...carOption) *CarMutation {
  47. m := &CarMutation{
  48. config: c,
  49. op: op,
  50. typ: TypeCar,
  51. clearedFields: make(map[string]struct{}),
  52. }
  53. for _, opt := range opts {
  54. opt(m)
  55. }
  56. return m
  57. }
  58. // withCarID sets the ID field of the mutation.
  59. func withCarID(id int) carOption {
  60. return func(m *CarMutation) {
  61. var (
  62. err error
  63. once sync.Once
  64. value *Car
  65. )
  66. m.oldValue = func(ctx context.Context) (*Car, error) {
  67. once.Do(func() {
  68. if m.done {
  69. err = errors.New("querying old values post mutation is not allowed")
  70. } else {
  71. value, err = m.Client().Car.Get(ctx, id)
  72. }
  73. })
  74. return value, err
  75. }
  76. m.id = &id
  77. }
  78. }
  79. // withCar sets the old Car of the mutation.
  80. func withCar(node *Car) carOption {
  81. return func(m *CarMutation) {
  82. m.oldValue = func(context.Context) (*Car, error) {
  83. return node, nil
  84. }
  85. m.id = &node.ID
  86. }
  87. }
  88. // Client returns a new `ent.Client` from the mutation. If the mutation was
  89. // executed in a transaction (ent.Tx), a transactional client is returned.
  90. func (m CarMutation) Client() *Client {
  91. client := &Client{config: m.config}
  92. client.init()
  93. return client
  94. }
  95. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  96. // it returns an error otherwise.
  97. func (m CarMutation) Tx() (*Tx, error) {
  98. if _, ok := m.driver.(*txDriver); !ok {
  99. return nil, errors.New("ent: mutation is not running in a transaction")
  100. }
  101. tx := &Tx{config: m.config}
  102. tx.init()
  103. return tx, nil
  104. }
  105. // ID returns the ID value in the mutation. Note that the ID is only available
  106. // if it was provided to the builder or after it was returned from the database.
  107. func (m *CarMutation) ID() (id int, exists bool) {
  108. if m.id == nil {
  109. return
  110. }
  111. return *m.id, true
  112. }
  113. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  114. // That means, if the mutation is applied within a transaction with an isolation level such
  115. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  116. // or updated by the mutation.
  117. func (m *CarMutation) IDs(ctx context.Context) ([]int, error) {
  118. switch {
  119. case m.op.Is(OpUpdateOne | OpDeleteOne):
  120. id, exists := m.ID()
  121. if exists {
  122. return []int{id}, nil
  123. }
  124. fallthrough
  125. case m.op.Is(OpUpdate | OpDelete):
  126. return m.Client().Car.Query().Where(m.predicates...).IDs(ctx)
  127. default:
  128. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  129. }
  130. }
  131. // SetModel sets the "model" field.
  132. func (m *CarMutation) SetModel(s string) {
  133. m.model = &s
  134. }
  135. // Model returns the value of the "model" field in the mutation.
  136. func (m *CarMutation) Model() (r string, exists bool) {
  137. v := m.model
  138. if v == nil {
  139. return
  140. }
  141. return *v, true
  142. }
  143. // OldModel returns the old "model" field's value of the Car entity.
  144. // If the Car object wasn't provided to the builder, the object is fetched from the database.
  145. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  146. func (m *CarMutation) OldModel(ctx context.Context) (v string, err error) {
  147. if !m.op.Is(OpUpdateOne) {
  148. return v, errors.New("OldModel is only allowed on UpdateOne operations")
  149. }
  150. if m.id == nil || m.oldValue == nil {
  151. return v, errors.New("OldModel requires an ID field in the mutation")
  152. }
  153. oldValue, err := m.oldValue(ctx)
  154. if err != nil {
  155. return v, fmt.Errorf("querying old value for OldModel: %w", err)
  156. }
  157. return oldValue.Model, nil
  158. }
  159. // ResetModel resets all changes to the "model" field.
  160. func (m *CarMutation) ResetModel() {
  161. m.model = nil
  162. }
  163. // SetRegisteredAt sets the "registered_at" field.
  164. func (m *CarMutation) SetRegisteredAt(t time.Time) {
  165. m.registered_at = &t
  166. }
  167. // RegisteredAt returns the value of the "registered_at" field in the mutation.
  168. func (m *CarMutation) RegisteredAt() (r time.Time, exists bool) {
  169. v := m.registered_at
  170. if v == nil {
  171. return
  172. }
  173. return *v, true
  174. }
  175. // OldRegisteredAt returns the old "registered_at" field's value of the Car entity.
  176. // If the Car object wasn't provided to the builder, the object is fetched from the database.
  177. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  178. func (m *CarMutation) OldRegisteredAt(ctx context.Context) (v time.Time, err error) {
  179. if !m.op.Is(OpUpdateOne) {
  180. return v, errors.New("OldRegisteredAt is only allowed on UpdateOne operations")
  181. }
  182. if m.id == nil || m.oldValue == nil {
  183. return v, errors.New("OldRegisteredAt requires an ID field in the mutation")
  184. }
  185. oldValue, err := m.oldValue(ctx)
  186. if err != nil {
  187. return v, fmt.Errorf("querying old value for OldRegisteredAt: %w", err)
  188. }
  189. return oldValue.RegisteredAt, nil
  190. }
  191. // ResetRegisteredAt resets all changes to the "registered_at" field.
  192. func (m *CarMutation) ResetRegisteredAt() {
  193. m.registered_at = nil
  194. }
  195. // SetOwnerID sets the "owner" edge to the User entity by id.
  196. func (m *CarMutation) SetOwnerID(id int) {
  197. m.owner = &id
  198. }
  199. // ClearOwner clears the "owner" edge to the User entity.
  200. func (m *CarMutation) ClearOwner() {
  201. m.clearedowner = true
  202. }
  203. // OwnerCleared reports if the "owner" edge to the User entity was cleared.
  204. func (m *CarMutation) OwnerCleared() bool {
  205. return m.clearedowner
  206. }
  207. // OwnerID returns the "owner" edge ID in the mutation.
  208. func (m *CarMutation) OwnerID() (id int, exists bool) {
  209. if m.owner != nil {
  210. return *m.owner, true
  211. }
  212. return
  213. }
  214. // OwnerIDs returns the "owner" edge IDs in the mutation.
  215. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  216. // OwnerID instead. It exists only for internal usage by the builders.
  217. func (m *CarMutation) OwnerIDs() (ids []int) {
  218. if id := m.owner; id != nil {
  219. ids = append(ids, *id)
  220. }
  221. return
  222. }
  223. // ResetOwner resets all changes to the "owner" edge.
  224. func (m *CarMutation) ResetOwner() {
  225. m.owner = nil
  226. m.clearedowner = false
  227. }
  228. // Where appends a list predicates to the CarMutation builder.
  229. func (m *CarMutation) Where(ps ...predicate.Car) {
  230. m.predicates = append(m.predicates, ps...)
  231. }
  232. // Op returns the operation name.
  233. func (m *CarMutation) Op() Op {
  234. return m.op
  235. }
  236. // Type returns the node type of this mutation (Car).
  237. func (m *CarMutation) Type() string {
  238. return m.typ
  239. }
  240. // Fields returns all fields that were changed during this mutation. Note that in
  241. // order to get all numeric fields that were incremented/decremented, call
  242. // AddedFields().
  243. func (m *CarMutation) Fields() []string {
  244. fields := make([]string, 0, 2)
  245. if m.model != nil {
  246. fields = append(fields, car.FieldModel)
  247. }
  248. if m.registered_at != nil {
  249. fields = append(fields, car.FieldRegisteredAt)
  250. }
  251. return fields
  252. }
  253. // Field returns the value of a field with the given name. The second boolean
  254. // return value indicates that this field was not set, or was not defined in the
  255. // schema.
  256. func (m *CarMutation) Field(name string) (ent.Value, bool) {
  257. switch name {
  258. case car.FieldModel:
  259. return m.Model()
  260. case car.FieldRegisteredAt:
  261. return m.RegisteredAt()
  262. }
  263. return nil, false
  264. }
  265. // OldField returns the old value of the field from the database. An error is
  266. // returned if the mutation operation is not UpdateOne, or the query to the
  267. // database failed.
  268. func (m *CarMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  269. switch name {
  270. case car.FieldModel:
  271. return m.OldModel(ctx)
  272. case car.FieldRegisteredAt:
  273. return m.OldRegisteredAt(ctx)
  274. }
  275. return nil, fmt.Errorf("unknown Car field %s", name)
  276. }
  277. // SetField sets the value of a field with the given name. It returns an error if
  278. // the field is not defined in the schema, or if the type mismatched the field
  279. // type.
  280. func (m *CarMutation) SetField(name string, value ent.Value) error {
  281. switch name {
  282. case car.FieldModel:
  283. v, ok := value.(string)
  284. if !ok {
  285. return fmt.Errorf("unexpected type %T for field %s", value, name)
  286. }
  287. m.SetModel(v)
  288. return nil
  289. case car.FieldRegisteredAt:
  290. v, ok := value.(time.Time)
  291. if !ok {
  292. return fmt.Errorf("unexpected type %T for field %s", value, name)
  293. }
  294. m.SetRegisteredAt(v)
  295. return nil
  296. }
  297. return fmt.Errorf("unknown Car field %s", name)
  298. }
  299. // AddedFields returns all numeric fields that were incremented/decremented during
  300. // this mutation.
  301. func (m *CarMutation) AddedFields() []string {
  302. return nil
  303. }
  304. // AddedField returns the numeric value that was incremented/decremented on a field
  305. // with the given name. The second boolean return value indicates that this field
  306. // was not set, or was not defined in the schema.
  307. func (m *CarMutation) AddedField(name string) (ent.Value, bool) {
  308. return nil, false
  309. }
  310. // AddField adds the value to the field with the given name. It returns an error if
  311. // the field is not defined in the schema, or if the type mismatched the field
  312. // type.
  313. func (m *CarMutation) AddField(name string, value ent.Value) error {
  314. switch name {
  315. }
  316. return fmt.Errorf("unknown Car numeric field %s", name)
  317. }
  318. // ClearedFields returns all nullable fields that were cleared during this
  319. // mutation.
  320. func (m *CarMutation) ClearedFields() []string {
  321. return nil
  322. }
  323. // FieldCleared returns a boolean indicating if a field with the given name was
  324. // cleared in this mutation.
  325. func (m *CarMutation) FieldCleared(name string) bool {
  326. _, ok := m.clearedFields[name]
  327. return ok
  328. }
  329. // ClearField clears the value of the field with the given name. It returns an
  330. // error if the field is not defined in the schema.
  331. func (m *CarMutation) ClearField(name string) error {
  332. return fmt.Errorf("unknown Car nullable field %s", name)
  333. }
  334. // ResetField resets all changes in the mutation for the field with the given name.
  335. // It returns an error if the field is not defined in the schema.
  336. func (m *CarMutation) ResetField(name string) error {
  337. switch name {
  338. case car.FieldModel:
  339. m.ResetModel()
  340. return nil
  341. case car.FieldRegisteredAt:
  342. m.ResetRegisteredAt()
  343. return nil
  344. }
  345. return fmt.Errorf("unknown Car field %s", name)
  346. }
  347. // AddedEdges returns all edge names that were set/added in this mutation.
  348. func (m *CarMutation) AddedEdges() []string {
  349. edges := make([]string, 0, 1)
  350. if m.owner != nil {
  351. edges = append(edges, car.EdgeOwner)
  352. }
  353. return edges
  354. }
  355. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  356. // name in this mutation.
  357. func (m *CarMutation) AddedIDs(name string) []ent.Value {
  358. switch name {
  359. case car.EdgeOwner:
  360. if id := m.owner; id != nil {
  361. return []ent.Value{*id}
  362. }
  363. }
  364. return nil
  365. }
  366. // RemovedEdges returns all edge names that were removed in this mutation.
  367. func (m *CarMutation) RemovedEdges() []string {
  368. edges := make([]string, 0, 1)
  369. return edges
  370. }
  371. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  372. // the given name in this mutation.
  373. func (m *CarMutation) RemovedIDs(name string) []ent.Value {
  374. switch name {
  375. }
  376. return nil
  377. }
  378. // ClearedEdges returns all edge names that were cleared in this mutation.
  379. func (m *CarMutation) ClearedEdges() []string {
  380. edges := make([]string, 0, 1)
  381. if m.clearedowner {
  382. edges = append(edges, car.EdgeOwner)
  383. }
  384. return edges
  385. }
  386. // EdgeCleared returns a boolean which indicates if the edge with the given name
  387. // was cleared in this mutation.
  388. func (m *CarMutation) EdgeCleared(name string) bool {
  389. switch name {
  390. case car.EdgeOwner:
  391. return m.clearedowner
  392. }
  393. return false
  394. }
  395. // ClearEdge clears the value of the edge with the given name. It returns an error
  396. // if that edge is not defined in the schema.
  397. func (m *CarMutation) ClearEdge(name string) error {
  398. switch name {
  399. case car.EdgeOwner:
  400. m.ClearOwner()
  401. return nil
  402. }
  403. return fmt.Errorf("unknown Car unique edge %s", name)
  404. }
  405. // ResetEdge resets all changes to the edge with the given name in this mutation.
  406. // It returns an error if the edge is not defined in the schema.
  407. func (m *CarMutation) ResetEdge(name string) error {
  408. switch name {
  409. case car.EdgeOwner:
  410. m.ResetOwner()
  411. return nil
  412. }
  413. return fmt.Errorf("unknown Car edge %s", name)
  414. }
  415. // GroupMutation represents an operation that mutates the Group nodes in the graph.
  416. type GroupMutation struct {
  417. config
  418. op Op
  419. typ string
  420. id *int
  421. name *string
  422. clearedFields map[string]struct{}
  423. users map[int]struct{}
  424. removedusers map[int]struct{}
  425. clearedusers bool
  426. done bool
  427. oldValue func(context.Context) (*Group, error)
  428. predicates []predicate.Group
  429. }
  430. var _ ent.Mutation = (*GroupMutation)(nil)
  431. // groupOption allows management of the mutation configuration using functional options.
  432. type groupOption func(*GroupMutation)
  433. // newGroupMutation creates new mutation for the Group entity.
  434. func newGroupMutation(c config, op Op, opts ...groupOption) *GroupMutation {
  435. m := &GroupMutation{
  436. config: c,
  437. op: op,
  438. typ: TypeGroup,
  439. clearedFields: make(map[string]struct{}),
  440. }
  441. for _, opt := range opts {
  442. opt(m)
  443. }
  444. return m
  445. }
  446. // withGroupID sets the ID field of the mutation.
  447. func withGroupID(id int) groupOption {
  448. return func(m *GroupMutation) {
  449. var (
  450. err error
  451. once sync.Once
  452. value *Group
  453. )
  454. m.oldValue = func(ctx context.Context) (*Group, error) {
  455. once.Do(func() {
  456. if m.done {
  457. err = errors.New("querying old values post mutation is not allowed")
  458. } else {
  459. value, err = m.Client().Group.Get(ctx, id)
  460. }
  461. })
  462. return value, err
  463. }
  464. m.id = &id
  465. }
  466. }
  467. // withGroup sets the old Group of the mutation.
  468. func withGroup(node *Group) groupOption {
  469. return func(m *GroupMutation) {
  470. m.oldValue = func(context.Context) (*Group, error) {
  471. return node, nil
  472. }
  473. m.id = &node.ID
  474. }
  475. }
  476. // Client returns a new `ent.Client` from the mutation. If the mutation was
  477. // executed in a transaction (ent.Tx), a transactional client is returned.
  478. func (m GroupMutation) Client() *Client {
  479. client := &Client{config: m.config}
  480. client.init()
  481. return client
  482. }
  483. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  484. // it returns an error otherwise.
  485. func (m GroupMutation) Tx() (*Tx, error) {
  486. if _, ok := m.driver.(*txDriver); !ok {
  487. return nil, errors.New("ent: mutation is not running in a transaction")
  488. }
  489. tx := &Tx{config: m.config}
  490. tx.init()
  491. return tx, nil
  492. }
  493. // ID returns the ID value in the mutation. Note that the ID is only available
  494. // if it was provided to the builder or after it was returned from the database.
  495. func (m *GroupMutation) ID() (id int, exists bool) {
  496. if m.id == nil {
  497. return
  498. }
  499. return *m.id, true
  500. }
  501. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  502. // That means, if the mutation is applied within a transaction with an isolation level such
  503. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  504. // or updated by the mutation.
  505. func (m *GroupMutation) IDs(ctx context.Context) ([]int, error) {
  506. switch {
  507. case m.op.Is(OpUpdateOne | OpDeleteOne):
  508. id, exists := m.ID()
  509. if exists {
  510. return []int{id}, nil
  511. }
  512. fallthrough
  513. case m.op.Is(OpUpdate | OpDelete):
  514. return m.Client().Group.Query().Where(m.predicates...).IDs(ctx)
  515. default:
  516. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  517. }
  518. }
  519. // SetName sets the "name" field.
  520. func (m *GroupMutation) SetName(s string) {
  521. m.name = &s
  522. }
  523. // Name returns the value of the "name" field in the mutation.
  524. func (m *GroupMutation) Name() (r string, exists bool) {
  525. v := m.name
  526. if v == nil {
  527. return
  528. }
  529. return *v, true
  530. }
  531. // OldName returns the old "name" field's value of the Group entity.
  532. // If the Group object wasn't provided to the builder, the object is fetched from the database.
  533. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  534. func (m *GroupMutation) OldName(ctx context.Context) (v string, err error) {
  535. if !m.op.Is(OpUpdateOne) {
  536. return v, errors.New("OldName is only allowed on UpdateOne operations")
  537. }
  538. if m.id == nil || m.oldValue == nil {
  539. return v, errors.New("OldName requires an ID field in the mutation")
  540. }
  541. oldValue, err := m.oldValue(ctx)
  542. if err != nil {
  543. return v, fmt.Errorf("querying old value for OldName: %w", err)
  544. }
  545. return oldValue.Name, nil
  546. }
  547. // ResetName resets all changes to the "name" field.
  548. func (m *GroupMutation) ResetName() {
  549. m.name = nil
  550. }
  551. // AddUserIDs adds the "users" edge to the User entity by ids.
  552. func (m *GroupMutation) AddUserIDs(ids ...int) {
  553. if m.users == nil {
  554. m.users = make(map[int]struct{})
  555. }
  556. for i := range ids {
  557. m.users[ids[i]] = struct{}{}
  558. }
  559. }
  560. // ClearUsers clears the "users" edge to the User entity.
  561. func (m *GroupMutation) ClearUsers() {
  562. m.clearedusers = true
  563. }
  564. // UsersCleared reports if the "users" edge to the User entity was cleared.
  565. func (m *GroupMutation) UsersCleared() bool {
  566. return m.clearedusers
  567. }
  568. // RemoveUserIDs removes the "users" edge to the User entity by IDs.
  569. func (m *GroupMutation) RemoveUserIDs(ids ...int) {
  570. if m.removedusers == nil {
  571. m.removedusers = make(map[int]struct{})
  572. }
  573. for i := range ids {
  574. delete(m.users, ids[i])
  575. m.removedusers[ids[i]] = struct{}{}
  576. }
  577. }
  578. // RemovedUsers returns the removed IDs of the "users" edge to the User entity.
  579. func (m *GroupMutation) RemovedUsersIDs() (ids []int) {
  580. for id := range m.removedusers {
  581. ids = append(ids, id)
  582. }
  583. return
  584. }
  585. // UsersIDs returns the "users" edge IDs in the mutation.
  586. func (m *GroupMutation) UsersIDs() (ids []int) {
  587. for id := range m.users {
  588. ids = append(ids, id)
  589. }
  590. return
  591. }
  592. // ResetUsers resets all changes to the "users" edge.
  593. func (m *GroupMutation) ResetUsers() {
  594. m.users = nil
  595. m.clearedusers = false
  596. m.removedusers = nil
  597. }
  598. // Where appends a list predicates to the GroupMutation builder.
  599. func (m *GroupMutation) Where(ps ...predicate.Group) {
  600. m.predicates = append(m.predicates, ps...)
  601. }
  602. // Op returns the operation name.
  603. func (m *GroupMutation) Op() Op {
  604. return m.op
  605. }
  606. // Type returns the node type of this mutation (Group).
  607. func (m *GroupMutation) Type() string {
  608. return m.typ
  609. }
  610. // Fields returns all fields that were changed during this mutation. Note that in
  611. // order to get all numeric fields that were incremented/decremented, call
  612. // AddedFields().
  613. func (m *GroupMutation) Fields() []string {
  614. fields := make([]string, 0, 1)
  615. if m.name != nil {
  616. fields = append(fields, group.FieldName)
  617. }
  618. return fields
  619. }
  620. // Field returns the value of a field with the given name. The second boolean
  621. // return value indicates that this field was not set, or was not defined in the
  622. // schema.
  623. func (m *GroupMutation) Field(name string) (ent.Value, bool) {
  624. switch name {
  625. case group.FieldName:
  626. return m.Name()
  627. }
  628. return nil, false
  629. }
  630. // OldField returns the old value of the field from the database. An error is
  631. // returned if the mutation operation is not UpdateOne, or the query to the
  632. // database failed.
  633. func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  634. switch name {
  635. case group.FieldName:
  636. return m.OldName(ctx)
  637. }
  638. return nil, fmt.Errorf("unknown Group field %s", name)
  639. }
  640. // SetField sets the value of a field with the given name. It returns an error if
  641. // the field is not defined in the schema, or if the type mismatched the field
  642. // type.
  643. func (m *GroupMutation) SetField(name string, value ent.Value) error {
  644. switch name {
  645. case group.FieldName:
  646. v, ok := value.(string)
  647. if !ok {
  648. return fmt.Errorf("unexpected type %T for field %s", value, name)
  649. }
  650. m.SetName(v)
  651. return nil
  652. }
  653. return fmt.Errorf("unknown Group field %s", name)
  654. }
  655. // AddedFields returns all numeric fields that were incremented/decremented during
  656. // this mutation.
  657. func (m *GroupMutation) AddedFields() []string {
  658. return nil
  659. }
  660. // AddedField returns the numeric value that was incremented/decremented on a field
  661. // with the given name. The second boolean return value indicates that this field
  662. // was not set, or was not defined in the schema.
  663. func (m *GroupMutation) AddedField(name string) (ent.Value, bool) {
  664. return nil, false
  665. }
  666. // AddField adds the value to the field with the given name. It returns an error if
  667. // the field is not defined in the schema, or if the type mismatched the field
  668. // type.
  669. func (m *GroupMutation) AddField(name string, value ent.Value) error {
  670. switch name {
  671. }
  672. return fmt.Errorf("unknown Group numeric field %s", name)
  673. }
  674. // ClearedFields returns all nullable fields that were cleared during this
  675. // mutation.
  676. func (m *GroupMutation) ClearedFields() []string {
  677. return nil
  678. }
  679. // FieldCleared returns a boolean indicating if a field with the given name was
  680. // cleared in this mutation.
  681. func (m *GroupMutation) FieldCleared(name string) bool {
  682. _, ok := m.clearedFields[name]
  683. return ok
  684. }
  685. // ClearField clears the value of the field with the given name. It returns an
  686. // error if the field is not defined in the schema.
  687. func (m *GroupMutation) ClearField(name string) error {
  688. return fmt.Errorf("unknown Group nullable field %s", name)
  689. }
  690. // ResetField resets all changes in the mutation for the field with the given name.
  691. // It returns an error if the field is not defined in the schema.
  692. func (m *GroupMutation) ResetField(name string) error {
  693. switch name {
  694. case group.FieldName:
  695. m.ResetName()
  696. return nil
  697. }
  698. return fmt.Errorf("unknown Group field %s", name)
  699. }
  700. // AddedEdges returns all edge names that were set/added in this mutation.
  701. func (m *GroupMutation) AddedEdges() []string {
  702. edges := make([]string, 0, 1)
  703. if m.users != nil {
  704. edges = append(edges, group.EdgeUsers)
  705. }
  706. return edges
  707. }
  708. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  709. // name in this mutation.
  710. func (m *GroupMutation) AddedIDs(name string) []ent.Value {
  711. switch name {
  712. case group.EdgeUsers:
  713. ids := make([]ent.Value, 0, len(m.users))
  714. for id := range m.users {
  715. ids = append(ids, id)
  716. }
  717. return ids
  718. }
  719. return nil
  720. }
  721. // RemovedEdges returns all edge names that were removed in this mutation.
  722. func (m *GroupMutation) RemovedEdges() []string {
  723. edges := make([]string, 0, 1)
  724. if m.removedusers != nil {
  725. edges = append(edges, group.EdgeUsers)
  726. }
  727. return edges
  728. }
  729. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  730. // the given name in this mutation.
  731. func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
  732. switch name {
  733. case group.EdgeUsers:
  734. ids := make([]ent.Value, 0, len(m.removedusers))
  735. for id := range m.removedusers {
  736. ids = append(ids, id)
  737. }
  738. return ids
  739. }
  740. return nil
  741. }
  742. // ClearedEdges returns all edge names that were cleared in this mutation.
  743. func (m *GroupMutation) ClearedEdges() []string {
  744. edges := make([]string, 0, 1)
  745. if m.clearedusers {
  746. edges = append(edges, group.EdgeUsers)
  747. }
  748. return edges
  749. }
  750. // EdgeCleared returns a boolean which indicates if the edge with the given name
  751. // was cleared in this mutation.
  752. func (m *GroupMutation) EdgeCleared(name string) bool {
  753. switch name {
  754. case group.EdgeUsers:
  755. return m.clearedusers
  756. }
  757. return false
  758. }
  759. // ClearEdge clears the value of the edge with the given name. It returns an error
  760. // if that edge is not defined in the schema.
  761. func (m *GroupMutation) ClearEdge(name string) error {
  762. switch name {
  763. }
  764. return fmt.Errorf("unknown Group unique edge %s", name)
  765. }
  766. // ResetEdge resets all changes to the edge with the given name in this mutation.
  767. // It returns an error if the edge is not defined in the schema.
  768. func (m *GroupMutation) ResetEdge(name string) error {
  769. switch name {
  770. case group.EdgeUsers:
  771. m.ResetUsers()
  772. return nil
  773. }
  774. return fmt.Errorf("unknown Group edge %s", name)
  775. }
  776. // UserMutation represents an operation that mutates the User nodes in the graph.
  777. type UserMutation struct {
  778. config
  779. op Op
  780. typ string
  781. id *int
  782. age *int
  783. addage *int
  784. name *string
  785. password *string
  786. size *user.Size
  787. clearedFields map[string]struct{}
  788. cars map[int]struct{}
  789. removedcars map[int]struct{}
  790. clearedcars bool
  791. groups map[int]struct{}
  792. removedgroups map[int]struct{}
  793. clearedgroups bool
  794. spouse *int
  795. clearedspouse bool
  796. followers map[int]struct{}
  797. removedfollowers map[int]struct{}
  798. clearedfollowers bool
  799. following map[int]struct{}
  800. removedfollowing map[int]struct{}
  801. clearedfollowing bool
  802. friends map[int]struct{}
  803. removedfriends map[int]struct{}
  804. clearedfriends bool
  805. done bool
  806. oldValue func(context.Context) (*User, error)
  807. predicates []predicate.User
  808. }
  809. var _ ent.Mutation = (*UserMutation)(nil)
  810. // userOption allows management of the mutation configuration using functional options.
  811. type userOption func(*UserMutation)
  812. // newUserMutation creates new mutation for the User entity.
  813. func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
  814. m := &UserMutation{
  815. config: c,
  816. op: op,
  817. typ: TypeUser,
  818. clearedFields: make(map[string]struct{}),
  819. }
  820. for _, opt := range opts {
  821. opt(m)
  822. }
  823. return m
  824. }
  825. // withUserID sets the ID field of the mutation.
  826. func withUserID(id int) userOption {
  827. return func(m *UserMutation) {
  828. var (
  829. err error
  830. once sync.Once
  831. value *User
  832. )
  833. m.oldValue = func(ctx context.Context) (*User, error) {
  834. once.Do(func() {
  835. if m.done {
  836. err = errors.New("querying old values post mutation is not allowed")
  837. } else {
  838. value, err = m.Client().User.Get(ctx, id)
  839. }
  840. })
  841. return value, err
  842. }
  843. m.id = &id
  844. }
  845. }
  846. // withUser sets the old User of the mutation.
  847. func withUser(node *User) userOption {
  848. return func(m *UserMutation) {
  849. m.oldValue = func(context.Context) (*User, error) {
  850. return node, nil
  851. }
  852. m.id = &node.ID
  853. }
  854. }
  855. // Client returns a new `ent.Client` from the mutation. If the mutation was
  856. // executed in a transaction (ent.Tx), a transactional client is returned.
  857. func (m UserMutation) Client() *Client {
  858. client := &Client{config: m.config}
  859. client.init()
  860. return client
  861. }
  862. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  863. // it returns an error otherwise.
  864. func (m UserMutation) Tx() (*Tx, error) {
  865. if _, ok := m.driver.(*txDriver); !ok {
  866. return nil, errors.New("ent: mutation is not running in a transaction")
  867. }
  868. tx := &Tx{config: m.config}
  869. tx.init()
  870. return tx, nil
  871. }
  872. // ID returns the ID value in the mutation. Note that the ID is only available
  873. // if it was provided to the builder or after it was returned from the database.
  874. func (m *UserMutation) ID() (id int, exists bool) {
  875. if m.id == nil {
  876. return
  877. }
  878. return *m.id, true
  879. }
  880. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  881. // That means, if the mutation is applied within a transaction with an isolation level such
  882. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  883. // or updated by the mutation.
  884. func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
  885. switch {
  886. case m.op.Is(OpUpdateOne | OpDeleteOne):
  887. id, exists := m.ID()
  888. if exists {
  889. return []int{id}, nil
  890. }
  891. fallthrough
  892. case m.op.Is(OpUpdate | OpDelete):
  893. return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
  894. default:
  895. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  896. }
  897. }
  898. // SetAge sets the "age" field.
  899. func (m *UserMutation) SetAge(i int) {
  900. m.age = &i
  901. m.addage = nil
  902. }
  903. // Age returns the value of the "age" field in the mutation.
  904. func (m *UserMutation) Age() (r int, exists bool) {
  905. v := m.age
  906. if v == nil {
  907. return
  908. }
  909. return *v, true
  910. }
  911. // OldAge returns the old "age" field's value of the User entity.
  912. // If the User object wasn't provided to the builder, the object is fetched from the database.
  913. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  914. func (m *UserMutation) OldAge(ctx context.Context) (v int, err error) {
  915. if !m.op.Is(OpUpdateOne) {
  916. return v, errors.New("OldAge is only allowed on UpdateOne operations")
  917. }
  918. if m.id == nil || m.oldValue == nil {
  919. return v, errors.New("OldAge requires an ID field in the mutation")
  920. }
  921. oldValue, err := m.oldValue(ctx)
  922. if err != nil {
  923. return v, fmt.Errorf("querying old value for OldAge: %w", err)
  924. }
  925. return oldValue.Age, nil
  926. }
  927. // AddAge adds i to the "age" field.
  928. func (m *UserMutation) AddAge(i int) {
  929. if m.addage != nil {
  930. *m.addage += i
  931. } else {
  932. m.addage = &i
  933. }
  934. }
  935. // AddedAge returns the value that was added to the "age" field in this mutation.
  936. func (m *UserMutation) AddedAge() (r int, exists bool) {
  937. v := m.addage
  938. if v == nil {
  939. return
  940. }
  941. return *v, true
  942. }
  943. // ResetAge resets all changes to the "age" field.
  944. func (m *UserMutation) ResetAge() {
  945. m.age = nil
  946. m.addage = nil
  947. }
  948. // SetName sets the "name" field.
  949. func (m *UserMutation) SetName(s string) {
  950. m.name = &s
  951. }
  952. // Name returns the value of the "name" field in the mutation.
  953. func (m *UserMutation) Name() (r string, exists bool) {
  954. v := m.name
  955. if v == nil {
  956. return
  957. }
  958. return *v, true
  959. }
  960. // OldName returns the old "name" field's value of the User entity.
  961. // If the User object wasn't provided to the builder, the object is fetched from the database.
  962. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  963. func (m *UserMutation) OldName(ctx context.Context) (v string, err error) {
  964. if !m.op.Is(OpUpdateOne) {
  965. return v, errors.New("OldName is only allowed on UpdateOne operations")
  966. }
  967. if m.id == nil || m.oldValue == nil {
  968. return v, errors.New("OldName requires an ID field in the mutation")
  969. }
  970. oldValue, err := m.oldValue(ctx)
  971. if err != nil {
  972. return v, fmt.Errorf("querying old value for OldName: %w", err)
  973. }
  974. return oldValue.Name, nil
  975. }
  976. // ResetName resets all changes to the "name" field.
  977. func (m *UserMutation) ResetName() {
  978. m.name = nil
  979. }
  980. // SetPassword sets the "password" field.
  981. func (m *UserMutation) SetPassword(s string) {
  982. m.password = &s
  983. }
  984. // Password returns the value of the "password" field in the mutation.
  985. func (m *UserMutation) Password() (r string, exists bool) {
  986. v := m.password
  987. if v == nil {
  988. return
  989. }
  990. return *v, true
  991. }
  992. // OldPassword returns the old "password" field's value of the User entity.
  993. // If the User object wasn't provided to the builder, the object is fetched from the database.
  994. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  995. func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) {
  996. if !m.op.Is(OpUpdateOne) {
  997. return v, errors.New("OldPassword is only allowed on UpdateOne operations")
  998. }
  999. if m.id == nil || m.oldValue == nil {
  1000. return v, errors.New("OldPassword requires an ID field in the mutation")
  1001. }
  1002. oldValue, err := m.oldValue(ctx)
  1003. if err != nil {
  1004. return v, fmt.Errorf("querying old value for OldPassword: %w", err)
  1005. }
  1006. return oldValue.Password, nil
  1007. }
  1008. // ClearPassword clears the value of the "password" field.
  1009. func (m *UserMutation) ClearPassword() {
  1010. m.password = nil
  1011. m.clearedFields[user.FieldPassword] = struct{}{}
  1012. }
  1013. // PasswordCleared returns if the "password" field was cleared in this mutation.
  1014. func (m *UserMutation) PasswordCleared() bool {
  1015. _, ok := m.clearedFields[user.FieldPassword]
  1016. return ok
  1017. }
  1018. // ResetPassword resets all changes to the "password" field.
  1019. func (m *UserMutation) ResetPassword() {
  1020. m.password = nil
  1021. delete(m.clearedFields, user.FieldPassword)
  1022. }
  1023. // SetSize sets the "size" field.
  1024. func (m *UserMutation) SetSize(u user.Size) {
  1025. m.size = &u
  1026. }
  1027. // Size returns the value of the "size" field in the mutation.
  1028. func (m *UserMutation) Size() (r user.Size, exists bool) {
  1029. v := m.size
  1030. if v == nil {
  1031. return
  1032. }
  1033. return *v, true
  1034. }
  1035. // OldSize returns the old "size" field's value of the User entity.
  1036. // If the User object wasn't provided to the builder, the object is fetched from the database.
  1037. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1038. func (m *UserMutation) OldSize(ctx context.Context) (v user.Size, err error) {
  1039. if !m.op.Is(OpUpdateOne) {
  1040. return v, errors.New("OldSize is only allowed on UpdateOne operations")
  1041. }
  1042. if m.id == nil || m.oldValue == nil {
  1043. return v, errors.New("OldSize requires an ID field in the mutation")
  1044. }
  1045. oldValue, err := m.oldValue(ctx)
  1046. if err != nil {
  1047. return v, fmt.Errorf("querying old value for OldSize: %w", err)
  1048. }
  1049. return oldValue.Size, nil
  1050. }
  1051. // ResetSize resets all changes to the "size" field.
  1052. func (m *UserMutation) ResetSize() {
  1053. m.size = nil
  1054. }
  1055. // SetSpouseID sets the "spouse_id" field.
  1056. func (m *UserMutation) SetSpouseID(i int) {
  1057. m.spouse = &i
  1058. }
  1059. // SpouseID returns the value of the "spouse_id" field in the mutation.
  1060. func (m *UserMutation) SpouseID() (r int, exists bool) {
  1061. v := m.spouse
  1062. if v == nil {
  1063. return
  1064. }
  1065. return *v, true
  1066. }
  1067. // OldSpouseID returns the old "spouse_id" field's value of the User entity.
  1068. // If the User object wasn't provided to the builder, the object is fetched from the database.
  1069. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1070. func (m *UserMutation) OldSpouseID(ctx context.Context) (v int, err error) {
  1071. if !m.op.Is(OpUpdateOne) {
  1072. return v, errors.New("OldSpouseID is only allowed on UpdateOne operations")
  1073. }
  1074. if m.id == nil || m.oldValue == nil {
  1075. return v, errors.New("OldSpouseID requires an ID field in the mutation")
  1076. }
  1077. oldValue, err := m.oldValue(ctx)
  1078. if err != nil {
  1079. return v, fmt.Errorf("querying old value for OldSpouseID: %w", err)
  1080. }
  1081. return oldValue.SpouseID, nil
  1082. }
  1083. // ClearSpouseID clears the value of the "spouse_id" field.
  1084. func (m *UserMutation) ClearSpouseID() {
  1085. m.spouse = nil
  1086. m.clearedFields[user.FieldSpouseID] = struct{}{}
  1087. }
  1088. // SpouseIDCleared returns if the "spouse_id" field was cleared in this mutation.
  1089. func (m *UserMutation) SpouseIDCleared() bool {
  1090. _, ok := m.clearedFields[user.FieldSpouseID]
  1091. return ok
  1092. }
  1093. // ResetSpouseID resets all changes to the "spouse_id" field.
  1094. func (m *UserMutation) ResetSpouseID() {
  1095. m.spouse = nil
  1096. delete(m.clearedFields, user.FieldSpouseID)
  1097. }
  1098. // AddCarIDs adds the "cars" edge to the Car entity by ids.
  1099. func (m *UserMutation) AddCarIDs(ids ...int) {
  1100. if m.cars == nil {
  1101. m.cars = make(map[int]struct{})
  1102. }
  1103. for i := range ids {
  1104. m.cars[ids[i]] = struct{}{}
  1105. }
  1106. }
  1107. // ClearCars clears the "cars" edge to the Car entity.
  1108. func (m *UserMutation) ClearCars() {
  1109. m.clearedcars = true
  1110. }
  1111. // CarsCleared reports if the "cars" edge to the Car entity was cleared.
  1112. func (m *UserMutation) CarsCleared() bool {
  1113. return m.clearedcars
  1114. }
  1115. // RemoveCarIDs removes the "cars" edge to the Car entity by IDs.
  1116. func (m *UserMutation) RemoveCarIDs(ids ...int) {
  1117. if m.removedcars == nil {
  1118. m.removedcars = make(map[int]struct{})
  1119. }
  1120. for i := range ids {
  1121. delete(m.cars, ids[i])
  1122. m.removedcars[ids[i]] = struct{}{}
  1123. }
  1124. }
  1125. // RemovedCars returns the removed IDs of the "cars" edge to the Car entity.
  1126. func (m *UserMutation) RemovedCarsIDs() (ids []int) {
  1127. for id := range m.removedcars {
  1128. ids = append(ids, id)
  1129. }
  1130. return
  1131. }
  1132. // CarsIDs returns the "cars" edge IDs in the mutation.
  1133. func (m *UserMutation) CarsIDs() (ids []int) {
  1134. for id := range m.cars {
  1135. ids = append(ids, id)
  1136. }
  1137. return
  1138. }
  1139. // ResetCars resets all changes to the "cars" edge.
  1140. func (m *UserMutation) ResetCars() {
  1141. m.cars = nil
  1142. m.clearedcars = false
  1143. m.removedcars = nil
  1144. }
  1145. // AddGroupIDs adds the "groups" edge to the Group entity by ids.
  1146. func (m *UserMutation) AddGroupIDs(ids ...int) {
  1147. if m.groups == nil {
  1148. m.groups = make(map[int]struct{})
  1149. }
  1150. for i := range ids {
  1151. m.groups[ids[i]] = struct{}{}
  1152. }
  1153. }
  1154. // ClearGroups clears the "groups" edge to the Group entity.
  1155. func (m *UserMutation) ClearGroups() {
  1156. m.clearedgroups = true
  1157. }
  1158. // GroupsCleared reports if the "groups" edge to the Group entity was cleared.
  1159. func (m *UserMutation) GroupsCleared() bool {
  1160. return m.clearedgroups
  1161. }
  1162. // RemoveGroupIDs removes the "groups" edge to the Group entity by IDs.
  1163. func (m *UserMutation) RemoveGroupIDs(ids ...int) {
  1164. if m.removedgroups == nil {
  1165. m.removedgroups = make(map[int]struct{})
  1166. }
  1167. for i := range ids {
  1168. delete(m.groups, ids[i])
  1169. m.removedgroups[ids[i]] = struct{}{}
  1170. }
  1171. }
  1172. // RemovedGroups returns the removed IDs of the "groups" edge to the Group entity.
  1173. func (m *UserMutation) RemovedGroupsIDs() (ids []int) {
  1174. for id := range m.removedgroups {
  1175. ids = append(ids, id)
  1176. }
  1177. return
  1178. }
  1179. // GroupsIDs returns the "groups" edge IDs in the mutation.
  1180. func (m *UserMutation) GroupsIDs() (ids []int) {
  1181. for id := range m.groups {
  1182. ids = append(ids, id)
  1183. }
  1184. return
  1185. }
  1186. // ResetGroups resets all changes to the "groups" edge.
  1187. func (m *UserMutation) ResetGroups() {
  1188. m.groups = nil
  1189. m.clearedgroups = false
  1190. m.removedgroups = nil
  1191. }
  1192. // ClearSpouse clears the "spouse" edge to the User entity.
  1193. func (m *UserMutation) ClearSpouse() {
  1194. m.clearedspouse = true
  1195. }
  1196. // SpouseCleared reports if the "spouse" edge to the User entity was cleared.
  1197. func (m *UserMutation) SpouseCleared() bool {
  1198. return m.SpouseIDCleared() || m.clearedspouse
  1199. }
  1200. // SpouseIDs returns the "spouse" edge IDs in the mutation.
  1201. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  1202. // SpouseID instead. It exists only for internal usage by the builders.
  1203. func (m *UserMutation) SpouseIDs() (ids []int) {
  1204. if id := m.spouse; id != nil {
  1205. ids = append(ids, *id)
  1206. }
  1207. return
  1208. }
  1209. // ResetSpouse resets all changes to the "spouse" edge.
  1210. func (m *UserMutation) ResetSpouse() {
  1211. m.spouse = nil
  1212. m.clearedspouse = false
  1213. }
  1214. // AddFollowerIDs adds the "followers" edge to the User entity by ids.
  1215. func (m *UserMutation) AddFollowerIDs(ids ...int) {
  1216. if m.followers == nil {
  1217. m.followers = make(map[int]struct{})
  1218. }
  1219. for i := range ids {
  1220. m.followers[ids[i]] = struct{}{}
  1221. }
  1222. }
  1223. // ClearFollowers clears the "followers" edge to the User entity.
  1224. func (m *UserMutation) ClearFollowers() {
  1225. m.clearedfollowers = true
  1226. }
  1227. // FollowersCleared reports if the "followers" edge to the User entity was cleared.
  1228. func (m *UserMutation) FollowersCleared() bool {
  1229. return m.clearedfollowers
  1230. }
  1231. // RemoveFollowerIDs removes the "followers" edge to the User entity by IDs.
  1232. func (m *UserMutation) RemoveFollowerIDs(ids ...int) {
  1233. if m.removedfollowers == nil {
  1234. m.removedfollowers = make(map[int]struct{})
  1235. }
  1236. for i := range ids {
  1237. delete(m.followers, ids[i])
  1238. m.removedfollowers[ids[i]] = struct{}{}
  1239. }
  1240. }
  1241. // RemovedFollowers returns the removed IDs of the "followers" edge to the User entity.
  1242. func (m *UserMutation) RemovedFollowersIDs() (ids []int) {
  1243. for id := range m.removedfollowers {
  1244. ids = append(ids, id)
  1245. }
  1246. return
  1247. }
  1248. // FollowersIDs returns the "followers" edge IDs in the mutation.
  1249. func (m *UserMutation) FollowersIDs() (ids []int) {
  1250. for id := range m.followers {
  1251. ids = append(ids, id)
  1252. }
  1253. return
  1254. }
  1255. // ResetFollowers resets all changes to the "followers" edge.
  1256. func (m *UserMutation) ResetFollowers() {
  1257. m.followers = nil
  1258. m.clearedfollowers = false
  1259. m.removedfollowers = nil
  1260. }
  1261. // AddFollowingIDs adds the "following" edge to the User entity by ids.
  1262. func (m *UserMutation) AddFollowingIDs(ids ...int) {
  1263. if m.following == nil {
  1264. m.following = make(map[int]struct{})
  1265. }
  1266. for i := range ids {
  1267. m.following[ids[i]] = struct{}{}
  1268. }
  1269. }
  1270. // ClearFollowing clears the "following" edge to the User entity.
  1271. func (m *UserMutation) ClearFollowing() {
  1272. m.clearedfollowing = true
  1273. }
  1274. // FollowingCleared reports if the "following" edge to the User entity was cleared.
  1275. func (m *UserMutation) FollowingCleared() bool {
  1276. return m.clearedfollowing
  1277. }
  1278. // RemoveFollowingIDs removes the "following" edge to the User entity by IDs.
  1279. func (m *UserMutation) RemoveFollowingIDs(ids ...int) {
  1280. if m.removedfollowing == nil {
  1281. m.removedfollowing = make(map[int]struct{})
  1282. }
  1283. for i := range ids {
  1284. delete(m.following, ids[i])
  1285. m.removedfollowing[ids[i]] = struct{}{}
  1286. }
  1287. }
  1288. // RemovedFollowing returns the removed IDs of the "following" edge to the User entity.
  1289. func (m *UserMutation) RemovedFollowingIDs() (ids []int) {
  1290. for id := range m.removedfollowing {
  1291. ids = append(ids, id)
  1292. }
  1293. return
  1294. }
  1295. // FollowingIDs returns the "following" edge IDs in the mutation.
  1296. func (m *UserMutation) FollowingIDs() (ids []int) {
  1297. for id := range m.following {
  1298. ids = append(ids, id)
  1299. }
  1300. return
  1301. }
  1302. // ResetFollowing resets all changes to the "following" edge.
  1303. func (m *UserMutation) ResetFollowing() {
  1304. m.following = nil
  1305. m.clearedfollowing = false
  1306. m.removedfollowing = nil
  1307. }
  1308. // AddFriendIDs adds the "friends" edge to the User entity by ids.
  1309. func (m *UserMutation) AddFriendIDs(ids ...int) {
  1310. if m.friends == nil {
  1311. m.friends = make(map[int]struct{})
  1312. }
  1313. for i := range ids {
  1314. m.friends[ids[i]] = struct{}{}
  1315. }
  1316. }
  1317. // ClearFriends clears the "friends" edge to the User entity.
  1318. func (m *UserMutation) ClearFriends() {
  1319. m.clearedfriends = true
  1320. }
  1321. // FriendsCleared reports if the "friends" edge to the User entity was cleared.
  1322. func (m *UserMutation) FriendsCleared() bool {
  1323. return m.clearedfriends
  1324. }
  1325. // RemoveFriendIDs removes the "friends" edge to the User entity by IDs.
  1326. func (m *UserMutation) RemoveFriendIDs(ids ...int) {
  1327. if m.removedfriends == nil {
  1328. m.removedfriends = make(map[int]struct{})
  1329. }
  1330. for i := range ids {
  1331. delete(m.friends, ids[i])
  1332. m.removedfriends[ids[i]] = struct{}{}
  1333. }
  1334. }
  1335. // RemovedFriends returns the removed IDs of the "friends" edge to the User entity.
  1336. func (m *UserMutation) RemovedFriendsIDs() (ids []int) {
  1337. for id := range m.removedfriends {
  1338. ids = append(ids, id)
  1339. }
  1340. return
  1341. }
  1342. // FriendsIDs returns the "friends" edge IDs in the mutation.
  1343. func (m *UserMutation) FriendsIDs() (ids []int) {
  1344. for id := range m.friends {
  1345. ids = append(ids, id)
  1346. }
  1347. return
  1348. }
  1349. // ResetFriends resets all changes to the "friends" edge.
  1350. func (m *UserMutation) ResetFriends() {
  1351. m.friends = nil
  1352. m.clearedfriends = false
  1353. m.removedfriends = nil
  1354. }
  1355. // Where appends a list predicates to the UserMutation builder.
  1356. func (m *UserMutation) Where(ps ...predicate.User) {
  1357. m.predicates = append(m.predicates, ps...)
  1358. }
  1359. // Op returns the operation name.
  1360. func (m *UserMutation) Op() Op {
  1361. return m.op
  1362. }
  1363. // Type returns the node type of this mutation (User).
  1364. func (m *UserMutation) Type() string {
  1365. return m.typ
  1366. }
  1367. // Fields returns all fields that were changed during this mutation. Note that in
  1368. // order to get all numeric fields that were incremented/decremented, call
  1369. // AddedFields().
  1370. func (m *UserMutation) Fields() []string {
  1371. fields := make([]string, 0, 5)
  1372. if m.age != nil {
  1373. fields = append(fields, user.FieldAge)
  1374. }
  1375. if m.name != nil {
  1376. fields = append(fields, user.FieldName)
  1377. }
  1378. if m.password != nil {
  1379. fields = append(fields, user.FieldPassword)
  1380. }
  1381. if m.size != nil {
  1382. fields = append(fields, user.FieldSize)
  1383. }
  1384. if m.spouse != nil {
  1385. fields = append(fields, user.FieldSpouseID)
  1386. }
  1387. return fields
  1388. }
  1389. // Field returns the value of a field with the given name. The second boolean
  1390. // return value indicates that this field was not set, or was not defined in the
  1391. // schema.
  1392. func (m *UserMutation) Field(name string) (ent.Value, bool) {
  1393. switch name {
  1394. case user.FieldAge:
  1395. return m.Age()
  1396. case user.FieldName:
  1397. return m.Name()
  1398. case user.FieldPassword:
  1399. return m.Password()
  1400. case user.FieldSize:
  1401. return m.Size()
  1402. case user.FieldSpouseID:
  1403. return m.SpouseID()
  1404. }
  1405. return nil, false
  1406. }
  1407. // OldField returns the old value of the field from the database. An error is
  1408. // returned if the mutation operation is not UpdateOne, or the query to the
  1409. // database failed.
  1410. func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  1411. switch name {
  1412. case user.FieldAge:
  1413. return m.OldAge(ctx)
  1414. case user.FieldName:
  1415. return m.OldName(ctx)
  1416. case user.FieldPassword:
  1417. return m.OldPassword(ctx)
  1418. case user.FieldSize:
  1419. return m.OldSize(ctx)
  1420. case user.FieldSpouseID:
  1421. return m.OldSpouseID(ctx)
  1422. }
  1423. return nil, fmt.Errorf("unknown User field %s", name)
  1424. }
  1425. // SetField sets the value of a field with the given name. It returns an error if
  1426. // the field is not defined in the schema, or if the type mismatched the field
  1427. // type.
  1428. func (m *UserMutation) SetField(name string, value ent.Value) error {
  1429. switch name {
  1430. case user.FieldAge:
  1431. v, ok := value.(int)
  1432. if !ok {
  1433. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1434. }
  1435. m.SetAge(v)
  1436. return nil
  1437. case user.FieldName:
  1438. v, ok := value.(string)
  1439. if !ok {
  1440. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1441. }
  1442. m.SetName(v)
  1443. return nil
  1444. case user.FieldPassword:
  1445. v, ok := value.(string)
  1446. if !ok {
  1447. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1448. }
  1449. m.SetPassword(v)
  1450. return nil
  1451. case user.FieldSize:
  1452. v, ok := value.(user.Size)
  1453. if !ok {
  1454. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1455. }
  1456. m.SetSize(v)
  1457. return nil
  1458. case user.FieldSpouseID:
  1459. v, ok := value.(int)
  1460. if !ok {
  1461. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1462. }
  1463. m.SetSpouseID(v)
  1464. return nil
  1465. }
  1466. return fmt.Errorf("unknown User field %s", name)
  1467. }
  1468. // AddedFields returns all numeric fields that were incremented/decremented during
  1469. // this mutation.
  1470. func (m *UserMutation) AddedFields() []string {
  1471. var fields []string
  1472. if m.addage != nil {
  1473. fields = append(fields, user.FieldAge)
  1474. }
  1475. return fields
  1476. }
  1477. // AddedField returns the numeric value that was incremented/decremented on a field
  1478. // with the given name. The second boolean return value indicates that this field
  1479. // was not set, or was not defined in the schema.
  1480. func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
  1481. switch name {
  1482. case user.FieldAge:
  1483. return m.AddedAge()
  1484. }
  1485. return nil, false
  1486. }
  1487. // AddField adds the value to the field with the given name. It returns an error if
  1488. // the field is not defined in the schema, or if the type mismatched the field
  1489. // type.
  1490. func (m *UserMutation) AddField(name string, value ent.Value) error {
  1491. switch name {
  1492. case user.FieldAge:
  1493. v, ok := value.(int)
  1494. if !ok {
  1495. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1496. }
  1497. m.AddAge(v)
  1498. return nil
  1499. }
  1500. return fmt.Errorf("unknown User numeric field %s", name)
  1501. }
  1502. // ClearedFields returns all nullable fields that were cleared during this
  1503. // mutation.
  1504. func (m *UserMutation) ClearedFields() []string {
  1505. var fields []string
  1506. if m.FieldCleared(user.FieldPassword) {
  1507. fields = append(fields, user.FieldPassword)
  1508. }
  1509. if m.FieldCleared(user.FieldSpouseID) {
  1510. fields = append(fields, user.FieldSpouseID)
  1511. }
  1512. return fields
  1513. }
  1514. // FieldCleared returns a boolean indicating if a field with the given name was
  1515. // cleared in this mutation.
  1516. func (m *UserMutation) FieldCleared(name string) bool {
  1517. _, ok := m.clearedFields[name]
  1518. return ok
  1519. }
  1520. // ClearField clears the value of the field with the given name. It returns an
  1521. // error if the field is not defined in the schema.
  1522. func (m *UserMutation) ClearField(name string) error {
  1523. switch name {
  1524. case user.FieldPassword:
  1525. m.ClearPassword()
  1526. return nil
  1527. case user.FieldSpouseID:
  1528. m.ClearSpouseID()
  1529. return nil
  1530. }
  1531. return fmt.Errorf("unknown User nullable field %s", name)
  1532. }
  1533. // ResetField resets all changes in the mutation for the field with the given name.
  1534. // It returns an error if the field is not defined in the schema.
  1535. func (m *UserMutation) ResetField(name string) error {
  1536. switch name {
  1537. case user.FieldAge:
  1538. m.ResetAge()
  1539. return nil
  1540. case user.FieldName:
  1541. m.ResetName()
  1542. return nil
  1543. case user.FieldPassword:
  1544. m.ResetPassword()
  1545. return nil
  1546. case user.FieldSize:
  1547. m.ResetSize()
  1548. return nil
  1549. case user.FieldSpouseID:
  1550. m.ResetSpouseID()
  1551. return nil
  1552. }
  1553. return fmt.Errorf("unknown User field %s", name)
  1554. }
  1555. // AddedEdges returns all edge names that were set/added in this mutation.
  1556. func (m *UserMutation) AddedEdges() []string {
  1557. edges := make([]string, 0, 6)
  1558. if m.cars != nil {
  1559. edges = append(edges, user.EdgeCars)
  1560. }
  1561. if m.groups != nil {
  1562. edges = append(edges, user.EdgeGroups)
  1563. }
  1564. if m.spouse != nil {
  1565. edges = append(edges, user.EdgeSpouse)
  1566. }
  1567. if m.followers != nil {
  1568. edges = append(edges, user.EdgeFollowers)
  1569. }
  1570. if m.following != nil {
  1571. edges = append(edges, user.EdgeFollowing)
  1572. }
  1573. if m.friends != nil {
  1574. edges = append(edges, user.EdgeFriends)
  1575. }
  1576. return edges
  1577. }
  1578. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  1579. // name in this mutation.
  1580. func (m *UserMutation) AddedIDs(name string) []ent.Value {
  1581. switch name {
  1582. case user.EdgeCars:
  1583. ids := make([]ent.Value, 0, len(m.cars))
  1584. for id := range m.cars {
  1585. ids = append(ids, id)
  1586. }
  1587. return ids
  1588. case user.EdgeGroups:
  1589. ids := make([]ent.Value, 0, len(m.groups))
  1590. for id := range m.groups {
  1591. ids = append(ids, id)
  1592. }
  1593. return ids
  1594. case user.EdgeSpouse:
  1595. if id := m.spouse; id != nil {
  1596. return []ent.Value{*id}
  1597. }
  1598. case user.EdgeFollowers:
  1599. ids := make([]ent.Value, 0, len(m.followers))
  1600. for id := range m.followers {
  1601. ids = append(ids, id)
  1602. }
  1603. return ids
  1604. case user.EdgeFollowing:
  1605. ids := make([]ent.Value, 0, len(m.following))
  1606. for id := range m.following {
  1607. ids = append(ids, id)
  1608. }
  1609. return ids
  1610. case user.EdgeFriends:
  1611. ids := make([]ent.Value, 0, len(m.friends))
  1612. for id := range m.friends {
  1613. ids = append(ids, id)
  1614. }
  1615. return ids
  1616. }
  1617. return nil
  1618. }
  1619. // RemovedEdges returns all edge names that were removed in this mutation.
  1620. func (m *UserMutation) RemovedEdges() []string {
  1621. edges := make([]string, 0, 6)
  1622. if m.removedcars != nil {
  1623. edges = append(edges, user.EdgeCars)
  1624. }
  1625. if m.removedgroups != nil {
  1626. edges = append(edges, user.EdgeGroups)
  1627. }
  1628. if m.removedfollowers != nil {
  1629. edges = append(edges, user.EdgeFollowers)
  1630. }
  1631. if m.removedfollowing != nil {
  1632. edges = append(edges, user.EdgeFollowing)
  1633. }
  1634. if m.removedfriends != nil {
  1635. edges = append(edges, user.EdgeFriends)
  1636. }
  1637. return edges
  1638. }
  1639. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  1640. // the given name in this mutation.
  1641. func (m *UserMutation) RemovedIDs(name string) []ent.Value {
  1642. switch name {
  1643. case user.EdgeCars:
  1644. ids := make([]ent.Value, 0, len(m.removedcars))
  1645. for id := range m.removedcars {
  1646. ids = append(ids, id)
  1647. }
  1648. return ids
  1649. case user.EdgeGroups:
  1650. ids := make([]ent.Value, 0, len(m.removedgroups))
  1651. for id := range m.removedgroups {
  1652. ids = append(ids, id)
  1653. }
  1654. return ids
  1655. case user.EdgeFollowers:
  1656. ids := make([]ent.Value, 0, len(m.removedfollowers))
  1657. for id := range m.removedfollowers {
  1658. ids = append(ids, id)
  1659. }
  1660. return ids
  1661. case user.EdgeFollowing:
  1662. ids := make([]ent.Value, 0, len(m.removedfollowing))
  1663. for id := range m.removedfollowing {
  1664. ids = append(ids, id)
  1665. }
  1666. return ids
  1667. case user.EdgeFriends:
  1668. ids := make([]ent.Value, 0, len(m.removedfriends))
  1669. for id := range m.removedfriends {
  1670. ids = append(ids, id)
  1671. }
  1672. return ids
  1673. }
  1674. return nil
  1675. }
  1676. // ClearedEdges returns all edge names that were cleared in this mutation.
  1677. func (m *UserMutation) ClearedEdges() []string {
  1678. edges := make([]string, 0, 6)
  1679. if m.clearedcars {
  1680. edges = append(edges, user.EdgeCars)
  1681. }
  1682. if m.clearedgroups {
  1683. edges = append(edges, user.EdgeGroups)
  1684. }
  1685. if m.clearedspouse {
  1686. edges = append(edges, user.EdgeSpouse)
  1687. }
  1688. if m.clearedfollowers {
  1689. edges = append(edges, user.EdgeFollowers)
  1690. }
  1691. if m.clearedfollowing {
  1692. edges = append(edges, user.EdgeFollowing)
  1693. }
  1694. if m.clearedfriends {
  1695. edges = append(edges, user.EdgeFriends)
  1696. }
  1697. return edges
  1698. }
  1699. // EdgeCleared returns a boolean which indicates if the edge with the given name
  1700. // was cleared in this mutation.
  1701. func (m *UserMutation) EdgeCleared(name string) bool {
  1702. switch name {
  1703. case user.EdgeCars:
  1704. return m.clearedcars
  1705. case user.EdgeGroups:
  1706. return m.clearedgroups
  1707. case user.EdgeSpouse:
  1708. return m.clearedspouse
  1709. case user.EdgeFollowers:
  1710. return m.clearedfollowers
  1711. case user.EdgeFollowing:
  1712. return m.clearedfollowing
  1713. case user.EdgeFriends:
  1714. return m.clearedfriends
  1715. }
  1716. return false
  1717. }
  1718. // ClearEdge clears the value of the edge with the given name. It returns an error
  1719. // if that edge is not defined in the schema.
  1720. func (m *UserMutation) ClearEdge(name string) error {
  1721. switch name {
  1722. case user.EdgeSpouse:
  1723. m.ClearSpouse()
  1724. return nil
  1725. }
  1726. return fmt.Errorf("unknown User unique edge %s", name)
  1727. }
  1728. // ResetEdge resets all changes to the edge with the given name in this mutation.
  1729. // It returns an error if the edge is not defined in the schema.
  1730. func (m *UserMutation) ResetEdge(name string) error {
  1731. switch name {
  1732. case user.EdgeCars:
  1733. m.ResetCars()
  1734. return nil
  1735. case user.EdgeGroups:
  1736. m.ResetGroups()
  1737. return nil
  1738. case user.EdgeSpouse:
  1739. m.ResetSpouse()
  1740. return nil
  1741. case user.EdgeFollowers:
  1742. m.ResetFollowers()
  1743. return nil
  1744. case user.EdgeFollowing:
  1745. m.ResetFollowing()
  1746. return nil
  1747. case user.EdgeFriends:
  1748. m.ResetFriends()
  1749. return nil
  1750. }
  1751. return fmt.Errorf("unknown User edge %s", name)
  1752. }