user_create.go 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  11. "github.com/Wei-Shaw/sub2api/ent/announcementread"
  12. "github.com/Wei-Shaw/sub2api/ent/apikey"
  13. "github.com/Wei-Shaw/sub2api/ent/authidentity"
  14. "github.com/Wei-Shaw/sub2api/ent/group"
  15. "github.com/Wei-Shaw/sub2api/ent/paymentorder"
  16. "github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
  17. "github.com/Wei-Shaw/sub2api/ent/promocodeusage"
  18. "github.com/Wei-Shaw/sub2api/ent/redeemcode"
  19. "github.com/Wei-Shaw/sub2api/ent/usagelog"
  20. "github.com/Wei-Shaw/sub2api/ent/user"
  21. "github.com/Wei-Shaw/sub2api/ent/userattributevalue"
  22. "github.com/Wei-Shaw/sub2api/ent/userplatformquota"
  23. "github.com/Wei-Shaw/sub2api/ent/usersubscription"
  24. )
  25. // UserCreate is the builder for creating a User entity.
  26. type UserCreate struct {
  27. config
  28. mutation *UserMutation
  29. hooks []Hook
  30. conflict []sql.ConflictOption
  31. }
  32. // SetCreatedAt sets the "created_at" field.
  33. func (_c *UserCreate) SetCreatedAt(v time.Time) *UserCreate {
  34. _c.mutation.SetCreatedAt(v)
  35. return _c
  36. }
  37. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  38. func (_c *UserCreate) SetNillableCreatedAt(v *time.Time) *UserCreate {
  39. if v != nil {
  40. _c.SetCreatedAt(*v)
  41. }
  42. return _c
  43. }
  44. // SetUpdatedAt sets the "updated_at" field.
  45. func (_c *UserCreate) SetUpdatedAt(v time.Time) *UserCreate {
  46. _c.mutation.SetUpdatedAt(v)
  47. return _c
  48. }
  49. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  50. func (_c *UserCreate) SetNillableUpdatedAt(v *time.Time) *UserCreate {
  51. if v != nil {
  52. _c.SetUpdatedAt(*v)
  53. }
  54. return _c
  55. }
  56. // SetDeletedAt sets the "deleted_at" field.
  57. func (_c *UserCreate) SetDeletedAt(v time.Time) *UserCreate {
  58. _c.mutation.SetDeletedAt(v)
  59. return _c
  60. }
  61. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  62. func (_c *UserCreate) SetNillableDeletedAt(v *time.Time) *UserCreate {
  63. if v != nil {
  64. _c.SetDeletedAt(*v)
  65. }
  66. return _c
  67. }
  68. // SetEmail sets the "email" field.
  69. func (_c *UserCreate) SetEmail(v string) *UserCreate {
  70. _c.mutation.SetEmail(v)
  71. return _c
  72. }
  73. // SetPasswordHash sets the "password_hash" field.
  74. func (_c *UserCreate) SetPasswordHash(v string) *UserCreate {
  75. _c.mutation.SetPasswordHash(v)
  76. return _c
  77. }
  78. // SetRole sets the "role" field.
  79. func (_c *UserCreate) SetRole(v string) *UserCreate {
  80. _c.mutation.SetRole(v)
  81. return _c
  82. }
  83. // SetNillableRole sets the "role" field if the given value is not nil.
  84. func (_c *UserCreate) SetNillableRole(v *string) *UserCreate {
  85. if v != nil {
  86. _c.SetRole(*v)
  87. }
  88. return _c
  89. }
  90. // SetBalance sets the "balance" field.
  91. func (_c *UserCreate) SetBalance(v float64) *UserCreate {
  92. _c.mutation.SetBalance(v)
  93. return _c
  94. }
  95. // SetNillableBalance sets the "balance" field if the given value is not nil.
  96. func (_c *UserCreate) SetNillableBalance(v *float64) *UserCreate {
  97. if v != nil {
  98. _c.SetBalance(*v)
  99. }
  100. return _c
  101. }
  102. // SetFrozenBalance sets the "frozen_balance" field.
  103. func (_c *UserCreate) SetFrozenBalance(v float64) *UserCreate {
  104. _c.mutation.SetFrozenBalance(v)
  105. return _c
  106. }
  107. // SetNillableFrozenBalance sets the "frozen_balance" field if the given value is not nil.
  108. func (_c *UserCreate) SetNillableFrozenBalance(v *float64) *UserCreate {
  109. if v != nil {
  110. _c.SetFrozenBalance(*v)
  111. }
  112. return _c
  113. }
  114. // SetConcurrency sets the "concurrency" field.
  115. func (_c *UserCreate) SetConcurrency(v int) *UserCreate {
  116. _c.mutation.SetConcurrency(v)
  117. return _c
  118. }
  119. // SetNillableConcurrency sets the "concurrency" field if the given value is not nil.
  120. func (_c *UserCreate) SetNillableConcurrency(v *int) *UserCreate {
  121. if v != nil {
  122. _c.SetConcurrency(*v)
  123. }
  124. return _c
  125. }
  126. // SetStatus sets the "status" field.
  127. func (_c *UserCreate) SetStatus(v string) *UserCreate {
  128. _c.mutation.SetStatus(v)
  129. return _c
  130. }
  131. // SetNillableStatus sets the "status" field if the given value is not nil.
  132. func (_c *UserCreate) SetNillableStatus(v *string) *UserCreate {
  133. if v != nil {
  134. _c.SetStatus(*v)
  135. }
  136. return _c
  137. }
  138. // SetUsername sets the "username" field.
  139. func (_c *UserCreate) SetUsername(v string) *UserCreate {
  140. _c.mutation.SetUsername(v)
  141. return _c
  142. }
  143. // SetNillableUsername sets the "username" field if the given value is not nil.
  144. func (_c *UserCreate) SetNillableUsername(v *string) *UserCreate {
  145. if v != nil {
  146. _c.SetUsername(*v)
  147. }
  148. return _c
  149. }
  150. // SetNotes sets the "notes" field.
  151. func (_c *UserCreate) SetNotes(v string) *UserCreate {
  152. _c.mutation.SetNotes(v)
  153. return _c
  154. }
  155. // SetNillableNotes sets the "notes" field if the given value is not nil.
  156. func (_c *UserCreate) SetNillableNotes(v *string) *UserCreate {
  157. if v != nil {
  158. _c.SetNotes(*v)
  159. }
  160. return _c
  161. }
  162. // SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
  163. func (_c *UserCreate) SetTotpSecretEncrypted(v string) *UserCreate {
  164. _c.mutation.SetTotpSecretEncrypted(v)
  165. return _c
  166. }
  167. // SetNillableTotpSecretEncrypted sets the "totp_secret_encrypted" field if the given value is not nil.
  168. func (_c *UserCreate) SetNillableTotpSecretEncrypted(v *string) *UserCreate {
  169. if v != nil {
  170. _c.SetTotpSecretEncrypted(*v)
  171. }
  172. return _c
  173. }
  174. // SetTotpEnabled sets the "totp_enabled" field.
  175. func (_c *UserCreate) SetTotpEnabled(v bool) *UserCreate {
  176. _c.mutation.SetTotpEnabled(v)
  177. return _c
  178. }
  179. // SetNillableTotpEnabled sets the "totp_enabled" field if the given value is not nil.
  180. func (_c *UserCreate) SetNillableTotpEnabled(v *bool) *UserCreate {
  181. if v != nil {
  182. _c.SetTotpEnabled(*v)
  183. }
  184. return _c
  185. }
  186. // SetTotpEnabledAt sets the "totp_enabled_at" field.
  187. func (_c *UserCreate) SetTotpEnabledAt(v time.Time) *UserCreate {
  188. _c.mutation.SetTotpEnabledAt(v)
  189. return _c
  190. }
  191. // SetNillableTotpEnabledAt sets the "totp_enabled_at" field if the given value is not nil.
  192. func (_c *UserCreate) SetNillableTotpEnabledAt(v *time.Time) *UserCreate {
  193. if v != nil {
  194. _c.SetTotpEnabledAt(*v)
  195. }
  196. return _c
  197. }
  198. // SetSignupSource sets the "signup_source" field.
  199. func (_c *UserCreate) SetSignupSource(v string) *UserCreate {
  200. _c.mutation.SetSignupSource(v)
  201. return _c
  202. }
  203. // SetNillableSignupSource sets the "signup_source" field if the given value is not nil.
  204. func (_c *UserCreate) SetNillableSignupSource(v *string) *UserCreate {
  205. if v != nil {
  206. _c.SetSignupSource(*v)
  207. }
  208. return _c
  209. }
  210. // SetLastLoginAt sets the "last_login_at" field.
  211. func (_c *UserCreate) SetLastLoginAt(v time.Time) *UserCreate {
  212. _c.mutation.SetLastLoginAt(v)
  213. return _c
  214. }
  215. // SetNillableLastLoginAt sets the "last_login_at" field if the given value is not nil.
  216. func (_c *UserCreate) SetNillableLastLoginAt(v *time.Time) *UserCreate {
  217. if v != nil {
  218. _c.SetLastLoginAt(*v)
  219. }
  220. return _c
  221. }
  222. // SetLastActiveAt sets the "last_active_at" field.
  223. func (_c *UserCreate) SetLastActiveAt(v time.Time) *UserCreate {
  224. _c.mutation.SetLastActiveAt(v)
  225. return _c
  226. }
  227. // SetNillableLastActiveAt sets the "last_active_at" field if the given value is not nil.
  228. func (_c *UserCreate) SetNillableLastActiveAt(v *time.Time) *UserCreate {
  229. if v != nil {
  230. _c.SetLastActiveAt(*v)
  231. }
  232. return _c
  233. }
  234. // SetRestrictPublicGroups sets the "restrict_public_groups" field.
  235. func (_c *UserCreate) SetRestrictPublicGroups(v bool) *UserCreate {
  236. _c.mutation.SetRestrictPublicGroups(v)
  237. return _c
  238. }
  239. // SetNillableRestrictPublicGroups sets the "restrict_public_groups" field if the given value is not nil.
  240. func (_c *UserCreate) SetNillableRestrictPublicGroups(v *bool) *UserCreate {
  241. if v != nil {
  242. _c.SetRestrictPublicGroups(*v)
  243. }
  244. return _c
  245. }
  246. // SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
  247. func (_c *UserCreate) SetBalanceNotifyEnabled(v bool) *UserCreate {
  248. _c.mutation.SetBalanceNotifyEnabled(v)
  249. return _c
  250. }
  251. // SetNillableBalanceNotifyEnabled sets the "balance_notify_enabled" field if the given value is not nil.
  252. func (_c *UserCreate) SetNillableBalanceNotifyEnabled(v *bool) *UserCreate {
  253. if v != nil {
  254. _c.SetBalanceNotifyEnabled(*v)
  255. }
  256. return _c
  257. }
  258. // SetBalanceNotifyThresholdType sets the "balance_notify_threshold_type" field.
  259. func (_c *UserCreate) SetBalanceNotifyThresholdType(v string) *UserCreate {
  260. _c.mutation.SetBalanceNotifyThresholdType(v)
  261. return _c
  262. }
  263. // SetNillableBalanceNotifyThresholdType sets the "balance_notify_threshold_type" field if the given value is not nil.
  264. func (_c *UserCreate) SetNillableBalanceNotifyThresholdType(v *string) *UserCreate {
  265. if v != nil {
  266. _c.SetBalanceNotifyThresholdType(*v)
  267. }
  268. return _c
  269. }
  270. // SetBalanceNotifyThreshold sets the "balance_notify_threshold" field.
  271. func (_c *UserCreate) SetBalanceNotifyThreshold(v float64) *UserCreate {
  272. _c.mutation.SetBalanceNotifyThreshold(v)
  273. return _c
  274. }
  275. // SetNillableBalanceNotifyThreshold sets the "balance_notify_threshold" field if the given value is not nil.
  276. func (_c *UserCreate) SetNillableBalanceNotifyThreshold(v *float64) *UserCreate {
  277. if v != nil {
  278. _c.SetBalanceNotifyThreshold(*v)
  279. }
  280. return _c
  281. }
  282. // SetBalanceNotifyExtraEmails sets the "balance_notify_extra_emails" field.
  283. func (_c *UserCreate) SetBalanceNotifyExtraEmails(v string) *UserCreate {
  284. _c.mutation.SetBalanceNotifyExtraEmails(v)
  285. return _c
  286. }
  287. // SetNillableBalanceNotifyExtraEmails sets the "balance_notify_extra_emails" field if the given value is not nil.
  288. func (_c *UserCreate) SetNillableBalanceNotifyExtraEmails(v *string) *UserCreate {
  289. if v != nil {
  290. _c.SetBalanceNotifyExtraEmails(*v)
  291. }
  292. return _c
  293. }
  294. // SetTotalRecharged sets the "total_recharged" field.
  295. func (_c *UserCreate) SetTotalRecharged(v float64) *UserCreate {
  296. _c.mutation.SetTotalRecharged(v)
  297. return _c
  298. }
  299. // SetNillableTotalRecharged sets the "total_recharged" field if the given value is not nil.
  300. func (_c *UserCreate) SetNillableTotalRecharged(v *float64) *UserCreate {
  301. if v != nil {
  302. _c.SetTotalRecharged(*v)
  303. }
  304. return _c
  305. }
  306. // SetRpmLimit sets the "rpm_limit" field.
  307. func (_c *UserCreate) SetRpmLimit(v int) *UserCreate {
  308. _c.mutation.SetRpmLimit(v)
  309. return _c
  310. }
  311. // SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
  312. func (_c *UserCreate) SetNillableRpmLimit(v *int) *UserCreate {
  313. if v != nil {
  314. _c.SetRpmLimit(*v)
  315. }
  316. return _c
  317. }
  318. // AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
  319. func (_c *UserCreate) AddAPIKeyIDs(ids ...int64) *UserCreate {
  320. _c.mutation.AddAPIKeyIDs(ids...)
  321. return _c
  322. }
  323. // AddAPIKeys adds the "api_keys" edges to the APIKey entity.
  324. func (_c *UserCreate) AddAPIKeys(v ...*APIKey) *UserCreate {
  325. ids := make([]int64, len(v))
  326. for i := range v {
  327. ids[i] = v[i].ID
  328. }
  329. return _c.AddAPIKeyIDs(ids...)
  330. }
  331. // AddRedeemCodeIDs adds the "redeem_codes" edge to the RedeemCode entity by IDs.
  332. func (_c *UserCreate) AddRedeemCodeIDs(ids ...int64) *UserCreate {
  333. _c.mutation.AddRedeemCodeIDs(ids...)
  334. return _c
  335. }
  336. // AddRedeemCodes adds the "redeem_codes" edges to the RedeemCode entity.
  337. func (_c *UserCreate) AddRedeemCodes(v ...*RedeemCode) *UserCreate {
  338. ids := make([]int64, len(v))
  339. for i := range v {
  340. ids[i] = v[i].ID
  341. }
  342. return _c.AddRedeemCodeIDs(ids...)
  343. }
  344. // AddSubscriptionIDs adds the "subscriptions" edge to the UserSubscription entity by IDs.
  345. func (_c *UserCreate) AddSubscriptionIDs(ids ...int64) *UserCreate {
  346. _c.mutation.AddSubscriptionIDs(ids...)
  347. return _c
  348. }
  349. // AddSubscriptions adds the "subscriptions" edges to the UserSubscription entity.
  350. func (_c *UserCreate) AddSubscriptions(v ...*UserSubscription) *UserCreate {
  351. ids := make([]int64, len(v))
  352. for i := range v {
  353. ids[i] = v[i].ID
  354. }
  355. return _c.AddSubscriptionIDs(ids...)
  356. }
  357. // AddAssignedSubscriptionIDs adds the "assigned_subscriptions" edge to the UserSubscription entity by IDs.
  358. func (_c *UserCreate) AddAssignedSubscriptionIDs(ids ...int64) *UserCreate {
  359. _c.mutation.AddAssignedSubscriptionIDs(ids...)
  360. return _c
  361. }
  362. // AddAssignedSubscriptions adds the "assigned_subscriptions" edges to the UserSubscription entity.
  363. func (_c *UserCreate) AddAssignedSubscriptions(v ...*UserSubscription) *UserCreate {
  364. ids := make([]int64, len(v))
  365. for i := range v {
  366. ids[i] = v[i].ID
  367. }
  368. return _c.AddAssignedSubscriptionIDs(ids...)
  369. }
  370. // AddAnnouncementReadIDs adds the "announcement_reads" edge to the AnnouncementRead entity by IDs.
  371. func (_c *UserCreate) AddAnnouncementReadIDs(ids ...int64) *UserCreate {
  372. _c.mutation.AddAnnouncementReadIDs(ids...)
  373. return _c
  374. }
  375. // AddAnnouncementReads adds the "announcement_reads" edges to the AnnouncementRead entity.
  376. func (_c *UserCreate) AddAnnouncementReads(v ...*AnnouncementRead) *UserCreate {
  377. ids := make([]int64, len(v))
  378. for i := range v {
  379. ids[i] = v[i].ID
  380. }
  381. return _c.AddAnnouncementReadIDs(ids...)
  382. }
  383. // AddAllowedGroupIDs adds the "allowed_groups" edge to the Group entity by IDs.
  384. func (_c *UserCreate) AddAllowedGroupIDs(ids ...int64) *UserCreate {
  385. _c.mutation.AddAllowedGroupIDs(ids...)
  386. return _c
  387. }
  388. // AddAllowedGroups adds the "allowed_groups" edges to the Group entity.
  389. func (_c *UserCreate) AddAllowedGroups(v ...*Group) *UserCreate {
  390. ids := make([]int64, len(v))
  391. for i := range v {
  392. ids[i] = v[i].ID
  393. }
  394. return _c.AddAllowedGroupIDs(ids...)
  395. }
  396. // AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
  397. func (_c *UserCreate) AddUsageLogIDs(ids ...int64) *UserCreate {
  398. _c.mutation.AddUsageLogIDs(ids...)
  399. return _c
  400. }
  401. // AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
  402. func (_c *UserCreate) AddUsageLogs(v ...*UsageLog) *UserCreate {
  403. ids := make([]int64, len(v))
  404. for i := range v {
  405. ids[i] = v[i].ID
  406. }
  407. return _c.AddUsageLogIDs(ids...)
  408. }
  409. // AddAttributeValueIDs adds the "attribute_values" edge to the UserAttributeValue entity by IDs.
  410. func (_c *UserCreate) AddAttributeValueIDs(ids ...int64) *UserCreate {
  411. _c.mutation.AddAttributeValueIDs(ids...)
  412. return _c
  413. }
  414. // AddAttributeValues adds the "attribute_values" edges to the UserAttributeValue entity.
  415. func (_c *UserCreate) AddAttributeValues(v ...*UserAttributeValue) *UserCreate {
  416. ids := make([]int64, len(v))
  417. for i := range v {
  418. ids[i] = v[i].ID
  419. }
  420. return _c.AddAttributeValueIDs(ids...)
  421. }
  422. // AddPromoCodeUsageIDs adds the "promo_code_usages" edge to the PromoCodeUsage entity by IDs.
  423. func (_c *UserCreate) AddPromoCodeUsageIDs(ids ...int64) *UserCreate {
  424. _c.mutation.AddPromoCodeUsageIDs(ids...)
  425. return _c
  426. }
  427. // AddPromoCodeUsages adds the "promo_code_usages" edges to the PromoCodeUsage entity.
  428. func (_c *UserCreate) AddPromoCodeUsages(v ...*PromoCodeUsage) *UserCreate {
  429. ids := make([]int64, len(v))
  430. for i := range v {
  431. ids[i] = v[i].ID
  432. }
  433. return _c.AddPromoCodeUsageIDs(ids...)
  434. }
  435. // AddPaymentOrderIDs adds the "payment_orders" edge to the PaymentOrder entity by IDs.
  436. func (_c *UserCreate) AddPaymentOrderIDs(ids ...int64) *UserCreate {
  437. _c.mutation.AddPaymentOrderIDs(ids...)
  438. return _c
  439. }
  440. // AddPaymentOrders adds the "payment_orders" edges to the PaymentOrder entity.
  441. func (_c *UserCreate) AddPaymentOrders(v ...*PaymentOrder) *UserCreate {
  442. ids := make([]int64, len(v))
  443. for i := range v {
  444. ids[i] = v[i].ID
  445. }
  446. return _c.AddPaymentOrderIDs(ids...)
  447. }
  448. // AddAuthIdentityIDs adds the "auth_identities" edge to the AuthIdentity entity by IDs.
  449. func (_c *UserCreate) AddAuthIdentityIDs(ids ...int64) *UserCreate {
  450. _c.mutation.AddAuthIdentityIDs(ids...)
  451. return _c
  452. }
  453. // AddAuthIdentities adds the "auth_identities" edges to the AuthIdentity entity.
  454. func (_c *UserCreate) AddAuthIdentities(v ...*AuthIdentity) *UserCreate {
  455. ids := make([]int64, len(v))
  456. for i := range v {
  457. ids[i] = v[i].ID
  458. }
  459. return _c.AddAuthIdentityIDs(ids...)
  460. }
  461. // AddPendingAuthSessionIDs adds the "pending_auth_sessions" edge to the PendingAuthSession entity by IDs.
  462. func (_c *UserCreate) AddPendingAuthSessionIDs(ids ...int64) *UserCreate {
  463. _c.mutation.AddPendingAuthSessionIDs(ids...)
  464. return _c
  465. }
  466. // AddPendingAuthSessions adds the "pending_auth_sessions" edges to the PendingAuthSession entity.
  467. func (_c *UserCreate) AddPendingAuthSessions(v ...*PendingAuthSession) *UserCreate {
  468. ids := make([]int64, len(v))
  469. for i := range v {
  470. ids[i] = v[i].ID
  471. }
  472. return _c.AddPendingAuthSessionIDs(ids...)
  473. }
  474. // AddPlatformQuotaIDs adds the "platform_quotas" edge to the UserPlatformQuota entity by IDs.
  475. func (_c *UserCreate) AddPlatformQuotaIDs(ids ...int64) *UserCreate {
  476. _c.mutation.AddPlatformQuotaIDs(ids...)
  477. return _c
  478. }
  479. // AddPlatformQuotas adds the "platform_quotas" edges to the UserPlatformQuota entity.
  480. func (_c *UserCreate) AddPlatformQuotas(v ...*UserPlatformQuota) *UserCreate {
  481. ids := make([]int64, len(v))
  482. for i := range v {
  483. ids[i] = v[i].ID
  484. }
  485. return _c.AddPlatformQuotaIDs(ids...)
  486. }
  487. // Mutation returns the UserMutation object of the builder.
  488. func (_c *UserCreate) Mutation() *UserMutation {
  489. return _c.mutation
  490. }
  491. // Save creates the User in the database.
  492. func (_c *UserCreate) Save(ctx context.Context) (*User, error) {
  493. if err := _c.defaults(); err != nil {
  494. return nil, err
  495. }
  496. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  497. }
  498. // SaveX calls Save and panics if Save returns an error.
  499. func (_c *UserCreate) SaveX(ctx context.Context) *User {
  500. v, err := _c.Save(ctx)
  501. if err != nil {
  502. panic(err)
  503. }
  504. return v
  505. }
  506. // Exec executes the query.
  507. func (_c *UserCreate) Exec(ctx context.Context) error {
  508. _, err := _c.Save(ctx)
  509. return err
  510. }
  511. // ExecX is like Exec, but panics if an error occurs.
  512. func (_c *UserCreate) ExecX(ctx context.Context) {
  513. if err := _c.Exec(ctx); err != nil {
  514. panic(err)
  515. }
  516. }
  517. // defaults sets the default values of the builder before save.
  518. func (_c *UserCreate) defaults() error {
  519. if _, ok := _c.mutation.CreatedAt(); !ok {
  520. if user.DefaultCreatedAt == nil {
  521. return fmt.Errorf("ent: uninitialized user.DefaultCreatedAt (forgotten import ent/runtime?)")
  522. }
  523. v := user.DefaultCreatedAt()
  524. _c.mutation.SetCreatedAt(v)
  525. }
  526. if _, ok := _c.mutation.UpdatedAt(); !ok {
  527. if user.DefaultUpdatedAt == nil {
  528. return fmt.Errorf("ent: uninitialized user.DefaultUpdatedAt (forgotten import ent/runtime?)")
  529. }
  530. v := user.DefaultUpdatedAt()
  531. _c.mutation.SetUpdatedAt(v)
  532. }
  533. if _, ok := _c.mutation.Role(); !ok {
  534. v := user.DefaultRole
  535. _c.mutation.SetRole(v)
  536. }
  537. if _, ok := _c.mutation.Balance(); !ok {
  538. v := user.DefaultBalance
  539. _c.mutation.SetBalance(v)
  540. }
  541. if _, ok := _c.mutation.FrozenBalance(); !ok {
  542. v := user.DefaultFrozenBalance
  543. _c.mutation.SetFrozenBalance(v)
  544. }
  545. if _, ok := _c.mutation.Concurrency(); !ok {
  546. v := user.DefaultConcurrency
  547. _c.mutation.SetConcurrency(v)
  548. }
  549. if _, ok := _c.mutation.Status(); !ok {
  550. v := user.DefaultStatus
  551. _c.mutation.SetStatus(v)
  552. }
  553. if _, ok := _c.mutation.Username(); !ok {
  554. v := user.DefaultUsername
  555. _c.mutation.SetUsername(v)
  556. }
  557. if _, ok := _c.mutation.Notes(); !ok {
  558. v := user.DefaultNotes
  559. _c.mutation.SetNotes(v)
  560. }
  561. if _, ok := _c.mutation.TotpEnabled(); !ok {
  562. v := user.DefaultTotpEnabled
  563. _c.mutation.SetTotpEnabled(v)
  564. }
  565. if _, ok := _c.mutation.SignupSource(); !ok {
  566. v := user.DefaultSignupSource
  567. _c.mutation.SetSignupSource(v)
  568. }
  569. if _, ok := _c.mutation.RestrictPublicGroups(); !ok {
  570. v := user.DefaultRestrictPublicGroups
  571. _c.mutation.SetRestrictPublicGroups(v)
  572. }
  573. if _, ok := _c.mutation.BalanceNotifyEnabled(); !ok {
  574. v := user.DefaultBalanceNotifyEnabled
  575. _c.mutation.SetBalanceNotifyEnabled(v)
  576. }
  577. if _, ok := _c.mutation.BalanceNotifyThresholdType(); !ok {
  578. v := user.DefaultBalanceNotifyThresholdType
  579. _c.mutation.SetBalanceNotifyThresholdType(v)
  580. }
  581. if _, ok := _c.mutation.BalanceNotifyExtraEmails(); !ok {
  582. v := user.DefaultBalanceNotifyExtraEmails
  583. _c.mutation.SetBalanceNotifyExtraEmails(v)
  584. }
  585. if _, ok := _c.mutation.TotalRecharged(); !ok {
  586. v := user.DefaultTotalRecharged
  587. _c.mutation.SetTotalRecharged(v)
  588. }
  589. if _, ok := _c.mutation.RpmLimit(); !ok {
  590. v := user.DefaultRpmLimit
  591. _c.mutation.SetRpmLimit(v)
  592. }
  593. return nil
  594. }
  595. // check runs all checks and user-defined validators on the builder.
  596. func (_c *UserCreate) check() error {
  597. if _, ok := _c.mutation.CreatedAt(); !ok {
  598. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "User.created_at"`)}
  599. }
  600. if _, ok := _c.mutation.UpdatedAt(); !ok {
  601. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "User.updated_at"`)}
  602. }
  603. if _, ok := _c.mutation.Email(); !ok {
  604. return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "User.email"`)}
  605. }
  606. if v, ok := _c.mutation.Email(); ok {
  607. if err := user.EmailValidator(v); err != nil {
  608. return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
  609. }
  610. }
  611. if _, ok := _c.mutation.PasswordHash(); !ok {
  612. return &ValidationError{Name: "password_hash", err: errors.New(`ent: missing required field "User.password_hash"`)}
  613. }
  614. if v, ok := _c.mutation.PasswordHash(); ok {
  615. if err := user.PasswordHashValidator(v); err != nil {
  616. return &ValidationError{Name: "password_hash", err: fmt.Errorf(`ent: validator failed for field "User.password_hash": %w`, err)}
  617. }
  618. }
  619. if _, ok := _c.mutation.Role(); !ok {
  620. return &ValidationError{Name: "role", err: errors.New(`ent: missing required field "User.role"`)}
  621. }
  622. if v, ok := _c.mutation.Role(); ok {
  623. if err := user.RoleValidator(v); err != nil {
  624. return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)}
  625. }
  626. }
  627. if _, ok := _c.mutation.Balance(); !ok {
  628. return &ValidationError{Name: "balance", err: errors.New(`ent: missing required field "User.balance"`)}
  629. }
  630. if _, ok := _c.mutation.FrozenBalance(); !ok {
  631. return &ValidationError{Name: "frozen_balance", err: errors.New(`ent: missing required field "User.frozen_balance"`)}
  632. }
  633. if _, ok := _c.mutation.Concurrency(); !ok {
  634. return &ValidationError{Name: "concurrency", err: errors.New(`ent: missing required field "User.concurrency"`)}
  635. }
  636. if _, ok := _c.mutation.Status(); !ok {
  637. return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "User.status"`)}
  638. }
  639. if v, ok := _c.mutation.Status(); ok {
  640. if err := user.StatusValidator(v); err != nil {
  641. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "User.status": %w`, err)}
  642. }
  643. }
  644. if _, ok := _c.mutation.Username(); !ok {
  645. return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "User.username"`)}
  646. }
  647. if v, ok := _c.mutation.Username(); ok {
  648. if err := user.UsernameValidator(v); err != nil {
  649. return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
  650. }
  651. }
  652. if _, ok := _c.mutation.Notes(); !ok {
  653. return &ValidationError{Name: "notes", err: errors.New(`ent: missing required field "User.notes"`)}
  654. }
  655. if _, ok := _c.mutation.TotpEnabled(); !ok {
  656. return &ValidationError{Name: "totp_enabled", err: errors.New(`ent: missing required field "User.totp_enabled"`)}
  657. }
  658. if _, ok := _c.mutation.SignupSource(); !ok {
  659. return &ValidationError{Name: "signup_source", err: errors.New(`ent: missing required field "User.signup_source"`)}
  660. }
  661. if v, ok := _c.mutation.SignupSource(); ok {
  662. if err := user.SignupSourceValidator(v); err != nil {
  663. return &ValidationError{Name: "signup_source", err: fmt.Errorf(`ent: validator failed for field "User.signup_source": %w`, err)}
  664. }
  665. }
  666. if _, ok := _c.mutation.RestrictPublicGroups(); !ok {
  667. return &ValidationError{Name: "restrict_public_groups", err: errors.New(`ent: missing required field "User.restrict_public_groups"`)}
  668. }
  669. if _, ok := _c.mutation.BalanceNotifyEnabled(); !ok {
  670. return &ValidationError{Name: "balance_notify_enabled", err: errors.New(`ent: missing required field "User.balance_notify_enabled"`)}
  671. }
  672. if _, ok := _c.mutation.BalanceNotifyThresholdType(); !ok {
  673. return &ValidationError{Name: "balance_notify_threshold_type", err: errors.New(`ent: missing required field "User.balance_notify_threshold_type"`)}
  674. }
  675. if _, ok := _c.mutation.BalanceNotifyExtraEmails(); !ok {
  676. return &ValidationError{Name: "balance_notify_extra_emails", err: errors.New(`ent: missing required field "User.balance_notify_extra_emails"`)}
  677. }
  678. if _, ok := _c.mutation.TotalRecharged(); !ok {
  679. return &ValidationError{Name: "total_recharged", err: errors.New(`ent: missing required field "User.total_recharged"`)}
  680. }
  681. if _, ok := _c.mutation.RpmLimit(); !ok {
  682. return &ValidationError{Name: "rpm_limit", err: errors.New(`ent: missing required field "User.rpm_limit"`)}
  683. }
  684. return nil
  685. }
  686. func (_c *UserCreate) sqlSave(ctx context.Context) (*User, error) {
  687. if err := _c.check(); err != nil {
  688. return nil, err
  689. }
  690. _node, _spec := _c.createSpec()
  691. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  692. if sqlgraph.IsConstraintError(err) {
  693. err = &ConstraintError{msg: err.Error(), wrap: err}
  694. }
  695. return nil, err
  696. }
  697. id := _spec.ID.Value.(int64)
  698. _node.ID = int64(id)
  699. _c.mutation.id = &_node.ID
  700. _c.mutation.done = true
  701. return _node, nil
  702. }
  703. func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
  704. var (
  705. _node = &User{config: _c.config}
  706. _spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64))
  707. )
  708. _spec.OnConflict = _c.conflict
  709. if value, ok := _c.mutation.CreatedAt(); ok {
  710. _spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
  711. _node.CreatedAt = value
  712. }
  713. if value, ok := _c.mutation.UpdatedAt(); ok {
  714. _spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
  715. _node.UpdatedAt = value
  716. }
  717. if value, ok := _c.mutation.DeletedAt(); ok {
  718. _spec.SetField(user.FieldDeletedAt, field.TypeTime, value)
  719. _node.DeletedAt = &value
  720. }
  721. if value, ok := _c.mutation.Email(); ok {
  722. _spec.SetField(user.FieldEmail, field.TypeString, value)
  723. _node.Email = value
  724. }
  725. if value, ok := _c.mutation.PasswordHash(); ok {
  726. _spec.SetField(user.FieldPasswordHash, field.TypeString, value)
  727. _node.PasswordHash = value
  728. }
  729. if value, ok := _c.mutation.Role(); ok {
  730. _spec.SetField(user.FieldRole, field.TypeString, value)
  731. _node.Role = value
  732. }
  733. if value, ok := _c.mutation.Balance(); ok {
  734. _spec.SetField(user.FieldBalance, field.TypeFloat64, value)
  735. _node.Balance = value
  736. }
  737. if value, ok := _c.mutation.FrozenBalance(); ok {
  738. _spec.SetField(user.FieldFrozenBalance, field.TypeFloat64, value)
  739. _node.FrozenBalance = value
  740. }
  741. if value, ok := _c.mutation.Concurrency(); ok {
  742. _spec.SetField(user.FieldConcurrency, field.TypeInt, value)
  743. _node.Concurrency = value
  744. }
  745. if value, ok := _c.mutation.Status(); ok {
  746. _spec.SetField(user.FieldStatus, field.TypeString, value)
  747. _node.Status = value
  748. }
  749. if value, ok := _c.mutation.Username(); ok {
  750. _spec.SetField(user.FieldUsername, field.TypeString, value)
  751. _node.Username = value
  752. }
  753. if value, ok := _c.mutation.Notes(); ok {
  754. _spec.SetField(user.FieldNotes, field.TypeString, value)
  755. _node.Notes = value
  756. }
  757. if value, ok := _c.mutation.TotpSecretEncrypted(); ok {
  758. _spec.SetField(user.FieldTotpSecretEncrypted, field.TypeString, value)
  759. _node.TotpSecretEncrypted = &value
  760. }
  761. if value, ok := _c.mutation.TotpEnabled(); ok {
  762. _spec.SetField(user.FieldTotpEnabled, field.TypeBool, value)
  763. _node.TotpEnabled = value
  764. }
  765. if value, ok := _c.mutation.TotpEnabledAt(); ok {
  766. _spec.SetField(user.FieldTotpEnabledAt, field.TypeTime, value)
  767. _node.TotpEnabledAt = &value
  768. }
  769. if value, ok := _c.mutation.SignupSource(); ok {
  770. _spec.SetField(user.FieldSignupSource, field.TypeString, value)
  771. _node.SignupSource = value
  772. }
  773. if value, ok := _c.mutation.LastLoginAt(); ok {
  774. _spec.SetField(user.FieldLastLoginAt, field.TypeTime, value)
  775. _node.LastLoginAt = &value
  776. }
  777. if value, ok := _c.mutation.LastActiveAt(); ok {
  778. _spec.SetField(user.FieldLastActiveAt, field.TypeTime, value)
  779. _node.LastActiveAt = &value
  780. }
  781. if value, ok := _c.mutation.RestrictPublicGroups(); ok {
  782. _spec.SetField(user.FieldRestrictPublicGroups, field.TypeBool, value)
  783. _node.RestrictPublicGroups = value
  784. }
  785. if value, ok := _c.mutation.BalanceNotifyEnabled(); ok {
  786. _spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
  787. _node.BalanceNotifyEnabled = value
  788. }
  789. if value, ok := _c.mutation.BalanceNotifyThresholdType(); ok {
  790. _spec.SetField(user.FieldBalanceNotifyThresholdType, field.TypeString, value)
  791. _node.BalanceNotifyThresholdType = value
  792. }
  793. if value, ok := _c.mutation.BalanceNotifyThreshold(); ok {
  794. _spec.SetField(user.FieldBalanceNotifyThreshold, field.TypeFloat64, value)
  795. _node.BalanceNotifyThreshold = &value
  796. }
  797. if value, ok := _c.mutation.BalanceNotifyExtraEmails(); ok {
  798. _spec.SetField(user.FieldBalanceNotifyExtraEmails, field.TypeString, value)
  799. _node.BalanceNotifyExtraEmails = value
  800. }
  801. if value, ok := _c.mutation.TotalRecharged(); ok {
  802. _spec.SetField(user.FieldTotalRecharged, field.TypeFloat64, value)
  803. _node.TotalRecharged = value
  804. }
  805. if value, ok := _c.mutation.RpmLimit(); ok {
  806. _spec.SetField(user.FieldRpmLimit, field.TypeInt, value)
  807. _node.RpmLimit = value
  808. }
  809. if nodes := _c.mutation.APIKeysIDs(); len(nodes) > 0 {
  810. edge := &sqlgraph.EdgeSpec{
  811. Rel: sqlgraph.O2M,
  812. Inverse: false,
  813. Table: user.APIKeysTable,
  814. Columns: []string{user.APIKeysColumn},
  815. Bidi: false,
  816. Target: &sqlgraph.EdgeTarget{
  817. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
  818. },
  819. }
  820. for _, k := range nodes {
  821. edge.Target.Nodes = append(edge.Target.Nodes, k)
  822. }
  823. _spec.Edges = append(_spec.Edges, edge)
  824. }
  825. if nodes := _c.mutation.RedeemCodesIDs(); len(nodes) > 0 {
  826. edge := &sqlgraph.EdgeSpec{
  827. Rel: sqlgraph.O2M,
  828. Inverse: false,
  829. Table: user.RedeemCodesTable,
  830. Columns: []string{user.RedeemCodesColumn},
  831. Bidi: false,
  832. Target: &sqlgraph.EdgeTarget{
  833. IDSpec: sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64),
  834. },
  835. }
  836. for _, k := range nodes {
  837. edge.Target.Nodes = append(edge.Target.Nodes, k)
  838. }
  839. _spec.Edges = append(_spec.Edges, edge)
  840. }
  841. if nodes := _c.mutation.SubscriptionsIDs(); len(nodes) > 0 {
  842. edge := &sqlgraph.EdgeSpec{
  843. Rel: sqlgraph.O2M,
  844. Inverse: false,
  845. Table: user.SubscriptionsTable,
  846. Columns: []string{user.SubscriptionsColumn},
  847. Bidi: false,
  848. Target: &sqlgraph.EdgeTarget{
  849. IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
  850. },
  851. }
  852. for _, k := range nodes {
  853. edge.Target.Nodes = append(edge.Target.Nodes, k)
  854. }
  855. _spec.Edges = append(_spec.Edges, edge)
  856. }
  857. if nodes := _c.mutation.AssignedSubscriptionsIDs(); len(nodes) > 0 {
  858. edge := &sqlgraph.EdgeSpec{
  859. Rel: sqlgraph.O2M,
  860. Inverse: false,
  861. Table: user.AssignedSubscriptionsTable,
  862. Columns: []string{user.AssignedSubscriptionsColumn},
  863. Bidi: false,
  864. Target: &sqlgraph.EdgeTarget{
  865. IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
  866. },
  867. }
  868. for _, k := range nodes {
  869. edge.Target.Nodes = append(edge.Target.Nodes, k)
  870. }
  871. _spec.Edges = append(_spec.Edges, edge)
  872. }
  873. if nodes := _c.mutation.AnnouncementReadsIDs(); len(nodes) > 0 {
  874. edge := &sqlgraph.EdgeSpec{
  875. Rel: sqlgraph.O2M,
  876. Inverse: false,
  877. Table: user.AnnouncementReadsTable,
  878. Columns: []string{user.AnnouncementReadsColumn},
  879. Bidi: false,
  880. Target: &sqlgraph.EdgeTarget{
  881. IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
  882. },
  883. }
  884. for _, k := range nodes {
  885. edge.Target.Nodes = append(edge.Target.Nodes, k)
  886. }
  887. _spec.Edges = append(_spec.Edges, edge)
  888. }
  889. if nodes := _c.mutation.AllowedGroupsIDs(); len(nodes) > 0 {
  890. edge := &sqlgraph.EdgeSpec{
  891. Rel: sqlgraph.M2M,
  892. Inverse: false,
  893. Table: user.AllowedGroupsTable,
  894. Columns: user.AllowedGroupsPrimaryKey,
  895. Bidi: false,
  896. Target: &sqlgraph.EdgeTarget{
  897. IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
  898. },
  899. }
  900. for _, k := range nodes {
  901. edge.Target.Nodes = append(edge.Target.Nodes, k)
  902. }
  903. createE := &UserAllowedGroupCreate{config: _c.config, mutation: newUserAllowedGroupMutation(_c.config, OpCreate)}
  904. createE.defaults()
  905. _, specE := createE.createSpec()
  906. edge.Target.Fields = specE.Fields
  907. _spec.Edges = append(_spec.Edges, edge)
  908. }
  909. if nodes := _c.mutation.UsageLogsIDs(); len(nodes) > 0 {
  910. edge := &sqlgraph.EdgeSpec{
  911. Rel: sqlgraph.O2M,
  912. Inverse: false,
  913. Table: user.UsageLogsTable,
  914. Columns: []string{user.UsageLogsColumn},
  915. Bidi: false,
  916. Target: &sqlgraph.EdgeTarget{
  917. IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
  918. },
  919. }
  920. for _, k := range nodes {
  921. edge.Target.Nodes = append(edge.Target.Nodes, k)
  922. }
  923. _spec.Edges = append(_spec.Edges, edge)
  924. }
  925. if nodes := _c.mutation.AttributeValuesIDs(); len(nodes) > 0 {
  926. edge := &sqlgraph.EdgeSpec{
  927. Rel: sqlgraph.O2M,
  928. Inverse: false,
  929. Table: user.AttributeValuesTable,
  930. Columns: []string{user.AttributeValuesColumn},
  931. Bidi: false,
  932. Target: &sqlgraph.EdgeTarget{
  933. IDSpec: sqlgraph.NewFieldSpec(userattributevalue.FieldID, field.TypeInt64),
  934. },
  935. }
  936. for _, k := range nodes {
  937. edge.Target.Nodes = append(edge.Target.Nodes, k)
  938. }
  939. _spec.Edges = append(_spec.Edges, edge)
  940. }
  941. if nodes := _c.mutation.PromoCodeUsagesIDs(); len(nodes) > 0 {
  942. edge := &sqlgraph.EdgeSpec{
  943. Rel: sqlgraph.O2M,
  944. Inverse: false,
  945. Table: user.PromoCodeUsagesTable,
  946. Columns: []string{user.PromoCodeUsagesColumn},
  947. Bidi: false,
  948. Target: &sqlgraph.EdgeTarget{
  949. IDSpec: sqlgraph.NewFieldSpec(promocodeusage.FieldID, field.TypeInt64),
  950. },
  951. }
  952. for _, k := range nodes {
  953. edge.Target.Nodes = append(edge.Target.Nodes, k)
  954. }
  955. _spec.Edges = append(_spec.Edges, edge)
  956. }
  957. if nodes := _c.mutation.PaymentOrdersIDs(); len(nodes) > 0 {
  958. edge := &sqlgraph.EdgeSpec{
  959. Rel: sqlgraph.O2M,
  960. Inverse: false,
  961. Table: user.PaymentOrdersTable,
  962. Columns: []string{user.PaymentOrdersColumn},
  963. Bidi: false,
  964. Target: &sqlgraph.EdgeTarget{
  965. IDSpec: sqlgraph.NewFieldSpec(paymentorder.FieldID, field.TypeInt64),
  966. },
  967. }
  968. for _, k := range nodes {
  969. edge.Target.Nodes = append(edge.Target.Nodes, k)
  970. }
  971. _spec.Edges = append(_spec.Edges, edge)
  972. }
  973. if nodes := _c.mutation.AuthIdentitiesIDs(); len(nodes) > 0 {
  974. edge := &sqlgraph.EdgeSpec{
  975. Rel: sqlgraph.O2M,
  976. Inverse: false,
  977. Table: user.AuthIdentitiesTable,
  978. Columns: []string{user.AuthIdentitiesColumn},
  979. Bidi: false,
  980. Target: &sqlgraph.EdgeTarget{
  981. IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
  982. },
  983. }
  984. for _, k := range nodes {
  985. edge.Target.Nodes = append(edge.Target.Nodes, k)
  986. }
  987. _spec.Edges = append(_spec.Edges, edge)
  988. }
  989. if nodes := _c.mutation.PendingAuthSessionsIDs(); len(nodes) > 0 {
  990. edge := &sqlgraph.EdgeSpec{
  991. Rel: sqlgraph.O2M,
  992. Inverse: false,
  993. Table: user.PendingAuthSessionsTable,
  994. Columns: []string{user.PendingAuthSessionsColumn},
  995. Bidi: false,
  996. Target: &sqlgraph.EdgeTarget{
  997. IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
  998. },
  999. }
  1000. for _, k := range nodes {
  1001. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1002. }
  1003. _spec.Edges = append(_spec.Edges, edge)
  1004. }
  1005. if nodes := _c.mutation.PlatformQuotasIDs(); len(nodes) > 0 {
  1006. edge := &sqlgraph.EdgeSpec{
  1007. Rel: sqlgraph.O2M,
  1008. Inverse: false,
  1009. Table: user.PlatformQuotasTable,
  1010. Columns: []string{user.PlatformQuotasColumn},
  1011. Bidi: false,
  1012. Target: &sqlgraph.EdgeTarget{
  1013. IDSpec: sqlgraph.NewFieldSpec(userplatformquota.FieldID, field.TypeInt64),
  1014. },
  1015. }
  1016. for _, k := range nodes {
  1017. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1018. }
  1019. _spec.Edges = append(_spec.Edges, edge)
  1020. }
  1021. return _node, _spec
  1022. }
  1023. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  1024. // of the `INSERT` statement. For example:
  1025. //
  1026. // client.User.Create().
  1027. // SetCreatedAt(v).
  1028. // OnConflict(
  1029. // // Update the row with the new values
  1030. // // the was proposed for insertion.
  1031. // sql.ResolveWithNewValues(),
  1032. // ).
  1033. // // Override some of the fields with custom
  1034. // // update values.
  1035. // Update(func(u *ent.UserUpsert) {
  1036. // SetCreatedAt(v+v).
  1037. // }).
  1038. // Exec(ctx)
  1039. func (_c *UserCreate) OnConflict(opts ...sql.ConflictOption) *UserUpsertOne {
  1040. _c.conflict = opts
  1041. return &UserUpsertOne{
  1042. create: _c,
  1043. }
  1044. }
  1045. // OnConflictColumns calls `OnConflict` and configures the columns
  1046. // as conflict target. Using this option is equivalent to using:
  1047. //
  1048. // client.User.Create().
  1049. // OnConflict(sql.ConflictColumns(columns...)).
  1050. // Exec(ctx)
  1051. func (_c *UserCreate) OnConflictColumns(columns ...string) *UserUpsertOne {
  1052. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  1053. return &UserUpsertOne{
  1054. create: _c,
  1055. }
  1056. }
  1057. type (
  1058. // UserUpsertOne is the builder for "upsert"-ing
  1059. // one User node.
  1060. UserUpsertOne struct {
  1061. create *UserCreate
  1062. }
  1063. // UserUpsert is the "OnConflict" setter.
  1064. UserUpsert struct {
  1065. *sql.UpdateSet
  1066. }
  1067. )
  1068. // SetUpdatedAt sets the "updated_at" field.
  1069. func (u *UserUpsert) SetUpdatedAt(v time.Time) *UserUpsert {
  1070. u.Set(user.FieldUpdatedAt, v)
  1071. return u
  1072. }
  1073. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1074. func (u *UserUpsert) UpdateUpdatedAt() *UserUpsert {
  1075. u.SetExcluded(user.FieldUpdatedAt)
  1076. return u
  1077. }
  1078. // SetDeletedAt sets the "deleted_at" field.
  1079. func (u *UserUpsert) SetDeletedAt(v time.Time) *UserUpsert {
  1080. u.Set(user.FieldDeletedAt, v)
  1081. return u
  1082. }
  1083. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1084. func (u *UserUpsert) UpdateDeletedAt() *UserUpsert {
  1085. u.SetExcluded(user.FieldDeletedAt)
  1086. return u
  1087. }
  1088. // ClearDeletedAt clears the value of the "deleted_at" field.
  1089. func (u *UserUpsert) ClearDeletedAt() *UserUpsert {
  1090. u.SetNull(user.FieldDeletedAt)
  1091. return u
  1092. }
  1093. // SetEmail sets the "email" field.
  1094. func (u *UserUpsert) SetEmail(v string) *UserUpsert {
  1095. u.Set(user.FieldEmail, v)
  1096. return u
  1097. }
  1098. // UpdateEmail sets the "email" field to the value that was provided on create.
  1099. func (u *UserUpsert) UpdateEmail() *UserUpsert {
  1100. u.SetExcluded(user.FieldEmail)
  1101. return u
  1102. }
  1103. // SetPasswordHash sets the "password_hash" field.
  1104. func (u *UserUpsert) SetPasswordHash(v string) *UserUpsert {
  1105. u.Set(user.FieldPasswordHash, v)
  1106. return u
  1107. }
  1108. // UpdatePasswordHash sets the "password_hash" field to the value that was provided on create.
  1109. func (u *UserUpsert) UpdatePasswordHash() *UserUpsert {
  1110. u.SetExcluded(user.FieldPasswordHash)
  1111. return u
  1112. }
  1113. // SetRole sets the "role" field.
  1114. func (u *UserUpsert) SetRole(v string) *UserUpsert {
  1115. u.Set(user.FieldRole, v)
  1116. return u
  1117. }
  1118. // UpdateRole sets the "role" field to the value that was provided on create.
  1119. func (u *UserUpsert) UpdateRole() *UserUpsert {
  1120. u.SetExcluded(user.FieldRole)
  1121. return u
  1122. }
  1123. // SetBalance sets the "balance" field.
  1124. func (u *UserUpsert) SetBalance(v float64) *UserUpsert {
  1125. u.Set(user.FieldBalance, v)
  1126. return u
  1127. }
  1128. // UpdateBalance sets the "balance" field to the value that was provided on create.
  1129. func (u *UserUpsert) UpdateBalance() *UserUpsert {
  1130. u.SetExcluded(user.FieldBalance)
  1131. return u
  1132. }
  1133. // AddBalance adds v to the "balance" field.
  1134. func (u *UserUpsert) AddBalance(v float64) *UserUpsert {
  1135. u.Add(user.FieldBalance, v)
  1136. return u
  1137. }
  1138. // SetFrozenBalance sets the "frozen_balance" field.
  1139. func (u *UserUpsert) SetFrozenBalance(v float64) *UserUpsert {
  1140. u.Set(user.FieldFrozenBalance, v)
  1141. return u
  1142. }
  1143. // UpdateFrozenBalance sets the "frozen_balance" field to the value that was provided on create.
  1144. func (u *UserUpsert) UpdateFrozenBalance() *UserUpsert {
  1145. u.SetExcluded(user.FieldFrozenBalance)
  1146. return u
  1147. }
  1148. // AddFrozenBalance adds v to the "frozen_balance" field.
  1149. func (u *UserUpsert) AddFrozenBalance(v float64) *UserUpsert {
  1150. u.Add(user.FieldFrozenBalance, v)
  1151. return u
  1152. }
  1153. // SetConcurrency sets the "concurrency" field.
  1154. func (u *UserUpsert) SetConcurrency(v int) *UserUpsert {
  1155. u.Set(user.FieldConcurrency, v)
  1156. return u
  1157. }
  1158. // UpdateConcurrency sets the "concurrency" field to the value that was provided on create.
  1159. func (u *UserUpsert) UpdateConcurrency() *UserUpsert {
  1160. u.SetExcluded(user.FieldConcurrency)
  1161. return u
  1162. }
  1163. // AddConcurrency adds v to the "concurrency" field.
  1164. func (u *UserUpsert) AddConcurrency(v int) *UserUpsert {
  1165. u.Add(user.FieldConcurrency, v)
  1166. return u
  1167. }
  1168. // SetStatus sets the "status" field.
  1169. func (u *UserUpsert) SetStatus(v string) *UserUpsert {
  1170. u.Set(user.FieldStatus, v)
  1171. return u
  1172. }
  1173. // UpdateStatus sets the "status" field to the value that was provided on create.
  1174. func (u *UserUpsert) UpdateStatus() *UserUpsert {
  1175. u.SetExcluded(user.FieldStatus)
  1176. return u
  1177. }
  1178. // SetUsername sets the "username" field.
  1179. func (u *UserUpsert) SetUsername(v string) *UserUpsert {
  1180. u.Set(user.FieldUsername, v)
  1181. return u
  1182. }
  1183. // UpdateUsername sets the "username" field to the value that was provided on create.
  1184. func (u *UserUpsert) UpdateUsername() *UserUpsert {
  1185. u.SetExcluded(user.FieldUsername)
  1186. return u
  1187. }
  1188. // SetNotes sets the "notes" field.
  1189. func (u *UserUpsert) SetNotes(v string) *UserUpsert {
  1190. u.Set(user.FieldNotes, v)
  1191. return u
  1192. }
  1193. // UpdateNotes sets the "notes" field to the value that was provided on create.
  1194. func (u *UserUpsert) UpdateNotes() *UserUpsert {
  1195. u.SetExcluded(user.FieldNotes)
  1196. return u
  1197. }
  1198. // SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
  1199. func (u *UserUpsert) SetTotpSecretEncrypted(v string) *UserUpsert {
  1200. u.Set(user.FieldTotpSecretEncrypted, v)
  1201. return u
  1202. }
  1203. // UpdateTotpSecretEncrypted sets the "totp_secret_encrypted" field to the value that was provided on create.
  1204. func (u *UserUpsert) UpdateTotpSecretEncrypted() *UserUpsert {
  1205. u.SetExcluded(user.FieldTotpSecretEncrypted)
  1206. return u
  1207. }
  1208. // ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
  1209. func (u *UserUpsert) ClearTotpSecretEncrypted() *UserUpsert {
  1210. u.SetNull(user.FieldTotpSecretEncrypted)
  1211. return u
  1212. }
  1213. // SetTotpEnabled sets the "totp_enabled" field.
  1214. func (u *UserUpsert) SetTotpEnabled(v bool) *UserUpsert {
  1215. u.Set(user.FieldTotpEnabled, v)
  1216. return u
  1217. }
  1218. // UpdateTotpEnabled sets the "totp_enabled" field to the value that was provided on create.
  1219. func (u *UserUpsert) UpdateTotpEnabled() *UserUpsert {
  1220. u.SetExcluded(user.FieldTotpEnabled)
  1221. return u
  1222. }
  1223. // SetTotpEnabledAt sets the "totp_enabled_at" field.
  1224. func (u *UserUpsert) SetTotpEnabledAt(v time.Time) *UserUpsert {
  1225. u.Set(user.FieldTotpEnabledAt, v)
  1226. return u
  1227. }
  1228. // UpdateTotpEnabledAt sets the "totp_enabled_at" field to the value that was provided on create.
  1229. func (u *UserUpsert) UpdateTotpEnabledAt() *UserUpsert {
  1230. u.SetExcluded(user.FieldTotpEnabledAt)
  1231. return u
  1232. }
  1233. // ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
  1234. func (u *UserUpsert) ClearTotpEnabledAt() *UserUpsert {
  1235. u.SetNull(user.FieldTotpEnabledAt)
  1236. return u
  1237. }
  1238. // SetSignupSource sets the "signup_source" field.
  1239. func (u *UserUpsert) SetSignupSource(v string) *UserUpsert {
  1240. u.Set(user.FieldSignupSource, v)
  1241. return u
  1242. }
  1243. // UpdateSignupSource sets the "signup_source" field to the value that was provided on create.
  1244. func (u *UserUpsert) UpdateSignupSource() *UserUpsert {
  1245. u.SetExcluded(user.FieldSignupSource)
  1246. return u
  1247. }
  1248. // SetLastLoginAt sets the "last_login_at" field.
  1249. func (u *UserUpsert) SetLastLoginAt(v time.Time) *UserUpsert {
  1250. u.Set(user.FieldLastLoginAt, v)
  1251. return u
  1252. }
  1253. // UpdateLastLoginAt sets the "last_login_at" field to the value that was provided on create.
  1254. func (u *UserUpsert) UpdateLastLoginAt() *UserUpsert {
  1255. u.SetExcluded(user.FieldLastLoginAt)
  1256. return u
  1257. }
  1258. // ClearLastLoginAt clears the value of the "last_login_at" field.
  1259. func (u *UserUpsert) ClearLastLoginAt() *UserUpsert {
  1260. u.SetNull(user.FieldLastLoginAt)
  1261. return u
  1262. }
  1263. // SetLastActiveAt sets the "last_active_at" field.
  1264. func (u *UserUpsert) SetLastActiveAt(v time.Time) *UserUpsert {
  1265. u.Set(user.FieldLastActiveAt, v)
  1266. return u
  1267. }
  1268. // UpdateLastActiveAt sets the "last_active_at" field to the value that was provided on create.
  1269. func (u *UserUpsert) UpdateLastActiveAt() *UserUpsert {
  1270. u.SetExcluded(user.FieldLastActiveAt)
  1271. return u
  1272. }
  1273. // ClearLastActiveAt clears the value of the "last_active_at" field.
  1274. func (u *UserUpsert) ClearLastActiveAt() *UserUpsert {
  1275. u.SetNull(user.FieldLastActiveAt)
  1276. return u
  1277. }
  1278. // SetRestrictPublicGroups sets the "restrict_public_groups" field.
  1279. func (u *UserUpsert) SetRestrictPublicGroups(v bool) *UserUpsert {
  1280. u.Set(user.FieldRestrictPublicGroups, v)
  1281. return u
  1282. }
  1283. // UpdateRestrictPublicGroups sets the "restrict_public_groups" field to the value that was provided on create.
  1284. func (u *UserUpsert) UpdateRestrictPublicGroups() *UserUpsert {
  1285. u.SetExcluded(user.FieldRestrictPublicGroups)
  1286. return u
  1287. }
  1288. // SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
  1289. func (u *UserUpsert) SetBalanceNotifyEnabled(v bool) *UserUpsert {
  1290. u.Set(user.FieldBalanceNotifyEnabled, v)
  1291. return u
  1292. }
  1293. // UpdateBalanceNotifyEnabled sets the "balance_notify_enabled" field to the value that was provided on create.
  1294. func (u *UserUpsert) UpdateBalanceNotifyEnabled() *UserUpsert {
  1295. u.SetExcluded(user.FieldBalanceNotifyEnabled)
  1296. return u
  1297. }
  1298. // SetBalanceNotifyThresholdType sets the "balance_notify_threshold_type" field.
  1299. func (u *UserUpsert) SetBalanceNotifyThresholdType(v string) *UserUpsert {
  1300. u.Set(user.FieldBalanceNotifyThresholdType, v)
  1301. return u
  1302. }
  1303. // UpdateBalanceNotifyThresholdType sets the "balance_notify_threshold_type" field to the value that was provided on create.
  1304. func (u *UserUpsert) UpdateBalanceNotifyThresholdType() *UserUpsert {
  1305. u.SetExcluded(user.FieldBalanceNotifyThresholdType)
  1306. return u
  1307. }
  1308. // SetBalanceNotifyThreshold sets the "balance_notify_threshold" field.
  1309. func (u *UserUpsert) SetBalanceNotifyThreshold(v float64) *UserUpsert {
  1310. u.Set(user.FieldBalanceNotifyThreshold, v)
  1311. return u
  1312. }
  1313. // UpdateBalanceNotifyThreshold sets the "balance_notify_threshold" field to the value that was provided on create.
  1314. func (u *UserUpsert) UpdateBalanceNotifyThreshold() *UserUpsert {
  1315. u.SetExcluded(user.FieldBalanceNotifyThreshold)
  1316. return u
  1317. }
  1318. // AddBalanceNotifyThreshold adds v to the "balance_notify_threshold" field.
  1319. func (u *UserUpsert) AddBalanceNotifyThreshold(v float64) *UserUpsert {
  1320. u.Add(user.FieldBalanceNotifyThreshold, v)
  1321. return u
  1322. }
  1323. // ClearBalanceNotifyThreshold clears the value of the "balance_notify_threshold" field.
  1324. func (u *UserUpsert) ClearBalanceNotifyThreshold() *UserUpsert {
  1325. u.SetNull(user.FieldBalanceNotifyThreshold)
  1326. return u
  1327. }
  1328. // SetBalanceNotifyExtraEmails sets the "balance_notify_extra_emails" field.
  1329. func (u *UserUpsert) SetBalanceNotifyExtraEmails(v string) *UserUpsert {
  1330. u.Set(user.FieldBalanceNotifyExtraEmails, v)
  1331. return u
  1332. }
  1333. // UpdateBalanceNotifyExtraEmails sets the "balance_notify_extra_emails" field to the value that was provided on create.
  1334. func (u *UserUpsert) UpdateBalanceNotifyExtraEmails() *UserUpsert {
  1335. u.SetExcluded(user.FieldBalanceNotifyExtraEmails)
  1336. return u
  1337. }
  1338. // SetTotalRecharged sets the "total_recharged" field.
  1339. func (u *UserUpsert) SetTotalRecharged(v float64) *UserUpsert {
  1340. u.Set(user.FieldTotalRecharged, v)
  1341. return u
  1342. }
  1343. // UpdateTotalRecharged sets the "total_recharged" field to the value that was provided on create.
  1344. func (u *UserUpsert) UpdateTotalRecharged() *UserUpsert {
  1345. u.SetExcluded(user.FieldTotalRecharged)
  1346. return u
  1347. }
  1348. // AddTotalRecharged adds v to the "total_recharged" field.
  1349. func (u *UserUpsert) AddTotalRecharged(v float64) *UserUpsert {
  1350. u.Add(user.FieldTotalRecharged, v)
  1351. return u
  1352. }
  1353. // SetRpmLimit sets the "rpm_limit" field.
  1354. func (u *UserUpsert) SetRpmLimit(v int) *UserUpsert {
  1355. u.Set(user.FieldRpmLimit, v)
  1356. return u
  1357. }
  1358. // UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
  1359. func (u *UserUpsert) UpdateRpmLimit() *UserUpsert {
  1360. u.SetExcluded(user.FieldRpmLimit)
  1361. return u
  1362. }
  1363. // AddRpmLimit adds v to the "rpm_limit" field.
  1364. func (u *UserUpsert) AddRpmLimit(v int) *UserUpsert {
  1365. u.Add(user.FieldRpmLimit, v)
  1366. return u
  1367. }
  1368. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  1369. // Using this option is equivalent to using:
  1370. //
  1371. // client.User.Create().
  1372. // OnConflict(
  1373. // sql.ResolveWithNewValues(),
  1374. // ).
  1375. // Exec(ctx)
  1376. func (u *UserUpsertOne) UpdateNewValues() *UserUpsertOne {
  1377. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  1378. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  1379. if _, exists := u.create.mutation.CreatedAt(); exists {
  1380. s.SetIgnore(user.FieldCreatedAt)
  1381. }
  1382. }))
  1383. return u
  1384. }
  1385. // Ignore sets each column to itself in case of conflict.
  1386. // Using this option is equivalent to using:
  1387. //
  1388. // client.User.Create().
  1389. // OnConflict(sql.ResolveWithIgnore()).
  1390. // Exec(ctx)
  1391. func (u *UserUpsertOne) Ignore() *UserUpsertOne {
  1392. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1393. return u
  1394. }
  1395. // DoNothing configures the conflict_action to `DO NOTHING`.
  1396. // Supported only by SQLite and PostgreSQL.
  1397. func (u *UserUpsertOne) DoNothing() *UserUpsertOne {
  1398. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1399. return u
  1400. }
  1401. // Update allows overriding fields `UPDATE` values. See the UserCreate.OnConflict
  1402. // documentation for more info.
  1403. func (u *UserUpsertOne) Update(set func(*UserUpsert)) *UserUpsertOne {
  1404. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1405. set(&UserUpsert{UpdateSet: update})
  1406. }))
  1407. return u
  1408. }
  1409. // SetUpdatedAt sets the "updated_at" field.
  1410. func (u *UserUpsertOne) SetUpdatedAt(v time.Time) *UserUpsertOne {
  1411. return u.Update(func(s *UserUpsert) {
  1412. s.SetUpdatedAt(v)
  1413. })
  1414. }
  1415. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1416. func (u *UserUpsertOne) UpdateUpdatedAt() *UserUpsertOne {
  1417. return u.Update(func(s *UserUpsert) {
  1418. s.UpdateUpdatedAt()
  1419. })
  1420. }
  1421. // SetDeletedAt sets the "deleted_at" field.
  1422. func (u *UserUpsertOne) SetDeletedAt(v time.Time) *UserUpsertOne {
  1423. return u.Update(func(s *UserUpsert) {
  1424. s.SetDeletedAt(v)
  1425. })
  1426. }
  1427. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1428. func (u *UserUpsertOne) UpdateDeletedAt() *UserUpsertOne {
  1429. return u.Update(func(s *UserUpsert) {
  1430. s.UpdateDeletedAt()
  1431. })
  1432. }
  1433. // ClearDeletedAt clears the value of the "deleted_at" field.
  1434. func (u *UserUpsertOne) ClearDeletedAt() *UserUpsertOne {
  1435. return u.Update(func(s *UserUpsert) {
  1436. s.ClearDeletedAt()
  1437. })
  1438. }
  1439. // SetEmail sets the "email" field.
  1440. func (u *UserUpsertOne) SetEmail(v string) *UserUpsertOne {
  1441. return u.Update(func(s *UserUpsert) {
  1442. s.SetEmail(v)
  1443. })
  1444. }
  1445. // UpdateEmail sets the "email" field to the value that was provided on create.
  1446. func (u *UserUpsertOne) UpdateEmail() *UserUpsertOne {
  1447. return u.Update(func(s *UserUpsert) {
  1448. s.UpdateEmail()
  1449. })
  1450. }
  1451. // SetPasswordHash sets the "password_hash" field.
  1452. func (u *UserUpsertOne) SetPasswordHash(v string) *UserUpsertOne {
  1453. return u.Update(func(s *UserUpsert) {
  1454. s.SetPasswordHash(v)
  1455. })
  1456. }
  1457. // UpdatePasswordHash sets the "password_hash" field to the value that was provided on create.
  1458. func (u *UserUpsertOne) UpdatePasswordHash() *UserUpsertOne {
  1459. return u.Update(func(s *UserUpsert) {
  1460. s.UpdatePasswordHash()
  1461. })
  1462. }
  1463. // SetRole sets the "role" field.
  1464. func (u *UserUpsertOne) SetRole(v string) *UserUpsertOne {
  1465. return u.Update(func(s *UserUpsert) {
  1466. s.SetRole(v)
  1467. })
  1468. }
  1469. // UpdateRole sets the "role" field to the value that was provided on create.
  1470. func (u *UserUpsertOne) UpdateRole() *UserUpsertOne {
  1471. return u.Update(func(s *UserUpsert) {
  1472. s.UpdateRole()
  1473. })
  1474. }
  1475. // SetBalance sets the "balance" field.
  1476. func (u *UserUpsertOne) SetBalance(v float64) *UserUpsertOne {
  1477. return u.Update(func(s *UserUpsert) {
  1478. s.SetBalance(v)
  1479. })
  1480. }
  1481. // AddBalance adds v to the "balance" field.
  1482. func (u *UserUpsertOne) AddBalance(v float64) *UserUpsertOne {
  1483. return u.Update(func(s *UserUpsert) {
  1484. s.AddBalance(v)
  1485. })
  1486. }
  1487. // UpdateBalance sets the "balance" field to the value that was provided on create.
  1488. func (u *UserUpsertOne) UpdateBalance() *UserUpsertOne {
  1489. return u.Update(func(s *UserUpsert) {
  1490. s.UpdateBalance()
  1491. })
  1492. }
  1493. // SetFrozenBalance sets the "frozen_balance" field.
  1494. func (u *UserUpsertOne) SetFrozenBalance(v float64) *UserUpsertOne {
  1495. return u.Update(func(s *UserUpsert) {
  1496. s.SetFrozenBalance(v)
  1497. })
  1498. }
  1499. // AddFrozenBalance adds v to the "frozen_balance" field.
  1500. func (u *UserUpsertOne) AddFrozenBalance(v float64) *UserUpsertOne {
  1501. return u.Update(func(s *UserUpsert) {
  1502. s.AddFrozenBalance(v)
  1503. })
  1504. }
  1505. // UpdateFrozenBalance sets the "frozen_balance" field to the value that was provided on create.
  1506. func (u *UserUpsertOne) UpdateFrozenBalance() *UserUpsertOne {
  1507. return u.Update(func(s *UserUpsert) {
  1508. s.UpdateFrozenBalance()
  1509. })
  1510. }
  1511. // SetConcurrency sets the "concurrency" field.
  1512. func (u *UserUpsertOne) SetConcurrency(v int) *UserUpsertOne {
  1513. return u.Update(func(s *UserUpsert) {
  1514. s.SetConcurrency(v)
  1515. })
  1516. }
  1517. // AddConcurrency adds v to the "concurrency" field.
  1518. func (u *UserUpsertOne) AddConcurrency(v int) *UserUpsertOne {
  1519. return u.Update(func(s *UserUpsert) {
  1520. s.AddConcurrency(v)
  1521. })
  1522. }
  1523. // UpdateConcurrency sets the "concurrency" field to the value that was provided on create.
  1524. func (u *UserUpsertOne) UpdateConcurrency() *UserUpsertOne {
  1525. return u.Update(func(s *UserUpsert) {
  1526. s.UpdateConcurrency()
  1527. })
  1528. }
  1529. // SetStatus sets the "status" field.
  1530. func (u *UserUpsertOne) SetStatus(v string) *UserUpsertOne {
  1531. return u.Update(func(s *UserUpsert) {
  1532. s.SetStatus(v)
  1533. })
  1534. }
  1535. // UpdateStatus sets the "status" field to the value that was provided on create.
  1536. func (u *UserUpsertOne) UpdateStatus() *UserUpsertOne {
  1537. return u.Update(func(s *UserUpsert) {
  1538. s.UpdateStatus()
  1539. })
  1540. }
  1541. // SetUsername sets the "username" field.
  1542. func (u *UserUpsertOne) SetUsername(v string) *UserUpsertOne {
  1543. return u.Update(func(s *UserUpsert) {
  1544. s.SetUsername(v)
  1545. })
  1546. }
  1547. // UpdateUsername sets the "username" field to the value that was provided on create.
  1548. func (u *UserUpsertOne) UpdateUsername() *UserUpsertOne {
  1549. return u.Update(func(s *UserUpsert) {
  1550. s.UpdateUsername()
  1551. })
  1552. }
  1553. // SetNotes sets the "notes" field.
  1554. func (u *UserUpsertOne) SetNotes(v string) *UserUpsertOne {
  1555. return u.Update(func(s *UserUpsert) {
  1556. s.SetNotes(v)
  1557. })
  1558. }
  1559. // UpdateNotes sets the "notes" field to the value that was provided on create.
  1560. func (u *UserUpsertOne) UpdateNotes() *UserUpsertOne {
  1561. return u.Update(func(s *UserUpsert) {
  1562. s.UpdateNotes()
  1563. })
  1564. }
  1565. // SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
  1566. func (u *UserUpsertOne) SetTotpSecretEncrypted(v string) *UserUpsertOne {
  1567. return u.Update(func(s *UserUpsert) {
  1568. s.SetTotpSecretEncrypted(v)
  1569. })
  1570. }
  1571. // UpdateTotpSecretEncrypted sets the "totp_secret_encrypted" field to the value that was provided on create.
  1572. func (u *UserUpsertOne) UpdateTotpSecretEncrypted() *UserUpsertOne {
  1573. return u.Update(func(s *UserUpsert) {
  1574. s.UpdateTotpSecretEncrypted()
  1575. })
  1576. }
  1577. // ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
  1578. func (u *UserUpsertOne) ClearTotpSecretEncrypted() *UserUpsertOne {
  1579. return u.Update(func(s *UserUpsert) {
  1580. s.ClearTotpSecretEncrypted()
  1581. })
  1582. }
  1583. // SetTotpEnabled sets the "totp_enabled" field.
  1584. func (u *UserUpsertOne) SetTotpEnabled(v bool) *UserUpsertOne {
  1585. return u.Update(func(s *UserUpsert) {
  1586. s.SetTotpEnabled(v)
  1587. })
  1588. }
  1589. // UpdateTotpEnabled sets the "totp_enabled" field to the value that was provided on create.
  1590. func (u *UserUpsertOne) UpdateTotpEnabled() *UserUpsertOne {
  1591. return u.Update(func(s *UserUpsert) {
  1592. s.UpdateTotpEnabled()
  1593. })
  1594. }
  1595. // SetTotpEnabledAt sets the "totp_enabled_at" field.
  1596. func (u *UserUpsertOne) SetTotpEnabledAt(v time.Time) *UserUpsertOne {
  1597. return u.Update(func(s *UserUpsert) {
  1598. s.SetTotpEnabledAt(v)
  1599. })
  1600. }
  1601. // UpdateTotpEnabledAt sets the "totp_enabled_at" field to the value that was provided on create.
  1602. func (u *UserUpsertOne) UpdateTotpEnabledAt() *UserUpsertOne {
  1603. return u.Update(func(s *UserUpsert) {
  1604. s.UpdateTotpEnabledAt()
  1605. })
  1606. }
  1607. // ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
  1608. func (u *UserUpsertOne) ClearTotpEnabledAt() *UserUpsertOne {
  1609. return u.Update(func(s *UserUpsert) {
  1610. s.ClearTotpEnabledAt()
  1611. })
  1612. }
  1613. // SetSignupSource sets the "signup_source" field.
  1614. func (u *UserUpsertOne) SetSignupSource(v string) *UserUpsertOne {
  1615. return u.Update(func(s *UserUpsert) {
  1616. s.SetSignupSource(v)
  1617. })
  1618. }
  1619. // UpdateSignupSource sets the "signup_source" field to the value that was provided on create.
  1620. func (u *UserUpsertOne) UpdateSignupSource() *UserUpsertOne {
  1621. return u.Update(func(s *UserUpsert) {
  1622. s.UpdateSignupSource()
  1623. })
  1624. }
  1625. // SetLastLoginAt sets the "last_login_at" field.
  1626. func (u *UserUpsertOne) SetLastLoginAt(v time.Time) *UserUpsertOne {
  1627. return u.Update(func(s *UserUpsert) {
  1628. s.SetLastLoginAt(v)
  1629. })
  1630. }
  1631. // UpdateLastLoginAt sets the "last_login_at" field to the value that was provided on create.
  1632. func (u *UserUpsertOne) UpdateLastLoginAt() *UserUpsertOne {
  1633. return u.Update(func(s *UserUpsert) {
  1634. s.UpdateLastLoginAt()
  1635. })
  1636. }
  1637. // ClearLastLoginAt clears the value of the "last_login_at" field.
  1638. func (u *UserUpsertOne) ClearLastLoginAt() *UserUpsertOne {
  1639. return u.Update(func(s *UserUpsert) {
  1640. s.ClearLastLoginAt()
  1641. })
  1642. }
  1643. // SetLastActiveAt sets the "last_active_at" field.
  1644. func (u *UserUpsertOne) SetLastActiveAt(v time.Time) *UserUpsertOne {
  1645. return u.Update(func(s *UserUpsert) {
  1646. s.SetLastActiveAt(v)
  1647. })
  1648. }
  1649. // UpdateLastActiveAt sets the "last_active_at" field to the value that was provided on create.
  1650. func (u *UserUpsertOne) UpdateLastActiveAt() *UserUpsertOne {
  1651. return u.Update(func(s *UserUpsert) {
  1652. s.UpdateLastActiveAt()
  1653. })
  1654. }
  1655. // ClearLastActiveAt clears the value of the "last_active_at" field.
  1656. func (u *UserUpsertOne) ClearLastActiveAt() *UserUpsertOne {
  1657. return u.Update(func(s *UserUpsert) {
  1658. s.ClearLastActiveAt()
  1659. })
  1660. }
  1661. // SetRestrictPublicGroups sets the "restrict_public_groups" field.
  1662. func (u *UserUpsertOne) SetRestrictPublicGroups(v bool) *UserUpsertOne {
  1663. return u.Update(func(s *UserUpsert) {
  1664. s.SetRestrictPublicGroups(v)
  1665. })
  1666. }
  1667. // UpdateRestrictPublicGroups sets the "restrict_public_groups" field to the value that was provided on create.
  1668. func (u *UserUpsertOne) UpdateRestrictPublicGroups() *UserUpsertOne {
  1669. return u.Update(func(s *UserUpsert) {
  1670. s.UpdateRestrictPublicGroups()
  1671. })
  1672. }
  1673. // SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
  1674. func (u *UserUpsertOne) SetBalanceNotifyEnabled(v bool) *UserUpsertOne {
  1675. return u.Update(func(s *UserUpsert) {
  1676. s.SetBalanceNotifyEnabled(v)
  1677. })
  1678. }
  1679. // UpdateBalanceNotifyEnabled sets the "balance_notify_enabled" field to the value that was provided on create.
  1680. func (u *UserUpsertOne) UpdateBalanceNotifyEnabled() *UserUpsertOne {
  1681. return u.Update(func(s *UserUpsert) {
  1682. s.UpdateBalanceNotifyEnabled()
  1683. })
  1684. }
  1685. // SetBalanceNotifyThresholdType sets the "balance_notify_threshold_type" field.
  1686. func (u *UserUpsertOne) SetBalanceNotifyThresholdType(v string) *UserUpsertOne {
  1687. return u.Update(func(s *UserUpsert) {
  1688. s.SetBalanceNotifyThresholdType(v)
  1689. })
  1690. }
  1691. // UpdateBalanceNotifyThresholdType sets the "balance_notify_threshold_type" field to the value that was provided on create.
  1692. func (u *UserUpsertOne) UpdateBalanceNotifyThresholdType() *UserUpsertOne {
  1693. return u.Update(func(s *UserUpsert) {
  1694. s.UpdateBalanceNotifyThresholdType()
  1695. })
  1696. }
  1697. // SetBalanceNotifyThreshold sets the "balance_notify_threshold" field.
  1698. func (u *UserUpsertOne) SetBalanceNotifyThreshold(v float64) *UserUpsertOne {
  1699. return u.Update(func(s *UserUpsert) {
  1700. s.SetBalanceNotifyThreshold(v)
  1701. })
  1702. }
  1703. // AddBalanceNotifyThreshold adds v to the "balance_notify_threshold" field.
  1704. func (u *UserUpsertOne) AddBalanceNotifyThreshold(v float64) *UserUpsertOne {
  1705. return u.Update(func(s *UserUpsert) {
  1706. s.AddBalanceNotifyThreshold(v)
  1707. })
  1708. }
  1709. // UpdateBalanceNotifyThreshold sets the "balance_notify_threshold" field to the value that was provided on create.
  1710. func (u *UserUpsertOne) UpdateBalanceNotifyThreshold() *UserUpsertOne {
  1711. return u.Update(func(s *UserUpsert) {
  1712. s.UpdateBalanceNotifyThreshold()
  1713. })
  1714. }
  1715. // ClearBalanceNotifyThreshold clears the value of the "balance_notify_threshold" field.
  1716. func (u *UserUpsertOne) ClearBalanceNotifyThreshold() *UserUpsertOne {
  1717. return u.Update(func(s *UserUpsert) {
  1718. s.ClearBalanceNotifyThreshold()
  1719. })
  1720. }
  1721. // SetBalanceNotifyExtraEmails sets the "balance_notify_extra_emails" field.
  1722. func (u *UserUpsertOne) SetBalanceNotifyExtraEmails(v string) *UserUpsertOne {
  1723. return u.Update(func(s *UserUpsert) {
  1724. s.SetBalanceNotifyExtraEmails(v)
  1725. })
  1726. }
  1727. // UpdateBalanceNotifyExtraEmails sets the "balance_notify_extra_emails" field to the value that was provided on create.
  1728. func (u *UserUpsertOne) UpdateBalanceNotifyExtraEmails() *UserUpsertOne {
  1729. return u.Update(func(s *UserUpsert) {
  1730. s.UpdateBalanceNotifyExtraEmails()
  1731. })
  1732. }
  1733. // SetTotalRecharged sets the "total_recharged" field.
  1734. func (u *UserUpsertOne) SetTotalRecharged(v float64) *UserUpsertOne {
  1735. return u.Update(func(s *UserUpsert) {
  1736. s.SetTotalRecharged(v)
  1737. })
  1738. }
  1739. // AddTotalRecharged adds v to the "total_recharged" field.
  1740. func (u *UserUpsertOne) AddTotalRecharged(v float64) *UserUpsertOne {
  1741. return u.Update(func(s *UserUpsert) {
  1742. s.AddTotalRecharged(v)
  1743. })
  1744. }
  1745. // UpdateTotalRecharged sets the "total_recharged" field to the value that was provided on create.
  1746. func (u *UserUpsertOne) UpdateTotalRecharged() *UserUpsertOne {
  1747. return u.Update(func(s *UserUpsert) {
  1748. s.UpdateTotalRecharged()
  1749. })
  1750. }
  1751. // SetRpmLimit sets the "rpm_limit" field.
  1752. func (u *UserUpsertOne) SetRpmLimit(v int) *UserUpsertOne {
  1753. return u.Update(func(s *UserUpsert) {
  1754. s.SetRpmLimit(v)
  1755. })
  1756. }
  1757. // AddRpmLimit adds v to the "rpm_limit" field.
  1758. func (u *UserUpsertOne) AddRpmLimit(v int) *UserUpsertOne {
  1759. return u.Update(func(s *UserUpsert) {
  1760. s.AddRpmLimit(v)
  1761. })
  1762. }
  1763. // UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
  1764. func (u *UserUpsertOne) UpdateRpmLimit() *UserUpsertOne {
  1765. return u.Update(func(s *UserUpsert) {
  1766. s.UpdateRpmLimit()
  1767. })
  1768. }
  1769. // Exec executes the query.
  1770. func (u *UserUpsertOne) Exec(ctx context.Context) error {
  1771. if len(u.create.conflict) == 0 {
  1772. return errors.New("ent: missing options for UserCreate.OnConflict")
  1773. }
  1774. return u.create.Exec(ctx)
  1775. }
  1776. // ExecX is like Exec, but panics if an error occurs.
  1777. func (u *UserUpsertOne) ExecX(ctx context.Context) {
  1778. if err := u.create.Exec(ctx); err != nil {
  1779. panic(err)
  1780. }
  1781. }
  1782. // Exec executes the UPSERT query and returns the inserted/updated ID.
  1783. func (u *UserUpsertOne) ID(ctx context.Context) (id int64, err error) {
  1784. node, err := u.create.Save(ctx)
  1785. if err != nil {
  1786. return id, err
  1787. }
  1788. return node.ID, nil
  1789. }
  1790. // IDX is like ID, but panics if an error occurs.
  1791. func (u *UserUpsertOne) IDX(ctx context.Context) int64 {
  1792. id, err := u.ID(ctx)
  1793. if err != nil {
  1794. panic(err)
  1795. }
  1796. return id
  1797. }
  1798. // UserCreateBulk is the builder for creating many User entities in bulk.
  1799. type UserCreateBulk struct {
  1800. config
  1801. err error
  1802. builders []*UserCreate
  1803. conflict []sql.ConflictOption
  1804. }
  1805. // Save creates the User entities in the database.
  1806. func (_c *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
  1807. if _c.err != nil {
  1808. return nil, _c.err
  1809. }
  1810. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  1811. nodes := make([]*User, len(_c.builders))
  1812. mutators := make([]Mutator, len(_c.builders))
  1813. for i := range _c.builders {
  1814. func(i int, root context.Context) {
  1815. builder := _c.builders[i]
  1816. builder.defaults()
  1817. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  1818. mutation, ok := m.(*UserMutation)
  1819. if !ok {
  1820. return nil, fmt.Errorf("unexpected mutation type %T", m)
  1821. }
  1822. if err := builder.check(); err != nil {
  1823. return nil, err
  1824. }
  1825. builder.mutation = mutation
  1826. var err error
  1827. nodes[i], specs[i] = builder.createSpec()
  1828. if i < len(mutators)-1 {
  1829. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  1830. } else {
  1831. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  1832. spec.OnConflict = _c.conflict
  1833. // Invoke the actual operation on the latest mutation in the chain.
  1834. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  1835. if sqlgraph.IsConstraintError(err) {
  1836. err = &ConstraintError{msg: err.Error(), wrap: err}
  1837. }
  1838. }
  1839. }
  1840. if err != nil {
  1841. return nil, err
  1842. }
  1843. mutation.id = &nodes[i].ID
  1844. if specs[i].ID.Value != nil {
  1845. id := specs[i].ID.Value.(int64)
  1846. nodes[i].ID = int64(id)
  1847. }
  1848. mutation.done = true
  1849. return nodes[i], nil
  1850. })
  1851. for i := len(builder.hooks) - 1; i >= 0; i-- {
  1852. mut = builder.hooks[i](mut)
  1853. }
  1854. mutators[i] = mut
  1855. }(i, ctx)
  1856. }
  1857. if len(mutators) > 0 {
  1858. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  1859. return nil, err
  1860. }
  1861. }
  1862. return nodes, nil
  1863. }
  1864. // SaveX is like Save, but panics if an error occurs.
  1865. func (_c *UserCreateBulk) SaveX(ctx context.Context) []*User {
  1866. v, err := _c.Save(ctx)
  1867. if err != nil {
  1868. panic(err)
  1869. }
  1870. return v
  1871. }
  1872. // Exec executes the query.
  1873. func (_c *UserCreateBulk) Exec(ctx context.Context) error {
  1874. _, err := _c.Save(ctx)
  1875. return err
  1876. }
  1877. // ExecX is like Exec, but panics if an error occurs.
  1878. func (_c *UserCreateBulk) ExecX(ctx context.Context) {
  1879. if err := _c.Exec(ctx); err != nil {
  1880. panic(err)
  1881. }
  1882. }
  1883. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  1884. // of the `INSERT` statement. For example:
  1885. //
  1886. // client.User.CreateBulk(builders...).
  1887. // OnConflict(
  1888. // // Update the row with the new values
  1889. // // the was proposed for insertion.
  1890. // sql.ResolveWithNewValues(),
  1891. // ).
  1892. // // Override some of the fields with custom
  1893. // // update values.
  1894. // Update(func(u *ent.UserUpsert) {
  1895. // SetCreatedAt(v+v).
  1896. // }).
  1897. // Exec(ctx)
  1898. func (_c *UserCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserUpsertBulk {
  1899. _c.conflict = opts
  1900. return &UserUpsertBulk{
  1901. create: _c,
  1902. }
  1903. }
  1904. // OnConflictColumns calls `OnConflict` and configures the columns
  1905. // as conflict target. Using this option is equivalent to using:
  1906. //
  1907. // client.User.Create().
  1908. // OnConflict(sql.ConflictColumns(columns...)).
  1909. // Exec(ctx)
  1910. func (_c *UserCreateBulk) OnConflictColumns(columns ...string) *UserUpsertBulk {
  1911. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  1912. return &UserUpsertBulk{
  1913. create: _c,
  1914. }
  1915. }
  1916. // UserUpsertBulk is the builder for "upsert"-ing
  1917. // a bulk of User nodes.
  1918. type UserUpsertBulk struct {
  1919. create *UserCreateBulk
  1920. }
  1921. // UpdateNewValues updates the mutable fields using the new values that
  1922. // were set on create. Using this option is equivalent to using:
  1923. //
  1924. // client.User.Create().
  1925. // OnConflict(
  1926. // sql.ResolveWithNewValues(),
  1927. // ).
  1928. // Exec(ctx)
  1929. func (u *UserUpsertBulk) UpdateNewValues() *UserUpsertBulk {
  1930. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  1931. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  1932. for _, b := range u.create.builders {
  1933. if _, exists := b.mutation.CreatedAt(); exists {
  1934. s.SetIgnore(user.FieldCreatedAt)
  1935. }
  1936. }
  1937. }))
  1938. return u
  1939. }
  1940. // Ignore sets each column to itself in case of conflict.
  1941. // Using this option is equivalent to using:
  1942. //
  1943. // client.User.Create().
  1944. // OnConflict(sql.ResolveWithIgnore()).
  1945. // Exec(ctx)
  1946. func (u *UserUpsertBulk) Ignore() *UserUpsertBulk {
  1947. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1948. return u
  1949. }
  1950. // DoNothing configures the conflict_action to `DO NOTHING`.
  1951. // Supported only by SQLite and PostgreSQL.
  1952. func (u *UserUpsertBulk) DoNothing() *UserUpsertBulk {
  1953. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1954. return u
  1955. }
  1956. // Update allows overriding fields `UPDATE` values. See the UserCreateBulk.OnConflict
  1957. // documentation for more info.
  1958. func (u *UserUpsertBulk) Update(set func(*UserUpsert)) *UserUpsertBulk {
  1959. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1960. set(&UserUpsert{UpdateSet: update})
  1961. }))
  1962. return u
  1963. }
  1964. // SetUpdatedAt sets the "updated_at" field.
  1965. func (u *UserUpsertBulk) SetUpdatedAt(v time.Time) *UserUpsertBulk {
  1966. return u.Update(func(s *UserUpsert) {
  1967. s.SetUpdatedAt(v)
  1968. })
  1969. }
  1970. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1971. func (u *UserUpsertBulk) UpdateUpdatedAt() *UserUpsertBulk {
  1972. return u.Update(func(s *UserUpsert) {
  1973. s.UpdateUpdatedAt()
  1974. })
  1975. }
  1976. // SetDeletedAt sets the "deleted_at" field.
  1977. func (u *UserUpsertBulk) SetDeletedAt(v time.Time) *UserUpsertBulk {
  1978. return u.Update(func(s *UserUpsert) {
  1979. s.SetDeletedAt(v)
  1980. })
  1981. }
  1982. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1983. func (u *UserUpsertBulk) UpdateDeletedAt() *UserUpsertBulk {
  1984. return u.Update(func(s *UserUpsert) {
  1985. s.UpdateDeletedAt()
  1986. })
  1987. }
  1988. // ClearDeletedAt clears the value of the "deleted_at" field.
  1989. func (u *UserUpsertBulk) ClearDeletedAt() *UserUpsertBulk {
  1990. return u.Update(func(s *UserUpsert) {
  1991. s.ClearDeletedAt()
  1992. })
  1993. }
  1994. // SetEmail sets the "email" field.
  1995. func (u *UserUpsertBulk) SetEmail(v string) *UserUpsertBulk {
  1996. return u.Update(func(s *UserUpsert) {
  1997. s.SetEmail(v)
  1998. })
  1999. }
  2000. // UpdateEmail sets the "email" field to the value that was provided on create.
  2001. func (u *UserUpsertBulk) UpdateEmail() *UserUpsertBulk {
  2002. return u.Update(func(s *UserUpsert) {
  2003. s.UpdateEmail()
  2004. })
  2005. }
  2006. // SetPasswordHash sets the "password_hash" field.
  2007. func (u *UserUpsertBulk) SetPasswordHash(v string) *UserUpsertBulk {
  2008. return u.Update(func(s *UserUpsert) {
  2009. s.SetPasswordHash(v)
  2010. })
  2011. }
  2012. // UpdatePasswordHash sets the "password_hash" field to the value that was provided on create.
  2013. func (u *UserUpsertBulk) UpdatePasswordHash() *UserUpsertBulk {
  2014. return u.Update(func(s *UserUpsert) {
  2015. s.UpdatePasswordHash()
  2016. })
  2017. }
  2018. // SetRole sets the "role" field.
  2019. func (u *UserUpsertBulk) SetRole(v string) *UserUpsertBulk {
  2020. return u.Update(func(s *UserUpsert) {
  2021. s.SetRole(v)
  2022. })
  2023. }
  2024. // UpdateRole sets the "role" field to the value that was provided on create.
  2025. func (u *UserUpsertBulk) UpdateRole() *UserUpsertBulk {
  2026. return u.Update(func(s *UserUpsert) {
  2027. s.UpdateRole()
  2028. })
  2029. }
  2030. // SetBalance sets the "balance" field.
  2031. func (u *UserUpsertBulk) SetBalance(v float64) *UserUpsertBulk {
  2032. return u.Update(func(s *UserUpsert) {
  2033. s.SetBalance(v)
  2034. })
  2035. }
  2036. // AddBalance adds v to the "balance" field.
  2037. func (u *UserUpsertBulk) AddBalance(v float64) *UserUpsertBulk {
  2038. return u.Update(func(s *UserUpsert) {
  2039. s.AddBalance(v)
  2040. })
  2041. }
  2042. // UpdateBalance sets the "balance" field to the value that was provided on create.
  2043. func (u *UserUpsertBulk) UpdateBalance() *UserUpsertBulk {
  2044. return u.Update(func(s *UserUpsert) {
  2045. s.UpdateBalance()
  2046. })
  2047. }
  2048. // SetFrozenBalance sets the "frozen_balance" field.
  2049. func (u *UserUpsertBulk) SetFrozenBalance(v float64) *UserUpsertBulk {
  2050. return u.Update(func(s *UserUpsert) {
  2051. s.SetFrozenBalance(v)
  2052. })
  2053. }
  2054. // AddFrozenBalance adds v to the "frozen_balance" field.
  2055. func (u *UserUpsertBulk) AddFrozenBalance(v float64) *UserUpsertBulk {
  2056. return u.Update(func(s *UserUpsert) {
  2057. s.AddFrozenBalance(v)
  2058. })
  2059. }
  2060. // UpdateFrozenBalance sets the "frozen_balance" field to the value that was provided on create.
  2061. func (u *UserUpsertBulk) UpdateFrozenBalance() *UserUpsertBulk {
  2062. return u.Update(func(s *UserUpsert) {
  2063. s.UpdateFrozenBalance()
  2064. })
  2065. }
  2066. // SetConcurrency sets the "concurrency" field.
  2067. func (u *UserUpsertBulk) SetConcurrency(v int) *UserUpsertBulk {
  2068. return u.Update(func(s *UserUpsert) {
  2069. s.SetConcurrency(v)
  2070. })
  2071. }
  2072. // AddConcurrency adds v to the "concurrency" field.
  2073. func (u *UserUpsertBulk) AddConcurrency(v int) *UserUpsertBulk {
  2074. return u.Update(func(s *UserUpsert) {
  2075. s.AddConcurrency(v)
  2076. })
  2077. }
  2078. // UpdateConcurrency sets the "concurrency" field to the value that was provided on create.
  2079. func (u *UserUpsertBulk) UpdateConcurrency() *UserUpsertBulk {
  2080. return u.Update(func(s *UserUpsert) {
  2081. s.UpdateConcurrency()
  2082. })
  2083. }
  2084. // SetStatus sets the "status" field.
  2085. func (u *UserUpsertBulk) SetStatus(v string) *UserUpsertBulk {
  2086. return u.Update(func(s *UserUpsert) {
  2087. s.SetStatus(v)
  2088. })
  2089. }
  2090. // UpdateStatus sets the "status" field to the value that was provided on create.
  2091. func (u *UserUpsertBulk) UpdateStatus() *UserUpsertBulk {
  2092. return u.Update(func(s *UserUpsert) {
  2093. s.UpdateStatus()
  2094. })
  2095. }
  2096. // SetUsername sets the "username" field.
  2097. func (u *UserUpsertBulk) SetUsername(v string) *UserUpsertBulk {
  2098. return u.Update(func(s *UserUpsert) {
  2099. s.SetUsername(v)
  2100. })
  2101. }
  2102. // UpdateUsername sets the "username" field to the value that was provided on create.
  2103. func (u *UserUpsertBulk) UpdateUsername() *UserUpsertBulk {
  2104. return u.Update(func(s *UserUpsert) {
  2105. s.UpdateUsername()
  2106. })
  2107. }
  2108. // SetNotes sets the "notes" field.
  2109. func (u *UserUpsertBulk) SetNotes(v string) *UserUpsertBulk {
  2110. return u.Update(func(s *UserUpsert) {
  2111. s.SetNotes(v)
  2112. })
  2113. }
  2114. // UpdateNotes sets the "notes" field to the value that was provided on create.
  2115. func (u *UserUpsertBulk) UpdateNotes() *UserUpsertBulk {
  2116. return u.Update(func(s *UserUpsert) {
  2117. s.UpdateNotes()
  2118. })
  2119. }
  2120. // SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
  2121. func (u *UserUpsertBulk) SetTotpSecretEncrypted(v string) *UserUpsertBulk {
  2122. return u.Update(func(s *UserUpsert) {
  2123. s.SetTotpSecretEncrypted(v)
  2124. })
  2125. }
  2126. // UpdateTotpSecretEncrypted sets the "totp_secret_encrypted" field to the value that was provided on create.
  2127. func (u *UserUpsertBulk) UpdateTotpSecretEncrypted() *UserUpsertBulk {
  2128. return u.Update(func(s *UserUpsert) {
  2129. s.UpdateTotpSecretEncrypted()
  2130. })
  2131. }
  2132. // ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
  2133. func (u *UserUpsertBulk) ClearTotpSecretEncrypted() *UserUpsertBulk {
  2134. return u.Update(func(s *UserUpsert) {
  2135. s.ClearTotpSecretEncrypted()
  2136. })
  2137. }
  2138. // SetTotpEnabled sets the "totp_enabled" field.
  2139. func (u *UserUpsertBulk) SetTotpEnabled(v bool) *UserUpsertBulk {
  2140. return u.Update(func(s *UserUpsert) {
  2141. s.SetTotpEnabled(v)
  2142. })
  2143. }
  2144. // UpdateTotpEnabled sets the "totp_enabled" field to the value that was provided on create.
  2145. func (u *UserUpsertBulk) UpdateTotpEnabled() *UserUpsertBulk {
  2146. return u.Update(func(s *UserUpsert) {
  2147. s.UpdateTotpEnabled()
  2148. })
  2149. }
  2150. // SetTotpEnabledAt sets the "totp_enabled_at" field.
  2151. func (u *UserUpsertBulk) SetTotpEnabledAt(v time.Time) *UserUpsertBulk {
  2152. return u.Update(func(s *UserUpsert) {
  2153. s.SetTotpEnabledAt(v)
  2154. })
  2155. }
  2156. // UpdateTotpEnabledAt sets the "totp_enabled_at" field to the value that was provided on create.
  2157. func (u *UserUpsertBulk) UpdateTotpEnabledAt() *UserUpsertBulk {
  2158. return u.Update(func(s *UserUpsert) {
  2159. s.UpdateTotpEnabledAt()
  2160. })
  2161. }
  2162. // ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
  2163. func (u *UserUpsertBulk) ClearTotpEnabledAt() *UserUpsertBulk {
  2164. return u.Update(func(s *UserUpsert) {
  2165. s.ClearTotpEnabledAt()
  2166. })
  2167. }
  2168. // SetSignupSource sets the "signup_source" field.
  2169. func (u *UserUpsertBulk) SetSignupSource(v string) *UserUpsertBulk {
  2170. return u.Update(func(s *UserUpsert) {
  2171. s.SetSignupSource(v)
  2172. })
  2173. }
  2174. // UpdateSignupSource sets the "signup_source" field to the value that was provided on create.
  2175. func (u *UserUpsertBulk) UpdateSignupSource() *UserUpsertBulk {
  2176. return u.Update(func(s *UserUpsert) {
  2177. s.UpdateSignupSource()
  2178. })
  2179. }
  2180. // SetLastLoginAt sets the "last_login_at" field.
  2181. func (u *UserUpsertBulk) SetLastLoginAt(v time.Time) *UserUpsertBulk {
  2182. return u.Update(func(s *UserUpsert) {
  2183. s.SetLastLoginAt(v)
  2184. })
  2185. }
  2186. // UpdateLastLoginAt sets the "last_login_at" field to the value that was provided on create.
  2187. func (u *UserUpsertBulk) UpdateLastLoginAt() *UserUpsertBulk {
  2188. return u.Update(func(s *UserUpsert) {
  2189. s.UpdateLastLoginAt()
  2190. })
  2191. }
  2192. // ClearLastLoginAt clears the value of the "last_login_at" field.
  2193. func (u *UserUpsertBulk) ClearLastLoginAt() *UserUpsertBulk {
  2194. return u.Update(func(s *UserUpsert) {
  2195. s.ClearLastLoginAt()
  2196. })
  2197. }
  2198. // SetLastActiveAt sets the "last_active_at" field.
  2199. func (u *UserUpsertBulk) SetLastActiveAt(v time.Time) *UserUpsertBulk {
  2200. return u.Update(func(s *UserUpsert) {
  2201. s.SetLastActiveAt(v)
  2202. })
  2203. }
  2204. // UpdateLastActiveAt sets the "last_active_at" field to the value that was provided on create.
  2205. func (u *UserUpsertBulk) UpdateLastActiveAt() *UserUpsertBulk {
  2206. return u.Update(func(s *UserUpsert) {
  2207. s.UpdateLastActiveAt()
  2208. })
  2209. }
  2210. // ClearLastActiveAt clears the value of the "last_active_at" field.
  2211. func (u *UserUpsertBulk) ClearLastActiveAt() *UserUpsertBulk {
  2212. return u.Update(func(s *UserUpsert) {
  2213. s.ClearLastActiveAt()
  2214. })
  2215. }
  2216. // SetRestrictPublicGroups sets the "restrict_public_groups" field.
  2217. func (u *UserUpsertBulk) SetRestrictPublicGroups(v bool) *UserUpsertBulk {
  2218. return u.Update(func(s *UserUpsert) {
  2219. s.SetRestrictPublicGroups(v)
  2220. })
  2221. }
  2222. // UpdateRestrictPublicGroups sets the "restrict_public_groups" field to the value that was provided on create.
  2223. func (u *UserUpsertBulk) UpdateRestrictPublicGroups() *UserUpsertBulk {
  2224. return u.Update(func(s *UserUpsert) {
  2225. s.UpdateRestrictPublicGroups()
  2226. })
  2227. }
  2228. // SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
  2229. func (u *UserUpsertBulk) SetBalanceNotifyEnabled(v bool) *UserUpsertBulk {
  2230. return u.Update(func(s *UserUpsert) {
  2231. s.SetBalanceNotifyEnabled(v)
  2232. })
  2233. }
  2234. // UpdateBalanceNotifyEnabled sets the "balance_notify_enabled" field to the value that was provided on create.
  2235. func (u *UserUpsertBulk) UpdateBalanceNotifyEnabled() *UserUpsertBulk {
  2236. return u.Update(func(s *UserUpsert) {
  2237. s.UpdateBalanceNotifyEnabled()
  2238. })
  2239. }
  2240. // SetBalanceNotifyThresholdType sets the "balance_notify_threshold_type" field.
  2241. func (u *UserUpsertBulk) SetBalanceNotifyThresholdType(v string) *UserUpsertBulk {
  2242. return u.Update(func(s *UserUpsert) {
  2243. s.SetBalanceNotifyThresholdType(v)
  2244. })
  2245. }
  2246. // UpdateBalanceNotifyThresholdType sets the "balance_notify_threshold_type" field to the value that was provided on create.
  2247. func (u *UserUpsertBulk) UpdateBalanceNotifyThresholdType() *UserUpsertBulk {
  2248. return u.Update(func(s *UserUpsert) {
  2249. s.UpdateBalanceNotifyThresholdType()
  2250. })
  2251. }
  2252. // SetBalanceNotifyThreshold sets the "balance_notify_threshold" field.
  2253. func (u *UserUpsertBulk) SetBalanceNotifyThreshold(v float64) *UserUpsertBulk {
  2254. return u.Update(func(s *UserUpsert) {
  2255. s.SetBalanceNotifyThreshold(v)
  2256. })
  2257. }
  2258. // AddBalanceNotifyThreshold adds v to the "balance_notify_threshold" field.
  2259. func (u *UserUpsertBulk) AddBalanceNotifyThreshold(v float64) *UserUpsertBulk {
  2260. return u.Update(func(s *UserUpsert) {
  2261. s.AddBalanceNotifyThreshold(v)
  2262. })
  2263. }
  2264. // UpdateBalanceNotifyThreshold sets the "balance_notify_threshold" field to the value that was provided on create.
  2265. func (u *UserUpsertBulk) UpdateBalanceNotifyThreshold() *UserUpsertBulk {
  2266. return u.Update(func(s *UserUpsert) {
  2267. s.UpdateBalanceNotifyThreshold()
  2268. })
  2269. }
  2270. // ClearBalanceNotifyThreshold clears the value of the "balance_notify_threshold" field.
  2271. func (u *UserUpsertBulk) ClearBalanceNotifyThreshold() *UserUpsertBulk {
  2272. return u.Update(func(s *UserUpsert) {
  2273. s.ClearBalanceNotifyThreshold()
  2274. })
  2275. }
  2276. // SetBalanceNotifyExtraEmails sets the "balance_notify_extra_emails" field.
  2277. func (u *UserUpsertBulk) SetBalanceNotifyExtraEmails(v string) *UserUpsertBulk {
  2278. return u.Update(func(s *UserUpsert) {
  2279. s.SetBalanceNotifyExtraEmails(v)
  2280. })
  2281. }
  2282. // UpdateBalanceNotifyExtraEmails sets the "balance_notify_extra_emails" field to the value that was provided on create.
  2283. func (u *UserUpsertBulk) UpdateBalanceNotifyExtraEmails() *UserUpsertBulk {
  2284. return u.Update(func(s *UserUpsert) {
  2285. s.UpdateBalanceNotifyExtraEmails()
  2286. })
  2287. }
  2288. // SetTotalRecharged sets the "total_recharged" field.
  2289. func (u *UserUpsertBulk) SetTotalRecharged(v float64) *UserUpsertBulk {
  2290. return u.Update(func(s *UserUpsert) {
  2291. s.SetTotalRecharged(v)
  2292. })
  2293. }
  2294. // AddTotalRecharged adds v to the "total_recharged" field.
  2295. func (u *UserUpsertBulk) AddTotalRecharged(v float64) *UserUpsertBulk {
  2296. return u.Update(func(s *UserUpsert) {
  2297. s.AddTotalRecharged(v)
  2298. })
  2299. }
  2300. // UpdateTotalRecharged sets the "total_recharged" field to the value that was provided on create.
  2301. func (u *UserUpsertBulk) UpdateTotalRecharged() *UserUpsertBulk {
  2302. return u.Update(func(s *UserUpsert) {
  2303. s.UpdateTotalRecharged()
  2304. })
  2305. }
  2306. // SetRpmLimit sets the "rpm_limit" field.
  2307. func (u *UserUpsertBulk) SetRpmLimit(v int) *UserUpsertBulk {
  2308. return u.Update(func(s *UserUpsert) {
  2309. s.SetRpmLimit(v)
  2310. })
  2311. }
  2312. // AddRpmLimit adds v to the "rpm_limit" field.
  2313. func (u *UserUpsertBulk) AddRpmLimit(v int) *UserUpsertBulk {
  2314. return u.Update(func(s *UserUpsert) {
  2315. s.AddRpmLimit(v)
  2316. })
  2317. }
  2318. // UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
  2319. func (u *UserUpsertBulk) UpdateRpmLimit() *UserUpsertBulk {
  2320. return u.Update(func(s *UserUpsert) {
  2321. s.UpdateRpmLimit()
  2322. })
  2323. }
  2324. // Exec executes the query.
  2325. func (u *UserUpsertBulk) Exec(ctx context.Context) error {
  2326. if u.create.err != nil {
  2327. return u.create.err
  2328. }
  2329. for i, b := range u.create.builders {
  2330. if len(b.conflict) != 0 {
  2331. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the UserCreateBulk instead", i)
  2332. }
  2333. }
  2334. if len(u.create.conflict) == 0 {
  2335. return errors.New("ent: missing options for UserCreateBulk.OnConflict")
  2336. }
  2337. return u.create.Exec(ctx)
  2338. }
  2339. // ExecX is like Exec, but panics if an error occurs.
  2340. func (u *UserUpsertBulk) ExecX(ctx context.Context) {
  2341. if err := u.create.Exec(ctx); err != nil {
  2342. panic(err)
  2343. }
  2344. }