mutation.go 227 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "sikey/w303a/http/internal/data/ent/child"
  8. "sikey/w303a/http/internal/data/ent/childref"
  9. "sikey/w303a/http/internal/data/ent/contacts"
  10. "sikey/w303a/http/internal/data/ent/device"
  11. "sikey/w303a/http/internal/data/ent/devicebind"
  12. "sikey/w303a/http/internal/data/ent/deviceconfig"
  13. "sikey/w303a/http/internal/data/ent/group"
  14. "sikey/w303a/http/internal/data/ent/member"
  15. "sikey/w303a/http/internal/data/ent/predicate"
  16. "sikey/w303a/http/internal/data/ent/user"
  17. "sync"
  18. "time"
  19. "entgo.io/ent"
  20. "entgo.io/ent/dialect/sql"
  21. "github.com/google/uuid"
  22. )
  23. const (
  24. // Operation types.
  25. OpCreate = ent.OpCreate
  26. OpDelete = ent.OpDelete
  27. OpDeleteOne = ent.OpDeleteOne
  28. OpUpdate = ent.OpUpdate
  29. OpUpdateOne = ent.OpUpdateOne
  30. // Node types.
  31. TypeChild = "Child"
  32. TypeChildRef = "ChildRef"
  33. TypeContacts = "Contacts"
  34. TypeDevice = "Device"
  35. TypeDeviceBind = "DeviceBind"
  36. TypeDeviceConfig = "DeviceConfig"
  37. TypeGroup = "Group"
  38. TypeMember = "Member"
  39. TypeUser = "User"
  40. )
  41. // ChildMutation represents an operation that mutates the Child nodes in the graph.
  42. type ChildMutation struct {
  43. config
  44. op Op
  45. typ string
  46. id *uuid.UUID
  47. created_at *time.Time
  48. updated_at *time.Time
  49. deleted_at *time.Time
  50. child_name *string
  51. phone_number *string
  52. area_code *string
  53. avatar *string
  54. gender *int8
  55. addgender *int8
  56. height *int32
  57. addheight *int32
  58. weight *int32
  59. addweight *int32
  60. birthday *string
  61. is_enable_block_unknown_call *bool
  62. is_enable_fence *bool
  63. clearedFields map[string]struct{}
  64. childRefs map[int64]struct{}
  65. removedchildRefs map[int64]struct{}
  66. clearedchildRefs bool
  67. childDevice map[int64]struct{}
  68. removedchildDevice map[int64]struct{}
  69. clearedchildDevice bool
  70. childContacts map[int]struct{}
  71. removedchildContacts map[int]struct{}
  72. clearedchildContacts bool
  73. done bool
  74. oldValue func(context.Context) (*Child, error)
  75. predicates []predicate.Child
  76. }
  77. var _ ent.Mutation = (*ChildMutation)(nil)
  78. // childOption allows management of the mutation configuration using functional options.
  79. type childOption func(*ChildMutation)
  80. // newChildMutation creates new mutation for the Child entity.
  81. func newChildMutation(c config, op Op, opts ...childOption) *ChildMutation {
  82. m := &ChildMutation{
  83. config: c,
  84. op: op,
  85. typ: TypeChild,
  86. clearedFields: make(map[string]struct{}),
  87. }
  88. for _, opt := range opts {
  89. opt(m)
  90. }
  91. return m
  92. }
  93. // withChildID sets the ID field of the mutation.
  94. func withChildID(id uuid.UUID) childOption {
  95. return func(m *ChildMutation) {
  96. var (
  97. err error
  98. once sync.Once
  99. value *Child
  100. )
  101. m.oldValue = func(ctx context.Context) (*Child, error) {
  102. once.Do(func() {
  103. if m.done {
  104. err = errors.New("querying old values post mutation is not allowed")
  105. } else {
  106. value, err = m.Client().Child.Get(ctx, id)
  107. }
  108. })
  109. return value, err
  110. }
  111. m.id = &id
  112. }
  113. }
  114. // withChild sets the old Child of the mutation.
  115. func withChild(node *Child) childOption {
  116. return func(m *ChildMutation) {
  117. m.oldValue = func(context.Context) (*Child, error) {
  118. return node, nil
  119. }
  120. m.id = &node.ID
  121. }
  122. }
  123. // Client returns a new `ent.Client` from the mutation. If the mutation was
  124. // executed in a transaction (ent.Tx), a transactional client is returned.
  125. func (m ChildMutation) Client() *Client {
  126. client := &Client{config: m.config}
  127. client.init()
  128. return client
  129. }
  130. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  131. // it returns an error otherwise.
  132. func (m ChildMutation) Tx() (*Tx, error) {
  133. if _, ok := m.driver.(*txDriver); !ok {
  134. return nil, errors.New("ent: mutation is not running in a transaction")
  135. }
  136. tx := &Tx{config: m.config}
  137. tx.init()
  138. return tx, nil
  139. }
  140. // SetID sets the value of the id field. Note that this
  141. // operation is only accepted on creation of Child entities.
  142. func (m *ChildMutation) SetID(id uuid.UUID) {
  143. m.id = &id
  144. }
  145. // ID returns the ID value in the mutation. Note that the ID is only available
  146. // if it was provided to the builder or after it was returned from the database.
  147. func (m *ChildMutation) ID() (id uuid.UUID, exists bool) {
  148. if m.id == nil {
  149. return
  150. }
  151. return *m.id, true
  152. }
  153. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  154. // That means, if the mutation is applied within a transaction with an isolation level such
  155. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  156. // or updated by the mutation.
  157. func (m *ChildMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
  158. switch {
  159. case m.op.Is(OpUpdateOne | OpDeleteOne):
  160. id, exists := m.ID()
  161. if exists {
  162. return []uuid.UUID{id}, nil
  163. }
  164. fallthrough
  165. case m.op.Is(OpUpdate | OpDelete):
  166. return m.Client().Child.Query().Where(m.predicates...).IDs(ctx)
  167. default:
  168. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  169. }
  170. }
  171. // SetCreatedAt sets the "created_at" field.
  172. func (m *ChildMutation) SetCreatedAt(t time.Time) {
  173. m.created_at = &t
  174. }
  175. // CreatedAt returns the value of the "created_at" field in the mutation.
  176. func (m *ChildMutation) CreatedAt() (r time.Time, exists bool) {
  177. v := m.created_at
  178. if v == nil {
  179. return
  180. }
  181. return *v, true
  182. }
  183. // OldCreatedAt returns the old "created_at" field's value of the Child entity.
  184. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  185. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  186. func (m *ChildMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  187. if !m.op.Is(OpUpdateOne) {
  188. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  189. }
  190. if m.id == nil || m.oldValue == nil {
  191. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  192. }
  193. oldValue, err := m.oldValue(ctx)
  194. if err != nil {
  195. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  196. }
  197. return oldValue.CreatedAt, nil
  198. }
  199. // ResetCreatedAt resets all changes to the "created_at" field.
  200. func (m *ChildMutation) ResetCreatedAt() {
  201. m.created_at = nil
  202. }
  203. // SetUpdatedAt sets the "updated_at" field.
  204. func (m *ChildMutation) SetUpdatedAt(t time.Time) {
  205. m.updated_at = &t
  206. }
  207. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  208. func (m *ChildMutation) UpdatedAt() (r time.Time, exists bool) {
  209. v := m.updated_at
  210. if v == nil {
  211. return
  212. }
  213. return *v, true
  214. }
  215. // OldUpdatedAt returns the old "updated_at" field's value of the Child entity.
  216. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  217. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  218. func (m *ChildMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  219. if !m.op.Is(OpUpdateOne) {
  220. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  221. }
  222. if m.id == nil || m.oldValue == nil {
  223. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  224. }
  225. oldValue, err := m.oldValue(ctx)
  226. if err != nil {
  227. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  228. }
  229. return oldValue.UpdatedAt, nil
  230. }
  231. // ResetUpdatedAt resets all changes to the "updated_at" field.
  232. func (m *ChildMutation) ResetUpdatedAt() {
  233. m.updated_at = nil
  234. }
  235. // SetDeletedAt sets the "deleted_at" field.
  236. func (m *ChildMutation) SetDeletedAt(t time.Time) {
  237. m.deleted_at = &t
  238. }
  239. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  240. func (m *ChildMutation) DeletedAt() (r time.Time, exists bool) {
  241. v := m.deleted_at
  242. if v == nil {
  243. return
  244. }
  245. return *v, true
  246. }
  247. // OldDeletedAt returns the old "deleted_at" field's value of the Child entity.
  248. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  249. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  250. func (m *ChildMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
  251. if !m.op.Is(OpUpdateOne) {
  252. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  253. }
  254. if m.id == nil || m.oldValue == nil {
  255. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  256. }
  257. oldValue, err := m.oldValue(ctx)
  258. if err != nil {
  259. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  260. }
  261. return oldValue.DeletedAt, nil
  262. }
  263. // ClearDeletedAt clears the value of the "deleted_at" field.
  264. func (m *ChildMutation) ClearDeletedAt() {
  265. m.deleted_at = nil
  266. m.clearedFields[child.FieldDeletedAt] = struct{}{}
  267. }
  268. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  269. func (m *ChildMutation) DeletedAtCleared() bool {
  270. _, ok := m.clearedFields[child.FieldDeletedAt]
  271. return ok
  272. }
  273. // ResetDeletedAt resets all changes to the "deleted_at" field.
  274. func (m *ChildMutation) ResetDeletedAt() {
  275. m.deleted_at = nil
  276. delete(m.clearedFields, child.FieldDeletedAt)
  277. }
  278. // SetChildName sets the "child_name" field.
  279. func (m *ChildMutation) SetChildName(s string) {
  280. m.child_name = &s
  281. }
  282. // ChildName returns the value of the "child_name" field in the mutation.
  283. func (m *ChildMutation) ChildName() (r string, exists bool) {
  284. v := m.child_name
  285. if v == nil {
  286. return
  287. }
  288. return *v, true
  289. }
  290. // OldChildName returns the old "child_name" field's value of the Child entity.
  291. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  292. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  293. func (m *ChildMutation) OldChildName(ctx context.Context) (v string, err error) {
  294. if !m.op.Is(OpUpdateOne) {
  295. return v, errors.New("OldChildName is only allowed on UpdateOne operations")
  296. }
  297. if m.id == nil || m.oldValue == nil {
  298. return v, errors.New("OldChildName requires an ID field in the mutation")
  299. }
  300. oldValue, err := m.oldValue(ctx)
  301. if err != nil {
  302. return v, fmt.Errorf("querying old value for OldChildName: %w", err)
  303. }
  304. return oldValue.ChildName, nil
  305. }
  306. // ResetChildName resets all changes to the "child_name" field.
  307. func (m *ChildMutation) ResetChildName() {
  308. m.child_name = nil
  309. }
  310. // SetPhoneNumber sets the "phone_number" field.
  311. func (m *ChildMutation) SetPhoneNumber(s string) {
  312. m.phone_number = &s
  313. }
  314. // PhoneNumber returns the value of the "phone_number" field in the mutation.
  315. func (m *ChildMutation) PhoneNumber() (r string, exists bool) {
  316. v := m.phone_number
  317. if v == nil {
  318. return
  319. }
  320. return *v, true
  321. }
  322. // OldPhoneNumber returns the old "phone_number" field's value of the Child entity.
  323. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  324. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  325. func (m *ChildMutation) OldPhoneNumber(ctx context.Context) (v string, err error) {
  326. if !m.op.Is(OpUpdateOne) {
  327. return v, errors.New("OldPhoneNumber is only allowed on UpdateOne operations")
  328. }
  329. if m.id == nil || m.oldValue == nil {
  330. return v, errors.New("OldPhoneNumber requires an ID field in the mutation")
  331. }
  332. oldValue, err := m.oldValue(ctx)
  333. if err != nil {
  334. return v, fmt.Errorf("querying old value for OldPhoneNumber: %w", err)
  335. }
  336. return oldValue.PhoneNumber, nil
  337. }
  338. // ResetPhoneNumber resets all changes to the "phone_number" field.
  339. func (m *ChildMutation) ResetPhoneNumber() {
  340. m.phone_number = nil
  341. }
  342. // SetAreaCode sets the "area_code" field.
  343. func (m *ChildMutation) SetAreaCode(s string) {
  344. m.area_code = &s
  345. }
  346. // AreaCode returns the value of the "area_code" field in the mutation.
  347. func (m *ChildMutation) AreaCode() (r string, exists bool) {
  348. v := m.area_code
  349. if v == nil {
  350. return
  351. }
  352. return *v, true
  353. }
  354. // OldAreaCode returns the old "area_code" field's value of the Child entity.
  355. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  356. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  357. func (m *ChildMutation) OldAreaCode(ctx context.Context) (v string, err error) {
  358. if !m.op.Is(OpUpdateOne) {
  359. return v, errors.New("OldAreaCode is only allowed on UpdateOne operations")
  360. }
  361. if m.id == nil || m.oldValue == nil {
  362. return v, errors.New("OldAreaCode requires an ID field in the mutation")
  363. }
  364. oldValue, err := m.oldValue(ctx)
  365. if err != nil {
  366. return v, fmt.Errorf("querying old value for OldAreaCode: %w", err)
  367. }
  368. return oldValue.AreaCode, nil
  369. }
  370. // ResetAreaCode resets all changes to the "area_code" field.
  371. func (m *ChildMutation) ResetAreaCode() {
  372. m.area_code = nil
  373. }
  374. // SetAvatar sets the "avatar" field.
  375. func (m *ChildMutation) SetAvatar(s string) {
  376. m.avatar = &s
  377. }
  378. // Avatar returns the value of the "avatar" field in the mutation.
  379. func (m *ChildMutation) Avatar() (r string, exists bool) {
  380. v := m.avatar
  381. if v == nil {
  382. return
  383. }
  384. return *v, true
  385. }
  386. // OldAvatar returns the old "avatar" field's value of the Child entity.
  387. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  388. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  389. func (m *ChildMutation) OldAvatar(ctx context.Context) (v *string, err error) {
  390. if !m.op.Is(OpUpdateOne) {
  391. return v, errors.New("OldAvatar is only allowed on UpdateOne operations")
  392. }
  393. if m.id == nil || m.oldValue == nil {
  394. return v, errors.New("OldAvatar requires an ID field in the mutation")
  395. }
  396. oldValue, err := m.oldValue(ctx)
  397. if err != nil {
  398. return v, fmt.Errorf("querying old value for OldAvatar: %w", err)
  399. }
  400. return oldValue.Avatar, nil
  401. }
  402. // ClearAvatar clears the value of the "avatar" field.
  403. func (m *ChildMutation) ClearAvatar() {
  404. m.avatar = nil
  405. m.clearedFields[child.FieldAvatar] = struct{}{}
  406. }
  407. // AvatarCleared returns if the "avatar" field was cleared in this mutation.
  408. func (m *ChildMutation) AvatarCleared() bool {
  409. _, ok := m.clearedFields[child.FieldAvatar]
  410. return ok
  411. }
  412. // ResetAvatar resets all changes to the "avatar" field.
  413. func (m *ChildMutation) ResetAvatar() {
  414. m.avatar = nil
  415. delete(m.clearedFields, child.FieldAvatar)
  416. }
  417. // SetGender sets the "gender" field.
  418. func (m *ChildMutation) SetGender(i int8) {
  419. m.gender = &i
  420. m.addgender = nil
  421. }
  422. // Gender returns the value of the "gender" field in the mutation.
  423. func (m *ChildMutation) Gender() (r int8, exists bool) {
  424. v := m.gender
  425. if v == nil {
  426. return
  427. }
  428. return *v, true
  429. }
  430. // OldGender returns the old "gender" field's value of the Child entity.
  431. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  432. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  433. func (m *ChildMutation) OldGender(ctx context.Context) (v int8, err error) {
  434. if !m.op.Is(OpUpdateOne) {
  435. return v, errors.New("OldGender is only allowed on UpdateOne operations")
  436. }
  437. if m.id == nil || m.oldValue == nil {
  438. return v, errors.New("OldGender requires an ID field in the mutation")
  439. }
  440. oldValue, err := m.oldValue(ctx)
  441. if err != nil {
  442. return v, fmt.Errorf("querying old value for OldGender: %w", err)
  443. }
  444. return oldValue.Gender, nil
  445. }
  446. // AddGender adds i to the "gender" field.
  447. func (m *ChildMutation) AddGender(i int8) {
  448. if m.addgender != nil {
  449. *m.addgender += i
  450. } else {
  451. m.addgender = &i
  452. }
  453. }
  454. // AddedGender returns the value that was added to the "gender" field in this mutation.
  455. func (m *ChildMutation) AddedGender() (r int8, exists bool) {
  456. v := m.addgender
  457. if v == nil {
  458. return
  459. }
  460. return *v, true
  461. }
  462. // ResetGender resets all changes to the "gender" field.
  463. func (m *ChildMutation) ResetGender() {
  464. m.gender = nil
  465. m.addgender = nil
  466. }
  467. // SetHeight sets the "height" field.
  468. func (m *ChildMutation) SetHeight(i int32) {
  469. m.height = &i
  470. m.addheight = nil
  471. }
  472. // Height returns the value of the "height" field in the mutation.
  473. func (m *ChildMutation) Height() (r int32, exists bool) {
  474. v := m.height
  475. if v == nil {
  476. return
  477. }
  478. return *v, true
  479. }
  480. // OldHeight returns the old "height" field's value of the Child entity.
  481. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  482. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  483. func (m *ChildMutation) OldHeight(ctx context.Context) (v int32, err error) {
  484. if !m.op.Is(OpUpdateOne) {
  485. return v, errors.New("OldHeight is only allowed on UpdateOne operations")
  486. }
  487. if m.id == nil || m.oldValue == nil {
  488. return v, errors.New("OldHeight requires an ID field in the mutation")
  489. }
  490. oldValue, err := m.oldValue(ctx)
  491. if err != nil {
  492. return v, fmt.Errorf("querying old value for OldHeight: %w", err)
  493. }
  494. return oldValue.Height, nil
  495. }
  496. // AddHeight adds i to the "height" field.
  497. func (m *ChildMutation) AddHeight(i int32) {
  498. if m.addheight != nil {
  499. *m.addheight += i
  500. } else {
  501. m.addheight = &i
  502. }
  503. }
  504. // AddedHeight returns the value that was added to the "height" field in this mutation.
  505. func (m *ChildMutation) AddedHeight() (r int32, exists bool) {
  506. v := m.addheight
  507. if v == nil {
  508. return
  509. }
  510. return *v, true
  511. }
  512. // ResetHeight resets all changes to the "height" field.
  513. func (m *ChildMutation) ResetHeight() {
  514. m.height = nil
  515. m.addheight = nil
  516. }
  517. // SetWeight sets the "weight" field.
  518. func (m *ChildMutation) SetWeight(i int32) {
  519. m.weight = &i
  520. m.addweight = nil
  521. }
  522. // Weight returns the value of the "weight" field in the mutation.
  523. func (m *ChildMutation) Weight() (r int32, exists bool) {
  524. v := m.weight
  525. if v == nil {
  526. return
  527. }
  528. return *v, true
  529. }
  530. // OldWeight returns the old "weight" field's value of the Child entity.
  531. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  532. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  533. func (m *ChildMutation) OldWeight(ctx context.Context) (v int32, err error) {
  534. if !m.op.Is(OpUpdateOne) {
  535. return v, errors.New("OldWeight is only allowed on UpdateOne operations")
  536. }
  537. if m.id == nil || m.oldValue == nil {
  538. return v, errors.New("OldWeight requires an ID field in the mutation")
  539. }
  540. oldValue, err := m.oldValue(ctx)
  541. if err != nil {
  542. return v, fmt.Errorf("querying old value for OldWeight: %w", err)
  543. }
  544. return oldValue.Weight, nil
  545. }
  546. // AddWeight adds i to the "weight" field.
  547. func (m *ChildMutation) AddWeight(i int32) {
  548. if m.addweight != nil {
  549. *m.addweight += i
  550. } else {
  551. m.addweight = &i
  552. }
  553. }
  554. // AddedWeight returns the value that was added to the "weight" field in this mutation.
  555. func (m *ChildMutation) AddedWeight() (r int32, exists bool) {
  556. v := m.addweight
  557. if v == nil {
  558. return
  559. }
  560. return *v, true
  561. }
  562. // ResetWeight resets all changes to the "weight" field.
  563. func (m *ChildMutation) ResetWeight() {
  564. m.weight = nil
  565. m.addweight = nil
  566. }
  567. // SetBirthday sets the "birthday" field.
  568. func (m *ChildMutation) SetBirthday(s string) {
  569. m.birthday = &s
  570. }
  571. // Birthday returns the value of the "birthday" field in the mutation.
  572. func (m *ChildMutation) Birthday() (r string, exists bool) {
  573. v := m.birthday
  574. if v == nil {
  575. return
  576. }
  577. return *v, true
  578. }
  579. // OldBirthday returns the old "birthday" field's value of the Child entity.
  580. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  581. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  582. func (m *ChildMutation) OldBirthday(ctx context.Context) (v *string, err error) {
  583. if !m.op.Is(OpUpdateOne) {
  584. return v, errors.New("OldBirthday is only allowed on UpdateOne operations")
  585. }
  586. if m.id == nil || m.oldValue == nil {
  587. return v, errors.New("OldBirthday requires an ID field in the mutation")
  588. }
  589. oldValue, err := m.oldValue(ctx)
  590. if err != nil {
  591. return v, fmt.Errorf("querying old value for OldBirthday: %w", err)
  592. }
  593. return oldValue.Birthday, nil
  594. }
  595. // ClearBirthday clears the value of the "birthday" field.
  596. func (m *ChildMutation) ClearBirthday() {
  597. m.birthday = nil
  598. m.clearedFields[child.FieldBirthday] = struct{}{}
  599. }
  600. // BirthdayCleared returns if the "birthday" field was cleared in this mutation.
  601. func (m *ChildMutation) BirthdayCleared() bool {
  602. _, ok := m.clearedFields[child.FieldBirthday]
  603. return ok
  604. }
  605. // ResetBirthday resets all changes to the "birthday" field.
  606. func (m *ChildMutation) ResetBirthday() {
  607. m.birthday = nil
  608. delete(m.clearedFields, child.FieldBirthday)
  609. }
  610. // SetIsEnableBlockUnknownCall sets the "is_enable_block_unknown_call" field.
  611. func (m *ChildMutation) SetIsEnableBlockUnknownCall(b bool) {
  612. m.is_enable_block_unknown_call = &b
  613. }
  614. // IsEnableBlockUnknownCall returns the value of the "is_enable_block_unknown_call" field in the mutation.
  615. func (m *ChildMutation) IsEnableBlockUnknownCall() (r bool, exists bool) {
  616. v := m.is_enable_block_unknown_call
  617. if v == nil {
  618. return
  619. }
  620. return *v, true
  621. }
  622. // OldIsEnableBlockUnknownCall returns the old "is_enable_block_unknown_call" field's value of the Child entity.
  623. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  624. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  625. func (m *ChildMutation) OldIsEnableBlockUnknownCall(ctx context.Context) (v bool, err error) {
  626. if !m.op.Is(OpUpdateOne) {
  627. return v, errors.New("OldIsEnableBlockUnknownCall is only allowed on UpdateOne operations")
  628. }
  629. if m.id == nil || m.oldValue == nil {
  630. return v, errors.New("OldIsEnableBlockUnknownCall requires an ID field in the mutation")
  631. }
  632. oldValue, err := m.oldValue(ctx)
  633. if err != nil {
  634. return v, fmt.Errorf("querying old value for OldIsEnableBlockUnknownCall: %w", err)
  635. }
  636. return oldValue.IsEnableBlockUnknownCall, nil
  637. }
  638. // ResetIsEnableBlockUnknownCall resets all changes to the "is_enable_block_unknown_call" field.
  639. func (m *ChildMutation) ResetIsEnableBlockUnknownCall() {
  640. m.is_enable_block_unknown_call = nil
  641. }
  642. // SetIsEnableFence sets the "is_enable_fence" field.
  643. func (m *ChildMutation) SetIsEnableFence(b bool) {
  644. m.is_enable_fence = &b
  645. }
  646. // IsEnableFence returns the value of the "is_enable_fence" field in the mutation.
  647. func (m *ChildMutation) IsEnableFence() (r bool, exists bool) {
  648. v := m.is_enable_fence
  649. if v == nil {
  650. return
  651. }
  652. return *v, true
  653. }
  654. // OldIsEnableFence returns the old "is_enable_fence" field's value of the Child entity.
  655. // If the Child object wasn't provided to the builder, the object is fetched from the database.
  656. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  657. func (m *ChildMutation) OldIsEnableFence(ctx context.Context) (v bool, err error) {
  658. if !m.op.Is(OpUpdateOne) {
  659. return v, errors.New("OldIsEnableFence is only allowed on UpdateOne operations")
  660. }
  661. if m.id == nil || m.oldValue == nil {
  662. return v, errors.New("OldIsEnableFence requires an ID field in the mutation")
  663. }
  664. oldValue, err := m.oldValue(ctx)
  665. if err != nil {
  666. return v, fmt.Errorf("querying old value for OldIsEnableFence: %w", err)
  667. }
  668. return oldValue.IsEnableFence, nil
  669. }
  670. // ResetIsEnableFence resets all changes to the "is_enable_fence" field.
  671. func (m *ChildMutation) ResetIsEnableFence() {
  672. m.is_enable_fence = nil
  673. }
  674. // AddChildRefIDs adds the "childRefs" edge to the ChildRef entity by ids.
  675. func (m *ChildMutation) AddChildRefIDs(ids ...int64) {
  676. if m.childRefs == nil {
  677. m.childRefs = make(map[int64]struct{})
  678. }
  679. for i := range ids {
  680. m.childRefs[ids[i]] = struct{}{}
  681. }
  682. }
  683. // ClearChildRefs clears the "childRefs" edge to the ChildRef entity.
  684. func (m *ChildMutation) ClearChildRefs() {
  685. m.clearedchildRefs = true
  686. }
  687. // ChildRefsCleared reports if the "childRefs" edge to the ChildRef entity was cleared.
  688. func (m *ChildMutation) ChildRefsCleared() bool {
  689. return m.clearedchildRefs
  690. }
  691. // RemoveChildRefIDs removes the "childRefs" edge to the ChildRef entity by IDs.
  692. func (m *ChildMutation) RemoveChildRefIDs(ids ...int64) {
  693. if m.removedchildRefs == nil {
  694. m.removedchildRefs = make(map[int64]struct{})
  695. }
  696. for i := range ids {
  697. delete(m.childRefs, ids[i])
  698. m.removedchildRefs[ids[i]] = struct{}{}
  699. }
  700. }
  701. // RemovedChildRefs returns the removed IDs of the "childRefs" edge to the ChildRef entity.
  702. func (m *ChildMutation) RemovedChildRefsIDs() (ids []int64) {
  703. for id := range m.removedchildRefs {
  704. ids = append(ids, id)
  705. }
  706. return
  707. }
  708. // ChildRefsIDs returns the "childRefs" edge IDs in the mutation.
  709. func (m *ChildMutation) ChildRefsIDs() (ids []int64) {
  710. for id := range m.childRefs {
  711. ids = append(ids, id)
  712. }
  713. return
  714. }
  715. // ResetChildRefs resets all changes to the "childRefs" edge.
  716. func (m *ChildMutation) ResetChildRefs() {
  717. m.childRefs = nil
  718. m.clearedchildRefs = false
  719. m.removedchildRefs = nil
  720. }
  721. // AddChildDeviceIDs adds the "childDevice" edge to the DeviceBind entity by ids.
  722. func (m *ChildMutation) AddChildDeviceIDs(ids ...int64) {
  723. if m.childDevice == nil {
  724. m.childDevice = make(map[int64]struct{})
  725. }
  726. for i := range ids {
  727. m.childDevice[ids[i]] = struct{}{}
  728. }
  729. }
  730. // ClearChildDevice clears the "childDevice" edge to the DeviceBind entity.
  731. func (m *ChildMutation) ClearChildDevice() {
  732. m.clearedchildDevice = true
  733. }
  734. // ChildDeviceCleared reports if the "childDevice" edge to the DeviceBind entity was cleared.
  735. func (m *ChildMutation) ChildDeviceCleared() bool {
  736. return m.clearedchildDevice
  737. }
  738. // RemoveChildDeviceIDs removes the "childDevice" edge to the DeviceBind entity by IDs.
  739. func (m *ChildMutation) RemoveChildDeviceIDs(ids ...int64) {
  740. if m.removedchildDevice == nil {
  741. m.removedchildDevice = make(map[int64]struct{})
  742. }
  743. for i := range ids {
  744. delete(m.childDevice, ids[i])
  745. m.removedchildDevice[ids[i]] = struct{}{}
  746. }
  747. }
  748. // RemovedChildDevice returns the removed IDs of the "childDevice" edge to the DeviceBind entity.
  749. func (m *ChildMutation) RemovedChildDeviceIDs() (ids []int64) {
  750. for id := range m.removedchildDevice {
  751. ids = append(ids, id)
  752. }
  753. return
  754. }
  755. // ChildDeviceIDs returns the "childDevice" edge IDs in the mutation.
  756. func (m *ChildMutation) ChildDeviceIDs() (ids []int64) {
  757. for id := range m.childDevice {
  758. ids = append(ids, id)
  759. }
  760. return
  761. }
  762. // ResetChildDevice resets all changes to the "childDevice" edge.
  763. func (m *ChildMutation) ResetChildDevice() {
  764. m.childDevice = nil
  765. m.clearedchildDevice = false
  766. m.removedchildDevice = nil
  767. }
  768. // AddChildContactIDs adds the "childContacts" edge to the Contacts entity by ids.
  769. func (m *ChildMutation) AddChildContactIDs(ids ...int) {
  770. if m.childContacts == nil {
  771. m.childContacts = make(map[int]struct{})
  772. }
  773. for i := range ids {
  774. m.childContacts[ids[i]] = struct{}{}
  775. }
  776. }
  777. // ClearChildContacts clears the "childContacts" edge to the Contacts entity.
  778. func (m *ChildMutation) ClearChildContacts() {
  779. m.clearedchildContacts = true
  780. }
  781. // ChildContactsCleared reports if the "childContacts" edge to the Contacts entity was cleared.
  782. func (m *ChildMutation) ChildContactsCleared() bool {
  783. return m.clearedchildContacts
  784. }
  785. // RemoveChildContactIDs removes the "childContacts" edge to the Contacts entity by IDs.
  786. func (m *ChildMutation) RemoveChildContactIDs(ids ...int) {
  787. if m.removedchildContacts == nil {
  788. m.removedchildContacts = make(map[int]struct{})
  789. }
  790. for i := range ids {
  791. delete(m.childContacts, ids[i])
  792. m.removedchildContacts[ids[i]] = struct{}{}
  793. }
  794. }
  795. // RemovedChildContacts returns the removed IDs of the "childContacts" edge to the Contacts entity.
  796. func (m *ChildMutation) RemovedChildContactsIDs() (ids []int) {
  797. for id := range m.removedchildContacts {
  798. ids = append(ids, id)
  799. }
  800. return
  801. }
  802. // ChildContactsIDs returns the "childContacts" edge IDs in the mutation.
  803. func (m *ChildMutation) ChildContactsIDs() (ids []int) {
  804. for id := range m.childContacts {
  805. ids = append(ids, id)
  806. }
  807. return
  808. }
  809. // ResetChildContacts resets all changes to the "childContacts" edge.
  810. func (m *ChildMutation) ResetChildContacts() {
  811. m.childContacts = nil
  812. m.clearedchildContacts = false
  813. m.removedchildContacts = nil
  814. }
  815. // Where appends a list predicates to the ChildMutation builder.
  816. func (m *ChildMutation) Where(ps ...predicate.Child) {
  817. m.predicates = append(m.predicates, ps...)
  818. }
  819. // WhereP appends storage-level predicates to the ChildMutation builder. Using this method,
  820. // users can use type-assertion to append predicates that do not depend on any generated package.
  821. func (m *ChildMutation) WhereP(ps ...func(*sql.Selector)) {
  822. p := make([]predicate.Child, len(ps))
  823. for i := range ps {
  824. p[i] = ps[i]
  825. }
  826. m.Where(p...)
  827. }
  828. // Op returns the operation name.
  829. func (m *ChildMutation) Op() Op {
  830. return m.op
  831. }
  832. // SetOp allows setting the mutation operation.
  833. func (m *ChildMutation) SetOp(op Op) {
  834. m.op = op
  835. }
  836. // Type returns the node type of this mutation (Child).
  837. func (m *ChildMutation) Type() string {
  838. return m.typ
  839. }
  840. // Fields returns all fields that were changed during this mutation. Note that in
  841. // order to get all numeric fields that were incremented/decremented, call
  842. // AddedFields().
  843. func (m *ChildMutation) Fields() []string {
  844. fields := make([]string, 0, 13)
  845. if m.created_at != nil {
  846. fields = append(fields, child.FieldCreatedAt)
  847. }
  848. if m.updated_at != nil {
  849. fields = append(fields, child.FieldUpdatedAt)
  850. }
  851. if m.deleted_at != nil {
  852. fields = append(fields, child.FieldDeletedAt)
  853. }
  854. if m.child_name != nil {
  855. fields = append(fields, child.FieldChildName)
  856. }
  857. if m.phone_number != nil {
  858. fields = append(fields, child.FieldPhoneNumber)
  859. }
  860. if m.area_code != nil {
  861. fields = append(fields, child.FieldAreaCode)
  862. }
  863. if m.avatar != nil {
  864. fields = append(fields, child.FieldAvatar)
  865. }
  866. if m.gender != nil {
  867. fields = append(fields, child.FieldGender)
  868. }
  869. if m.height != nil {
  870. fields = append(fields, child.FieldHeight)
  871. }
  872. if m.weight != nil {
  873. fields = append(fields, child.FieldWeight)
  874. }
  875. if m.birthday != nil {
  876. fields = append(fields, child.FieldBirthday)
  877. }
  878. if m.is_enable_block_unknown_call != nil {
  879. fields = append(fields, child.FieldIsEnableBlockUnknownCall)
  880. }
  881. if m.is_enable_fence != nil {
  882. fields = append(fields, child.FieldIsEnableFence)
  883. }
  884. return fields
  885. }
  886. // Field returns the value of a field with the given name. The second boolean
  887. // return value indicates that this field was not set, or was not defined in the
  888. // schema.
  889. func (m *ChildMutation) Field(name string) (ent.Value, bool) {
  890. switch name {
  891. case child.FieldCreatedAt:
  892. return m.CreatedAt()
  893. case child.FieldUpdatedAt:
  894. return m.UpdatedAt()
  895. case child.FieldDeletedAt:
  896. return m.DeletedAt()
  897. case child.FieldChildName:
  898. return m.ChildName()
  899. case child.FieldPhoneNumber:
  900. return m.PhoneNumber()
  901. case child.FieldAreaCode:
  902. return m.AreaCode()
  903. case child.FieldAvatar:
  904. return m.Avatar()
  905. case child.FieldGender:
  906. return m.Gender()
  907. case child.FieldHeight:
  908. return m.Height()
  909. case child.FieldWeight:
  910. return m.Weight()
  911. case child.FieldBirthday:
  912. return m.Birthday()
  913. case child.FieldIsEnableBlockUnknownCall:
  914. return m.IsEnableBlockUnknownCall()
  915. case child.FieldIsEnableFence:
  916. return m.IsEnableFence()
  917. }
  918. return nil, false
  919. }
  920. // OldField returns the old value of the field from the database. An error is
  921. // returned if the mutation operation is not UpdateOne, or the query to the
  922. // database failed.
  923. func (m *ChildMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  924. switch name {
  925. case child.FieldCreatedAt:
  926. return m.OldCreatedAt(ctx)
  927. case child.FieldUpdatedAt:
  928. return m.OldUpdatedAt(ctx)
  929. case child.FieldDeletedAt:
  930. return m.OldDeletedAt(ctx)
  931. case child.FieldChildName:
  932. return m.OldChildName(ctx)
  933. case child.FieldPhoneNumber:
  934. return m.OldPhoneNumber(ctx)
  935. case child.FieldAreaCode:
  936. return m.OldAreaCode(ctx)
  937. case child.FieldAvatar:
  938. return m.OldAvatar(ctx)
  939. case child.FieldGender:
  940. return m.OldGender(ctx)
  941. case child.FieldHeight:
  942. return m.OldHeight(ctx)
  943. case child.FieldWeight:
  944. return m.OldWeight(ctx)
  945. case child.FieldBirthday:
  946. return m.OldBirthday(ctx)
  947. case child.FieldIsEnableBlockUnknownCall:
  948. return m.OldIsEnableBlockUnknownCall(ctx)
  949. case child.FieldIsEnableFence:
  950. return m.OldIsEnableFence(ctx)
  951. }
  952. return nil, fmt.Errorf("unknown Child field %s", name)
  953. }
  954. // SetField sets the value of a field with the given name. It returns an error if
  955. // the field is not defined in the schema, or if the type mismatched the field
  956. // type.
  957. func (m *ChildMutation) SetField(name string, value ent.Value) error {
  958. switch name {
  959. case child.FieldCreatedAt:
  960. v, ok := value.(time.Time)
  961. if !ok {
  962. return fmt.Errorf("unexpected type %T for field %s", value, name)
  963. }
  964. m.SetCreatedAt(v)
  965. return nil
  966. case child.FieldUpdatedAt:
  967. v, ok := value.(time.Time)
  968. if !ok {
  969. return fmt.Errorf("unexpected type %T for field %s", value, name)
  970. }
  971. m.SetUpdatedAt(v)
  972. return nil
  973. case child.FieldDeletedAt:
  974. v, ok := value.(time.Time)
  975. if !ok {
  976. return fmt.Errorf("unexpected type %T for field %s", value, name)
  977. }
  978. m.SetDeletedAt(v)
  979. return nil
  980. case child.FieldChildName:
  981. v, ok := value.(string)
  982. if !ok {
  983. return fmt.Errorf("unexpected type %T for field %s", value, name)
  984. }
  985. m.SetChildName(v)
  986. return nil
  987. case child.FieldPhoneNumber:
  988. v, ok := value.(string)
  989. if !ok {
  990. return fmt.Errorf("unexpected type %T for field %s", value, name)
  991. }
  992. m.SetPhoneNumber(v)
  993. return nil
  994. case child.FieldAreaCode:
  995. v, ok := value.(string)
  996. if !ok {
  997. return fmt.Errorf("unexpected type %T for field %s", value, name)
  998. }
  999. m.SetAreaCode(v)
  1000. return nil
  1001. case child.FieldAvatar:
  1002. v, ok := value.(string)
  1003. if !ok {
  1004. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1005. }
  1006. m.SetAvatar(v)
  1007. return nil
  1008. case child.FieldGender:
  1009. v, ok := value.(int8)
  1010. if !ok {
  1011. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1012. }
  1013. m.SetGender(v)
  1014. return nil
  1015. case child.FieldHeight:
  1016. v, ok := value.(int32)
  1017. if !ok {
  1018. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1019. }
  1020. m.SetHeight(v)
  1021. return nil
  1022. case child.FieldWeight:
  1023. v, ok := value.(int32)
  1024. if !ok {
  1025. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1026. }
  1027. m.SetWeight(v)
  1028. return nil
  1029. case child.FieldBirthday:
  1030. v, ok := value.(string)
  1031. if !ok {
  1032. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1033. }
  1034. m.SetBirthday(v)
  1035. return nil
  1036. case child.FieldIsEnableBlockUnknownCall:
  1037. v, ok := value.(bool)
  1038. if !ok {
  1039. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1040. }
  1041. m.SetIsEnableBlockUnknownCall(v)
  1042. return nil
  1043. case child.FieldIsEnableFence:
  1044. v, ok := value.(bool)
  1045. if !ok {
  1046. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1047. }
  1048. m.SetIsEnableFence(v)
  1049. return nil
  1050. }
  1051. return fmt.Errorf("unknown Child field %s", name)
  1052. }
  1053. // AddedFields returns all numeric fields that were incremented/decremented during
  1054. // this mutation.
  1055. func (m *ChildMutation) AddedFields() []string {
  1056. var fields []string
  1057. if m.addgender != nil {
  1058. fields = append(fields, child.FieldGender)
  1059. }
  1060. if m.addheight != nil {
  1061. fields = append(fields, child.FieldHeight)
  1062. }
  1063. if m.addweight != nil {
  1064. fields = append(fields, child.FieldWeight)
  1065. }
  1066. return fields
  1067. }
  1068. // AddedField returns the numeric value that was incremented/decremented on a field
  1069. // with the given name. The second boolean return value indicates that this field
  1070. // was not set, or was not defined in the schema.
  1071. func (m *ChildMutation) AddedField(name string) (ent.Value, bool) {
  1072. switch name {
  1073. case child.FieldGender:
  1074. return m.AddedGender()
  1075. case child.FieldHeight:
  1076. return m.AddedHeight()
  1077. case child.FieldWeight:
  1078. return m.AddedWeight()
  1079. }
  1080. return nil, false
  1081. }
  1082. // AddField adds the value to the field with the given name. It returns an error if
  1083. // the field is not defined in the schema, or if the type mismatched the field
  1084. // type.
  1085. func (m *ChildMutation) AddField(name string, value ent.Value) error {
  1086. switch name {
  1087. case child.FieldGender:
  1088. v, ok := value.(int8)
  1089. if !ok {
  1090. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1091. }
  1092. m.AddGender(v)
  1093. return nil
  1094. case child.FieldHeight:
  1095. v, ok := value.(int32)
  1096. if !ok {
  1097. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1098. }
  1099. m.AddHeight(v)
  1100. return nil
  1101. case child.FieldWeight:
  1102. v, ok := value.(int32)
  1103. if !ok {
  1104. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1105. }
  1106. m.AddWeight(v)
  1107. return nil
  1108. }
  1109. return fmt.Errorf("unknown Child numeric field %s", name)
  1110. }
  1111. // ClearedFields returns all nullable fields that were cleared during this
  1112. // mutation.
  1113. func (m *ChildMutation) ClearedFields() []string {
  1114. var fields []string
  1115. if m.FieldCleared(child.FieldDeletedAt) {
  1116. fields = append(fields, child.FieldDeletedAt)
  1117. }
  1118. if m.FieldCleared(child.FieldAvatar) {
  1119. fields = append(fields, child.FieldAvatar)
  1120. }
  1121. if m.FieldCleared(child.FieldBirthday) {
  1122. fields = append(fields, child.FieldBirthday)
  1123. }
  1124. return fields
  1125. }
  1126. // FieldCleared returns a boolean indicating if a field with the given name was
  1127. // cleared in this mutation.
  1128. func (m *ChildMutation) FieldCleared(name string) bool {
  1129. _, ok := m.clearedFields[name]
  1130. return ok
  1131. }
  1132. // ClearField clears the value of the field with the given name. It returns an
  1133. // error if the field is not defined in the schema.
  1134. func (m *ChildMutation) ClearField(name string) error {
  1135. switch name {
  1136. case child.FieldDeletedAt:
  1137. m.ClearDeletedAt()
  1138. return nil
  1139. case child.FieldAvatar:
  1140. m.ClearAvatar()
  1141. return nil
  1142. case child.FieldBirthday:
  1143. m.ClearBirthday()
  1144. return nil
  1145. }
  1146. return fmt.Errorf("unknown Child nullable field %s", name)
  1147. }
  1148. // ResetField resets all changes in the mutation for the field with the given name.
  1149. // It returns an error if the field is not defined in the schema.
  1150. func (m *ChildMutation) ResetField(name string) error {
  1151. switch name {
  1152. case child.FieldCreatedAt:
  1153. m.ResetCreatedAt()
  1154. return nil
  1155. case child.FieldUpdatedAt:
  1156. m.ResetUpdatedAt()
  1157. return nil
  1158. case child.FieldDeletedAt:
  1159. m.ResetDeletedAt()
  1160. return nil
  1161. case child.FieldChildName:
  1162. m.ResetChildName()
  1163. return nil
  1164. case child.FieldPhoneNumber:
  1165. m.ResetPhoneNumber()
  1166. return nil
  1167. case child.FieldAreaCode:
  1168. m.ResetAreaCode()
  1169. return nil
  1170. case child.FieldAvatar:
  1171. m.ResetAvatar()
  1172. return nil
  1173. case child.FieldGender:
  1174. m.ResetGender()
  1175. return nil
  1176. case child.FieldHeight:
  1177. m.ResetHeight()
  1178. return nil
  1179. case child.FieldWeight:
  1180. m.ResetWeight()
  1181. return nil
  1182. case child.FieldBirthday:
  1183. m.ResetBirthday()
  1184. return nil
  1185. case child.FieldIsEnableBlockUnknownCall:
  1186. m.ResetIsEnableBlockUnknownCall()
  1187. return nil
  1188. case child.FieldIsEnableFence:
  1189. m.ResetIsEnableFence()
  1190. return nil
  1191. }
  1192. return fmt.Errorf("unknown Child field %s", name)
  1193. }
  1194. // AddedEdges returns all edge names that were set/added in this mutation.
  1195. func (m *ChildMutation) AddedEdges() []string {
  1196. edges := make([]string, 0, 3)
  1197. if m.childRefs != nil {
  1198. edges = append(edges, child.EdgeChildRefs)
  1199. }
  1200. if m.childDevice != nil {
  1201. edges = append(edges, child.EdgeChildDevice)
  1202. }
  1203. if m.childContacts != nil {
  1204. edges = append(edges, child.EdgeChildContacts)
  1205. }
  1206. return edges
  1207. }
  1208. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  1209. // name in this mutation.
  1210. func (m *ChildMutation) AddedIDs(name string) []ent.Value {
  1211. switch name {
  1212. case child.EdgeChildRefs:
  1213. ids := make([]ent.Value, 0, len(m.childRefs))
  1214. for id := range m.childRefs {
  1215. ids = append(ids, id)
  1216. }
  1217. return ids
  1218. case child.EdgeChildDevice:
  1219. ids := make([]ent.Value, 0, len(m.childDevice))
  1220. for id := range m.childDevice {
  1221. ids = append(ids, id)
  1222. }
  1223. return ids
  1224. case child.EdgeChildContacts:
  1225. ids := make([]ent.Value, 0, len(m.childContacts))
  1226. for id := range m.childContacts {
  1227. ids = append(ids, id)
  1228. }
  1229. return ids
  1230. }
  1231. return nil
  1232. }
  1233. // RemovedEdges returns all edge names that were removed in this mutation.
  1234. func (m *ChildMutation) RemovedEdges() []string {
  1235. edges := make([]string, 0, 3)
  1236. if m.removedchildRefs != nil {
  1237. edges = append(edges, child.EdgeChildRefs)
  1238. }
  1239. if m.removedchildDevice != nil {
  1240. edges = append(edges, child.EdgeChildDevice)
  1241. }
  1242. if m.removedchildContacts != nil {
  1243. edges = append(edges, child.EdgeChildContacts)
  1244. }
  1245. return edges
  1246. }
  1247. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  1248. // the given name in this mutation.
  1249. func (m *ChildMutation) RemovedIDs(name string) []ent.Value {
  1250. switch name {
  1251. case child.EdgeChildRefs:
  1252. ids := make([]ent.Value, 0, len(m.removedchildRefs))
  1253. for id := range m.removedchildRefs {
  1254. ids = append(ids, id)
  1255. }
  1256. return ids
  1257. case child.EdgeChildDevice:
  1258. ids := make([]ent.Value, 0, len(m.removedchildDevice))
  1259. for id := range m.removedchildDevice {
  1260. ids = append(ids, id)
  1261. }
  1262. return ids
  1263. case child.EdgeChildContacts:
  1264. ids := make([]ent.Value, 0, len(m.removedchildContacts))
  1265. for id := range m.removedchildContacts {
  1266. ids = append(ids, id)
  1267. }
  1268. return ids
  1269. }
  1270. return nil
  1271. }
  1272. // ClearedEdges returns all edge names that were cleared in this mutation.
  1273. func (m *ChildMutation) ClearedEdges() []string {
  1274. edges := make([]string, 0, 3)
  1275. if m.clearedchildRefs {
  1276. edges = append(edges, child.EdgeChildRefs)
  1277. }
  1278. if m.clearedchildDevice {
  1279. edges = append(edges, child.EdgeChildDevice)
  1280. }
  1281. if m.clearedchildContacts {
  1282. edges = append(edges, child.EdgeChildContacts)
  1283. }
  1284. return edges
  1285. }
  1286. // EdgeCleared returns a boolean which indicates if the edge with the given name
  1287. // was cleared in this mutation.
  1288. func (m *ChildMutation) EdgeCleared(name string) bool {
  1289. switch name {
  1290. case child.EdgeChildRefs:
  1291. return m.clearedchildRefs
  1292. case child.EdgeChildDevice:
  1293. return m.clearedchildDevice
  1294. case child.EdgeChildContacts:
  1295. return m.clearedchildContacts
  1296. }
  1297. return false
  1298. }
  1299. // ClearEdge clears the value of the edge with the given name. It returns an error
  1300. // if that edge is not defined in the schema.
  1301. func (m *ChildMutation) ClearEdge(name string) error {
  1302. switch name {
  1303. }
  1304. return fmt.Errorf("unknown Child unique edge %s", name)
  1305. }
  1306. // ResetEdge resets all changes to the edge with the given name in this mutation.
  1307. // It returns an error if the edge is not defined in the schema.
  1308. func (m *ChildMutation) ResetEdge(name string) error {
  1309. switch name {
  1310. case child.EdgeChildRefs:
  1311. m.ResetChildRefs()
  1312. return nil
  1313. case child.EdgeChildDevice:
  1314. m.ResetChildDevice()
  1315. return nil
  1316. case child.EdgeChildContacts:
  1317. m.ResetChildContacts()
  1318. return nil
  1319. }
  1320. return fmt.Errorf("unknown Child edge %s", name)
  1321. }
  1322. // ChildRefMutation represents an operation that mutates the ChildRef nodes in the graph.
  1323. type ChildRefMutation struct {
  1324. config
  1325. op Op
  1326. typ string
  1327. id *int64
  1328. created_at *time.Time
  1329. updated_at *time.Time
  1330. deleted_at *time.Time
  1331. clearedFields map[string]struct{}
  1332. child *uuid.UUID
  1333. clearedchild bool
  1334. user *uuid.UUID
  1335. cleareduser bool
  1336. done bool
  1337. oldValue func(context.Context) (*ChildRef, error)
  1338. predicates []predicate.ChildRef
  1339. }
  1340. var _ ent.Mutation = (*ChildRefMutation)(nil)
  1341. // childrefOption allows management of the mutation configuration using functional options.
  1342. type childrefOption func(*ChildRefMutation)
  1343. // newChildRefMutation creates new mutation for the ChildRef entity.
  1344. func newChildRefMutation(c config, op Op, opts ...childrefOption) *ChildRefMutation {
  1345. m := &ChildRefMutation{
  1346. config: c,
  1347. op: op,
  1348. typ: TypeChildRef,
  1349. clearedFields: make(map[string]struct{}),
  1350. }
  1351. for _, opt := range opts {
  1352. opt(m)
  1353. }
  1354. return m
  1355. }
  1356. // withChildRefID sets the ID field of the mutation.
  1357. func withChildRefID(id int64) childrefOption {
  1358. return func(m *ChildRefMutation) {
  1359. var (
  1360. err error
  1361. once sync.Once
  1362. value *ChildRef
  1363. )
  1364. m.oldValue = func(ctx context.Context) (*ChildRef, error) {
  1365. once.Do(func() {
  1366. if m.done {
  1367. err = errors.New("querying old values post mutation is not allowed")
  1368. } else {
  1369. value, err = m.Client().ChildRef.Get(ctx, id)
  1370. }
  1371. })
  1372. return value, err
  1373. }
  1374. m.id = &id
  1375. }
  1376. }
  1377. // withChildRef sets the old ChildRef of the mutation.
  1378. func withChildRef(node *ChildRef) childrefOption {
  1379. return func(m *ChildRefMutation) {
  1380. m.oldValue = func(context.Context) (*ChildRef, error) {
  1381. return node, nil
  1382. }
  1383. m.id = &node.ID
  1384. }
  1385. }
  1386. // Client returns a new `ent.Client` from the mutation. If the mutation was
  1387. // executed in a transaction (ent.Tx), a transactional client is returned.
  1388. func (m ChildRefMutation) Client() *Client {
  1389. client := &Client{config: m.config}
  1390. client.init()
  1391. return client
  1392. }
  1393. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  1394. // it returns an error otherwise.
  1395. func (m ChildRefMutation) Tx() (*Tx, error) {
  1396. if _, ok := m.driver.(*txDriver); !ok {
  1397. return nil, errors.New("ent: mutation is not running in a transaction")
  1398. }
  1399. tx := &Tx{config: m.config}
  1400. tx.init()
  1401. return tx, nil
  1402. }
  1403. // SetID sets the value of the id field. Note that this
  1404. // operation is only accepted on creation of ChildRef entities.
  1405. func (m *ChildRefMutation) SetID(id int64) {
  1406. m.id = &id
  1407. }
  1408. // ID returns the ID value in the mutation. Note that the ID is only available
  1409. // if it was provided to the builder or after it was returned from the database.
  1410. func (m *ChildRefMutation) ID() (id int64, exists bool) {
  1411. if m.id == nil {
  1412. return
  1413. }
  1414. return *m.id, true
  1415. }
  1416. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  1417. // That means, if the mutation is applied within a transaction with an isolation level such
  1418. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  1419. // or updated by the mutation.
  1420. func (m *ChildRefMutation) IDs(ctx context.Context) ([]int64, error) {
  1421. switch {
  1422. case m.op.Is(OpUpdateOne | OpDeleteOne):
  1423. id, exists := m.ID()
  1424. if exists {
  1425. return []int64{id}, nil
  1426. }
  1427. fallthrough
  1428. case m.op.Is(OpUpdate | OpDelete):
  1429. return m.Client().ChildRef.Query().Where(m.predicates...).IDs(ctx)
  1430. default:
  1431. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  1432. }
  1433. }
  1434. // SetCreatedAt sets the "created_at" field.
  1435. func (m *ChildRefMutation) SetCreatedAt(t time.Time) {
  1436. m.created_at = &t
  1437. }
  1438. // CreatedAt returns the value of the "created_at" field in the mutation.
  1439. func (m *ChildRefMutation) CreatedAt() (r time.Time, exists bool) {
  1440. v := m.created_at
  1441. if v == nil {
  1442. return
  1443. }
  1444. return *v, true
  1445. }
  1446. // OldCreatedAt returns the old "created_at" field's value of the ChildRef entity.
  1447. // If the ChildRef object wasn't provided to the builder, the object is fetched from the database.
  1448. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1449. func (m *ChildRefMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  1450. if !m.op.Is(OpUpdateOne) {
  1451. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  1452. }
  1453. if m.id == nil || m.oldValue == nil {
  1454. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  1455. }
  1456. oldValue, err := m.oldValue(ctx)
  1457. if err != nil {
  1458. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  1459. }
  1460. return oldValue.CreatedAt, nil
  1461. }
  1462. // ResetCreatedAt resets all changes to the "created_at" field.
  1463. func (m *ChildRefMutation) ResetCreatedAt() {
  1464. m.created_at = nil
  1465. }
  1466. // SetUpdatedAt sets the "updated_at" field.
  1467. func (m *ChildRefMutation) SetUpdatedAt(t time.Time) {
  1468. m.updated_at = &t
  1469. }
  1470. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  1471. func (m *ChildRefMutation) UpdatedAt() (r time.Time, exists bool) {
  1472. v := m.updated_at
  1473. if v == nil {
  1474. return
  1475. }
  1476. return *v, true
  1477. }
  1478. // OldUpdatedAt returns the old "updated_at" field's value of the ChildRef entity.
  1479. // If the ChildRef object wasn't provided to the builder, the object is fetched from the database.
  1480. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1481. func (m *ChildRefMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  1482. if !m.op.Is(OpUpdateOne) {
  1483. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  1484. }
  1485. if m.id == nil || m.oldValue == nil {
  1486. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  1487. }
  1488. oldValue, err := m.oldValue(ctx)
  1489. if err != nil {
  1490. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  1491. }
  1492. return oldValue.UpdatedAt, nil
  1493. }
  1494. // ResetUpdatedAt resets all changes to the "updated_at" field.
  1495. func (m *ChildRefMutation) ResetUpdatedAt() {
  1496. m.updated_at = nil
  1497. }
  1498. // SetDeletedAt sets the "deleted_at" field.
  1499. func (m *ChildRefMutation) SetDeletedAt(t time.Time) {
  1500. m.deleted_at = &t
  1501. }
  1502. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  1503. func (m *ChildRefMutation) DeletedAt() (r time.Time, exists bool) {
  1504. v := m.deleted_at
  1505. if v == nil {
  1506. return
  1507. }
  1508. return *v, true
  1509. }
  1510. // OldDeletedAt returns the old "deleted_at" field's value of the ChildRef entity.
  1511. // If the ChildRef object wasn't provided to the builder, the object is fetched from the database.
  1512. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1513. func (m *ChildRefMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
  1514. if !m.op.Is(OpUpdateOne) {
  1515. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  1516. }
  1517. if m.id == nil || m.oldValue == nil {
  1518. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  1519. }
  1520. oldValue, err := m.oldValue(ctx)
  1521. if err != nil {
  1522. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  1523. }
  1524. return oldValue.DeletedAt, nil
  1525. }
  1526. // ClearDeletedAt clears the value of the "deleted_at" field.
  1527. func (m *ChildRefMutation) ClearDeletedAt() {
  1528. m.deleted_at = nil
  1529. m.clearedFields[childref.FieldDeletedAt] = struct{}{}
  1530. }
  1531. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  1532. func (m *ChildRefMutation) DeletedAtCleared() bool {
  1533. _, ok := m.clearedFields[childref.FieldDeletedAt]
  1534. return ok
  1535. }
  1536. // ResetDeletedAt resets all changes to the "deleted_at" field.
  1537. func (m *ChildRefMutation) ResetDeletedAt() {
  1538. m.deleted_at = nil
  1539. delete(m.clearedFields, childref.FieldDeletedAt)
  1540. }
  1541. // SetUserID sets the "user_id" field.
  1542. func (m *ChildRefMutation) SetUserID(u uuid.UUID) {
  1543. m.user = &u
  1544. }
  1545. // UserID returns the value of the "user_id" field in the mutation.
  1546. func (m *ChildRefMutation) UserID() (r uuid.UUID, exists bool) {
  1547. v := m.user
  1548. if v == nil {
  1549. return
  1550. }
  1551. return *v, true
  1552. }
  1553. // OldUserID returns the old "user_id" field's value of the ChildRef entity.
  1554. // If the ChildRef object wasn't provided to the builder, the object is fetched from the database.
  1555. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1556. func (m *ChildRefMutation) OldUserID(ctx context.Context) (v uuid.UUID, err error) {
  1557. if !m.op.Is(OpUpdateOne) {
  1558. return v, errors.New("OldUserID is only allowed on UpdateOne operations")
  1559. }
  1560. if m.id == nil || m.oldValue == nil {
  1561. return v, errors.New("OldUserID requires an ID field in the mutation")
  1562. }
  1563. oldValue, err := m.oldValue(ctx)
  1564. if err != nil {
  1565. return v, fmt.Errorf("querying old value for OldUserID: %w", err)
  1566. }
  1567. return oldValue.UserID, nil
  1568. }
  1569. // ClearUserID clears the value of the "user_id" field.
  1570. func (m *ChildRefMutation) ClearUserID() {
  1571. m.user = nil
  1572. m.clearedFields[childref.FieldUserID] = struct{}{}
  1573. }
  1574. // UserIDCleared returns if the "user_id" field was cleared in this mutation.
  1575. func (m *ChildRefMutation) UserIDCleared() bool {
  1576. _, ok := m.clearedFields[childref.FieldUserID]
  1577. return ok
  1578. }
  1579. // ResetUserID resets all changes to the "user_id" field.
  1580. func (m *ChildRefMutation) ResetUserID() {
  1581. m.user = nil
  1582. delete(m.clearedFields, childref.FieldUserID)
  1583. }
  1584. // SetChildID sets the "child_id" field.
  1585. func (m *ChildRefMutation) SetChildID(u uuid.UUID) {
  1586. m.child = &u
  1587. }
  1588. // ChildID returns the value of the "child_id" field in the mutation.
  1589. func (m *ChildRefMutation) ChildID() (r uuid.UUID, exists bool) {
  1590. v := m.child
  1591. if v == nil {
  1592. return
  1593. }
  1594. return *v, true
  1595. }
  1596. // OldChildID returns the old "child_id" field's value of the ChildRef entity.
  1597. // If the ChildRef object wasn't provided to the builder, the object is fetched from the database.
  1598. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1599. func (m *ChildRefMutation) OldChildID(ctx context.Context) (v uuid.UUID, err error) {
  1600. if !m.op.Is(OpUpdateOne) {
  1601. return v, errors.New("OldChildID is only allowed on UpdateOne operations")
  1602. }
  1603. if m.id == nil || m.oldValue == nil {
  1604. return v, errors.New("OldChildID requires an ID field in the mutation")
  1605. }
  1606. oldValue, err := m.oldValue(ctx)
  1607. if err != nil {
  1608. return v, fmt.Errorf("querying old value for OldChildID: %w", err)
  1609. }
  1610. return oldValue.ChildID, nil
  1611. }
  1612. // ClearChildID clears the value of the "child_id" field.
  1613. func (m *ChildRefMutation) ClearChildID() {
  1614. m.child = nil
  1615. m.clearedFields[childref.FieldChildID] = struct{}{}
  1616. }
  1617. // ChildIDCleared returns if the "child_id" field was cleared in this mutation.
  1618. func (m *ChildRefMutation) ChildIDCleared() bool {
  1619. _, ok := m.clearedFields[childref.FieldChildID]
  1620. return ok
  1621. }
  1622. // ResetChildID resets all changes to the "child_id" field.
  1623. func (m *ChildRefMutation) ResetChildID() {
  1624. m.child = nil
  1625. delete(m.clearedFields, childref.FieldChildID)
  1626. }
  1627. // ClearChild clears the "child" edge to the Child entity.
  1628. func (m *ChildRefMutation) ClearChild() {
  1629. m.clearedchild = true
  1630. m.clearedFields[childref.FieldChildID] = struct{}{}
  1631. }
  1632. // ChildCleared reports if the "child" edge to the Child entity was cleared.
  1633. func (m *ChildRefMutation) ChildCleared() bool {
  1634. return m.ChildIDCleared() || m.clearedchild
  1635. }
  1636. // ChildIDs returns the "child" edge IDs in the mutation.
  1637. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  1638. // ChildID instead. It exists only for internal usage by the builders.
  1639. func (m *ChildRefMutation) ChildIDs() (ids []uuid.UUID) {
  1640. if id := m.child; id != nil {
  1641. ids = append(ids, *id)
  1642. }
  1643. return
  1644. }
  1645. // ResetChild resets all changes to the "child" edge.
  1646. func (m *ChildRefMutation) ResetChild() {
  1647. m.child = nil
  1648. m.clearedchild = false
  1649. }
  1650. // ClearUser clears the "user" edge to the User entity.
  1651. func (m *ChildRefMutation) ClearUser() {
  1652. m.cleareduser = true
  1653. m.clearedFields[childref.FieldUserID] = struct{}{}
  1654. }
  1655. // UserCleared reports if the "user" edge to the User entity was cleared.
  1656. func (m *ChildRefMutation) UserCleared() bool {
  1657. return m.UserIDCleared() || m.cleareduser
  1658. }
  1659. // UserIDs returns the "user" edge IDs in the mutation.
  1660. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  1661. // UserID instead. It exists only for internal usage by the builders.
  1662. func (m *ChildRefMutation) UserIDs() (ids []uuid.UUID) {
  1663. if id := m.user; id != nil {
  1664. ids = append(ids, *id)
  1665. }
  1666. return
  1667. }
  1668. // ResetUser resets all changes to the "user" edge.
  1669. func (m *ChildRefMutation) ResetUser() {
  1670. m.user = nil
  1671. m.cleareduser = false
  1672. }
  1673. // Where appends a list predicates to the ChildRefMutation builder.
  1674. func (m *ChildRefMutation) Where(ps ...predicate.ChildRef) {
  1675. m.predicates = append(m.predicates, ps...)
  1676. }
  1677. // WhereP appends storage-level predicates to the ChildRefMutation builder. Using this method,
  1678. // users can use type-assertion to append predicates that do not depend on any generated package.
  1679. func (m *ChildRefMutation) WhereP(ps ...func(*sql.Selector)) {
  1680. p := make([]predicate.ChildRef, len(ps))
  1681. for i := range ps {
  1682. p[i] = ps[i]
  1683. }
  1684. m.Where(p...)
  1685. }
  1686. // Op returns the operation name.
  1687. func (m *ChildRefMutation) Op() Op {
  1688. return m.op
  1689. }
  1690. // SetOp allows setting the mutation operation.
  1691. func (m *ChildRefMutation) SetOp(op Op) {
  1692. m.op = op
  1693. }
  1694. // Type returns the node type of this mutation (ChildRef).
  1695. func (m *ChildRefMutation) Type() string {
  1696. return m.typ
  1697. }
  1698. // Fields returns all fields that were changed during this mutation. Note that in
  1699. // order to get all numeric fields that were incremented/decremented, call
  1700. // AddedFields().
  1701. func (m *ChildRefMutation) Fields() []string {
  1702. fields := make([]string, 0, 5)
  1703. if m.created_at != nil {
  1704. fields = append(fields, childref.FieldCreatedAt)
  1705. }
  1706. if m.updated_at != nil {
  1707. fields = append(fields, childref.FieldUpdatedAt)
  1708. }
  1709. if m.deleted_at != nil {
  1710. fields = append(fields, childref.FieldDeletedAt)
  1711. }
  1712. if m.user != nil {
  1713. fields = append(fields, childref.FieldUserID)
  1714. }
  1715. if m.child != nil {
  1716. fields = append(fields, childref.FieldChildID)
  1717. }
  1718. return fields
  1719. }
  1720. // Field returns the value of a field with the given name. The second boolean
  1721. // return value indicates that this field was not set, or was not defined in the
  1722. // schema.
  1723. func (m *ChildRefMutation) Field(name string) (ent.Value, bool) {
  1724. switch name {
  1725. case childref.FieldCreatedAt:
  1726. return m.CreatedAt()
  1727. case childref.FieldUpdatedAt:
  1728. return m.UpdatedAt()
  1729. case childref.FieldDeletedAt:
  1730. return m.DeletedAt()
  1731. case childref.FieldUserID:
  1732. return m.UserID()
  1733. case childref.FieldChildID:
  1734. return m.ChildID()
  1735. }
  1736. return nil, false
  1737. }
  1738. // OldField returns the old value of the field from the database. An error is
  1739. // returned if the mutation operation is not UpdateOne, or the query to the
  1740. // database failed.
  1741. func (m *ChildRefMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  1742. switch name {
  1743. case childref.FieldCreatedAt:
  1744. return m.OldCreatedAt(ctx)
  1745. case childref.FieldUpdatedAt:
  1746. return m.OldUpdatedAt(ctx)
  1747. case childref.FieldDeletedAt:
  1748. return m.OldDeletedAt(ctx)
  1749. case childref.FieldUserID:
  1750. return m.OldUserID(ctx)
  1751. case childref.FieldChildID:
  1752. return m.OldChildID(ctx)
  1753. }
  1754. return nil, fmt.Errorf("unknown ChildRef field %s", name)
  1755. }
  1756. // SetField sets the value of a field with the given name. It returns an error if
  1757. // the field is not defined in the schema, or if the type mismatched the field
  1758. // type.
  1759. func (m *ChildRefMutation) SetField(name string, value ent.Value) error {
  1760. switch name {
  1761. case childref.FieldCreatedAt:
  1762. v, ok := value.(time.Time)
  1763. if !ok {
  1764. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1765. }
  1766. m.SetCreatedAt(v)
  1767. return nil
  1768. case childref.FieldUpdatedAt:
  1769. v, ok := value.(time.Time)
  1770. if !ok {
  1771. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1772. }
  1773. m.SetUpdatedAt(v)
  1774. return nil
  1775. case childref.FieldDeletedAt:
  1776. v, ok := value.(time.Time)
  1777. if !ok {
  1778. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1779. }
  1780. m.SetDeletedAt(v)
  1781. return nil
  1782. case childref.FieldUserID:
  1783. v, ok := value.(uuid.UUID)
  1784. if !ok {
  1785. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1786. }
  1787. m.SetUserID(v)
  1788. return nil
  1789. case childref.FieldChildID:
  1790. v, ok := value.(uuid.UUID)
  1791. if !ok {
  1792. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1793. }
  1794. m.SetChildID(v)
  1795. return nil
  1796. }
  1797. return fmt.Errorf("unknown ChildRef field %s", name)
  1798. }
  1799. // AddedFields returns all numeric fields that were incremented/decremented during
  1800. // this mutation.
  1801. func (m *ChildRefMutation) AddedFields() []string {
  1802. return nil
  1803. }
  1804. // AddedField returns the numeric value that was incremented/decremented on a field
  1805. // with the given name. The second boolean return value indicates that this field
  1806. // was not set, or was not defined in the schema.
  1807. func (m *ChildRefMutation) AddedField(name string) (ent.Value, bool) {
  1808. return nil, false
  1809. }
  1810. // AddField adds the value to the field with the given name. It returns an error if
  1811. // the field is not defined in the schema, or if the type mismatched the field
  1812. // type.
  1813. func (m *ChildRefMutation) AddField(name string, value ent.Value) error {
  1814. switch name {
  1815. }
  1816. return fmt.Errorf("unknown ChildRef numeric field %s", name)
  1817. }
  1818. // ClearedFields returns all nullable fields that were cleared during this
  1819. // mutation.
  1820. func (m *ChildRefMutation) ClearedFields() []string {
  1821. var fields []string
  1822. if m.FieldCleared(childref.FieldDeletedAt) {
  1823. fields = append(fields, childref.FieldDeletedAt)
  1824. }
  1825. if m.FieldCleared(childref.FieldUserID) {
  1826. fields = append(fields, childref.FieldUserID)
  1827. }
  1828. if m.FieldCleared(childref.FieldChildID) {
  1829. fields = append(fields, childref.FieldChildID)
  1830. }
  1831. return fields
  1832. }
  1833. // FieldCleared returns a boolean indicating if a field with the given name was
  1834. // cleared in this mutation.
  1835. func (m *ChildRefMutation) FieldCleared(name string) bool {
  1836. _, ok := m.clearedFields[name]
  1837. return ok
  1838. }
  1839. // ClearField clears the value of the field with the given name. It returns an
  1840. // error if the field is not defined in the schema.
  1841. func (m *ChildRefMutation) ClearField(name string) error {
  1842. switch name {
  1843. case childref.FieldDeletedAt:
  1844. m.ClearDeletedAt()
  1845. return nil
  1846. case childref.FieldUserID:
  1847. m.ClearUserID()
  1848. return nil
  1849. case childref.FieldChildID:
  1850. m.ClearChildID()
  1851. return nil
  1852. }
  1853. return fmt.Errorf("unknown ChildRef nullable field %s", name)
  1854. }
  1855. // ResetField resets all changes in the mutation for the field with the given name.
  1856. // It returns an error if the field is not defined in the schema.
  1857. func (m *ChildRefMutation) ResetField(name string) error {
  1858. switch name {
  1859. case childref.FieldCreatedAt:
  1860. m.ResetCreatedAt()
  1861. return nil
  1862. case childref.FieldUpdatedAt:
  1863. m.ResetUpdatedAt()
  1864. return nil
  1865. case childref.FieldDeletedAt:
  1866. m.ResetDeletedAt()
  1867. return nil
  1868. case childref.FieldUserID:
  1869. m.ResetUserID()
  1870. return nil
  1871. case childref.FieldChildID:
  1872. m.ResetChildID()
  1873. return nil
  1874. }
  1875. return fmt.Errorf("unknown ChildRef field %s", name)
  1876. }
  1877. // AddedEdges returns all edge names that were set/added in this mutation.
  1878. func (m *ChildRefMutation) AddedEdges() []string {
  1879. edges := make([]string, 0, 2)
  1880. if m.child != nil {
  1881. edges = append(edges, childref.EdgeChild)
  1882. }
  1883. if m.user != nil {
  1884. edges = append(edges, childref.EdgeUser)
  1885. }
  1886. return edges
  1887. }
  1888. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  1889. // name in this mutation.
  1890. func (m *ChildRefMutation) AddedIDs(name string) []ent.Value {
  1891. switch name {
  1892. case childref.EdgeChild:
  1893. if id := m.child; id != nil {
  1894. return []ent.Value{*id}
  1895. }
  1896. case childref.EdgeUser:
  1897. if id := m.user; id != nil {
  1898. return []ent.Value{*id}
  1899. }
  1900. }
  1901. return nil
  1902. }
  1903. // RemovedEdges returns all edge names that were removed in this mutation.
  1904. func (m *ChildRefMutation) RemovedEdges() []string {
  1905. edges := make([]string, 0, 2)
  1906. return edges
  1907. }
  1908. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  1909. // the given name in this mutation.
  1910. func (m *ChildRefMutation) RemovedIDs(name string) []ent.Value {
  1911. return nil
  1912. }
  1913. // ClearedEdges returns all edge names that were cleared in this mutation.
  1914. func (m *ChildRefMutation) ClearedEdges() []string {
  1915. edges := make([]string, 0, 2)
  1916. if m.clearedchild {
  1917. edges = append(edges, childref.EdgeChild)
  1918. }
  1919. if m.cleareduser {
  1920. edges = append(edges, childref.EdgeUser)
  1921. }
  1922. return edges
  1923. }
  1924. // EdgeCleared returns a boolean which indicates if the edge with the given name
  1925. // was cleared in this mutation.
  1926. func (m *ChildRefMutation) EdgeCleared(name string) bool {
  1927. switch name {
  1928. case childref.EdgeChild:
  1929. return m.clearedchild
  1930. case childref.EdgeUser:
  1931. return m.cleareduser
  1932. }
  1933. return false
  1934. }
  1935. // ClearEdge clears the value of the edge with the given name. It returns an error
  1936. // if that edge is not defined in the schema.
  1937. func (m *ChildRefMutation) ClearEdge(name string) error {
  1938. switch name {
  1939. case childref.EdgeChild:
  1940. m.ClearChild()
  1941. return nil
  1942. case childref.EdgeUser:
  1943. m.ClearUser()
  1944. return nil
  1945. }
  1946. return fmt.Errorf("unknown ChildRef unique edge %s", name)
  1947. }
  1948. // ResetEdge resets all changes to the edge with the given name in this mutation.
  1949. // It returns an error if the edge is not defined in the schema.
  1950. func (m *ChildRefMutation) ResetEdge(name string) error {
  1951. switch name {
  1952. case childref.EdgeChild:
  1953. m.ResetChild()
  1954. return nil
  1955. case childref.EdgeUser:
  1956. m.ResetUser()
  1957. return nil
  1958. }
  1959. return fmt.Errorf("unknown ChildRef edge %s", name)
  1960. }
  1961. // ContactsMutation represents an operation that mutates the Contacts nodes in the graph.
  1962. type ContactsMutation struct {
  1963. config
  1964. op Op
  1965. typ string
  1966. id *int
  1967. created_at *time.Time
  1968. updated_at *time.Time
  1969. deleted_at *time.Time
  1970. ref_id *uuid.UUID
  1971. ref_type *contacts.RefType
  1972. remark_name *string
  1973. remark_avatar *string
  1974. clearedFields map[string]struct{}
  1975. child *uuid.UUID
  1976. clearedchild bool
  1977. done bool
  1978. oldValue func(context.Context) (*Contacts, error)
  1979. predicates []predicate.Contacts
  1980. }
  1981. var _ ent.Mutation = (*ContactsMutation)(nil)
  1982. // contactsOption allows management of the mutation configuration using functional options.
  1983. type contactsOption func(*ContactsMutation)
  1984. // newContactsMutation creates new mutation for the Contacts entity.
  1985. func newContactsMutation(c config, op Op, opts ...contactsOption) *ContactsMutation {
  1986. m := &ContactsMutation{
  1987. config: c,
  1988. op: op,
  1989. typ: TypeContacts,
  1990. clearedFields: make(map[string]struct{}),
  1991. }
  1992. for _, opt := range opts {
  1993. opt(m)
  1994. }
  1995. return m
  1996. }
  1997. // withContactsID sets the ID field of the mutation.
  1998. func withContactsID(id int) contactsOption {
  1999. return func(m *ContactsMutation) {
  2000. var (
  2001. err error
  2002. once sync.Once
  2003. value *Contacts
  2004. )
  2005. m.oldValue = func(ctx context.Context) (*Contacts, error) {
  2006. once.Do(func() {
  2007. if m.done {
  2008. err = errors.New("querying old values post mutation is not allowed")
  2009. } else {
  2010. value, err = m.Client().Contacts.Get(ctx, id)
  2011. }
  2012. })
  2013. return value, err
  2014. }
  2015. m.id = &id
  2016. }
  2017. }
  2018. // withContacts sets the old Contacts of the mutation.
  2019. func withContacts(node *Contacts) contactsOption {
  2020. return func(m *ContactsMutation) {
  2021. m.oldValue = func(context.Context) (*Contacts, error) {
  2022. return node, nil
  2023. }
  2024. m.id = &node.ID
  2025. }
  2026. }
  2027. // Client returns a new `ent.Client` from the mutation. If the mutation was
  2028. // executed in a transaction (ent.Tx), a transactional client is returned.
  2029. func (m ContactsMutation) Client() *Client {
  2030. client := &Client{config: m.config}
  2031. client.init()
  2032. return client
  2033. }
  2034. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  2035. // it returns an error otherwise.
  2036. func (m ContactsMutation) Tx() (*Tx, error) {
  2037. if _, ok := m.driver.(*txDriver); !ok {
  2038. return nil, errors.New("ent: mutation is not running in a transaction")
  2039. }
  2040. tx := &Tx{config: m.config}
  2041. tx.init()
  2042. return tx, nil
  2043. }
  2044. // ID returns the ID value in the mutation. Note that the ID is only available
  2045. // if it was provided to the builder or after it was returned from the database.
  2046. func (m *ContactsMutation) ID() (id int, exists bool) {
  2047. if m.id == nil {
  2048. return
  2049. }
  2050. return *m.id, true
  2051. }
  2052. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  2053. // That means, if the mutation is applied within a transaction with an isolation level such
  2054. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  2055. // or updated by the mutation.
  2056. func (m *ContactsMutation) IDs(ctx context.Context) ([]int, error) {
  2057. switch {
  2058. case m.op.Is(OpUpdateOne | OpDeleteOne):
  2059. id, exists := m.ID()
  2060. if exists {
  2061. return []int{id}, nil
  2062. }
  2063. fallthrough
  2064. case m.op.Is(OpUpdate | OpDelete):
  2065. return m.Client().Contacts.Query().Where(m.predicates...).IDs(ctx)
  2066. default:
  2067. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  2068. }
  2069. }
  2070. // SetCreatedAt sets the "created_at" field.
  2071. func (m *ContactsMutation) SetCreatedAt(t time.Time) {
  2072. m.created_at = &t
  2073. }
  2074. // CreatedAt returns the value of the "created_at" field in the mutation.
  2075. func (m *ContactsMutation) CreatedAt() (r time.Time, exists bool) {
  2076. v := m.created_at
  2077. if v == nil {
  2078. return
  2079. }
  2080. return *v, true
  2081. }
  2082. // OldCreatedAt returns the old "created_at" field's value of the Contacts entity.
  2083. // If the Contacts object wasn't provided to the builder, the object is fetched from the database.
  2084. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2085. func (m *ContactsMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  2086. if !m.op.Is(OpUpdateOne) {
  2087. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  2088. }
  2089. if m.id == nil || m.oldValue == nil {
  2090. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  2091. }
  2092. oldValue, err := m.oldValue(ctx)
  2093. if err != nil {
  2094. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  2095. }
  2096. return oldValue.CreatedAt, nil
  2097. }
  2098. // ResetCreatedAt resets all changes to the "created_at" field.
  2099. func (m *ContactsMutation) ResetCreatedAt() {
  2100. m.created_at = nil
  2101. }
  2102. // SetUpdatedAt sets the "updated_at" field.
  2103. func (m *ContactsMutation) SetUpdatedAt(t time.Time) {
  2104. m.updated_at = &t
  2105. }
  2106. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  2107. func (m *ContactsMutation) UpdatedAt() (r time.Time, exists bool) {
  2108. v := m.updated_at
  2109. if v == nil {
  2110. return
  2111. }
  2112. return *v, true
  2113. }
  2114. // OldUpdatedAt returns the old "updated_at" field's value of the Contacts entity.
  2115. // If the Contacts object wasn't provided to the builder, the object is fetched from the database.
  2116. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2117. func (m *ContactsMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  2118. if !m.op.Is(OpUpdateOne) {
  2119. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  2120. }
  2121. if m.id == nil || m.oldValue == nil {
  2122. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  2123. }
  2124. oldValue, err := m.oldValue(ctx)
  2125. if err != nil {
  2126. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  2127. }
  2128. return oldValue.UpdatedAt, nil
  2129. }
  2130. // ResetUpdatedAt resets all changes to the "updated_at" field.
  2131. func (m *ContactsMutation) ResetUpdatedAt() {
  2132. m.updated_at = nil
  2133. }
  2134. // SetDeletedAt sets the "deleted_at" field.
  2135. func (m *ContactsMutation) SetDeletedAt(t time.Time) {
  2136. m.deleted_at = &t
  2137. }
  2138. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  2139. func (m *ContactsMutation) DeletedAt() (r time.Time, exists bool) {
  2140. v := m.deleted_at
  2141. if v == nil {
  2142. return
  2143. }
  2144. return *v, true
  2145. }
  2146. // OldDeletedAt returns the old "deleted_at" field's value of the Contacts entity.
  2147. // If the Contacts object wasn't provided to the builder, the object is fetched from the database.
  2148. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2149. func (m *ContactsMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
  2150. if !m.op.Is(OpUpdateOne) {
  2151. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  2152. }
  2153. if m.id == nil || m.oldValue == nil {
  2154. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  2155. }
  2156. oldValue, err := m.oldValue(ctx)
  2157. if err != nil {
  2158. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  2159. }
  2160. return oldValue.DeletedAt, nil
  2161. }
  2162. // ClearDeletedAt clears the value of the "deleted_at" field.
  2163. func (m *ContactsMutation) ClearDeletedAt() {
  2164. m.deleted_at = nil
  2165. m.clearedFields[contacts.FieldDeletedAt] = struct{}{}
  2166. }
  2167. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  2168. func (m *ContactsMutation) DeletedAtCleared() bool {
  2169. _, ok := m.clearedFields[contacts.FieldDeletedAt]
  2170. return ok
  2171. }
  2172. // ResetDeletedAt resets all changes to the "deleted_at" field.
  2173. func (m *ContactsMutation) ResetDeletedAt() {
  2174. m.deleted_at = nil
  2175. delete(m.clearedFields, contacts.FieldDeletedAt)
  2176. }
  2177. // SetChildID sets the "child_id" field.
  2178. func (m *ContactsMutation) SetChildID(u uuid.UUID) {
  2179. m.child = &u
  2180. }
  2181. // ChildID returns the value of the "child_id" field in the mutation.
  2182. func (m *ContactsMutation) ChildID() (r uuid.UUID, exists bool) {
  2183. v := m.child
  2184. if v == nil {
  2185. return
  2186. }
  2187. return *v, true
  2188. }
  2189. // OldChildID returns the old "child_id" field's value of the Contacts entity.
  2190. // If the Contacts object wasn't provided to the builder, the object is fetched from the database.
  2191. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2192. func (m *ContactsMutation) OldChildID(ctx context.Context) (v uuid.UUID, err error) {
  2193. if !m.op.Is(OpUpdateOne) {
  2194. return v, errors.New("OldChildID is only allowed on UpdateOne operations")
  2195. }
  2196. if m.id == nil || m.oldValue == nil {
  2197. return v, errors.New("OldChildID requires an ID field in the mutation")
  2198. }
  2199. oldValue, err := m.oldValue(ctx)
  2200. if err != nil {
  2201. return v, fmt.Errorf("querying old value for OldChildID: %w", err)
  2202. }
  2203. return oldValue.ChildID, nil
  2204. }
  2205. // ClearChildID clears the value of the "child_id" field.
  2206. func (m *ContactsMutation) ClearChildID() {
  2207. m.child = nil
  2208. m.clearedFields[contacts.FieldChildID] = struct{}{}
  2209. }
  2210. // ChildIDCleared returns if the "child_id" field was cleared in this mutation.
  2211. func (m *ContactsMutation) ChildIDCleared() bool {
  2212. _, ok := m.clearedFields[contacts.FieldChildID]
  2213. return ok
  2214. }
  2215. // ResetChildID resets all changes to the "child_id" field.
  2216. func (m *ContactsMutation) ResetChildID() {
  2217. m.child = nil
  2218. delete(m.clearedFields, contacts.FieldChildID)
  2219. }
  2220. // SetRefID sets the "ref_id" field.
  2221. func (m *ContactsMutation) SetRefID(u uuid.UUID) {
  2222. m.ref_id = &u
  2223. }
  2224. // RefID returns the value of the "ref_id" field in the mutation.
  2225. func (m *ContactsMutation) RefID() (r uuid.UUID, exists bool) {
  2226. v := m.ref_id
  2227. if v == nil {
  2228. return
  2229. }
  2230. return *v, true
  2231. }
  2232. // OldRefID returns the old "ref_id" field's value of the Contacts entity.
  2233. // If the Contacts object wasn't provided to the builder, the object is fetched from the database.
  2234. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2235. func (m *ContactsMutation) OldRefID(ctx context.Context) (v uuid.UUID, err error) {
  2236. if !m.op.Is(OpUpdateOne) {
  2237. return v, errors.New("OldRefID is only allowed on UpdateOne operations")
  2238. }
  2239. if m.id == nil || m.oldValue == nil {
  2240. return v, errors.New("OldRefID requires an ID field in the mutation")
  2241. }
  2242. oldValue, err := m.oldValue(ctx)
  2243. if err != nil {
  2244. return v, fmt.Errorf("querying old value for OldRefID: %w", err)
  2245. }
  2246. return oldValue.RefID, nil
  2247. }
  2248. // ResetRefID resets all changes to the "ref_id" field.
  2249. func (m *ContactsMutation) ResetRefID() {
  2250. m.ref_id = nil
  2251. }
  2252. // SetRefType sets the "ref_type" field.
  2253. func (m *ContactsMutation) SetRefType(ct contacts.RefType) {
  2254. m.ref_type = &ct
  2255. }
  2256. // RefType returns the value of the "ref_type" field in the mutation.
  2257. func (m *ContactsMutation) RefType() (r contacts.RefType, exists bool) {
  2258. v := m.ref_type
  2259. if v == nil {
  2260. return
  2261. }
  2262. return *v, true
  2263. }
  2264. // OldRefType returns the old "ref_type" field's value of the Contacts entity.
  2265. // If the Contacts object wasn't provided to the builder, the object is fetched from the database.
  2266. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2267. func (m *ContactsMutation) OldRefType(ctx context.Context) (v contacts.RefType, err error) {
  2268. if !m.op.Is(OpUpdateOne) {
  2269. return v, errors.New("OldRefType is only allowed on UpdateOne operations")
  2270. }
  2271. if m.id == nil || m.oldValue == nil {
  2272. return v, errors.New("OldRefType requires an ID field in the mutation")
  2273. }
  2274. oldValue, err := m.oldValue(ctx)
  2275. if err != nil {
  2276. return v, fmt.Errorf("querying old value for OldRefType: %w", err)
  2277. }
  2278. return oldValue.RefType, nil
  2279. }
  2280. // ResetRefType resets all changes to the "ref_type" field.
  2281. func (m *ContactsMutation) ResetRefType() {
  2282. m.ref_type = nil
  2283. }
  2284. // SetRemarkName sets the "remark_name" field.
  2285. func (m *ContactsMutation) SetRemarkName(s string) {
  2286. m.remark_name = &s
  2287. }
  2288. // RemarkName returns the value of the "remark_name" field in the mutation.
  2289. func (m *ContactsMutation) RemarkName() (r string, exists bool) {
  2290. v := m.remark_name
  2291. if v == nil {
  2292. return
  2293. }
  2294. return *v, true
  2295. }
  2296. // OldRemarkName returns the old "remark_name" field's value of the Contacts entity.
  2297. // If the Contacts object wasn't provided to the builder, the object is fetched from the database.
  2298. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2299. func (m *ContactsMutation) OldRemarkName(ctx context.Context) (v *string, err error) {
  2300. if !m.op.Is(OpUpdateOne) {
  2301. return v, errors.New("OldRemarkName is only allowed on UpdateOne operations")
  2302. }
  2303. if m.id == nil || m.oldValue == nil {
  2304. return v, errors.New("OldRemarkName requires an ID field in the mutation")
  2305. }
  2306. oldValue, err := m.oldValue(ctx)
  2307. if err != nil {
  2308. return v, fmt.Errorf("querying old value for OldRemarkName: %w", err)
  2309. }
  2310. return oldValue.RemarkName, nil
  2311. }
  2312. // ClearRemarkName clears the value of the "remark_name" field.
  2313. func (m *ContactsMutation) ClearRemarkName() {
  2314. m.remark_name = nil
  2315. m.clearedFields[contacts.FieldRemarkName] = struct{}{}
  2316. }
  2317. // RemarkNameCleared returns if the "remark_name" field was cleared in this mutation.
  2318. func (m *ContactsMutation) RemarkNameCleared() bool {
  2319. _, ok := m.clearedFields[contacts.FieldRemarkName]
  2320. return ok
  2321. }
  2322. // ResetRemarkName resets all changes to the "remark_name" field.
  2323. func (m *ContactsMutation) ResetRemarkName() {
  2324. m.remark_name = nil
  2325. delete(m.clearedFields, contacts.FieldRemarkName)
  2326. }
  2327. // SetRemarkAvatar sets the "remark_avatar" field.
  2328. func (m *ContactsMutation) SetRemarkAvatar(s string) {
  2329. m.remark_avatar = &s
  2330. }
  2331. // RemarkAvatar returns the value of the "remark_avatar" field in the mutation.
  2332. func (m *ContactsMutation) RemarkAvatar() (r string, exists bool) {
  2333. v := m.remark_avatar
  2334. if v == nil {
  2335. return
  2336. }
  2337. return *v, true
  2338. }
  2339. // OldRemarkAvatar returns the old "remark_avatar" field's value of the Contacts entity.
  2340. // If the Contacts object wasn't provided to the builder, the object is fetched from the database.
  2341. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2342. func (m *ContactsMutation) OldRemarkAvatar(ctx context.Context) (v *string, err error) {
  2343. if !m.op.Is(OpUpdateOne) {
  2344. return v, errors.New("OldRemarkAvatar is only allowed on UpdateOne operations")
  2345. }
  2346. if m.id == nil || m.oldValue == nil {
  2347. return v, errors.New("OldRemarkAvatar requires an ID field in the mutation")
  2348. }
  2349. oldValue, err := m.oldValue(ctx)
  2350. if err != nil {
  2351. return v, fmt.Errorf("querying old value for OldRemarkAvatar: %w", err)
  2352. }
  2353. return oldValue.RemarkAvatar, nil
  2354. }
  2355. // ClearRemarkAvatar clears the value of the "remark_avatar" field.
  2356. func (m *ContactsMutation) ClearRemarkAvatar() {
  2357. m.remark_avatar = nil
  2358. m.clearedFields[contacts.FieldRemarkAvatar] = struct{}{}
  2359. }
  2360. // RemarkAvatarCleared returns if the "remark_avatar" field was cleared in this mutation.
  2361. func (m *ContactsMutation) RemarkAvatarCleared() bool {
  2362. _, ok := m.clearedFields[contacts.FieldRemarkAvatar]
  2363. return ok
  2364. }
  2365. // ResetRemarkAvatar resets all changes to the "remark_avatar" field.
  2366. func (m *ContactsMutation) ResetRemarkAvatar() {
  2367. m.remark_avatar = nil
  2368. delete(m.clearedFields, contacts.FieldRemarkAvatar)
  2369. }
  2370. // ClearChild clears the "child" edge to the Child entity.
  2371. func (m *ContactsMutation) ClearChild() {
  2372. m.clearedchild = true
  2373. m.clearedFields[contacts.FieldChildID] = struct{}{}
  2374. }
  2375. // ChildCleared reports if the "child" edge to the Child entity was cleared.
  2376. func (m *ContactsMutation) ChildCleared() bool {
  2377. return m.ChildIDCleared() || m.clearedchild
  2378. }
  2379. // ChildIDs returns the "child" edge IDs in the mutation.
  2380. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  2381. // ChildID instead. It exists only for internal usage by the builders.
  2382. func (m *ContactsMutation) ChildIDs() (ids []uuid.UUID) {
  2383. if id := m.child; id != nil {
  2384. ids = append(ids, *id)
  2385. }
  2386. return
  2387. }
  2388. // ResetChild resets all changes to the "child" edge.
  2389. func (m *ContactsMutation) ResetChild() {
  2390. m.child = nil
  2391. m.clearedchild = false
  2392. }
  2393. // Where appends a list predicates to the ContactsMutation builder.
  2394. func (m *ContactsMutation) Where(ps ...predicate.Contacts) {
  2395. m.predicates = append(m.predicates, ps...)
  2396. }
  2397. // WhereP appends storage-level predicates to the ContactsMutation builder. Using this method,
  2398. // users can use type-assertion to append predicates that do not depend on any generated package.
  2399. func (m *ContactsMutation) WhereP(ps ...func(*sql.Selector)) {
  2400. p := make([]predicate.Contacts, len(ps))
  2401. for i := range ps {
  2402. p[i] = ps[i]
  2403. }
  2404. m.Where(p...)
  2405. }
  2406. // Op returns the operation name.
  2407. func (m *ContactsMutation) Op() Op {
  2408. return m.op
  2409. }
  2410. // SetOp allows setting the mutation operation.
  2411. func (m *ContactsMutation) SetOp(op Op) {
  2412. m.op = op
  2413. }
  2414. // Type returns the node type of this mutation (Contacts).
  2415. func (m *ContactsMutation) Type() string {
  2416. return m.typ
  2417. }
  2418. // Fields returns all fields that were changed during this mutation. Note that in
  2419. // order to get all numeric fields that were incremented/decremented, call
  2420. // AddedFields().
  2421. func (m *ContactsMutation) Fields() []string {
  2422. fields := make([]string, 0, 8)
  2423. if m.created_at != nil {
  2424. fields = append(fields, contacts.FieldCreatedAt)
  2425. }
  2426. if m.updated_at != nil {
  2427. fields = append(fields, contacts.FieldUpdatedAt)
  2428. }
  2429. if m.deleted_at != nil {
  2430. fields = append(fields, contacts.FieldDeletedAt)
  2431. }
  2432. if m.child != nil {
  2433. fields = append(fields, contacts.FieldChildID)
  2434. }
  2435. if m.ref_id != nil {
  2436. fields = append(fields, contacts.FieldRefID)
  2437. }
  2438. if m.ref_type != nil {
  2439. fields = append(fields, contacts.FieldRefType)
  2440. }
  2441. if m.remark_name != nil {
  2442. fields = append(fields, contacts.FieldRemarkName)
  2443. }
  2444. if m.remark_avatar != nil {
  2445. fields = append(fields, contacts.FieldRemarkAvatar)
  2446. }
  2447. return fields
  2448. }
  2449. // Field returns the value of a field with the given name. The second boolean
  2450. // return value indicates that this field was not set, or was not defined in the
  2451. // schema.
  2452. func (m *ContactsMutation) Field(name string) (ent.Value, bool) {
  2453. switch name {
  2454. case contacts.FieldCreatedAt:
  2455. return m.CreatedAt()
  2456. case contacts.FieldUpdatedAt:
  2457. return m.UpdatedAt()
  2458. case contacts.FieldDeletedAt:
  2459. return m.DeletedAt()
  2460. case contacts.FieldChildID:
  2461. return m.ChildID()
  2462. case contacts.FieldRefID:
  2463. return m.RefID()
  2464. case contacts.FieldRefType:
  2465. return m.RefType()
  2466. case contacts.FieldRemarkName:
  2467. return m.RemarkName()
  2468. case contacts.FieldRemarkAvatar:
  2469. return m.RemarkAvatar()
  2470. }
  2471. return nil, false
  2472. }
  2473. // OldField returns the old value of the field from the database. An error is
  2474. // returned if the mutation operation is not UpdateOne, or the query to the
  2475. // database failed.
  2476. func (m *ContactsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  2477. switch name {
  2478. case contacts.FieldCreatedAt:
  2479. return m.OldCreatedAt(ctx)
  2480. case contacts.FieldUpdatedAt:
  2481. return m.OldUpdatedAt(ctx)
  2482. case contacts.FieldDeletedAt:
  2483. return m.OldDeletedAt(ctx)
  2484. case contacts.FieldChildID:
  2485. return m.OldChildID(ctx)
  2486. case contacts.FieldRefID:
  2487. return m.OldRefID(ctx)
  2488. case contacts.FieldRefType:
  2489. return m.OldRefType(ctx)
  2490. case contacts.FieldRemarkName:
  2491. return m.OldRemarkName(ctx)
  2492. case contacts.FieldRemarkAvatar:
  2493. return m.OldRemarkAvatar(ctx)
  2494. }
  2495. return nil, fmt.Errorf("unknown Contacts field %s", name)
  2496. }
  2497. // SetField sets the value of a field with the given name. It returns an error if
  2498. // the field is not defined in the schema, or if the type mismatched the field
  2499. // type.
  2500. func (m *ContactsMutation) SetField(name string, value ent.Value) error {
  2501. switch name {
  2502. case contacts.FieldCreatedAt:
  2503. v, ok := value.(time.Time)
  2504. if !ok {
  2505. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2506. }
  2507. m.SetCreatedAt(v)
  2508. return nil
  2509. case contacts.FieldUpdatedAt:
  2510. v, ok := value.(time.Time)
  2511. if !ok {
  2512. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2513. }
  2514. m.SetUpdatedAt(v)
  2515. return nil
  2516. case contacts.FieldDeletedAt:
  2517. v, ok := value.(time.Time)
  2518. if !ok {
  2519. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2520. }
  2521. m.SetDeletedAt(v)
  2522. return nil
  2523. case contacts.FieldChildID:
  2524. v, ok := value.(uuid.UUID)
  2525. if !ok {
  2526. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2527. }
  2528. m.SetChildID(v)
  2529. return nil
  2530. case contacts.FieldRefID:
  2531. v, ok := value.(uuid.UUID)
  2532. if !ok {
  2533. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2534. }
  2535. m.SetRefID(v)
  2536. return nil
  2537. case contacts.FieldRefType:
  2538. v, ok := value.(contacts.RefType)
  2539. if !ok {
  2540. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2541. }
  2542. m.SetRefType(v)
  2543. return nil
  2544. case contacts.FieldRemarkName:
  2545. v, ok := value.(string)
  2546. if !ok {
  2547. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2548. }
  2549. m.SetRemarkName(v)
  2550. return nil
  2551. case contacts.FieldRemarkAvatar:
  2552. v, ok := value.(string)
  2553. if !ok {
  2554. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2555. }
  2556. m.SetRemarkAvatar(v)
  2557. return nil
  2558. }
  2559. return fmt.Errorf("unknown Contacts field %s", name)
  2560. }
  2561. // AddedFields returns all numeric fields that were incremented/decremented during
  2562. // this mutation.
  2563. func (m *ContactsMutation) AddedFields() []string {
  2564. return nil
  2565. }
  2566. // AddedField returns the numeric value that was incremented/decremented on a field
  2567. // with the given name. The second boolean return value indicates that this field
  2568. // was not set, or was not defined in the schema.
  2569. func (m *ContactsMutation) AddedField(name string) (ent.Value, bool) {
  2570. return nil, false
  2571. }
  2572. // AddField adds the value to the field with the given name. It returns an error if
  2573. // the field is not defined in the schema, or if the type mismatched the field
  2574. // type.
  2575. func (m *ContactsMutation) AddField(name string, value ent.Value) error {
  2576. switch name {
  2577. }
  2578. return fmt.Errorf("unknown Contacts numeric field %s", name)
  2579. }
  2580. // ClearedFields returns all nullable fields that were cleared during this
  2581. // mutation.
  2582. func (m *ContactsMutation) ClearedFields() []string {
  2583. var fields []string
  2584. if m.FieldCleared(contacts.FieldDeletedAt) {
  2585. fields = append(fields, contacts.FieldDeletedAt)
  2586. }
  2587. if m.FieldCleared(contacts.FieldChildID) {
  2588. fields = append(fields, contacts.FieldChildID)
  2589. }
  2590. if m.FieldCleared(contacts.FieldRemarkName) {
  2591. fields = append(fields, contacts.FieldRemarkName)
  2592. }
  2593. if m.FieldCleared(contacts.FieldRemarkAvatar) {
  2594. fields = append(fields, contacts.FieldRemarkAvatar)
  2595. }
  2596. return fields
  2597. }
  2598. // FieldCleared returns a boolean indicating if a field with the given name was
  2599. // cleared in this mutation.
  2600. func (m *ContactsMutation) FieldCleared(name string) bool {
  2601. _, ok := m.clearedFields[name]
  2602. return ok
  2603. }
  2604. // ClearField clears the value of the field with the given name. It returns an
  2605. // error if the field is not defined in the schema.
  2606. func (m *ContactsMutation) ClearField(name string) error {
  2607. switch name {
  2608. case contacts.FieldDeletedAt:
  2609. m.ClearDeletedAt()
  2610. return nil
  2611. case contacts.FieldChildID:
  2612. m.ClearChildID()
  2613. return nil
  2614. case contacts.FieldRemarkName:
  2615. m.ClearRemarkName()
  2616. return nil
  2617. case contacts.FieldRemarkAvatar:
  2618. m.ClearRemarkAvatar()
  2619. return nil
  2620. }
  2621. return fmt.Errorf("unknown Contacts nullable field %s", name)
  2622. }
  2623. // ResetField resets all changes in the mutation for the field with the given name.
  2624. // It returns an error if the field is not defined in the schema.
  2625. func (m *ContactsMutation) ResetField(name string) error {
  2626. switch name {
  2627. case contacts.FieldCreatedAt:
  2628. m.ResetCreatedAt()
  2629. return nil
  2630. case contacts.FieldUpdatedAt:
  2631. m.ResetUpdatedAt()
  2632. return nil
  2633. case contacts.FieldDeletedAt:
  2634. m.ResetDeletedAt()
  2635. return nil
  2636. case contacts.FieldChildID:
  2637. m.ResetChildID()
  2638. return nil
  2639. case contacts.FieldRefID:
  2640. m.ResetRefID()
  2641. return nil
  2642. case contacts.FieldRefType:
  2643. m.ResetRefType()
  2644. return nil
  2645. case contacts.FieldRemarkName:
  2646. m.ResetRemarkName()
  2647. return nil
  2648. case contacts.FieldRemarkAvatar:
  2649. m.ResetRemarkAvatar()
  2650. return nil
  2651. }
  2652. return fmt.Errorf("unknown Contacts field %s", name)
  2653. }
  2654. // AddedEdges returns all edge names that were set/added in this mutation.
  2655. func (m *ContactsMutation) AddedEdges() []string {
  2656. edges := make([]string, 0, 1)
  2657. if m.child != nil {
  2658. edges = append(edges, contacts.EdgeChild)
  2659. }
  2660. return edges
  2661. }
  2662. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  2663. // name in this mutation.
  2664. func (m *ContactsMutation) AddedIDs(name string) []ent.Value {
  2665. switch name {
  2666. case contacts.EdgeChild:
  2667. if id := m.child; id != nil {
  2668. return []ent.Value{*id}
  2669. }
  2670. }
  2671. return nil
  2672. }
  2673. // RemovedEdges returns all edge names that were removed in this mutation.
  2674. func (m *ContactsMutation) RemovedEdges() []string {
  2675. edges := make([]string, 0, 1)
  2676. return edges
  2677. }
  2678. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  2679. // the given name in this mutation.
  2680. func (m *ContactsMutation) RemovedIDs(name string) []ent.Value {
  2681. return nil
  2682. }
  2683. // ClearedEdges returns all edge names that were cleared in this mutation.
  2684. func (m *ContactsMutation) ClearedEdges() []string {
  2685. edges := make([]string, 0, 1)
  2686. if m.clearedchild {
  2687. edges = append(edges, contacts.EdgeChild)
  2688. }
  2689. return edges
  2690. }
  2691. // EdgeCleared returns a boolean which indicates if the edge with the given name
  2692. // was cleared in this mutation.
  2693. func (m *ContactsMutation) EdgeCleared(name string) bool {
  2694. switch name {
  2695. case contacts.EdgeChild:
  2696. return m.clearedchild
  2697. }
  2698. return false
  2699. }
  2700. // ClearEdge clears the value of the edge with the given name. It returns an error
  2701. // if that edge is not defined in the schema.
  2702. func (m *ContactsMutation) ClearEdge(name string) error {
  2703. switch name {
  2704. case contacts.EdgeChild:
  2705. m.ClearChild()
  2706. return nil
  2707. }
  2708. return fmt.Errorf("unknown Contacts unique edge %s", name)
  2709. }
  2710. // ResetEdge resets all changes to the edge with the given name in this mutation.
  2711. // It returns an error if the edge is not defined in the schema.
  2712. func (m *ContactsMutation) ResetEdge(name string) error {
  2713. switch name {
  2714. case contacts.EdgeChild:
  2715. m.ResetChild()
  2716. return nil
  2717. }
  2718. return fmt.Errorf("unknown Contacts edge %s", name)
  2719. }
  2720. // DeviceMutation represents an operation that mutates the Device nodes in the graph.
  2721. type DeviceMutation struct {
  2722. config
  2723. op Op
  2724. typ string
  2725. id *int64
  2726. created_at *time.Time
  2727. updated_at *time.Time
  2728. deleted_at *time.Time
  2729. imei *string
  2730. model *string
  2731. ticket *string
  2732. hc *string
  2733. aes_key *string
  2734. activation_time *time.Time
  2735. clearedFields map[string]struct{}
  2736. bind *int64
  2737. clearedbind bool
  2738. configs map[int64]struct{}
  2739. removedconfigs map[int64]struct{}
  2740. clearedconfigs bool
  2741. done bool
  2742. oldValue func(context.Context) (*Device, error)
  2743. predicates []predicate.Device
  2744. }
  2745. var _ ent.Mutation = (*DeviceMutation)(nil)
  2746. // deviceOption allows management of the mutation configuration using functional options.
  2747. type deviceOption func(*DeviceMutation)
  2748. // newDeviceMutation creates new mutation for the Device entity.
  2749. func newDeviceMutation(c config, op Op, opts ...deviceOption) *DeviceMutation {
  2750. m := &DeviceMutation{
  2751. config: c,
  2752. op: op,
  2753. typ: TypeDevice,
  2754. clearedFields: make(map[string]struct{}),
  2755. }
  2756. for _, opt := range opts {
  2757. opt(m)
  2758. }
  2759. return m
  2760. }
  2761. // withDeviceID sets the ID field of the mutation.
  2762. func withDeviceID(id int64) deviceOption {
  2763. return func(m *DeviceMutation) {
  2764. var (
  2765. err error
  2766. once sync.Once
  2767. value *Device
  2768. )
  2769. m.oldValue = func(ctx context.Context) (*Device, error) {
  2770. once.Do(func() {
  2771. if m.done {
  2772. err = errors.New("querying old values post mutation is not allowed")
  2773. } else {
  2774. value, err = m.Client().Device.Get(ctx, id)
  2775. }
  2776. })
  2777. return value, err
  2778. }
  2779. m.id = &id
  2780. }
  2781. }
  2782. // withDevice sets the old Device of the mutation.
  2783. func withDevice(node *Device) deviceOption {
  2784. return func(m *DeviceMutation) {
  2785. m.oldValue = func(context.Context) (*Device, error) {
  2786. return node, nil
  2787. }
  2788. m.id = &node.ID
  2789. }
  2790. }
  2791. // Client returns a new `ent.Client` from the mutation. If the mutation was
  2792. // executed in a transaction (ent.Tx), a transactional client is returned.
  2793. func (m DeviceMutation) Client() *Client {
  2794. client := &Client{config: m.config}
  2795. client.init()
  2796. return client
  2797. }
  2798. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  2799. // it returns an error otherwise.
  2800. func (m DeviceMutation) Tx() (*Tx, error) {
  2801. if _, ok := m.driver.(*txDriver); !ok {
  2802. return nil, errors.New("ent: mutation is not running in a transaction")
  2803. }
  2804. tx := &Tx{config: m.config}
  2805. tx.init()
  2806. return tx, nil
  2807. }
  2808. // SetID sets the value of the id field. Note that this
  2809. // operation is only accepted on creation of Device entities.
  2810. func (m *DeviceMutation) SetID(id int64) {
  2811. m.id = &id
  2812. }
  2813. // ID returns the ID value in the mutation. Note that the ID is only available
  2814. // if it was provided to the builder or after it was returned from the database.
  2815. func (m *DeviceMutation) ID() (id int64, exists bool) {
  2816. if m.id == nil {
  2817. return
  2818. }
  2819. return *m.id, true
  2820. }
  2821. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  2822. // That means, if the mutation is applied within a transaction with an isolation level such
  2823. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  2824. // or updated by the mutation.
  2825. func (m *DeviceMutation) IDs(ctx context.Context) ([]int64, error) {
  2826. switch {
  2827. case m.op.Is(OpUpdateOne | OpDeleteOne):
  2828. id, exists := m.ID()
  2829. if exists {
  2830. return []int64{id}, nil
  2831. }
  2832. fallthrough
  2833. case m.op.Is(OpUpdate | OpDelete):
  2834. return m.Client().Device.Query().Where(m.predicates...).IDs(ctx)
  2835. default:
  2836. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  2837. }
  2838. }
  2839. // SetCreatedAt sets the "created_at" field.
  2840. func (m *DeviceMutation) SetCreatedAt(t time.Time) {
  2841. m.created_at = &t
  2842. }
  2843. // CreatedAt returns the value of the "created_at" field in the mutation.
  2844. func (m *DeviceMutation) CreatedAt() (r time.Time, exists bool) {
  2845. v := m.created_at
  2846. if v == nil {
  2847. return
  2848. }
  2849. return *v, true
  2850. }
  2851. // OldCreatedAt returns the old "created_at" field's value of the Device entity.
  2852. // If the Device object wasn't provided to the builder, the object is fetched from the database.
  2853. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2854. func (m *DeviceMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  2855. if !m.op.Is(OpUpdateOne) {
  2856. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  2857. }
  2858. if m.id == nil || m.oldValue == nil {
  2859. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  2860. }
  2861. oldValue, err := m.oldValue(ctx)
  2862. if err != nil {
  2863. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  2864. }
  2865. return oldValue.CreatedAt, nil
  2866. }
  2867. // ResetCreatedAt resets all changes to the "created_at" field.
  2868. func (m *DeviceMutation) ResetCreatedAt() {
  2869. m.created_at = nil
  2870. }
  2871. // SetUpdatedAt sets the "updated_at" field.
  2872. func (m *DeviceMutation) SetUpdatedAt(t time.Time) {
  2873. m.updated_at = &t
  2874. }
  2875. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  2876. func (m *DeviceMutation) UpdatedAt() (r time.Time, exists bool) {
  2877. v := m.updated_at
  2878. if v == nil {
  2879. return
  2880. }
  2881. return *v, true
  2882. }
  2883. // OldUpdatedAt returns the old "updated_at" field's value of the Device entity.
  2884. // If the Device object wasn't provided to the builder, the object is fetched from the database.
  2885. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2886. func (m *DeviceMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  2887. if !m.op.Is(OpUpdateOne) {
  2888. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  2889. }
  2890. if m.id == nil || m.oldValue == nil {
  2891. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  2892. }
  2893. oldValue, err := m.oldValue(ctx)
  2894. if err != nil {
  2895. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  2896. }
  2897. return oldValue.UpdatedAt, nil
  2898. }
  2899. // ResetUpdatedAt resets all changes to the "updated_at" field.
  2900. func (m *DeviceMutation) ResetUpdatedAt() {
  2901. m.updated_at = nil
  2902. }
  2903. // SetDeletedAt sets the "deleted_at" field.
  2904. func (m *DeviceMutation) SetDeletedAt(t time.Time) {
  2905. m.deleted_at = &t
  2906. }
  2907. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  2908. func (m *DeviceMutation) DeletedAt() (r time.Time, exists bool) {
  2909. v := m.deleted_at
  2910. if v == nil {
  2911. return
  2912. }
  2913. return *v, true
  2914. }
  2915. // OldDeletedAt returns the old "deleted_at" field's value of the Device entity.
  2916. // If the Device object wasn't provided to the builder, the object is fetched from the database.
  2917. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2918. func (m *DeviceMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
  2919. if !m.op.Is(OpUpdateOne) {
  2920. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  2921. }
  2922. if m.id == nil || m.oldValue == nil {
  2923. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  2924. }
  2925. oldValue, err := m.oldValue(ctx)
  2926. if err != nil {
  2927. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  2928. }
  2929. return oldValue.DeletedAt, nil
  2930. }
  2931. // ClearDeletedAt clears the value of the "deleted_at" field.
  2932. func (m *DeviceMutation) ClearDeletedAt() {
  2933. m.deleted_at = nil
  2934. m.clearedFields[device.FieldDeletedAt] = struct{}{}
  2935. }
  2936. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  2937. func (m *DeviceMutation) DeletedAtCleared() bool {
  2938. _, ok := m.clearedFields[device.FieldDeletedAt]
  2939. return ok
  2940. }
  2941. // ResetDeletedAt resets all changes to the "deleted_at" field.
  2942. func (m *DeviceMutation) ResetDeletedAt() {
  2943. m.deleted_at = nil
  2944. delete(m.clearedFields, device.FieldDeletedAt)
  2945. }
  2946. // SetImei sets the "imei" field.
  2947. func (m *DeviceMutation) SetImei(s string) {
  2948. m.imei = &s
  2949. }
  2950. // Imei returns the value of the "imei" field in the mutation.
  2951. func (m *DeviceMutation) Imei() (r string, exists bool) {
  2952. v := m.imei
  2953. if v == nil {
  2954. return
  2955. }
  2956. return *v, true
  2957. }
  2958. // OldImei returns the old "imei" field's value of the Device entity.
  2959. // If the Device object wasn't provided to the builder, the object is fetched from the database.
  2960. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2961. func (m *DeviceMutation) OldImei(ctx context.Context) (v string, err error) {
  2962. if !m.op.Is(OpUpdateOne) {
  2963. return v, errors.New("OldImei is only allowed on UpdateOne operations")
  2964. }
  2965. if m.id == nil || m.oldValue == nil {
  2966. return v, errors.New("OldImei requires an ID field in the mutation")
  2967. }
  2968. oldValue, err := m.oldValue(ctx)
  2969. if err != nil {
  2970. return v, fmt.Errorf("querying old value for OldImei: %w", err)
  2971. }
  2972. return oldValue.Imei, nil
  2973. }
  2974. // ResetImei resets all changes to the "imei" field.
  2975. func (m *DeviceMutation) ResetImei() {
  2976. m.imei = nil
  2977. }
  2978. // SetModel sets the "model" field.
  2979. func (m *DeviceMutation) SetModel(s string) {
  2980. m.model = &s
  2981. }
  2982. // Model returns the value of the "model" field in the mutation.
  2983. func (m *DeviceMutation) Model() (r string, exists bool) {
  2984. v := m.model
  2985. if v == nil {
  2986. return
  2987. }
  2988. return *v, true
  2989. }
  2990. // OldModel returns the old "model" field's value of the Device entity.
  2991. // If the Device object wasn't provided to the builder, the object is fetched from the database.
  2992. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2993. func (m *DeviceMutation) OldModel(ctx context.Context) (v string, err error) {
  2994. if !m.op.Is(OpUpdateOne) {
  2995. return v, errors.New("OldModel is only allowed on UpdateOne operations")
  2996. }
  2997. if m.id == nil || m.oldValue == nil {
  2998. return v, errors.New("OldModel requires an ID field in the mutation")
  2999. }
  3000. oldValue, err := m.oldValue(ctx)
  3001. if err != nil {
  3002. return v, fmt.Errorf("querying old value for OldModel: %w", err)
  3003. }
  3004. return oldValue.Model, nil
  3005. }
  3006. // ResetModel resets all changes to the "model" field.
  3007. func (m *DeviceMutation) ResetModel() {
  3008. m.model = nil
  3009. }
  3010. // SetTicket sets the "ticket" field.
  3011. func (m *DeviceMutation) SetTicket(s string) {
  3012. m.ticket = &s
  3013. }
  3014. // Ticket returns the value of the "ticket" field in the mutation.
  3015. func (m *DeviceMutation) Ticket() (r string, exists bool) {
  3016. v := m.ticket
  3017. if v == nil {
  3018. return
  3019. }
  3020. return *v, true
  3021. }
  3022. // OldTicket returns the old "ticket" field's value of the Device entity.
  3023. // If the Device object wasn't provided to the builder, the object is fetched from the database.
  3024. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3025. func (m *DeviceMutation) OldTicket(ctx context.Context) (v string, err error) {
  3026. if !m.op.Is(OpUpdateOne) {
  3027. return v, errors.New("OldTicket is only allowed on UpdateOne operations")
  3028. }
  3029. if m.id == nil || m.oldValue == nil {
  3030. return v, errors.New("OldTicket requires an ID field in the mutation")
  3031. }
  3032. oldValue, err := m.oldValue(ctx)
  3033. if err != nil {
  3034. return v, fmt.Errorf("querying old value for OldTicket: %w", err)
  3035. }
  3036. return oldValue.Ticket, nil
  3037. }
  3038. // ResetTicket resets all changes to the "ticket" field.
  3039. func (m *DeviceMutation) ResetTicket() {
  3040. m.ticket = nil
  3041. }
  3042. // SetHc sets the "hc" field.
  3043. func (m *DeviceMutation) SetHc(s string) {
  3044. m.hc = &s
  3045. }
  3046. // Hc returns the value of the "hc" field in the mutation.
  3047. func (m *DeviceMutation) Hc() (r string, exists bool) {
  3048. v := m.hc
  3049. if v == nil {
  3050. return
  3051. }
  3052. return *v, true
  3053. }
  3054. // OldHc returns the old "hc" field's value of the Device entity.
  3055. // If the Device object wasn't provided to the builder, the object is fetched from the database.
  3056. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3057. func (m *DeviceMutation) OldHc(ctx context.Context) (v string, err error) {
  3058. if !m.op.Is(OpUpdateOne) {
  3059. return v, errors.New("OldHc is only allowed on UpdateOne operations")
  3060. }
  3061. if m.id == nil || m.oldValue == nil {
  3062. return v, errors.New("OldHc requires an ID field in the mutation")
  3063. }
  3064. oldValue, err := m.oldValue(ctx)
  3065. if err != nil {
  3066. return v, fmt.Errorf("querying old value for OldHc: %w", err)
  3067. }
  3068. return oldValue.Hc, nil
  3069. }
  3070. // ResetHc resets all changes to the "hc" field.
  3071. func (m *DeviceMutation) ResetHc() {
  3072. m.hc = nil
  3073. }
  3074. // SetAesKey sets the "aes_key" field.
  3075. func (m *DeviceMutation) SetAesKey(s string) {
  3076. m.aes_key = &s
  3077. }
  3078. // AesKey returns the value of the "aes_key" field in the mutation.
  3079. func (m *DeviceMutation) AesKey() (r string, exists bool) {
  3080. v := m.aes_key
  3081. if v == nil {
  3082. return
  3083. }
  3084. return *v, true
  3085. }
  3086. // OldAesKey returns the old "aes_key" field's value of the Device entity.
  3087. // If the Device object wasn't provided to the builder, the object is fetched from the database.
  3088. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3089. func (m *DeviceMutation) OldAesKey(ctx context.Context) (v string, err error) {
  3090. if !m.op.Is(OpUpdateOne) {
  3091. return v, errors.New("OldAesKey is only allowed on UpdateOne operations")
  3092. }
  3093. if m.id == nil || m.oldValue == nil {
  3094. return v, errors.New("OldAesKey requires an ID field in the mutation")
  3095. }
  3096. oldValue, err := m.oldValue(ctx)
  3097. if err != nil {
  3098. return v, fmt.Errorf("querying old value for OldAesKey: %w", err)
  3099. }
  3100. return oldValue.AesKey, nil
  3101. }
  3102. // ResetAesKey resets all changes to the "aes_key" field.
  3103. func (m *DeviceMutation) ResetAesKey() {
  3104. m.aes_key = nil
  3105. }
  3106. // SetActivationTime sets the "activation_time" field.
  3107. func (m *DeviceMutation) SetActivationTime(t time.Time) {
  3108. m.activation_time = &t
  3109. }
  3110. // ActivationTime returns the value of the "activation_time" field in the mutation.
  3111. func (m *DeviceMutation) ActivationTime() (r time.Time, exists bool) {
  3112. v := m.activation_time
  3113. if v == nil {
  3114. return
  3115. }
  3116. return *v, true
  3117. }
  3118. // OldActivationTime returns the old "activation_time" field's value of the Device entity.
  3119. // If the Device object wasn't provided to the builder, the object is fetched from the database.
  3120. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3121. func (m *DeviceMutation) OldActivationTime(ctx context.Context) (v *time.Time, err error) {
  3122. if !m.op.Is(OpUpdateOne) {
  3123. return v, errors.New("OldActivationTime is only allowed on UpdateOne operations")
  3124. }
  3125. if m.id == nil || m.oldValue == nil {
  3126. return v, errors.New("OldActivationTime requires an ID field in the mutation")
  3127. }
  3128. oldValue, err := m.oldValue(ctx)
  3129. if err != nil {
  3130. return v, fmt.Errorf("querying old value for OldActivationTime: %w", err)
  3131. }
  3132. return oldValue.ActivationTime, nil
  3133. }
  3134. // ClearActivationTime clears the value of the "activation_time" field.
  3135. func (m *DeviceMutation) ClearActivationTime() {
  3136. m.activation_time = nil
  3137. m.clearedFields[device.FieldActivationTime] = struct{}{}
  3138. }
  3139. // ActivationTimeCleared returns if the "activation_time" field was cleared in this mutation.
  3140. func (m *DeviceMutation) ActivationTimeCleared() bool {
  3141. _, ok := m.clearedFields[device.FieldActivationTime]
  3142. return ok
  3143. }
  3144. // ResetActivationTime resets all changes to the "activation_time" field.
  3145. func (m *DeviceMutation) ResetActivationTime() {
  3146. m.activation_time = nil
  3147. delete(m.clearedFields, device.FieldActivationTime)
  3148. }
  3149. // SetBindID sets the "bind" edge to the DeviceBind entity by id.
  3150. func (m *DeviceMutation) SetBindID(id int64) {
  3151. m.bind = &id
  3152. }
  3153. // ClearBind clears the "bind" edge to the DeviceBind entity.
  3154. func (m *DeviceMutation) ClearBind() {
  3155. m.clearedbind = true
  3156. }
  3157. // BindCleared reports if the "bind" edge to the DeviceBind entity was cleared.
  3158. func (m *DeviceMutation) BindCleared() bool {
  3159. return m.clearedbind
  3160. }
  3161. // BindID returns the "bind" edge ID in the mutation.
  3162. func (m *DeviceMutation) BindID() (id int64, exists bool) {
  3163. if m.bind != nil {
  3164. return *m.bind, true
  3165. }
  3166. return
  3167. }
  3168. // BindIDs returns the "bind" edge IDs in the mutation.
  3169. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  3170. // BindID instead. It exists only for internal usage by the builders.
  3171. func (m *DeviceMutation) BindIDs() (ids []int64) {
  3172. if id := m.bind; id != nil {
  3173. ids = append(ids, *id)
  3174. }
  3175. return
  3176. }
  3177. // ResetBind resets all changes to the "bind" edge.
  3178. func (m *DeviceMutation) ResetBind() {
  3179. m.bind = nil
  3180. m.clearedbind = false
  3181. }
  3182. // AddConfigIDs adds the "configs" edge to the DeviceConfig entity by ids.
  3183. func (m *DeviceMutation) AddConfigIDs(ids ...int64) {
  3184. if m.configs == nil {
  3185. m.configs = make(map[int64]struct{})
  3186. }
  3187. for i := range ids {
  3188. m.configs[ids[i]] = struct{}{}
  3189. }
  3190. }
  3191. // ClearConfigs clears the "configs" edge to the DeviceConfig entity.
  3192. func (m *DeviceMutation) ClearConfigs() {
  3193. m.clearedconfigs = true
  3194. }
  3195. // ConfigsCleared reports if the "configs" edge to the DeviceConfig entity was cleared.
  3196. func (m *DeviceMutation) ConfigsCleared() bool {
  3197. return m.clearedconfigs
  3198. }
  3199. // RemoveConfigIDs removes the "configs" edge to the DeviceConfig entity by IDs.
  3200. func (m *DeviceMutation) RemoveConfigIDs(ids ...int64) {
  3201. if m.removedconfigs == nil {
  3202. m.removedconfigs = make(map[int64]struct{})
  3203. }
  3204. for i := range ids {
  3205. delete(m.configs, ids[i])
  3206. m.removedconfigs[ids[i]] = struct{}{}
  3207. }
  3208. }
  3209. // RemovedConfigs returns the removed IDs of the "configs" edge to the DeviceConfig entity.
  3210. func (m *DeviceMutation) RemovedConfigsIDs() (ids []int64) {
  3211. for id := range m.removedconfigs {
  3212. ids = append(ids, id)
  3213. }
  3214. return
  3215. }
  3216. // ConfigsIDs returns the "configs" edge IDs in the mutation.
  3217. func (m *DeviceMutation) ConfigsIDs() (ids []int64) {
  3218. for id := range m.configs {
  3219. ids = append(ids, id)
  3220. }
  3221. return
  3222. }
  3223. // ResetConfigs resets all changes to the "configs" edge.
  3224. func (m *DeviceMutation) ResetConfigs() {
  3225. m.configs = nil
  3226. m.clearedconfigs = false
  3227. m.removedconfigs = nil
  3228. }
  3229. // Where appends a list predicates to the DeviceMutation builder.
  3230. func (m *DeviceMutation) Where(ps ...predicate.Device) {
  3231. m.predicates = append(m.predicates, ps...)
  3232. }
  3233. // WhereP appends storage-level predicates to the DeviceMutation builder. Using this method,
  3234. // users can use type-assertion to append predicates that do not depend on any generated package.
  3235. func (m *DeviceMutation) WhereP(ps ...func(*sql.Selector)) {
  3236. p := make([]predicate.Device, len(ps))
  3237. for i := range ps {
  3238. p[i] = ps[i]
  3239. }
  3240. m.Where(p...)
  3241. }
  3242. // Op returns the operation name.
  3243. func (m *DeviceMutation) Op() Op {
  3244. return m.op
  3245. }
  3246. // SetOp allows setting the mutation operation.
  3247. func (m *DeviceMutation) SetOp(op Op) {
  3248. m.op = op
  3249. }
  3250. // Type returns the node type of this mutation (Device).
  3251. func (m *DeviceMutation) Type() string {
  3252. return m.typ
  3253. }
  3254. // Fields returns all fields that were changed during this mutation. Note that in
  3255. // order to get all numeric fields that were incremented/decremented, call
  3256. // AddedFields().
  3257. func (m *DeviceMutation) Fields() []string {
  3258. fields := make([]string, 0, 9)
  3259. if m.created_at != nil {
  3260. fields = append(fields, device.FieldCreatedAt)
  3261. }
  3262. if m.updated_at != nil {
  3263. fields = append(fields, device.FieldUpdatedAt)
  3264. }
  3265. if m.deleted_at != nil {
  3266. fields = append(fields, device.FieldDeletedAt)
  3267. }
  3268. if m.imei != nil {
  3269. fields = append(fields, device.FieldImei)
  3270. }
  3271. if m.model != nil {
  3272. fields = append(fields, device.FieldModel)
  3273. }
  3274. if m.ticket != nil {
  3275. fields = append(fields, device.FieldTicket)
  3276. }
  3277. if m.hc != nil {
  3278. fields = append(fields, device.FieldHc)
  3279. }
  3280. if m.aes_key != nil {
  3281. fields = append(fields, device.FieldAesKey)
  3282. }
  3283. if m.activation_time != nil {
  3284. fields = append(fields, device.FieldActivationTime)
  3285. }
  3286. return fields
  3287. }
  3288. // Field returns the value of a field with the given name. The second boolean
  3289. // return value indicates that this field was not set, or was not defined in the
  3290. // schema.
  3291. func (m *DeviceMutation) Field(name string) (ent.Value, bool) {
  3292. switch name {
  3293. case device.FieldCreatedAt:
  3294. return m.CreatedAt()
  3295. case device.FieldUpdatedAt:
  3296. return m.UpdatedAt()
  3297. case device.FieldDeletedAt:
  3298. return m.DeletedAt()
  3299. case device.FieldImei:
  3300. return m.Imei()
  3301. case device.FieldModel:
  3302. return m.Model()
  3303. case device.FieldTicket:
  3304. return m.Ticket()
  3305. case device.FieldHc:
  3306. return m.Hc()
  3307. case device.FieldAesKey:
  3308. return m.AesKey()
  3309. case device.FieldActivationTime:
  3310. return m.ActivationTime()
  3311. }
  3312. return nil, false
  3313. }
  3314. // OldField returns the old value of the field from the database. An error is
  3315. // returned if the mutation operation is not UpdateOne, or the query to the
  3316. // database failed.
  3317. func (m *DeviceMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  3318. switch name {
  3319. case device.FieldCreatedAt:
  3320. return m.OldCreatedAt(ctx)
  3321. case device.FieldUpdatedAt:
  3322. return m.OldUpdatedAt(ctx)
  3323. case device.FieldDeletedAt:
  3324. return m.OldDeletedAt(ctx)
  3325. case device.FieldImei:
  3326. return m.OldImei(ctx)
  3327. case device.FieldModel:
  3328. return m.OldModel(ctx)
  3329. case device.FieldTicket:
  3330. return m.OldTicket(ctx)
  3331. case device.FieldHc:
  3332. return m.OldHc(ctx)
  3333. case device.FieldAesKey:
  3334. return m.OldAesKey(ctx)
  3335. case device.FieldActivationTime:
  3336. return m.OldActivationTime(ctx)
  3337. }
  3338. return nil, fmt.Errorf("unknown Device field %s", name)
  3339. }
  3340. // SetField sets the value of a field with the given name. It returns an error if
  3341. // the field is not defined in the schema, or if the type mismatched the field
  3342. // type.
  3343. func (m *DeviceMutation) SetField(name string, value ent.Value) error {
  3344. switch name {
  3345. case device.FieldCreatedAt:
  3346. v, ok := value.(time.Time)
  3347. if !ok {
  3348. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3349. }
  3350. m.SetCreatedAt(v)
  3351. return nil
  3352. case device.FieldUpdatedAt:
  3353. v, ok := value.(time.Time)
  3354. if !ok {
  3355. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3356. }
  3357. m.SetUpdatedAt(v)
  3358. return nil
  3359. case device.FieldDeletedAt:
  3360. v, ok := value.(time.Time)
  3361. if !ok {
  3362. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3363. }
  3364. m.SetDeletedAt(v)
  3365. return nil
  3366. case device.FieldImei:
  3367. v, ok := value.(string)
  3368. if !ok {
  3369. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3370. }
  3371. m.SetImei(v)
  3372. return nil
  3373. case device.FieldModel:
  3374. v, ok := value.(string)
  3375. if !ok {
  3376. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3377. }
  3378. m.SetModel(v)
  3379. return nil
  3380. case device.FieldTicket:
  3381. v, ok := value.(string)
  3382. if !ok {
  3383. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3384. }
  3385. m.SetTicket(v)
  3386. return nil
  3387. case device.FieldHc:
  3388. v, ok := value.(string)
  3389. if !ok {
  3390. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3391. }
  3392. m.SetHc(v)
  3393. return nil
  3394. case device.FieldAesKey:
  3395. v, ok := value.(string)
  3396. if !ok {
  3397. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3398. }
  3399. m.SetAesKey(v)
  3400. return nil
  3401. case device.FieldActivationTime:
  3402. v, ok := value.(time.Time)
  3403. if !ok {
  3404. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3405. }
  3406. m.SetActivationTime(v)
  3407. return nil
  3408. }
  3409. return fmt.Errorf("unknown Device field %s", name)
  3410. }
  3411. // AddedFields returns all numeric fields that were incremented/decremented during
  3412. // this mutation.
  3413. func (m *DeviceMutation) AddedFields() []string {
  3414. return nil
  3415. }
  3416. // AddedField returns the numeric value that was incremented/decremented on a field
  3417. // with the given name. The second boolean return value indicates that this field
  3418. // was not set, or was not defined in the schema.
  3419. func (m *DeviceMutation) AddedField(name string) (ent.Value, bool) {
  3420. return nil, false
  3421. }
  3422. // AddField adds the value to the field with the given name. It returns an error if
  3423. // the field is not defined in the schema, or if the type mismatched the field
  3424. // type.
  3425. func (m *DeviceMutation) AddField(name string, value ent.Value) error {
  3426. switch name {
  3427. }
  3428. return fmt.Errorf("unknown Device numeric field %s", name)
  3429. }
  3430. // ClearedFields returns all nullable fields that were cleared during this
  3431. // mutation.
  3432. func (m *DeviceMutation) ClearedFields() []string {
  3433. var fields []string
  3434. if m.FieldCleared(device.FieldDeletedAt) {
  3435. fields = append(fields, device.FieldDeletedAt)
  3436. }
  3437. if m.FieldCleared(device.FieldActivationTime) {
  3438. fields = append(fields, device.FieldActivationTime)
  3439. }
  3440. return fields
  3441. }
  3442. // FieldCleared returns a boolean indicating if a field with the given name was
  3443. // cleared in this mutation.
  3444. func (m *DeviceMutation) FieldCleared(name string) bool {
  3445. _, ok := m.clearedFields[name]
  3446. return ok
  3447. }
  3448. // ClearField clears the value of the field with the given name. It returns an
  3449. // error if the field is not defined in the schema.
  3450. func (m *DeviceMutation) ClearField(name string) error {
  3451. switch name {
  3452. case device.FieldDeletedAt:
  3453. m.ClearDeletedAt()
  3454. return nil
  3455. case device.FieldActivationTime:
  3456. m.ClearActivationTime()
  3457. return nil
  3458. }
  3459. return fmt.Errorf("unknown Device nullable field %s", name)
  3460. }
  3461. // ResetField resets all changes in the mutation for the field with the given name.
  3462. // It returns an error if the field is not defined in the schema.
  3463. func (m *DeviceMutation) ResetField(name string) error {
  3464. switch name {
  3465. case device.FieldCreatedAt:
  3466. m.ResetCreatedAt()
  3467. return nil
  3468. case device.FieldUpdatedAt:
  3469. m.ResetUpdatedAt()
  3470. return nil
  3471. case device.FieldDeletedAt:
  3472. m.ResetDeletedAt()
  3473. return nil
  3474. case device.FieldImei:
  3475. m.ResetImei()
  3476. return nil
  3477. case device.FieldModel:
  3478. m.ResetModel()
  3479. return nil
  3480. case device.FieldTicket:
  3481. m.ResetTicket()
  3482. return nil
  3483. case device.FieldHc:
  3484. m.ResetHc()
  3485. return nil
  3486. case device.FieldAesKey:
  3487. m.ResetAesKey()
  3488. return nil
  3489. case device.FieldActivationTime:
  3490. m.ResetActivationTime()
  3491. return nil
  3492. }
  3493. return fmt.Errorf("unknown Device field %s", name)
  3494. }
  3495. // AddedEdges returns all edge names that were set/added in this mutation.
  3496. func (m *DeviceMutation) AddedEdges() []string {
  3497. edges := make([]string, 0, 2)
  3498. if m.bind != nil {
  3499. edges = append(edges, device.EdgeBind)
  3500. }
  3501. if m.configs != nil {
  3502. edges = append(edges, device.EdgeConfigs)
  3503. }
  3504. return edges
  3505. }
  3506. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  3507. // name in this mutation.
  3508. func (m *DeviceMutation) AddedIDs(name string) []ent.Value {
  3509. switch name {
  3510. case device.EdgeBind:
  3511. if id := m.bind; id != nil {
  3512. return []ent.Value{*id}
  3513. }
  3514. case device.EdgeConfigs:
  3515. ids := make([]ent.Value, 0, len(m.configs))
  3516. for id := range m.configs {
  3517. ids = append(ids, id)
  3518. }
  3519. return ids
  3520. }
  3521. return nil
  3522. }
  3523. // RemovedEdges returns all edge names that were removed in this mutation.
  3524. func (m *DeviceMutation) RemovedEdges() []string {
  3525. edges := make([]string, 0, 2)
  3526. if m.removedconfigs != nil {
  3527. edges = append(edges, device.EdgeConfigs)
  3528. }
  3529. return edges
  3530. }
  3531. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  3532. // the given name in this mutation.
  3533. func (m *DeviceMutation) RemovedIDs(name string) []ent.Value {
  3534. switch name {
  3535. case device.EdgeConfigs:
  3536. ids := make([]ent.Value, 0, len(m.removedconfigs))
  3537. for id := range m.removedconfigs {
  3538. ids = append(ids, id)
  3539. }
  3540. return ids
  3541. }
  3542. return nil
  3543. }
  3544. // ClearedEdges returns all edge names that were cleared in this mutation.
  3545. func (m *DeviceMutation) ClearedEdges() []string {
  3546. edges := make([]string, 0, 2)
  3547. if m.clearedbind {
  3548. edges = append(edges, device.EdgeBind)
  3549. }
  3550. if m.clearedconfigs {
  3551. edges = append(edges, device.EdgeConfigs)
  3552. }
  3553. return edges
  3554. }
  3555. // EdgeCleared returns a boolean which indicates if the edge with the given name
  3556. // was cleared in this mutation.
  3557. func (m *DeviceMutation) EdgeCleared(name string) bool {
  3558. switch name {
  3559. case device.EdgeBind:
  3560. return m.clearedbind
  3561. case device.EdgeConfigs:
  3562. return m.clearedconfigs
  3563. }
  3564. return false
  3565. }
  3566. // ClearEdge clears the value of the edge with the given name. It returns an error
  3567. // if that edge is not defined in the schema.
  3568. func (m *DeviceMutation) ClearEdge(name string) error {
  3569. switch name {
  3570. case device.EdgeBind:
  3571. m.ClearBind()
  3572. return nil
  3573. }
  3574. return fmt.Errorf("unknown Device unique edge %s", name)
  3575. }
  3576. // ResetEdge resets all changes to the edge with the given name in this mutation.
  3577. // It returns an error if the edge is not defined in the schema.
  3578. func (m *DeviceMutation) ResetEdge(name string) error {
  3579. switch name {
  3580. case device.EdgeBind:
  3581. m.ResetBind()
  3582. return nil
  3583. case device.EdgeConfigs:
  3584. m.ResetConfigs()
  3585. return nil
  3586. }
  3587. return fmt.Errorf("unknown Device edge %s", name)
  3588. }
  3589. // DeviceBindMutation represents an operation that mutates the DeviceBind nodes in the graph.
  3590. type DeviceBindMutation struct {
  3591. config
  3592. op Op
  3593. typ string
  3594. id *int64
  3595. created_at *time.Time
  3596. updated_at *time.Time
  3597. deleted_at *time.Time
  3598. clearedFields map[string]struct{}
  3599. device *int64
  3600. cleareddevice bool
  3601. child *uuid.UUID
  3602. clearedchild bool
  3603. done bool
  3604. oldValue func(context.Context) (*DeviceBind, error)
  3605. predicates []predicate.DeviceBind
  3606. }
  3607. var _ ent.Mutation = (*DeviceBindMutation)(nil)
  3608. // devicebindOption allows management of the mutation configuration using functional options.
  3609. type devicebindOption func(*DeviceBindMutation)
  3610. // newDeviceBindMutation creates new mutation for the DeviceBind entity.
  3611. func newDeviceBindMutation(c config, op Op, opts ...devicebindOption) *DeviceBindMutation {
  3612. m := &DeviceBindMutation{
  3613. config: c,
  3614. op: op,
  3615. typ: TypeDeviceBind,
  3616. clearedFields: make(map[string]struct{}),
  3617. }
  3618. for _, opt := range opts {
  3619. opt(m)
  3620. }
  3621. return m
  3622. }
  3623. // withDeviceBindID sets the ID field of the mutation.
  3624. func withDeviceBindID(id int64) devicebindOption {
  3625. return func(m *DeviceBindMutation) {
  3626. var (
  3627. err error
  3628. once sync.Once
  3629. value *DeviceBind
  3630. )
  3631. m.oldValue = func(ctx context.Context) (*DeviceBind, error) {
  3632. once.Do(func() {
  3633. if m.done {
  3634. err = errors.New("querying old values post mutation is not allowed")
  3635. } else {
  3636. value, err = m.Client().DeviceBind.Get(ctx, id)
  3637. }
  3638. })
  3639. return value, err
  3640. }
  3641. m.id = &id
  3642. }
  3643. }
  3644. // withDeviceBind sets the old DeviceBind of the mutation.
  3645. func withDeviceBind(node *DeviceBind) devicebindOption {
  3646. return func(m *DeviceBindMutation) {
  3647. m.oldValue = func(context.Context) (*DeviceBind, error) {
  3648. return node, nil
  3649. }
  3650. m.id = &node.ID
  3651. }
  3652. }
  3653. // Client returns a new `ent.Client` from the mutation. If the mutation was
  3654. // executed in a transaction (ent.Tx), a transactional client is returned.
  3655. func (m DeviceBindMutation) Client() *Client {
  3656. client := &Client{config: m.config}
  3657. client.init()
  3658. return client
  3659. }
  3660. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  3661. // it returns an error otherwise.
  3662. func (m DeviceBindMutation) Tx() (*Tx, error) {
  3663. if _, ok := m.driver.(*txDriver); !ok {
  3664. return nil, errors.New("ent: mutation is not running in a transaction")
  3665. }
  3666. tx := &Tx{config: m.config}
  3667. tx.init()
  3668. return tx, nil
  3669. }
  3670. // SetID sets the value of the id field. Note that this
  3671. // operation is only accepted on creation of DeviceBind entities.
  3672. func (m *DeviceBindMutation) SetID(id int64) {
  3673. m.id = &id
  3674. }
  3675. // ID returns the ID value in the mutation. Note that the ID is only available
  3676. // if it was provided to the builder or after it was returned from the database.
  3677. func (m *DeviceBindMutation) ID() (id int64, exists bool) {
  3678. if m.id == nil {
  3679. return
  3680. }
  3681. return *m.id, true
  3682. }
  3683. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  3684. // That means, if the mutation is applied within a transaction with an isolation level such
  3685. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  3686. // or updated by the mutation.
  3687. func (m *DeviceBindMutation) IDs(ctx context.Context) ([]int64, error) {
  3688. switch {
  3689. case m.op.Is(OpUpdateOne | OpDeleteOne):
  3690. id, exists := m.ID()
  3691. if exists {
  3692. return []int64{id}, nil
  3693. }
  3694. fallthrough
  3695. case m.op.Is(OpUpdate | OpDelete):
  3696. return m.Client().DeviceBind.Query().Where(m.predicates...).IDs(ctx)
  3697. default:
  3698. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  3699. }
  3700. }
  3701. // SetCreatedAt sets the "created_at" field.
  3702. func (m *DeviceBindMutation) SetCreatedAt(t time.Time) {
  3703. m.created_at = &t
  3704. }
  3705. // CreatedAt returns the value of the "created_at" field in the mutation.
  3706. func (m *DeviceBindMutation) CreatedAt() (r time.Time, exists bool) {
  3707. v := m.created_at
  3708. if v == nil {
  3709. return
  3710. }
  3711. return *v, true
  3712. }
  3713. // OldCreatedAt returns the old "created_at" field's value of the DeviceBind entity.
  3714. // If the DeviceBind object wasn't provided to the builder, the object is fetched from the database.
  3715. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3716. func (m *DeviceBindMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  3717. if !m.op.Is(OpUpdateOne) {
  3718. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  3719. }
  3720. if m.id == nil || m.oldValue == nil {
  3721. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  3722. }
  3723. oldValue, err := m.oldValue(ctx)
  3724. if err != nil {
  3725. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  3726. }
  3727. return oldValue.CreatedAt, nil
  3728. }
  3729. // ResetCreatedAt resets all changes to the "created_at" field.
  3730. func (m *DeviceBindMutation) ResetCreatedAt() {
  3731. m.created_at = nil
  3732. }
  3733. // SetUpdatedAt sets the "updated_at" field.
  3734. func (m *DeviceBindMutation) SetUpdatedAt(t time.Time) {
  3735. m.updated_at = &t
  3736. }
  3737. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  3738. func (m *DeviceBindMutation) UpdatedAt() (r time.Time, exists bool) {
  3739. v := m.updated_at
  3740. if v == nil {
  3741. return
  3742. }
  3743. return *v, true
  3744. }
  3745. // OldUpdatedAt returns the old "updated_at" field's value of the DeviceBind entity.
  3746. // If the DeviceBind object wasn't provided to the builder, the object is fetched from the database.
  3747. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3748. func (m *DeviceBindMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  3749. if !m.op.Is(OpUpdateOne) {
  3750. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  3751. }
  3752. if m.id == nil || m.oldValue == nil {
  3753. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  3754. }
  3755. oldValue, err := m.oldValue(ctx)
  3756. if err != nil {
  3757. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  3758. }
  3759. return oldValue.UpdatedAt, nil
  3760. }
  3761. // ResetUpdatedAt resets all changes to the "updated_at" field.
  3762. func (m *DeviceBindMutation) ResetUpdatedAt() {
  3763. m.updated_at = nil
  3764. }
  3765. // SetDeletedAt sets the "deleted_at" field.
  3766. func (m *DeviceBindMutation) SetDeletedAt(t time.Time) {
  3767. m.deleted_at = &t
  3768. }
  3769. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  3770. func (m *DeviceBindMutation) DeletedAt() (r time.Time, exists bool) {
  3771. v := m.deleted_at
  3772. if v == nil {
  3773. return
  3774. }
  3775. return *v, true
  3776. }
  3777. // OldDeletedAt returns the old "deleted_at" field's value of the DeviceBind entity.
  3778. // If the DeviceBind object wasn't provided to the builder, the object is fetched from the database.
  3779. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3780. func (m *DeviceBindMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
  3781. if !m.op.Is(OpUpdateOne) {
  3782. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  3783. }
  3784. if m.id == nil || m.oldValue == nil {
  3785. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  3786. }
  3787. oldValue, err := m.oldValue(ctx)
  3788. if err != nil {
  3789. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  3790. }
  3791. return oldValue.DeletedAt, nil
  3792. }
  3793. // ClearDeletedAt clears the value of the "deleted_at" field.
  3794. func (m *DeviceBindMutation) ClearDeletedAt() {
  3795. m.deleted_at = nil
  3796. m.clearedFields[devicebind.FieldDeletedAt] = struct{}{}
  3797. }
  3798. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  3799. func (m *DeviceBindMutation) DeletedAtCleared() bool {
  3800. _, ok := m.clearedFields[devicebind.FieldDeletedAt]
  3801. return ok
  3802. }
  3803. // ResetDeletedAt resets all changes to the "deleted_at" field.
  3804. func (m *DeviceBindMutation) ResetDeletedAt() {
  3805. m.deleted_at = nil
  3806. delete(m.clearedFields, devicebind.FieldDeletedAt)
  3807. }
  3808. // SetDeviceID sets the "device_id" field.
  3809. func (m *DeviceBindMutation) SetDeviceID(i int64) {
  3810. m.device = &i
  3811. }
  3812. // DeviceID returns the value of the "device_id" field in the mutation.
  3813. func (m *DeviceBindMutation) DeviceID() (r int64, exists bool) {
  3814. v := m.device
  3815. if v == nil {
  3816. return
  3817. }
  3818. return *v, true
  3819. }
  3820. // OldDeviceID returns the old "device_id" field's value of the DeviceBind entity.
  3821. // If the DeviceBind object wasn't provided to the builder, the object is fetched from the database.
  3822. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3823. func (m *DeviceBindMutation) OldDeviceID(ctx context.Context) (v int64, err error) {
  3824. if !m.op.Is(OpUpdateOne) {
  3825. return v, errors.New("OldDeviceID is only allowed on UpdateOne operations")
  3826. }
  3827. if m.id == nil || m.oldValue == nil {
  3828. return v, errors.New("OldDeviceID requires an ID field in the mutation")
  3829. }
  3830. oldValue, err := m.oldValue(ctx)
  3831. if err != nil {
  3832. return v, fmt.Errorf("querying old value for OldDeviceID: %w", err)
  3833. }
  3834. return oldValue.DeviceID, nil
  3835. }
  3836. // ClearDeviceID clears the value of the "device_id" field.
  3837. func (m *DeviceBindMutation) ClearDeviceID() {
  3838. m.device = nil
  3839. m.clearedFields[devicebind.FieldDeviceID] = struct{}{}
  3840. }
  3841. // DeviceIDCleared returns if the "device_id" field was cleared in this mutation.
  3842. func (m *DeviceBindMutation) DeviceIDCleared() bool {
  3843. _, ok := m.clearedFields[devicebind.FieldDeviceID]
  3844. return ok
  3845. }
  3846. // ResetDeviceID resets all changes to the "device_id" field.
  3847. func (m *DeviceBindMutation) ResetDeviceID() {
  3848. m.device = nil
  3849. delete(m.clearedFields, devicebind.FieldDeviceID)
  3850. }
  3851. // SetChildID sets the "child_id" field.
  3852. func (m *DeviceBindMutation) SetChildID(u uuid.UUID) {
  3853. m.child = &u
  3854. }
  3855. // ChildID returns the value of the "child_id" field in the mutation.
  3856. func (m *DeviceBindMutation) ChildID() (r uuid.UUID, exists bool) {
  3857. v := m.child
  3858. if v == nil {
  3859. return
  3860. }
  3861. return *v, true
  3862. }
  3863. // OldChildID returns the old "child_id" field's value of the DeviceBind entity.
  3864. // If the DeviceBind object wasn't provided to the builder, the object is fetched from the database.
  3865. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3866. func (m *DeviceBindMutation) OldChildID(ctx context.Context) (v uuid.UUID, err error) {
  3867. if !m.op.Is(OpUpdateOne) {
  3868. return v, errors.New("OldChildID is only allowed on UpdateOne operations")
  3869. }
  3870. if m.id == nil || m.oldValue == nil {
  3871. return v, errors.New("OldChildID requires an ID field in the mutation")
  3872. }
  3873. oldValue, err := m.oldValue(ctx)
  3874. if err != nil {
  3875. return v, fmt.Errorf("querying old value for OldChildID: %w", err)
  3876. }
  3877. return oldValue.ChildID, nil
  3878. }
  3879. // ClearChildID clears the value of the "child_id" field.
  3880. func (m *DeviceBindMutation) ClearChildID() {
  3881. m.child = nil
  3882. m.clearedFields[devicebind.FieldChildID] = struct{}{}
  3883. }
  3884. // ChildIDCleared returns if the "child_id" field was cleared in this mutation.
  3885. func (m *DeviceBindMutation) ChildIDCleared() bool {
  3886. _, ok := m.clearedFields[devicebind.FieldChildID]
  3887. return ok
  3888. }
  3889. // ResetChildID resets all changes to the "child_id" field.
  3890. func (m *DeviceBindMutation) ResetChildID() {
  3891. m.child = nil
  3892. delete(m.clearedFields, devicebind.FieldChildID)
  3893. }
  3894. // ClearDevice clears the "device" edge to the Device entity.
  3895. func (m *DeviceBindMutation) ClearDevice() {
  3896. m.cleareddevice = true
  3897. m.clearedFields[devicebind.FieldDeviceID] = struct{}{}
  3898. }
  3899. // DeviceCleared reports if the "device" edge to the Device entity was cleared.
  3900. func (m *DeviceBindMutation) DeviceCleared() bool {
  3901. return m.DeviceIDCleared() || m.cleareddevice
  3902. }
  3903. // DeviceIDs returns the "device" edge IDs in the mutation.
  3904. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  3905. // DeviceID instead. It exists only for internal usage by the builders.
  3906. func (m *DeviceBindMutation) DeviceIDs() (ids []int64) {
  3907. if id := m.device; id != nil {
  3908. ids = append(ids, *id)
  3909. }
  3910. return
  3911. }
  3912. // ResetDevice resets all changes to the "device" edge.
  3913. func (m *DeviceBindMutation) ResetDevice() {
  3914. m.device = nil
  3915. m.cleareddevice = false
  3916. }
  3917. // ClearChild clears the "child" edge to the Child entity.
  3918. func (m *DeviceBindMutation) ClearChild() {
  3919. m.clearedchild = true
  3920. m.clearedFields[devicebind.FieldChildID] = struct{}{}
  3921. }
  3922. // ChildCleared reports if the "child" edge to the Child entity was cleared.
  3923. func (m *DeviceBindMutation) ChildCleared() bool {
  3924. return m.ChildIDCleared() || m.clearedchild
  3925. }
  3926. // ChildIDs returns the "child" edge IDs in the mutation.
  3927. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  3928. // ChildID instead. It exists only for internal usage by the builders.
  3929. func (m *DeviceBindMutation) ChildIDs() (ids []uuid.UUID) {
  3930. if id := m.child; id != nil {
  3931. ids = append(ids, *id)
  3932. }
  3933. return
  3934. }
  3935. // ResetChild resets all changes to the "child" edge.
  3936. func (m *DeviceBindMutation) ResetChild() {
  3937. m.child = nil
  3938. m.clearedchild = false
  3939. }
  3940. // Where appends a list predicates to the DeviceBindMutation builder.
  3941. func (m *DeviceBindMutation) Where(ps ...predicate.DeviceBind) {
  3942. m.predicates = append(m.predicates, ps...)
  3943. }
  3944. // WhereP appends storage-level predicates to the DeviceBindMutation builder. Using this method,
  3945. // users can use type-assertion to append predicates that do not depend on any generated package.
  3946. func (m *DeviceBindMutation) WhereP(ps ...func(*sql.Selector)) {
  3947. p := make([]predicate.DeviceBind, len(ps))
  3948. for i := range ps {
  3949. p[i] = ps[i]
  3950. }
  3951. m.Where(p...)
  3952. }
  3953. // Op returns the operation name.
  3954. func (m *DeviceBindMutation) Op() Op {
  3955. return m.op
  3956. }
  3957. // SetOp allows setting the mutation operation.
  3958. func (m *DeviceBindMutation) SetOp(op Op) {
  3959. m.op = op
  3960. }
  3961. // Type returns the node type of this mutation (DeviceBind).
  3962. func (m *DeviceBindMutation) Type() string {
  3963. return m.typ
  3964. }
  3965. // Fields returns all fields that were changed during this mutation. Note that in
  3966. // order to get all numeric fields that were incremented/decremented, call
  3967. // AddedFields().
  3968. func (m *DeviceBindMutation) Fields() []string {
  3969. fields := make([]string, 0, 5)
  3970. if m.created_at != nil {
  3971. fields = append(fields, devicebind.FieldCreatedAt)
  3972. }
  3973. if m.updated_at != nil {
  3974. fields = append(fields, devicebind.FieldUpdatedAt)
  3975. }
  3976. if m.deleted_at != nil {
  3977. fields = append(fields, devicebind.FieldDeletedAt)
  3978. }
  3979. if m.device != nil {
  3980. fields = append(fields, devicebind.FieldDeviceID)
  3981. }
  3982. if m.child != nil {
  3983. fields = append(fields, devicebind.FieldChildID)
  3984. }
  3985. return fields
  3986. }
  3987. // Field returns the value of a field with the given name. The second boolean
  3988. // return value indicates that this field was not set, or was not defined in the
  3989. // schema.
  3990. func (m *DeviceBindMutation) Field(name string) (ent.Value, bool) {
  3991. switch name {
  3992. case devicebind.FieldCreatedAt:
  3993. return m.CreatedAt()
  3994. case devicebind.FieldUpdatedAt:
  3995. return m.UpdatedAt()
  3996. case devicebind.FieldDeletedAt:
  3997. return m.DeletedAt()
  3998. case devicebind.FieldDeviceID:
  3999. return m.DeviceID()
  4000. case devicebind.FieldChildID:
  4001. return m.ChildID()
  4002. }
  4003. return nil, false
  4004. }
  4005. // OldField returns the old value of the field from the database. An error is
  4006. // returned if the mutation operation is not UpdateOne, or the query to the
  4007. // database failed.
  4008. func (m *DeviceBindMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  4009. switch name {
  4010. case devicebind.FieldCreatedAt:
  4011. return m.OldCreatedAt(ctx)
  4012. case devicebind.FieldUpdatedAt:
  4013. return m.OldUpdatedAt(ctx)
  4014. case devicebind.FieldDeletedAt:
  4015. return m.OldDeletedAt(ctx)
  4016. case devicebind.FieldDeviceID:
  4017. return m.OldDeviceID(ctx)
  4018. case devicebind.FieldChildID:
  4019. return m.OldChildID(ctx)
  4020. }
  4021. return nil, fmt.Errorf("unknown DeviceBind field %s", name)
  4022. }
  4023. // SetField sets the value of a field with the given name. It returns an error if
  4024. // the field is not defined in the schema, or if the type mismatched the field
  4025. // type.
  4026. func (m *DeviceBindMutation) SetField(name string, value ent.Value) error {
  4027. switch name {
  4028. case devicebind.FieldCreatedAt:
  4029. v, ok := value.(time.Time)
  4030. if !ok {
  4031. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4032. }
  4033. m.SetCreatedAt(v)
  4034. return nil
  4035. case devicebind.FieldUpdatedAt:
  4036. v, ok := value.(time.Time)
  4037. if !ok {
  4038. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4039. }
  4040. m.SetUpdatedAt(v)
  4041. return nil
  4042. case devicebind.FieldDeletedAt:
  4043. v, ok := value.(time.Time)
  4044. if !ok {
  4045. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4046. }
  4047. m.SetDeletedAt(v)
  4048. return nil
  4049. case devicebind.FieldDeviceID:
  4050. v, ok := value.(int64)
  4051. if !ok {
  4052. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4053. }
  4054. m.SetDeviceID(v)
  4055. return nil
  4056. case devicebind.FieldChildID:
  4057. v, ok := value.(uuid.UUID)
  4058. if !ok {
  4059. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4060. }
  4061. m.SetChildID(v)
  4062. return nil
  4063. }
  4064. return fmt.Errorf("unknown DeviceBind field %s", name)
  4065. }
  4066. // AddedFields returns all numeric fields that were incremented/decremented during
  4067. // this mutation.
  4068. func (m *DeviceBindMutation) AddedFields() []string {
  4069. var fields []string
  4070. return fields
  4071. }
  4072. // AddedField returns the numeric value that was incremented/decremented on a field
  4073. // with the given name. The second boolean return value indicates that this field
  4074. // was not set, or was not defined in the schema.
  4075. func (m *DeviceBindMutation) AddedField(name string) (ent.Value, bool) {
  4076. switch name {
  4077. }
  4078. return nil, false
  4079. }
  4080. // AddField adds the value to the field with the given name. It returns an error if
  4081. // the field is not defined in the schema, or if the type mismatched the field
  4082. // type.
  4083. func (m *DeviceBindMutation) AddField(name string, value ent.Value) error {
  4084. switch name {
  4085. }
  4086. return fmt.Errorf("unknown DeviceBind numeric field %s", name)
  4087. }
  4088. // ClearedFields returns all nullable fields that were cleared during this
  4089. // mutation.
  4090. func (m *DeviceBindMutation) ClearedFields() []string {
  4091. var fields []string
  4092. if m.FieldCleared(devicebind.FieldDeletedAt) {
  4093. fields = append(fields, devicebind.FieldDeletedAt)
  4094. }
  4095. if m.FieldCleared(devicebind.FieldDeviceID) {
  4096. fields = append(fields, devicebind.FieldDeviceID)
  4097. }
  4098. if m.FieldCleared(devicebind.FieldChildID) {
  4099. fields = append(fields, devicebind.FieldChildID)
  4100. }
  4101. return fields
  4102. }
  4103. // FieldCleared returns a boolean indicating if a field with the given name was
  4104. // cleared in this mutation.
  4105. func (m *DeviceBindMutation) FieldCleared(name string) bool {
  4106. _, ok := m.clearedFields[name]
  4107. return ok
  4108. }
  4109. // ClearField clears the value of the field with the given name. It returns an
  4110. // error if the field is not defined in the schema.
  4111. func (m *DeviceBindMutation) ClearField(name string) error {
  4112. switch name {
  4113. case devicebind.FieldDeletedAt:
  4114. m.ClearDeletedAt()
  4115. return nil
  4116. case devicebind.FieldDeviceID:
  4117. m.ClearDeviceID()
  4118. return nil
  4119. case devicebind.FieldChildID:
  4120. m.ClearChildID()
  4121. return nil
  4122. }
  4123. return fmt.Errorf("unknown DeviceBind nullable field %s", name)
  4124. }
  4125. // ResetField resets all changes in the mutation for the field with the given name.
  4126. // It returns an error if the field is not defined in the schema.
  4127. func (m *DeviceBindMutation) ResetField(name string) error {
  4128. switch name {
  4129. case devicebind.FieldCreatedAt:
  4130. m.ResetCreatedAt()
  4131. return nil
  4132. case devicebind.FieldUpdatedAt:
  4133. m.ResetUpdatedAt()
  4134. return nil
  4135. case devicebind.FieldDeletedAt:
  4136. m.ResetDeletedAt()
  4137. return nil
  4138. case devicebind.FieldDeviceID:
  4139. m.ResetDeviceID()
  4140. return nil
  4141. case devicebind.FieldChildID:
  4142. m.ResetChildID()
  4143. return nil
  4144. }
  4145. return fmt.Errorf("unknown DeviceBind field %s", name)
  4146. }
  4147. // AddedEdges returns all edge names that were set/added in this mutation.
  4148. func (m *DeviceBindMutation) AddedEdges() []string {
  4149. edges := make([]string, 0, 2)
  4150. if m.device != nil {
  4151. edges = append(edges, devicebind.EdgeDevice)
  4152. }
  4153. if m.child != nil {
  4154. edges = append(edges, devicebind.EdgeChild)
  4155. }
  4156. return edges
  4157. }
  4158. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  4159. // name in this mutation.
  4160. func (m *DeviceBindMutation) AddedIDs(name string) []ent.Value {
  4161. switch name {
  4162. case devicebind.EdgeDevice:
  4163. if id := m.device; id != nil {
  4164. return []ent.Value{*id}
  4165. }
  4166. case devicebind.EdgeChild:
  4167. if id := m.child; id != nil {
  4168. return []ent.Value{*id}
  4169. }
  4170. }
  4171. return nil
  4172. }
  4173. // RemovedEdges returns all edge names that were removed in this mutation.
  4174. func (m *DeviceBindMutation) RemovedEdges() []string {
  4175. edges := make([]string, 0, 2)
  4176. return edges
  4177. }
  4178. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  4179. // the given name in this mutation.
  4180. func (m *DeviceBindMutation) RemovedIDs(name string) []ent.Value {
  4181. return nil
  4182. }
  4183. // ClearedEdges returns all edge names that were cleared in this mutation.
  4184. func (m *DeviceBindMutation) ClearedEdges() []string {
  4185. edges := make([]string, 0, 2)
  4186. if m.cleareddevice {
  4187. edges = append(edges, devicebind.EdgeDevice)
  4188. }
  4189. if m.clearedchild {
  4190. edges = append(edges, devicebind.EdgeChild)
  4191. }
  4192. return edges
  4193. }
  4194. // EdgeCleared returns a boolean which indicates if the edge with the given name
  4195. // was cleared in this mutation.
  4196. func (m *DeviceBindMutation) EdgeCleared(name string) bool {
  4197. switch name {
  4198. case devicebind.EdgeDevice:
  4199. return m.cleareddevice
  4200. case devicebind.EdgeChild:
  4201. return m.clearedchild
  4202. }
  4203. return false
  4204. }
  4205. // ClearEdge clears the value of the edge with the given name. It returns an error
  4206. // if that edge is not defined in the schema.
  4207. func (m *DeviceBindMutation) ClearEdge(name string) error {
  4208. switch name {
  4209. case devicebind.EdgeDevice:
  4210. m.ClearDevice()
  4211. return nil
  4212. case devicebind.EdgeChild:
  4213. m.ClearChild()
  4214. return nil
  4215. }
  4216. return fmt.Errorf("unknown DeviceBind unique edge %s", name)
  4217. }
  4218. // ResetEdge resets all changes to the edge with the given name in this mutation.
  4219. // It returns an error if the edge is not defined in the schema.
  4220. func (m *DeviceBindMutation) ResetEdge(name string) error {
  4221. switch name {
  4222. case devicebind.EdgeDevice:
  4223. m.ResetDevice()
  4224. return nil
  4225. case devicebind.EdgeChild:
  4226. m.ResetChild()
  4227. return nil
  4228. }
  4229. return fmt.Errorf("unknown DeviceBind edge %s", name)
  4230. }
  4231. // DeviceConfigMutation represents an operation that mutates the DeviceConfig nodes in the graph.
  4232. type DeviceConfigMutation struct {
  4233. config
  4234. op Op
  4235. typ string
  4236. id *int64
  4237. created_at *time.Time
  4238. updated_at *time.Time
  4239. deleted_at *time.Time
  4240. key *string
  4241. value *string
  4242. before_value *string
  4243. clearedFields map[string]struct{}
  4244. device *int64
  4245. cleareddevice bool
  4246. done bool
  4247. oldValue func(context.Context) (*DeviceConfig, error)
  4248. predicates []predicate.DeviceConfig
  4249. }
  4250. var _ ent.Mutation = (*DeviceConfigMutation)(nil)
  4251. // deviceconfigOption allows management of the mutation configuration using functional options.
  4252. type deviceconfigOption func(*DeviceConfigMutation)
  4253. // newDeviceConfigMutation creates new mutation for the DeviceConfig entity.
  4254. func newDeviceConfigMutation(c config, op Op, opts ...deviceconfigOption) *DeviceConfigMutation {
  4255. m := &DeviceConfigMutation{
  4256. config: c,
  4257. op: op,
  4258. typ: TypeDeviceConfig,
  4259. clearedFields: make(map[string]struct{}),
  4260. }
  4261. for _, opt := range opts {
  4262. opt(m)
  4263. }
  4264. return m
  4265. }
  4266. // withDeviceConfigID sets the ID field of the mutation.
  4267. func withDeviceConfigID(id int64) deviceconfigOption {
  4268. return func(m *DeviceConfigMutation) {
  4269. var (
  4270. err error
  4271. once sync.Once
  4272. value *DeviceConfig
  4273. )
  4274. m.oldValue = func(ctx context.Context) (*DeviceConfig, error) {
  4275. once.Do(func() {
  4276. if m.done {
  4277. err = errors.New("querying old values post mutation is not allowed")
  4278. } else {
  4279. value, err = m.Client().DeviceConfig.Get(ctx, id)
  4280. }
  4281. })
  4282. return value, err
  4283. }
  4284. m.id = &id
  4285. }
  4286. }
  4287. // withDeviceConfig sets the old DeviceConfig of the mutation.
  4288. func withDeviceConfig(node *DeviceConfig) deviceconfigOption {
  4289. return func(m *DeviceConfigMutation) {
  4290. m.oldValue = func(context.Context) (*DeviceConfig, error) {
  4291. return node, nil
  4292. }
  4293. m.id = &node.ID
  4294. }
  4295. }
  4296. // Client returns a new `ent.Client` from the mutation. If the mutation was
  4297. // executed in a transaction (ent.Tx), a transactional client is returned.
  4298. func (m DeviceConfigMutation) Client() *Client {
  4299. client := &Client{config: m.config}
  4300. client.init()
  4301. return client
  4302. }
  4303. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  4304. // it returns an error otherwise.
  4305. func (m DeviceConfigMutation) Tx() (*Tx, error) {
  4306. if _, ok := m.driver.(*txDriver); !ok {
  4307. return nil, errors.New("ent: mutation is not running in a transaction")
  4308. }
  4309. tx := &Tx{config: m.config}
  4310. tx.init()
  4311. return tx, nil
  4312. }
  4313. // SetID sets the value of the id field. Note that this
  4314. // operation is only accepted on creation of DeviceConfig entities.
  4315. func (m *DeviceConfigMutation) SetID(id int64) {
  4316. m.id = &id
  4317. }
  4318. // ID returns the ID value in the mutation. Note that the ID is only available
  4319. // if it was provided to the builder or after it was returned from the database.
  4320. func (m *DeviceConfigMutation) ID() (id int64, exists bool) {
  4321. if m.id == nil {
  4322. return
  4323. }
  4324. return *m.id, true
  4325. }
  4326. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  4327. // That means, if the mutation is applied within a transaction with an isolation level such
  4328. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  4329. // or updated by the mutation.
  4330. func (m *DeviceConfigMutation) IDs(ctx context.Context) ([]int64, error) {
  4331. switch {
  4332. case m.op.Is(OpUpdateOne | OpDeleteOne):
  4333. id, exists := m.ID()
  4334. if exists {
  4335. return []int64{id}, nil
  4336. }
  4337. fallthrough
  4338. case m.op.Is(OpUpdate | OpDelete):
  4339. return m.Client().DeviceConfig.Query().Where(m.predicates...).IDs(ctx)
  4340. default:
  4341. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  4342. }
  4343. }
  4344. // SetCreatedAt sets the "created_at" field.
  4345. func (m *DeviceConfigMutation) SetCreatedAt(t time.Time) {
  4346. m.created_at = &t
  4347. }
  4348. // CreatedAt returns the value of the "created_at" field in the mutation.
  4349. func (m *DeviceConfigMutation) CreatedAt() (r time.Time, exists bool) {
  4350. v := m.created_at
  4351. if v == nil {
  4352. return
  4353. }
  4354. return *v, true
  4355. }
  4356. // OldCreatedAt returns the old "created_at" field's value of the DeviceConfig entity.
  4357. // If the DeviceConfig object wasn't provided to the builder, the object is fetched from the database.
  4358. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4359. func (m *DeviceConfigMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  4360. if !m.op.Is(OpUpdateOne) {
  4361. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  4362. }
  4363. if m.id == nil || m.oldValue == nil {
  4364. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  4365. }
  4366. oldValue, err := m.oldValue(ctx)
  4367. if err != nil {
  4368. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  4369. }
  4370. return oldValue.CreatedAt, nil
  4371. }
  4372. // ResetCreatedAt resets all changes to the "created_at" field.
  4373. func (m *DeviceConfigMutation) ResetCreatedAt() {
  4374. m.created_at = nil
  4375. }
  4376. // SetUpdatedAt sets the "updated_at" field.
  4377. func (m *DeviceConfigMutation) SetUpdatedAt(t time.Time) {
  4378. m.updated_at = &t
  4379. }
  4380. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  4381. func (m *DeviceConfigMutation) UpdatedAt() (r time.Time, exists bool) {
  4382. v := m.updated_at
  4383. if v == nil {
  4384. return
  4385. }
  4386. return *v, true
  4387. }
  4388. // OldUpdatedAt returns the old "updated_at" field's value of the DeviceConfig entity.
  4389. // If the DeviceConfig object wasn't provided to the builder, the object is fetched from the database.
  4390. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4391. func (m *DeviceConfigMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  4392. if !m.op.Is(OpUpdateOne) {
  4393. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  4394. }
  4395. if m.id == nil || m.oldValue == nil {
  4396. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  4397. }
  4398. oldValue, err := m.oldValue(ctx)
  4399. if err != nil {
  4400. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  4401. }
  4402. return oldValue.UpdatedAt, nil
  4403. }
  4404. // ResetUpdatedAt resets all changes to the "updated_at" field.
  4405. func (m *DeviceConfigMutation) ResetUpdatedAt() {
  4406. m.updated_at = nil
  4407. }
  4408. // SetDeletedAt sets the "deleted_at" field.
  4409. func (m *DeviceConfigMutation) SetDeletedAt(t time.Time) {
  4410. m.deleted_at = &t
  4411. }
  4412. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  4413. func (m *DeviceConfigMutation) DeletedAt() (r time.Time, exists bool) {
  4414. v := m.deleted_at
  4415. if v == nil {
  4416. return
  4417. }
  4418. return *v, true
  4419. }
  4420. // OldDeletedAt returns the old "deleted_at" field's value of the DeviceConfig entity.
  4421. // If the DeviceConfig object wasn't provided to the builder, the object is fetched from the database.
  4422. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4423. func (m *DeviceConfigMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
  4424. if !m.op.Is(OpUpdateOne) {
  4425. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  4426. }
  4427. if m.id == nil || m.oldValue == nil {
  4428. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  4429. }
  4430. oldValue, err := m.oldValue(ctx)
  4431. if err != nil {
  4432. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  4433. }
  4434. return oldValue.DeletedAt, nil
  4435. }
  4436. // ClearDeletedAt clears the value of the "deleted_at" field.
  4437. func (m *DeviceConfigMutation) ClearDeletedAt() {
  4438. m.deleted_at = nil
  4439. m.clearedFields[deviceconfig.FieldDeletedAt] = struct{}{}
  4440. }
  4441. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  4442. func (m *DeviceConfigMutation) DeletedAtCleared() bool {
  4443. _, ok := m.clearedFields[deviceconfig.FieldDeletedAt]
  4444. return ok
  4445. }
  4446. // ResetDeletedAt resets all changes to the "deleted_at" field.
  4447. func (m *DeviceConfigMutation) ResetDeletedAt() {
  4448. m.deleted_at = nil
  4449. delete(m.clearedFields, deviceconfig.FieldDeletedAt)
  4450. }
  4451. // SetDeviceID sets the "device_id" field.
  4452. func (m *DeviceConfigMutation) SetDeviceID(i int64) {
  4453. m.device = &i
  4454. }
  4455. // DeviceID returns the value of the "device_id" field in the mutation.
  4456. func (m *DeviceConfigMutation) DeviceID() (r int64, exists bool) {
  4457. v := m.device
  4458. if v == nil {
  4459. return
  4460. }
  4461. return *v, true
  4462. }
  4463. // OldDeviceID returns the old "device_id" field's value of the DeviceConfig entity.
  4464. // If the DeviceConfig object wasn't provided to the builder, the object is fetched from the database.
  4465. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4466. func (m *DeviceConfigMutation) OldDeviceID(ctx context.Context) (v int64, err error) {
  4467. if !m.op.Is(OpUpdateOne) {
  4468. return v, errors.New("OldDeviceID is only allowed on UpdateOne operations")
  4469. }
  4470. if m.id == nil || m.oldValue == nil {
  4471. return v, errors.New("OldDeviceID requires an ID field in the mutation")
  4472. }
  4473. oldValue, err := m.oldValue(ctx)
  4474. if err != nil {
  4475. return v, fmt.Errorf("querying old value for OldDeviceID: %w", err)
  4476. }
  4477. return oldValue.DeviceID, nil
  4478. }
  4479. // ClearDeviceID clears the value of the "device_id" field.
  4480. func (m *DeviceConfigMutation) ClearDeviceID() {
  4481. m.device = nil
  4482. m.clearedFields[deviceconfig.FieldDeviceID] = struct{}{}
  4483. }
  4484. // DeviceIDCleared returns if the "device_id" field was cleared in this mutation.
  4485. func (m *DeviceConfigMutation) DeviceIDCleared() bool {
  4486. _, ok := m.clearedFields[deviceconfig.FieldDeviceID]
  4487. return ok
  4488. }
  4489. // ResetDeviceID resets all changes to the "device_id" field.
  4490. func (m *DeviceConfigMutation) ResetDeviceID() {
  4491. m.device = nil
  4492. delete(m.clearedFields, deviceconfig.FieldDeviceID)
  4493. }
  4494. // SetKey sets the "key" field.
  4495. func (m *DeviceConfigMutation) SetKey(s string) {
  4496. m.key = &s
  4497. }
  4498. // Key returns the value of the "key" field in the mutation.
  4499. func (m *DeviceConfigMutation) Key() (r string, exists bool) {
  4500. v := m.key
  4501. if v == nil {
  4502. return
  4503. }
  4504. return *v, true
  4505. }
  4506. // OldKey returns the old "key" field's value of the DeviceConfig entity.
  4507. // If the DeviceConfig object wasn't provided to the builder, the object is fetched from the database.
  4508. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4509. func (m *DeviceConfigMutation) OldKey(ctx context.Context) (v string, err error) {
  4510. if !m.op.Is(OpUpdateOne) {
  4511. return v, errors.New("OldKey is only allowed on UpdateOne operations")
  4512. }
  4513. if m.id == nil || m.oldValue == nil {
  4514. return v, errors.New("OldKey requires an ID field in the mutation")
  4515. }
  4516. oldValue, err := m.oldValue(ctx)
  4517. if err != nil {
  4518. return v, fmt.Errorf("querying old value for OldKey: %w", err)
  4519. }
  4520. return oldValue.Key, nil
  4521. }
  4522. // ResetKey resets all changes to the "key" field.
  4523. func (m *DeviceConfigMutation) ResetKey() {
  4524. m.key = nil
  4525. }
  4526. // SetValue sets the "value" field.
  4527. func (m *DeviceConfigMutation) SetValue(s string) {
  4528. m.value = &s
  4529. }
  4530. // Value returns the value of the "value" field in the mutation.
  4531. func (m *DeviceConfigMutation) Value() (r string, exists bool) {
  4532. v := m.value
  4533. if v == nil {
  4534. return
  4535. }
  4536. return *v, true
  4537. }
  4538. // OldValue returns the old "value" field's value of the DeviceConfig entity.
  4539. // If the DeviceConfig object wasn't provided to the builder, the object is fetched from the database.
  4540. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4541. func (m *DeviceConfigMutation) OldValue(ctx context.Context) (v string, err error) {
  4542. if !m.op.Is(OpUpdateOne) {
  4543. return v, errors.New("OldValue is only allowed on UpdateOne operations")
  4544. }
  4545. if m.id == nil || m.oldValue == nil {
  4546. return v, errors.New("OldValue requires an ID field in the mutation")
  4547. }
  4548. oldValue, err := m.oldValue(ctx)
  4549. if err != nil {
  4550. return v, fmt.Errorf("querying old value for OldValue: %w", err)
  4551. }
  4552. return oldValue.Value, nil
  4553. }
  4554. // ResetValue resets all changes to the "value" field.
  4555. func (m *DeviceConfigMutation) ResetValue() {
  4556. m.value = nil
  4557. }
  4558. // SetBeforeValue sets the "before_value" field.
  4559. func (m *DeviceConfigMutation) SetBeforeValue(s string) {
  4560. m.before_value = &s
  4561. }
  4562. // BeforeValue returns the value of the "before_value" field in the mutation.
  4563. func (m *DeviceConfigMutation) BeforeValue() (r string, exists bool) {
  4564. v := m.before_value
  4565. if v == nil {
  4566. return
  4567. }
  4568. return *v, true
  4569. }
  4570. // OldBeforeValue returns the old "before_value" field's value of the DeviceConfig entity.
  4571. // If the DeviceConfig object wasn't provided to the builder, the object is fetched from the database.
  4572. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4573. func (m *DeviceConfigMutation) OldBeforeValue(ctx context.Context) (v *string, err error) {
  4574. if !m.op.Is(OpUpdateOne) {
  4575. return v, errors.New("OldBeforeValue is only allowed on UpdateOne operations")
  4576. }
  4577. if m.id == nil || m.oldValue == nil {
  4578. return v, errors.New("OldBeforeValue requires an ID field in the mutation")
  4579. }
  4580. oldValue, err := m.oldValue(ctx)
  4581. if err != nil {
  4582. return v, fmt.Errorf("querying old value for OldBeforeValue: %w", err)
  4583. }
  4584. return oldValue.BeforeValue, nil
  4585. }
  4586. // ClearBeforeValue clears the value of the "before_value" field.
  4587. func (m *DeviceConfigMutation) ClearBeforeValue() {
  4588. m.before_value = nil
  4589. m.clearedFields[deviceconfig.FieldBeforeValue] = struct{}{}
  4590. }
  4591. // BeforeValueCleared returns if the "before_value" field was cleared in this mutation.
  4592. func (m *DeviceConfigMutation) BeforeValueCleared() bool {
  4593. _, ok := m.clearedFields[deviceconfig.FieldBeforeValue]
  4594. return ok
  4595. }
  4596. // ResetBeforeValue resets all changes to the "before_value" field.
  4597. func (m *DeviceConfigMutation) ResetBeforeValue() {
  4598. m.before_value = nil
  4599. delete(m.clearedFields, deviceconfig.FieldBeforeValue)
  4600. }
  4601. // ClearDevice clears the "device" edge to the Device entity.
  4602. func (m *DeviceConfigMutation) ClearDevice() {
  4603. m.cleareddevice = true
  4604. m.clearedFields[deviceconfig.FieldDeviceID] = struct{}{}
  4605. }
  4606. // DeviceCleared reports if the "device" edge to the Device entity was cleared.
  4607. func (m *DeviceConfigMutation) DeviceCleared() bool {
  4608. return m.DeviceIDCleared() || m.cleareddevice
  4609. }
  4610. // DeviceIDs returns the "device" edge IDs in the mutation.
  4611. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  4612. // DeviceID instead. It exists only for internal usage by the builders.
  4613. func (m *DeviceConfigMutation) DeviceIDs() (ids []int64) {
  4614. if id := m.device; id != nil {
  4615. ids = append(ids, *id)
  4616. }
  4617. return
  4618. }
  4619. // ResetDevice resets all changes to the "device" edge.
  4620. func (m *DeviceConfigMutation) ResetDevice() {
  4621. m.device = nil
  4622. m.cleareddevice = false
  4623. }
  4624. // Where appends a list predicates to the DeviceConfigMutation builder.
  4625. func (m *DeviceConfigMutation) Where(ps ...predicate.DeviceConfig) {
  4626. m.predicates = append(m.predicates, ps...)
  4627. }
  4628. // WhereP appends storage-level predicates to the DeviceConfigMutation builder. Using this method,
  4629. // users can use type-assertion to append predicates that do not depend on any generated package.
  4630. func (m *DeviceConfigMutation) WhereP(ps ...func(*sql.Selector)) {
  4631. p := make([]predicate.DeviceConfig, len(ps))
  4632. for i := range ps {
  4633. p[i] = ps[i]
  4634. }
  4635. m.Where(p...)
  4636. }
  4637. // Op returns the operation name.
  4638. func (m *DeviceConfigMutation) Op() Op {
  4639. return m.op
  4640. }
  4641. // SetOp allows setting the mutation operation.
  4642. func (m *DeviceConfigMutation) SetOp(op Op) {
  4643. m.op = op
  4644. }
  4645. // Type returns the node type of this mutation (DeviceConfig).
  4646. func (m *DeviceConfigMutation) Type() string {
  4647. return m.typ
  4648. }
  4649. // Fields returns all fields that were changed during this mutation. Note that in
  4650. // order to get all numeric fields that were incremented/decremented, call
  4651. // AddedFields().
  4652. func (m *DeviceConfigMutation) Fields() []string {
  4653. fields := make([]string, 0, 7)
  4654. if m.created_at != nil {
  4655. fields = append(fields, deviceconfig.FieldCreatedAt)
  4656. }
  4657. if m.updated_at != nil {
  4658. fields = append(fields, deviceconfig.FieldUpdatedAt)
  4659. }
  4660. if m.deleted_at != nil {
  4661. fields = append(fields, deviceconfig.FieldDeletedAt)
  4662. }
  4663. if m.device != nil {
  4664. fields = append(fields, deviceconfig.FieldDeviceID)
  4665. }
  4666. if m.key != nil {
  4667. fields = append(fields, deviceconfig.FieldKey)
  4668. }
  4669. if m.value != nil {
  4670. fields = append(fields, deviceconfig.FieldValue)
  4671. }
  4672. if m.before_value != nil {
  4673. fields = append(fields, deviceconfig.FieldBeforeValue)
  4674. }
  4675. return fields
  4676. }
  4677. // Field returns the value of a field with the given name. The second boolean
  4678. // return value indicates that this field was not set, or was not defined in the
  4679. // schema.
  4680. func (m *DeviceConfigMutation) Field(name string) (ent.Value, bool) {
  4681. switch name {
  4682. case deviceconfig.FieldCreatedAt:
  4683. return m.CreatedAt()
  4684. case deviceconfig.FieldUpdatedAt:
  4685. return m.UpdatedAt()
  4686. case deviceconfig.FieldDeletedAt:
  4687. return m.DeletedAt()
  4688. case deviceconfig.FieldDeviceID:
  4689. return m.DeviceID()
  4690. case deviceconfig.FieldKey:
  4691. return m.Key()
  4692. case deviceconfig.FieldValue:
  4693. return m.Value()
  4694. case deviceconfig.FieldBeforeValue:
  4695. return m.BeforeValue()
  4696. }
  4697. return nil, false
  4698. }
  4699. // OldField returns the old value of the field from the database. An error is
  4700. // returned if the mutation operation is not UpdateOne, or the query to the
  4701. // database failed.
  4702. func (m *DeviceConfigMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  4703. switch name {
  4704. case deviceconfig.FieldCreatedAt:
  4705. return m.OldCreatedAt(ctx)
  4706. case deviceconfig.FieldUpdatedAt:
  4707. return m.OldUpdatedAt(ctx)
  4708. case deviceconfig.FieldDeletedAt:
  4709. return m.OldDeletedAt(ctx)
  4710. case deviceconfig.FieldDeviceID:
  4711. return m.OldDeviceID(ctx)
  4712. case deviceconfig.FieldKey:
  4713. return m.OldKey(ctx)
  4714. case deviceconfig.FieldValue:
  4715. return m.OldValue(ctx)
  4716. case deviceconfig.FieldBeforeValue:
  4717. return m.OldBeforeValue(ctx)
  4718. }
  4719. return nil, fmt.Errorf("unknown DeviceConfig field %s", name)
  4720. }
  4721. // SetField sets the value of a field with the given name. It returns an error if
  4722. // the field is not defined in the schema, or if the type mismatched the field
  4723. // type.
  4724. func (m *DeviceConfigMutation) SetField(name string, value ent.Value) error {
  4725. switch name {
  4726. case deviceconfig.FieldCreatedAt:
  4727. v, ok := value.(time.Time)
  4728. if !ok {
  4729. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4730. }
  4731. m.SetCreatedAt(v)
  4732. return nil
  4733. case deviceconfig.FieldUpdatedAt:
  4734. v, ok := value.(time.Time)
  4735. if !ok {
  4736. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4737. }
  4738. m.SetUpdatedAt(v)
  4739. return nil
  4740. case deviceconfig.FieldDeletedAt:
  4741. v, ok := value.(time.Time)
  4742. if !ok {
  4743. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4744. }
  4745. m.SetDeletedAt(v)
  4746. return nil
  4747. case deviceconfig.FieldDeviceID:
  4748. v, ok := value.(int64)
  4749. if !ok {
  4750. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4751. }
  4752. m.SetDeviceID(v)
  4753. return nil
  4754. case deviceconfig.FieldKey:
  4755. v, ok := value.(string)
  4756. if !ok {
  4757. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4758. }
  4759. m.SetKey(v)
  4760. return nil
  4761. case deviceconfig.FieldValue:
  4762. v, ok := value.(string)
  4763. if !ok {
  4764. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4765. }
  4766. m.SetValue(v)
  4767. return nil
  4768. case deviceconfig.FieldBeforeValue:
  4769. v, ok := value.(string)
  4770. if !ok {
  4771. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4772. }
  4773. m.SetBeforeValue(v)
  4774. return nil
  4775. }
  4776. return fmt.Errorf("unknown DeviceConfig field %s", name)
  4777. }
  4778. // AddedFields returns all numeric fields that were incremented/decremented during
  4779. // this mutation.
  4780. func (m *DeviceConfigMutation) AddedFields() []string {
  4781. var fields []string
  4782. return fields
  4783. }
  4784. // AddedField returns the numeric value that was incremented/decremented on a field
  4785. // with the given name. The second boolean return value indicates that this field
  4786. // was not set, or was not defined in the schema.
  4787. func (m *DeviceConfigMutation) AddedField(name string) (ent.Value, bool) {
  4788. switch name {
  4789. }
  4790. return nil, false
  4791. }
  4792. // AddField adds the value to the field with the given name. It returns an error if
  4793. // the field is not defined in the schema, or if the type mismatched the field
  4794. // type.
  4795. func (m *DeviceConfigMutation) AddField(name string, value ent.Value) error {
  4796. switch name {
  4797. }
  4798. return fmt.Errorf("unknown DeviceConfig numeric field %s", name)
  4799. }
  4800. // ClearedFields returns all nullable fields that were cleared during this
  4801. // mutation.
  4802. func (m *DeviceConfigMutation) ClearedFields() []string {
  4803. var fields []string
  4804. if m.FieldCleared(deviceconfig.FieldDeletedAt) {
  4805. fields = append(fields, deviceconfig.FieldDeletedAt)
  4806. }
  4807. if m.FieldCleared(deviceconfig.FieldDeviceID) {
  4808. fields = append(fields, deviceconfig.FieldDeviceID)
  4809. }
  4810. if m.FieldCleared(deviceconfig.FieldBeforeValue) {
  4811. fields = append(fields, deviceconfig.FieldBeforeValue)
  4812. }
  4813. return fields
  4814. }
  4815. // FieldCleared returns a boolean indicating if a field with the given name was
  4816. // cleared in this mutation.
  4817. func (m *DeviceConfigMutation) FieldCleared(name string) bool {
  4818. _, ok := m.clearedFields[name]
  4819. return ok
  4820. }
  4821. // ClearField clears the value of the field with the given name. It returns an
  4822. // error if the field is not defined in the schema.
  4823. func (m *DeviceConfigMutation) ClearField(name string) error {
  4824. switch name {
  4825. case deviceconfig.FieldDeletedAt:
  4826. m.ClearDeletedAt()
  4827. return nil
  4828. case deviceconfig.FieldDeviceID:
  4829. m.ClearDeviceID()
  4830. return nil
  4831. case deviceconfig.FieldBeforeValue:
  4832. m.ClearBeforeValue()
  4833. return nil
  4834. }
  4835. return fmt.Errorf("unknown DeviceConfig nullable field %s", name)
  4836. }
  4837. // ResetField resets all changes in the mutation for the field with the given name.
  4838. // It returns an error if the field is not defined in the schema.
  4839. func (m *DeviceConfigMutation) ResetField(name string) error {
  4840. switch name {
  4841. case deviceconfig.FieldCreatedAt:
  4842. m.ResetCreatedAt()
  4843. return nil
  4844. case deviceconfig.FieldUpdatedAt:
  4845. m.ResetUpdatedAt()
  4846. return nil
  4847. case deviceconfig.FieldDeletedAt:
  4848. m.ResetDeletedAt()
  4849. return nil
  4850. case deviceconfig.FieldDeviceID:
  4851. m.ResetDeviceID()
  4852. return nil
  4853. case deviceconfig.FieldKey:
  4854. m.ResetKey()
  4855. return nil
  4856. case deviceconfig.FieldValue:
  4857. m.ResetValue()
  4858. return nil
  4859. case deviceconfig.FieldBeforeValue:
  4860. m.ResetBeforeValue()
  4861. return nil
  4862. }
  4863. return fmt.Errorf("unknown DeviceConfig field %s", name)
  4864. }
  4865. // AddedEdges returns all edge names that were set/added in this mutation.
  4866. func (m *DeviceConfigMutation) AddedEdges() []string {
  4867. edges := make([]string, 0, 1)
  4868. if m.device != nil {
  4869. edges = append(edges, deviceconfig.EdgeDevice)
  4870. }
  4871. return edges
  4872. }
  4873. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  4874. // name in this mutation.
  4875. func (m *DeviceConfigMutation) AddedIDs(name string) []ent.Value {
  4876. switch name {
  4877. case deviceconfig.EdgeDevice:
  4878. if id := m.device; id != nil {
  4879. return []ent.Value{*id}
  4880. }
  4881. }
  4882. return nil
  4883. }
  4884. // RemovedEdges returns all edge names that were removed in this mutation.
  4885. func (m *DeviceConfigMutation) RemovedEdges() []string {
  4886. edges := make([]string, 0, 1)
  4887. return edges
  4888. }
  4889. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  4890. // the given name in this mutation.
  4891. func (m *DeviceConfigMutation) RemovedIDs(name string) []ent.Value {
  4892. return nil
  4893. }
  4894. // ClearedEdges returns all edge names that were cleared in this mutation.
  4895. func (m *DeviceConfigMutation) ClearedEdges() []string {
  4896. edges := make([]string, 0, 1)
  4897. if m.cleareddevice {
  4898. edges = append(edges, deviceconfig.EdgeDevice)
  4899. }
  4900. return edges
  4901. }
  4902. // EdgeCleared returns a boolean which indicates if the edge with the given name
  4903. // was cleared in this mutation.
  4904. func (m *DeviceConfigMutation) EdgeCleared(name string) bool {
  4905. switch name {
  4906. case deviceconfig.EdgeDevice:
  4907. return m.cleareddevice
  4908. }
  4909. return false
  4910. }
  4911. // ClearEdge clears the value of the edge with the given name. It returns an error
  4912. // if that edge is not defined in the schema.
  4913. func (m *DeviceConfigMutation) ClearEdge(name string) error {
  4914. switch name {
  4915. case deviceconfig.EdgeDevice:
  4916. m.ClearDevice()
  4917. return nil
  4918. }
  4919. return fmt.Errorf("unknown DeviceConfig unique edge %s", name)
  4920. }
  4921. // ResetEdge resets all changes to the edge with the given name in this mutation.
  4922. // It returns an error if the edge is not defined in the schema.
  4923. func (m *DeviceConfigMutation) ResetEdge(name string) error {
  4924. switch name {
  4925. case deviceconfig.EdgeDevice:
  4926. m.ResetDevice()
  4927. return nil
  4928. }
  4929. return fmt.Errorf("unknown DeviceConfig edge %s", name)
  4930. }
  4931. // GroupMutation represents an operation that mutates the Group nodes in the graph.
  4932. type GroupMutation struct {
  4933. config
  4934. op Op
  4935. typ string
  4936. id *uuid.UUID
  4937. created_at *time.Time
  4938. updated_at *time.Time
  4939. deleted_at *time.Time
  4940. child_id *uuid.UUID
  4941. clearedFields map[string]struct{}
  4942. members map[int64]struct{}
  4943. removedmembers map[int64]struct{}
  4944. clearedmembers bool
  4945. done bool
  4946. oldValue func(context.Context) (*Group, error)
  4947. predicates []predicate.Group
  4948. }
  4949. var _ ent.Mutation = (*GroupMutation)(nil)
  4950. // groupOption allows management of the mutation configuration using functional options.
  4951. type groupOption func(*GroupMutation)
  4952. // newGroupMutation creates new mutation for the Group entity.
  4953. func newGroupMutation(c config, op Op, opts ...groupOption) *GroupMutation {
  4954. m := &GroupMutation{
  4955. config: c,
  4956. op: op,
  4957. typ: TypeGroup,
  4958. clearedFields: make(map[string]struct{}),
  4959. }
  4960. for _, opt := range opts {
  4961. opt(m)
  4962. }
  4963. return m
  4964. }
  4965. // withGroupID sets the ID field of the mutation.
  4966. func withGroupID(id uuid.UUID) groupOption {
  4967. return func(m *GroupMutation) {
  4968. var (
  4969. err error
  4970. once sync.Once
  4971. value *Group
  4972. )
  4973. m.oldValue = func(ctx context.Context) (*Group, error) {
  4974. once.Do(func() {
  4975. if m.done {
  4976. err = errors.New("querying old values post mutation is not allowed")
  4977. } else {
  4978. value, err = m.Client().Group.Get(ctx, id)
  4979. }
  4980. })
  4981. return value, err
  4982. }
  4983. m.id = &id
  4984. }
  4985. }
  4986. // withGroup sets the old Group of the mutation.
  4987. func withGroup(node *Group) groupOption {
  4988. return func(m *GroupMutation) {
  4989. m.oldValue = func(context.Context) (*Group, error) {
  4990. return node, nil
  4991. }
  4992. m.id = &node.ID
  4993. }
  4994. }
  4995. // Client returns a new `ent.Client` from the mutation. If the mutation was
  4996. // executed in a transaction (ent.Tx), a transactional client is returned.
  4997. func (m GroupMutation) Client() *Client {
  4998. client := &Client{config: m.config}
  4999. client.init()
  5000. return client
  5001. }
  5002. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  5003. // it returns an error otherwise.
  5004. func (m GroupMutation) Tx() (*Tx, error) {
  5005. if _, ok := m.driver.(*txDriver); !ok {
  5006. return nil, errors.New("ent: mutation is not running in a transaction")
  5007. }
  5008. tx := &Tx{config: m.config}
  5009. tx.init()
  5010. return tx, nil
  5011. }
  5012. // SetID sets the value of the id field. Note that this
  5013. // operation is only accepted on creation of Group entities.
  5014. func (m *GroupMutation) SetID(id uuid.UUID) {
  5015. m.id = &id
  5016. }
  5017. // ID returns the ID value in the mutation. Note that the ID is only available
  5018. // if it was provided to the builder or after it was returned from the database.
  5019. func (m *GroupMutation) ID() (id uuid.UUID, exists bool) {
  5020. if m.id == nil {
  5021. return
  5022. }
  5023. return *m.id, true
  5024. }
  5025. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  5026. // That means, if the mutation is applied within a transaction with an isolation level such
  5027. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  5028. // or updated by the mutation.
  5029. func (m *GroupMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
  5030. switch {
  5031. case m.op.Is(OpUpdateOne | OpDeleteOne):
  5032. id, exists := m.ID()
  5033. if exists {
  5034. return []uuid.UUID{id}, nil
  5035. }
  5036. fallthrough
  5037. case m.op.Is(OpUpdate | OpDelete):
  5038. return m.Client().Group.Query().Where(m.predicates...).IDs(ctx)
  5039. default:
  5040. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  5041. }
  5042. }
  5043. // SetCreatedAt sets the "created_at" field.
  5044. func (m *GroupMutation) SetCreatedAt(t time.Time) {
  5045. m.created_at = &t
  5046. }
  5047. // CreatedAt returns the value of the "created_at" field in the mutation.
  5048. func (m *GroupMutation) CreatedAt() (r time.Time, exists bool) {
  5049. v := m.created_at
  5050. if v == nil {
  5051. return
  5052. }
  5053. return *v, true
  5054. }
  5055. // OldCreatedAt returns the old "created_at" field's value of the Group entity.
  5056. // If the Group object wasn't provided to the builder, the object is fetched from the database.
  5057. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5058. func (m *GroupMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  5059. if !m.op.Is(OpUpdateOne) {
  5060. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  5061. }
  5062. if m.id == nil || m.oldValue == nil {
  5063. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  5064. }
  5065. oldValue, err := m.oldValue(ctx)
  5066. if err != nil {
  5067. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  5068. }
  5069. return oldValue.CreatedAt, nil
  5070. }
  5071. // ResetCreatedAt resets all changes to the "created_at" field.
  5072. func (m *GroupMutation) ResetCreatedAt() {
  5073. m.created_at = nil
  5074. }
  5075. // SetUpdatedAt sets the "updated_at" field.
  5076. func (m *GroupMutation) SetUpdatedAt(t time.Time) {
  5077. m.updated_at = &t
  5078. }
  5079. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  5080. func (m *GroupMutation) UpdatedAt() (r time.Time, exists bool) {
  5081. v := m.updated_at
  5082. if v == nil {
  5083. return
  5084. }
  5085. return *v, true
  5086. }
  5087. // OldUpdatedAt returns the old "updated_at" field's value of the Group entity.
  5088. // If the Group object wasn't provided to the builder, the object is fetched from the database.
  5089. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5090. func (m *GroupMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  5091. if !m.op.Is(OpUpdateOne) {
  5092. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  5093. }
  5094. if m.id == nil || m.oldValue == nil {
  5095. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  5096. }
  5097. oldValue, err := m.oldValue(ctx)
  5098. if err != nil {
  5099. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  5100. }
  5101. return oldValue.UpdatedAt, nil
  5102. }
  5103. // ResetUpdatedAt resets all changes to the "updated_at" field.
  5104. func (m *GroupMutation) ResetUpdatedAt() {
  5105. m.updated_at = nil
  5106. }
  5107. // SetDeletedAt sets the "deleted_at" field.
  5108. func (m *GroupMutation) SetDeletedAt(t time.Time) {
  5109. m.deleted_at = &t
  5110. }
  5111. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  5112. func (m *GroupMutation) DeletedAt() (r time.Time, exists bool) {
  5113. v := m.deleted_at
  5114. if v == nil {
  5115. return
  5116. }
  5117. return *v, true
  5118. }
  5119. // OldDeletedAt returns the old "deleted_at" field's value of the Group entity.
  5120. // If the Group object wasn't provided to the builder, the object is fetched from the database.
  5121. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5122. func (m *GroupMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
  5123. if !m.op.Is(OpUpdateOne) {
  5124. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  5125. }
  5126. if m.id == nil || m.oldValue == nil {
  5127. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  5128. }
  5129. oldValue, err := m.oldValue(ctx)
  5130. if err != nil {
  5131. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  5132. }
  5133. return oldValue.DeletedAt, nil
  5134. }
  5135. // ClearDeletedAt clears the value of the "deleted_at" field.
  5136. func (m *GroupMutation) ClearDeletedAt() {
  5137. m.deleted_at = nil
  5138. m.clearedFields[group.FieldDeletedAt] = struct{}{}
  5139. }
  5140. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  5141. func (m *GroupMutation) DeletedAtCleared() bool {
  5142. _, ok := m.clearedFields[group.FieldDeletedAt]
  5143. return ok
  5144. }
  5145. // ResetDeletedAt resets all changes to the "deleted_at" field.
  5146. func (m *GroupMutation) ResetDeletedAt() {
  5147. m.deleted_at = nil
  5148. delete(m.clearedFields, group.FieldDeletedAt)
  5149. }
  5150. // SetChildID sets the "child_id" field.
  5151. func (m *GroupMutation) SetChildID(u uuid.UUID) {
  5152. m.child_id = &u
  5153. }
  5154. // ChildID returns the value of the "child_id" field in the mutation.
  5155. func (m *GroupMutation) ChildID() (r uuid.UUID, exists bool) {
  5156. v := m.child_id
  5157. if v == nil {
  5158. return
  5159. }
  5160. return *v, true
  5161. }
  5162. // OldChildID returns the old "child_id" field's value of the Group entity.
  5163. // If the Group object wasn't provided to the builder, the object is fetched from the database.
  5164. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5165. func (m *GroupMutation) OldChildID(ctx context.Context) (v uuid.UUID, err error) {
  5166. if !m.op.Is(OpUpdateOne) {
  5167. return v, errors.New("OldChildID is only allowed on UpdateOne operations")
  5168. }
  5169. if m.id == nil || m.oldValue == nil {
  5170. return v, errors.New("OldChildID requires an ID field in the mutation")
  5171. }
  5172. oldValue, err := m.oldValue(ctx)
  5173. if err != nil {
  5174. return v, fmt.Errorf("querying old value for OldChildID: %w", err)
  5175. }
  5176. return oldValue.ChildID, nil
  5177. }
  5178. // ResetChildID resets all changes to the "child_id" field.
  5179. func (m *GroupMutation) ResetChildID() {
  5180. m.child_id = nil
  5181. }
  5182. // AddMemberIDs adds the "members" edge to the Member entity by ids.
  5183. func (m *GroupMutation) AddMemberIDs(ids ...int64) {
  5184. if m.members == nil {
  5185. m.members = make(map[int64]struct{})
  5186. }
  5187. for i := range ids {
  5188. m.members[ids[i]] = struct{}{}
  5189. }
  5190. }
  5191. // ClearMembers clears the "members" edge to the Member entity.
  5192. func (m *GroupMutation) ClearMembers() {
  5193. m.clearedmembers = true
  5194. }
  5195. // MembersCleared reports if the "members" edge to the Member entity was cleared.
  5196. func (m *GroupMutation) MembersCleared() bool {
  5197. return m.clearedmembers
  5198. }
  5199. // RemoveMemberIDs removes the "members" edge to the Member entity by IDs.
  5200. func (m *GroupMutation) RemoveMemberIDs(ids ...int64) {
  5201. if m.removedmembers == nil {
  5202. m.removedmembers = make(map[int64]struct{})
  5203. }
  5204. for i := range ids {
  5205. delete(m.members, ids[i])
  5206. m.removedmembers[ids[i]] = struct{}{}
  5207. }
  5208. }
  5209. // RemovedMembers returns the removed IDs of the "members" edge to the Member entity.
  5210. func (m *GroupMutation) RemovedMembersIDs() (ids []int64) {
  5211. for id := range m.removedmembers {
  5212. ids = append(ids, id)
  5213. }
  5214. return
  5215. }
  5216. // MembersIDs returns the "members" edge IDs in the mutation.
  5217. func (m *GroupMutation) MembersIDs() (ids []int64) {
  5218. for id := range m.members {
  5219. ids = append(ids, id)
  5220. }
  5221. return
  5222. }
  5223. // ResetMembers resets all changes to the "members" edge.
  5224. func (m *GroupMutation) ResetMembers() {
  5225. m.members = nil
  5226. m.clearedmembers = false
  5227. m.removedmembers = nil
  5228. }
  5229. // Where appends a list predicates to the GroupMutation builder.
  5230. func (m *GroupMutation) Where(ps ...predicate.Group) {
  5231. m.predicates = append(m.predicates, ps...)
  5232. }
  5233. // WhereP appends storage-level predicates to the GroupMutation builder. Using this method,
  5234. // users can use type-assertion to append predicates that do not depend on any generated package.
  5235. func (m *GroupMutation) WhereP(ps ...func(*sql.Selector)) {
  5236. p := make([]predicate.Group, len(ps))
  5237. for i := range ps {
  5238. p[i] = ps[i]
  5239. }
  5240. m.Where(p...)
  5241. }
  5242. // Op returns the operation name.
  5243. func (m *GroupMutation) Op() Op {
  5244. return m.op
  5245. }
  5246. // SetOp allows setting the mutation operation.
  5247. func (m *GroupMutation) SetOp(op Op) {
  5248. m.op = op
  5249. }
  5250. // Type returns the node type of this mutation (Group).
  5251. func (m *GroupMutation) Type() string {
  5252. return m.typ
  5253. }
  5254. // Fields returns all fields that were changed during this mutation. Note that in
  5255. // order to get all numeric fields that were incremented/decremented, call
  5256. // AddedFields().
  5257. func (m *GroupMutation) Fields() []string {
  5258. fields := make([]string, 0, 4)
  5259. if m.created_at != nil {
  5260. fields = append(fields, group.FieldCreatedAt)
  5261. }
  5262. if m.updated_at != nil {
  5263. fields = append(fields, group.FieldUpdatedAt)
  5264. }
  5265. if m.deleted_at != nil {
  5266. fields = append(fields, group.FieldDeletedAt)
  5267. }
  5268. if m.child_id != nil {
  5269. fields = append(fields, group.FieldChildID)
  5270. }
  5271. return fields
  5272. }
  5273. // Field returns the value of a field with the given name. The second boolean
  5274. // return value indicates that this field was not set, or was not defined in the
  5275. // schema.
  5276. func (m *GroupMutation) Field(name string) (ent.Value, bool) {
  5277. switch name {
  5278. case group.FieldCreatedAt:
  5279. return m.CreatedAt()
  5280. case group.FieldUpdatedAt:
  5281. return m.UpdatedAt()
  5282. case group.FieldDeletedAt:
  5283. return m.DeletedAt()
  5284. case group.FieldChildID:
  5285. return m.ChildID()
  5286. }
  5287. return nil, false
  5288. }
  5289. // OldField returns the old value of the field from the database. An error is
  5290. // returned if the mutation operation is not UpdateOne, or the query to the
  5291. // database failed.
  5292. func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  5293. switch name {
  5294. case group.FieldCreatedAt:
  5295. return m.OldCreatedAt(ctx)
  5296. case group.FieldUpdatedAt:
  5297. return m.OldUpdatedAt(ctx)
  5298. case group.FieldDeletedAt:
  5299. return m.OldDeletedAt(ctx)
  5300. case group.FieldChildID:
  5301. return m.OldChildID(ctx)
  5302. }
  5303. return nil, fmt.Errorf("unknown Group field %s", name)
  5304. }
  5305. // SetField sets the value of a field with the given name. It returns an error if
  5306. // the field is not defined in the schema, or if the type mismatched the field
  5307. // type.
  5308. func (m *GroupMutation) SetField(name string, value ent.Value) error {
  5309. switch name {
  5310. case group.FieldCreatedAt:
  5311. v, ok := value.(time.Time)
  5312. if !ok {
  5313. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5314. }
  5315. m.SetCreatedAt(v)
  5316. return nil
  5317. case group.FieldUpdatedAt:
  5318. v, ok := value.(time.Time)
  5319. if !ok {
  5320. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5321. }
  5322. m.SetUpdatedAt(v)
  5323. return nil
  5324. case group.FieldDeletedAt:
  5325. v, ok := value.(time.Time)
  5326. if !ok {
  5327. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5328. }
  5329. m.SetDeletedAt(v)
  5330. return nil
  5331. case group.FieldChildID:
  5332. v, ok := value.(uuid.UUID)
  5333. if !ok {
  5334. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5335. }
  5336. m.SetChildID(v)
  5337. return nil
  5338. }
  5339. return fmt.Errorf("unknown Group field %s", name)
  5340. }
  5341. // AddedFields returns all numeric fields that were incremented/decremented during
  5342. // this mutation.
  5343. func (m *GroupMutation) AddedFields() []string {
  5344. return nil
  5345. }
  5346. // AddedField returns the numeric value that was incremented/decremented on a field
  5347. // with the given name. The second boolean return value indicates that this field
  5348. // was not set, or was not defined in the schema.
  5349. func (m *GroupMutation) AddedField(name string) (ent.Value, bool) {
  5350. return nil, false
  5351. }
  5352. // AddField adds the value to the field with the given name. It returns an error if
  5353. // the field is not defined in the schema, or if the type mismatched the field
  5354. // type.
  5355. func (m *GroupMutation) AddField(name string, value ent.Value) error {
  5356. switch name {
  5357. }
  5358. return fmt.Errorf("unknown Group numeric field %s", name)
  5359. }
  5360. // ClearedFields returns all nullable fields that were cleared during this
  5361. // mutation.
  5362. func (m *GroupMutation) ClearedFields() []string {
  5363. var fields []string
  5364. if m.FieldCleared(group.FieldDeletedAt) {
  5365. fields = append(fields, group.FieldDeletedAt)
  5366. }
  5367. return fields
  5368. }
  5369. // FieldCleared returns a boolean indicating if a field with the given name was
  5370. // cleared in this mutation.
  5371. func (m *GroupMutation) FieldCleared(name string) bool {
  5372. _, ok := m.clearedFields[name]
  5373. return ok
  5374. }
  5375. // ClearField clears the value of the field with the given name. It returns an
  5376. // error if the field is not defined in the schema.
  5377. func (m *GroupMutation) ClearField(name string) error {
  5378. switch name {
  5379. case group.FieldDeletedAt:
  5380. m.ClearDeletedAt()
  5381. return nil
  5382. }
  5383. return fmt.Errorf("unknown Group nullable field %s", name)
  5384. }
  5385. // ResetField resets all changes in the mutation for the field with the given name.
  5386. // It returns an error if the field is not defined in the schema.
  5387. func (m *GroupMutation) ResetField(name string) error {
  5388. switch name {
  5389. case group.FieldCreatedAt:
  5390. m.ResetCreatedAt()
  5391. return nil
  5392. case group.FieldUpdatedAt:
  5393. m.ResetUpdatedAt()
  5394. return nil
  5395. case group.FieldDeletedAt:
  5396. m.ResetDeletedAt()
  5397. return nil
  5398. case group.FieldChildID:
  5399. m.ResetChildID()
  5400. return nil
  5401. }
  5402. return fmt.Errorf("unknown Group field %s", name)
  5403. }
  5404. // AddedEdges returns all edge names that were set/added in this mutation.
  5405. func (m *GroupMutation) AddedEdges() []string {
  5406. edges := make([]string, 0, 1)
  5407. if m.members != nil {
  5408. edges = append(edges, group.EdgeMembers)
  5409. }
  5410. return edges
  5411. }
  5412. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  5413. // name in this mutation.
  5414. func (m *GroupMutation) AddedIDs(name string) []ent.Value {
  5415. switch name {
  5416. case group.EdgeMembers:
  5417. ids := make([]ent.Value, 0, len(m.members))
  5418. for id := range m.members {
  5419. ids = append(ids, id)
  5420. }
  5421. return ids
  5422. }
  5423. return nil
  5424. }
  5425. // RemovedEdges returns all edge names that were removed in this mutation.
  5426. func (m *GroupMutation) RemovedEdges() []string {
  5427. edges := make([]string, 0, 1)
  5428. if m.removedmembers != nil {
  5429. edges = append(edges, group.EdgeMembers)
  5430. }
  5431. return edges
  5432. }
  5433. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  5434. // the given name in this mutation.
  5435. func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
  5436. switch name {
  5437. case group.EdgeMembers:
  5438. ids := make([]ent.Value, 0, len(m.removedmembers))
  5439. for id := range m.removedmembers {
  5440. ids = append(ids, id)
  5441. }
  5442. return ids
  5443. }
  5444. return nil
  5445. }
  5446. // ClearedEdges returns all edge names that were cleared in this mutation.
  5447. func (m *GroupMutation) ClearedEdges() []string {
  5448. edges := make([]string, 0, 1)
  5449. if m.clearedmembers {
  5450. edges = append(edges, group.EdgeMembers)
  5451. }
  5452. return edges
  5453. }
  5454. // EdgeCleared returns a boolean which indicates if the edge with the given name
  5455. // was cleared in this mutation.
  5456. func (m *GroupMutation) EdgeCleared(name string) bool {
  5457. switch name {
  5458. case group.EdgeMembers:
  5459. return m.clearedmembers
  5460. }
  5461. return false
  5462. }
  5463. // ClearEdge clears the value of the edge with the given name. It returns an error
  5464. // if that edge is not defined in the schema.
  5465. func (m *GroupMutation) ClearEdge(name string) error {
  5466. switch name {
  5467. }
  5468. return fmt.Errorf("unknown Group unique edge %s", name)
  5469. }
  5470. // ResetEdge resets all changes to the edge with the given name in this mutation.
  5471. // It returns an error if the edge is not defined in the schema.
  5472. func (m *GroupMutation) ResetEdge(name string) error {
  5473. switch name {
  5474. case group.EdgeMembers:
  5475. m.ResetMembers()
  5476. return nil
  5477. }
  5478. return fmt.Errorf("unknown Group edge %s", name)
  5479. }
  5480. // MemberMutation represents an operation that mutates the Member nodes in the graph.
  5481. type MemberMutation struct {
  5482. config
  5483. op Op
  5484. typ string
  5485. id *int64
  5486. created_at *time.Time
  5487. updated_at *time.Time
  5488. deleted_at *time.Time
  5489. ref_id *string
  5490. _type *int8
  5491. add_type *int8
  5492. role *int8
  5493. addrole *int8
  5494. clearedFields map[string]struct{}
  5495. group *uuid.UUID
  5496. clearedgroup bool
  5497. done bool
  5498. oldValue func(context.Context) (*Member, error)
  5499. predicates []predicate.Member
  5500. }
  5501. var _ ent.Mutation = (*MemberMutation)(nil)
  5502. // memberOption allows management of the mutation configuration using functional options.
  5503. type memberOption func(*MemberMutation)
  5504. // newMemberMutation creates new mutation for the Member entity.
  5505. func newMemberMutation(c config, op Op, opts ...memberOption) *MemberMutation {
  5506. m := &MemberMutation{
  5507. config: c,
  5508. op: op,
  5509. typ: TypeMember,
  5510. clearedFields: make(map[string]struct{}),
  5511. }
  5512. for _, opt := range opts {
  5513. opt(m)
  5514. }
  5515. return m
  5516. }
  5517. // withMemberID sets the ID field of the mutation.
  5518. func withMemberID(id int64) memberOption {
  5519. return func(m *MemberMutation) {
  5520. var (
  5521. err error
  5522. once sync.Once
  5523. value *Member
  5524. )
  5525. m.oldValue = func(ctx context.Context) (*Member, error) {
  5526. once.Do(func() {
  5527. if m.done {
  5528. err = errors.New("querying old values post mutation is not allowed")
  5529. } else {
  5530. value, err = m.Client().Member.Get(ctx, id)
  5531. }
  5532. })
  5533. return value, err
  5534. }
  5535. m.id = &id
  5536. }
  5537. }
  5538. // withMember sets the old Member of the mutation.
  5539. func withMember(node *Member) memberOption {
  5540. return func(m *MemberMutation) {
  5541. m.oldValue = func(context.Context) (*Member, error) {
  5542. return node, nil
  5543. }
  5544. m.id = &node.ID
  5545. }
  5546. }
  5547. // Client returns a new `ent.Client` from the mutation. If the mutation was
  5548. // executed in a transaction (ent.Tx), a transactional client is returned.
  5549. func (m MemberMutation) Client() *Client {
  5550. client := &Client{config: m.config}
  5551. client.init()
  5552. return client
  5553. }
  5554. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  5555. // it returns an error otherwise.
  5556. func (m MemberMutation) Tx() (*Tx, error) {
  5557. if _, ok := m.driver.(*txDriver); !ok {
  5558. return nil, errors.New("ent: mutation is not running in a transaction")
  5559. }
  5560. tx := &Tx{config: m.config}
  5561. tx.init()
  5562. return tx, nil
  5563. }
  5564. // SetID sets the value of the id field. Note that this
  5565. // operation is only accepted on creation of Member entities.
  5566. func (m *MemberMutation) SetID(id int64) {
  5567. m.id = &id
  5568. }
  5569. // ID returns the ID value in the mutation. Note that the ID is only available
  5570. // if it was provided to the builder or after it was returned from the database.
  5571. func (m *MemberMutation) ID() (id int64, exists bool) {
  5572. if m.id == nil {
  5573. return
  5574. }
  5575. return *m.id, true
  5576. }
  5577. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  5578. // That means, if the mutation is applied within a transaction with an isolation level such
  5579. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  5580. // or updated by the mutation.
  5581. func (m *MemberMutation) IDs(ctx context.Context) ([]int64, error) {
  5582. switch {
  5583. case m.op.Is(OpUpdateOne | OpDeleteOne):
  5584. id, exists := m.ID()
  5585. if exists {
  5586. return []int64{id}, nil
  5587. }
  5588. fallthrough
  5589. case m.op.Is(OpUpdate | OpDelete):
  5590. return m.Client().Member.Query().Where(m.predicates...).IDs(ctx)
  5591. default:
  5592. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  5593. }
  5594. }
  5595. // SetCreatedAt sets the "created_at" field.
  5596. func (m *MemberMutation) SetCreatedAt(t time.Time) {
  5597. m.created_at = &t
  5598. }
  5599. // CreatedAt returns the value of the "created_at" field in the mutation.
  5600. func (m *MemberMutation) CreatedAt() (r time.Time, exists bool) {
  5601. v := m.created_at
  5602. if v == nil {
  5603. return
  5604. }
  5605. return *v, true
  5606. }
  5607. // OldCreatedAt returns the old "created_at" field's value of the Member entity.
  5608. // If the Member object wasn't provided to the builder, the object is fetched from the database.
  5609. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5610. func (m *MemberMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  5611. if !m.op.Is(OpUpdateOne) {
  5612. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  5613. }
  5614. if m.id == nil || m.oldValue == nil {
  5615. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  5616. }
  5617. oldValue, err := m.oldValue(ctx)
  5618. if err != nil {
  5619. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  5620. }
  5621. return oldValue.CreatedAt, nil
  5622. }
  5623. // ResetCreatedAt resets all changes to the "created_at" field.
  5624. func (m *MemberMutation) ResetCreatedAt() {
  5625. m.created_at = nil
  5626. }
  5627. // SetUpdatedAt sets the "updated_at" field.
  5628. func (m *MemberMutation) SetUpdatedAt(t time.Time) {
  5629. m.updated_at = &t
  5630. }
  5631. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  5632. func (m *MemberMutation) UpdatedAt() (r time.Time, exists bool) {
  5633. v := m.updated_at
  5634. if v == nil {
  5635. return
  5636. }
  5637. return *v, true
  5638. }
  5639. // OldUpdatedAt returns the old "updated_at" field's value of the Member entity.
  5640. // If the Member object wasn't provided to the builder, the object is fetched from the database.
  5641. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5642. func (m *MemberMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  5643. if !m.op.Is(OpUpdateOne) {
  5644. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  5645. }
  5646. if m.id == nil || m.oldValue == nil {
  5647. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  5648. }
  5649. oldValue, err := m.oldValue(ctx)
  5650. if err != nil {
  5651. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  5652. }
  5653. return oldValue.UpdatedAt, nil
  5654. }
  5655. // ResetUpdatedAt resets all changes to the "updated_at" field.
  5656. func (m *MemberMutation) ResetUpdatedAt() {
  5657. m.updated_at = nil
  5658. }
  5659. // SetDeletedAt sets the "deleted_at" field.
  5660. func (m *MemberMutation) SetDeletedAt(t time.Time) {
  5661. m.deleted_at = &t
  5662. }
  5663. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  5664. func (m *MemberMutation) DeletedAt() (r time.Time, exists bool) {
  5665. v := m.deleted_at
  5666. if v == nil {
  5667. return
  5668. }
  5669. return *v, true
  5670. }
  5671. // OldDeletedAt returns the old "deleted_at" field's value of the Member entity.
  5672. // If the Member object wasn't provided to the builder, the object is fetched from the database.
  5673. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5674. func (m *MemberMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
  5675. if !m.op.Is(OpUpdateOne) {
  5676. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  5677. }
  5678. if m.id == nil || m.oldValue == nil {
  5679. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  5680. }
  5681. oldValue, err := m.oldValue(ctx)
  5682. if err != nil {
  5683. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  5684. }
  5685. return oldValue.DeletedAt, nil
  5686. }
  5687. // ClearDeletedAt clears the value of the "deleted_at" field.
  5688. func (m *MemberMutation) ClearDeletedAt() {
  5689. m.deleted_at = nil
  5690. m.clearedFields[member.FieldDeletedAt] = struct{}{}
  5691. }
  5692. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  5693. func (m *MemberMutation) DeletedAtCleared() bool {
  5694. _, ok := m.clearedFields[member.FieldDeletedAt]
  5695. return ok
  5696. }
  5697. // ResetDeletedAt resets all changes to the "deleted_at" field.
  5698. func (m *MemberMutation) ResetDeletedAt() {
  5699. m.deleted_at = nil
  5700. delete(m.clearedFields, member.FieldDeletedAt)
  5701. }
  5702. // SetGroupID sets the "group_id" field.
  5703. func (m *MemberMutation) SetGroupID(u uuid.UUID) {
  5704. m.group = &u
  5705. }
  5706. // GroupID returns the value of the "group_id" field in the mutation.
  5707. func (m *MemberMutation) GroupID() (r uuid.UUID, exists bool) {
  5708. v := m.group
  5709. if v == nil {
  5710. return
  5711. }
  5712. return *v, true
  5713. }
  5714. // OldGroupID returns the old "group_id" field's value of the Member entity.
  5715. // If the Member object wasn't provided to the builder, the object is fetched from the database.
  5716. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5717. func (m *MemberMutation) OldGroupID(ctx context.Context) (v uuid.UUID, err error) {
  5718. if !m.op.Is(OpUpdateOne) {
  5719. return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
  5720. }
  5721. if m.id == nil || m.oldValue == nil {
  5722. return v, errors.New("OldGroupID requires an ID field in the mutation")
  5723. }
  5724. oldValue, err := m.oldValue(ctx)
  5725. if err != nil {
  5726. return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
  5727. }
  5728. return oldValue.GroupID, nil
  5729. }
  5730. // ClearGroupID clears the value of the "group_id" field.
  5731. func (m *MemberMutation) ClearGroupID() {
  5732. m.group = nil
  5733. m.clearedFields[member.FieldGroupID] = struct{}{}
  5734. }
  5735. // GroupIDCleared returns if the "group_id" field was cleared in this mutation.
  5736. func (m *MemberMutation) GroupIDCleared() bool {
  5737. _, ok := m.clearedFields[member.FieldGroupID]
  5738. return ok
  5739. }
  5740. // ResetGroupID resets all changes to the "group_id" field.
  5741. func (m *MemberMutation) ResetGroupID() {
  5742. m.group = nil
  5743. delete(m.clearedFields, member.FieldGroupID)
  5744. }
  5745. // SetRefID sets the "ref_id" field.
  5746. func (m *MemberMutation) SetRefID(s string) {
  5747. m.ref_id = &s
  5748. }
  5749. // RefID returns the value of the "ref_id" field in the mutation.
  5750. func (m *MemberMutation) RefID() (r string, exists bool) {
  5751. v := m.ref_id
  5752. if v == nil {
  5753. return
  5754. }
  5755. return *v, true
  5756. }
  5757. // OldRefID returns the old "ref_id" field's value of the Member entity.
  5758. // If the Member object wasn't provided to the builder, the object is fetched from the database.
  5759. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5760. func (m *MemberMutation) OldRefID(ctx context.Context) (v string, err error) {
  5761. if !m.op.Is(OpUpdateOne) {
  5762. return v, errors.New("OldRefID is only allowed on UpdateOne operations")
  5763. }
  5764. if m.id == nil || m.oldValue == nil {
  5765. return v, errors.New("OldRefID requires an ID field in the mutation")
  5766. }
  5767. oldValue, err := m.oldValue(ctx)
  5768. if err != nil {
  5769. return v, fmt.Errorf("querying old value for OldRefID: %w", err)
  5770. }
  5771. return oldValue.RefID, nil
  5772. }
  5773. // ResetRefID resets all changes to the "ref_id" field.
  5774. func (m *MemberMutation) ResetRefID() {
  5775. m.ref_id = nil
  5776. }
  5777. // SetType sets the "type" field.
  5778. func (m *MemberMutation) SetType(i int8) {
  5779. m._type = &i
  5780. m.add_type = nil
  5781. }
  5782. // GetType returns the value of the "type" field in the mutation.
  5783. func (m *MemberMutation) GetType() (r int8, exists bool) {
  5784. v := m._type
  5785. if v == nil {
  5786. return
  5787. }
  5788. return *v, true
  5789. }
  5790. // OldType returns the old "type" field's value of the Member entity.
  5791. // If the Member object wasn't provided to the builder, the object is fetched from the database.
  5792. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5793. func (m *MemberMutation) OldType(ctx context.Context) (v int8, err error) {
  5794. if !m.op.Is(OpUpdateOne) {
  5795. return v, errors.New("OldType is only allowed on UpdateOne operations")
  5796. }
  5797. if m.id == nil || m.oldValue == nil {
  5798. return v, errors.New("OldType requires an ID field in the mutation")
  5799. }
  5800. oldValue, err := m.oldValue(ctx)
  5801. if err != nil {
  5802. return v, fmt.Errorf("querying old value for OldType: %w", err)
  5803. }
  5804. return oldValue.Type, nil
  5805. }
  5806. // AddType adds i to the "type" field.
  5807. func (m *MemberMutation) AddType(i int8) {
  5808. if m.add_type != nil {
  5809. *m.add_type += i
  5810. } else {
  5811. m.add_type = &i
  5812. }
  5813. }
  5814. // AddedType returns the value that was added to the "type" field in this mutation.
  5815. func (m *MemberMutation) AddedType() (r int8, exists bool) {
  5816. v := m.add_type
  5817. if v == nil {
  5818. return
  5819. }
  5820. return *v, true
  5821. }
  5822. // ResetType resets all changes to the "type" field.
  5823. func (m *MemberMutation) ResetType() {
  5824. m._type = nil
  5825. m.add_type = nil
  5826. }
  5827. // SetRole sets the "role" field.
  5828. func (m *MemberMutation) SetRole(i int8) {
  5829. m.role = &i
  5830. m.addrole = nil
  5831. }
  5832. // Role returns the value of the "role" field in the mutation.
  5833. func (m *MemberMutation) Role() (r int8, exists bool) {
  5834. v := m.role
  5835. if v == nil {
  5836. return
  5837. }
  5838. return *v, true
  5839. }
  5840. // OldRole returns the old "role" field's value of the Member entity.
  5841. // If the Member object wasn't provided to the builder, the object is fetched from the database.
  5842. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5843. func (m *MemberMutation) OldRole(ctx context.Context) (v int8, err error) {
  5844. if !m.op.Is(OpUpdateOne) {
  5845. return v, errors.New("OldRole is only allowed on UpdateOne operations")
  5846. }
  5847. if m.id == nil || m.oldValue == nil {
  5848. return v, errors.New("OldRole requires an ID field in the mutation")
  5849. }
  5850. oldValue, err := m.oldValue(ctx)
  5851. if err != nil {
  5852. return v, fmt.Errorf("querying old value for OldRole: %w", err)
  5853. }
  5854. return oldValue.Role, nil
  5855. }
  5856. // AddRole adds i to the "role" field.
  5857. func (m *MemberMutation) AddRole(i int8) {
  5858. if m.addrole != nil {
  5859. *m.addrole += i
  5860. } else {
  5861. m.addrole = &i
  5862. }
  5863. }
  5864. // AddedRole returns the value that was added to the "role" field in this mutation.
  5865. func (m *MemberMutation) AddedRole() (r int8, exists bool) {
  5866. v := m.addrole
  5867. if v == nil {
  5868. return
  5869. }
  5870. return *v, true
  5871. }
  5872. // ClearRole clears the value of the "role" field.
  5873. func (m *MemberMutation) ClearRole() {
  5874. m.role = nil
  5875. m.addrole = nil
  5876. m.clearedFields[member.FieldRole] = struct{}{}
  5877. }
  5878. // RoleCleared returns if the "role" field was cleared in this mutation.
  5879. func (m *MemberMutation) RoleCleared() bool {
  5880. _, ok := m.clearedFields[member.FieldRole]
  5881. return ok
  5882. }
  5883. // ResetRole resets all changes to the "role" field.
  5884. func (m *MemberMutation) ResetRole() {
  5885. m.role = nil
  5886. m.addrole = nil
  5887. delete(m.clearedFields, member.FieldRole)
  5888. }
  5889. // ClearGroup clears the "group" edge to the Group entity.
  5890. func (m *MemberMutation) ClearGroup() {
  5891. m.clearedgroup = true
  5892. m.clearedFields[member.FieldGroupID] = struct{}{}
  5893. }
  5894. // GroupCleared reports if the "group" edge to the Group entity was cleared.
  5895. func (m *MemberMutation) GroupCleared() bool {
  5896. return m.GroupIDCleared() || m.clearedgroup
  5897. }
  5898. // GroupIDs returns the "group" edge IDs in the mutation.
  5899. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  5900. // GroupID instead. It exists only for internal usage by the builders.
  5901. func (m *MemberMutation) GroupIDs() (ids []uuid.UUID) {
  5902. if id := m.group; id != nil {
  5903. ids = append(ids, *id)
  5904. }
  5905. return
  5906. }
  5907. // ResetGroup resets all changes to the "group" edge.
  5908. func (m *MemberMutation) ResetGroup() {
  5909. m.group = nil
  5910. m.clearedgroup = false
  5911. }
  5912. // Where appends a list predicates to the MemberMutation builder.
  5913. func (m *MemberMutation) Where(ps ...predicate.Member) {
  5914. m.predicates = append(m.predicates, ps...)
  5915. }
  5916. // WhereP appends storage-level predicates to the MemberMutation builder. Using this method,
  5917. // users can use type-assertion to append predicates that do not depend on any generated package.
  5918. func (m *MemberMutation) WhereP(ps ...func(*sql.Selector)) {
  5919. p := make([]predicate.Member, len(ps))
  5920. for i := range ps {
  5921. p[i] = ps[i]
  5922. }
  5923. m.Where(p...)
  5924. }
  5925. // Op returns the operation name.
  5926. func (m *MemberMutation) Op() Op {
  5927. return m.op
  5928. }
  5929. // SetOp allows setting the mutation operation.
  5930. func (m *MemberMutation) SetOp(op Op) {
  5931. m.op = op
  5932. }
  5933. // Type returns the node type of this mutation (Member).
  5934. func (m *MemberMutation) Type() string {
  5935. return m.typ
  5936. }
  5937. // Fields returns all fields that were changed during this mutation. Note that in
  5938. // order to get all numeric fields that were incremented/decremented, call
  5939. // AddedFields().
  5940. func (m *MemberMutation) Fields() []string {
  5941. fields := make([]string, 0, 7)
  5942. if m.created_at != nil {
  5943. fields = append(fields, member.FieldCreatedAt)
  5944. }
  5945. if m.updated_at != nil {
  5946. fields = append(fields, member.FieldUpdatedAt)
  5947. }
  5948. if m.deleted_at != nil {
  5949. fields = append(fields, member.FieldDeletedAt)
  5950. }
  5951. if m.group != nil {
  5952. fields = append(fields, member.FieldGroupID)
  5953. }
  5954. if m.ref_id != nil {
  5955. fields = append(fields, member.FieldRefID)
  5956. }
  5957. if m._type != nil {
  5958. fields = append(fields, member.FieldType)
  5959. }
  5960. if m.role != nil {
  5961. fields = append(fields, member.FieldRole)
  5962. }
  5963. return fields
  5964. }
  5965. // Field returns the value of a field with the given name. The second boolean
  5966. // return value indicates that this field was not set, or was not defined in the
  5967. // schema.
  5968. func (m *MemberMutation) Field(name string) (ent.Value, bool) {
  5969. switch name {
  5970. case member.FieldCreatedAt:
  5971. return m.CreatedAt()
  5972. case member.FieldUpdatedAt:
  5973. return m.UpdatedAt()
  5974. case member.FieldDeletedAt:
  5975. return m.DeletedAt()
  5976. case member.FieldGroupID:
  5977. return m.GroupID()
  5978. case member.FieldRefID:
  5979. return m.RefID()
  5980. case member.FieldType:
  5981. return m.GetType()
  5982. case member.FieldRole:
  5983. return m.Role()
  5984. }
  5985. return nil, false
  5986. }
  5987. // OldField returns the old value of the field from the database. An error is
  5988. // returned if the mutation operation is not UpdateOne, or the query to the
  5989. // database failed.
  5990. func (m *MemberMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  5991. switch name {
  5992. case member.FieldCreatedAt:
  5993. return m.OldCreatedAt(ctx)
  5994. case member.FieldUpdatedAt:
  5995. return m.OldUpdatedAt(ctx)
  5996. case member.FieldDeletedAt:
  5997. return m.OldDeletedAt(ctx)
  5998. case member.FieldGroupID:
  5999. return m.OldGroupID(ctx)
  6000. case member.FieldRefID:
  6001. return m.OldRefID(ctx)
  6002. case member.FieldType:
  6003. return m.OldType(ctx)
  6004. case member.FieldRole:
  6005. return m.OldRole(ctx)
  6006. }
  6007. return nil, fmt.Errorf("unknown Member field %s", name)
  6008. }
  6009. // SetField sets the value of a field with the given name. It returns an error if
  6010. // the field is not defined in the schema, or if the type mismatched the field
  6011. // type.
  6012. func (m *MemberMutation) SetField(name string, value ent.Value) error {
  6013. switch name {
  6014. case member.FieldCreatedAt:
  6015. v, ok := value.(time.Time)
  6016. if !ok {
  6017. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6018. }
  6019. m.SetCreatedAt(v)
  6020. return nil
  6021. case member.FieldUpdatedAt:
  6022. v, ok := value.(time.Time)
  6023. if !ok {
  6024. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6025. }
  6026. m.SetUpdatedAt(v)
  6027. return nil
  6028. case member.FieldDeletedAt:
  6029. v, ok := value.(time.Time)
  6030. if !ok {
  6031. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6032. }
  6033. m.SetDeletedAt(v)
  6034. return nil
  6035. case member.FieldGroupID:
  6036. v, ok := value.(uuid.UUID)
  6037. if !ok {
  6038. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6039. }
  6040. m.SetGroupID(v)
  6041. return nil
  6042. case member.FieldRefID:
  6043. v, ok := value.(string)
  6044. if !ok {
  6045. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6046. }
  6047. m.SetRefID(v)
  6048. return nil
  6049. case member.FieldType:
  6050. v, ok := value.(int8)
  6051. if !ok {
  6052. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6053. }
  6054. m.SetType(v)
  6055. return nil
  6056. case member.FieldRole:
  6057. v, ok := value.(int8)
  6058. if !ok {
  6059. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6060. }
  6061. m.SetRole(v)
  6062. return nil
  6063. }
  6064. return fmt.Errorf("unknown Member field %s", name)
  6065. }
  6066. // AddedFields returns all numeric fields that were incremented/decremented during
  6067. // this mutation.
  6068. func (m *MemberMutation) AddedFields() []string {
  6069. var fields []string
  6070. if m.add_type != nil {
  6071. fields = append(fields, member.FieldType)
  6072. }
  6073. if m.addrole != nil {
  6074. fields = append(fields, member.FieldRole)
  6075. }
  6076. return fields
  6077. }
  6078. // AddedField returns the numeric value that was incremented/decremented on a field
  6079. // with the given name. The second boolean return value indicates that this field
  6080. // was not set, or was not defined in the schema.
  6081. func (m *MemberMutation) AddedField(name string) (ent.Value, bool) {
  6082. switch name {
  6083. case member.FieldType:
  6084. return m.AddedType()
  6085. case member.FieldRole:
  6086. return m.AddedRole()
  6087. }
  6088. return nil, false
  6089. }
  6090. // AddField adds the value to the field with the given name. It returns an error if
  6091. // the field is not defined in the schema, or if the type mismatched the field
  6092. // type.
  6093. func (m *MemberMutation) AddField(name string, value ent.Value) error {
  6094. switch name {
  6095. case member.FieldType:
  6096. v, ok := value.(int8)
  6097. if !ok {
  6098. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6099. }
  6100. m.AddType(v)
  6101. return nil
  6102. case member.FieldRole:
  6103. v, ok := value.(int8)
  6104. if !ok {
  6105. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6106. }
  6107. m.AddRole(v)
  6108. return nil
  6109. }
  6110. return fmt.Errorf("unknown Member numeric field %s", name)
  6111. }
  6112. // ClearedFields returns all nullable fields that were cleared during this
  6113. // mutation.
  6114. func (m *MemberMutation) ClearedFields() []string {
  6115. var fields []string
  6116. if m.FieldCleared(member.FieldDeletedAt) {
  6117. fields = append(fields, member.FieldDeletedAt)
  6118. }
  6119. if m.FieldCleared(member.FieldGroupID) {
  6120. fields = append(fields, member.FieldGroupID)
  6121. }
  6122. if m.FieldCleared(member.FieldRole) {
  6123. fields = append(fields, member.FieldRole)
  6124. }
  6125. return fields
  6126. }
  6127. // FieldCleared returns a boolean indicating if a field with the given name was
  6128. // cleared in this mutation.
  6129. func (m *MemberMutation) FieldCleared(name string) bool {
  6130. _, ok := m.clearedFields[name]
  6131. return ok
  6132. }
  6133. // ClearField clears the value of the field with the given name. It returns an
  6134. // error if the field is not defined in the schema.
  6135. func (m *MemberMutation) ClearField(name string) error {
  6136. switch name {
  6137. case member.FieldDeletedAt:
  6138. m.ClearDeletedAt()
  6139. return nil
  6140. case member.FieldGroupID:
  6141. m.ClearGroupID()
  6142. return nil
  6143. case member.FieldRole:
  6144. m.ClearRole()
  6145. return nil
  6146. }
  6147. return fmt.Errorf("unknown Member nullable field %s", name)
  6148. }
  6149. // ResetField resets all changes in the mutation for the field with the given name.
  6150. // It returns an error if the field is not defined in the schema.
  6151. func (m *MemberMutation) ResetField(name string) error {
  6152. switch name {
  6153. case member.FieldCreatedAt:
  6154. m.ResetCreatedAt()
  6155. return nil
  6156. case member.FieldUpdatedAt:
  6157. m.ResetUpdatedAt()
  6158. return nil
  6159. case member.FieldDeletedAt:
  6160. m.ResetDeletedAt()
  6161. return nil
  6162. case member.FieldGroupID:
  6163. m.ResetGroupID()
  6164. return nil
  6165. case member.FieldRefID:
  6166. m.ResetRefID()
  6167. return nil
  6168. case member.FieldType:
  6169. m.ResetType()
  6170. return nil
  6171. case member.FieldRole:
  6172. m.ResetRole()
  6173. return nil
  6174. }
  6175. return fmt.Errorf("unknown Member field %s", name)
  6176. }
  6177. // AddedEdges returns all edge names that were set/added in this mutation.
  6178. func (m *MemberMutation) AddedEdges() []string {
  6179. edges := make([]string, 0, 1)
  6180. if m.group != nil {
  6181. edges = append(edges, member.EdgeGroup)
  6182. }
  6183. return edges
  6184. }
  6185. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  6186. // name in this mutation.
  6187. func (m *MemberMutation) AddedIDs(name string) []ent.Value {
  6188. switch name {
  6189. case member.EdgeGroup:
  6190. if id := m.group; id != nil {
  6191. return []ent.Value{*id}
  6192. }
  6193. }
  6194. return nil
  6195. }
  6196. // RemovedEdges returns all edge names that were removed in this mutation.
  6197. func (m *MemberMutation) RemovedEdges() []string {
  6198. edges := make([]string, 0, 1)
  6199. return edges
  6200. }
  6201. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  6202. // the given name in this mutation.
  6203. func (m *MemberMutation) RemovedIDs(name string) []ent.Value {
  6204. return nil
  6205. }
  6206. // ClearedEdges returns all edge names that were cleared in this mutation.
  6207. func (m *MemberMutation) ClearedEdges() []string {
  6208. edges := make([]string, 0, 1)
  6209. if m.clearedgroup {
  6210. edges = append(edges, member.EdgeGroup)
  6211. }
  6212. return edges
  6213. }
  6214. // EdgeCleared returns a boolean which indicates if the edge with the given name
  6215. // was cleared in this mutation.
  6216. func (m *MemberMutation) EdgeCleared(name string) bool {
  6217. switch name {
  6218. case member.EdgeGroup:
  6219. return m.clearedgroup
  6220. }
  6221. return false
  6222. }
  6223. // ClearEdge clears the value of the edge with the given name. It returns an error
  6224. // if that edge is not defined in the schema.
  6225. func (m *MemberMutation) ClearEdge(name string) error {
  6226. switch name {
  6227. case member.EdgeGroup:
  6228. m.ClearGroup()
  6229. return nil
  6230. }
  6231. return fmt.Errorf("unknown Member unique edge %s", name)
  6232. }
  6233. // ResetEdge resets all changes to the edge with the given name in this mutation.
  6234. // It returns an error if the edge is not defined in the schema.
  6235. func (m *MemberMutation) ResetEdge(name string) error {
  6236. switch name {
  6237. case member.EdgeGroup:
  6238. m.ResetGroup()
  6239. return nil
  6240. }
  6241. return fmt.Errorf("unknown Member edge %s", name)
  6242. }
  6243. // UserMutation represents an operation that mutates the User nodes in the graph.
  6244. type UserMutation struct {
  6245. config
  6246. op Op
  6247. typ string
  6248. id *uuid.UUID
  6249. created_at *time.Time
  6250. updated_at *time.Time
  6251. deleted_at *time.Time
  6252. phone_number *string
  6253. area_code *string
  6254. email *string
  6255. password *string
  6256. is_registered *bool
  6257. clearedFields map[string]struct{}
  6258. userRefs map[int64]struct{}
  6259. removeduserRefs map[int64]struct{}
  6260. cleareduserRefs bool
  6261. done bool
  6262. oldValue func(context.Context) (*User, error)
  6263. predicates []predicate.User
  6264. }
  6265. var _ ent.Mutation = (*UserMutation)(nil)
  6266. // userOption allows management of the mutation configuration using functional options.
  6267. type userOption func(*UserMutation)
  6268. // newUserMutation creates new mutation for the User entity.
  6269. func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
  6270. m := &UserMutation{
  6271. config: c,
  6272. op: op,
  6273. typ: TypeUser,
  6274. clearedFields: make(map[string]struct{}),
  6275. }
  6276. for _, opt := range opts {
  6277. opt(m)
  6278. }
  6279. return m
  6280. }
  6281. // withUserID sets the ID field of the mutation.
  6282. func withUserID(id uuid.UUID) userOption {
  6283. return func(m *UserMutation) {
  6284. var (
  6285. err error
  6286. once sync.Once
  6287. value *User
  6288. )
  6289. m.oldValue = func(ctx context.Context) (*User, error) {
  6290. once.Do(func() {
  6291. if m.done {
  6292. err = errors.New("querying old values post mutation is not allowed")
  6293. } else {
  6294. value, err = m.Client().User.Get(ctx, id)
  6295. }
  6296. })
  6297. return value, err
  6298. }
  6299. m.id = &id
  6300. }
  6301. }
  6302. // withUser sets the old User of the mutation.
  6303. func withUser(node *User) userOption {
  6304. return func(m *UserMutation) {
  6305. m.oldValue = func(context.Context) (*User, error) {
  6306. return node, nil
  6307. }
  6308. m.id = &node.ID
  6309. }
  6310. }
  6311. // Client returns a new `ent.Client` from the mutation. If the mutation was
  6312. // executed in a transaction (ent.Tx), a transactional client is returned.
  6313. func (m UserMutation) Client() *Client {
  6314. client := &Client{config: m.config}
  6315. client.init()
  6316. return client
  6317. }
  6318. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  6319. // it returns an error otherwise.
  6320. func (m UserMutation) Tx() (*Tx, error) {
  6321. if _, ok := m.driver.(*txDriver); !ok {
  6322. return nil, errors.New("ent: mutation is not running in a transaction")
  6323. }
  6324. tx := &Tx{config: m.config}
  6325. tx.init()
  6326. return tx, nil
  6327. }
  6328. // SetID sets the value of the id field. Note that this
  6329. // operation is only accepted on creation of User entities.
  6330. func (m *UserMutation) SetID(id uuid.UUID) {
  6331. m.id = &id
  6332. }
  6333. // ID returns the ID value in the mutation. Note that the ID is only available
  6334. // if it was provided to the builder or after it was returned from the database.
  6335. func (m *UserMutation) ID() (id uuid.UUID, exists bool) {
  6336. if m.id == nil {
  6337. return
  6338. }
  6339. return *m.id, true
  6340. }
  6341. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  6342. // That means, if the mutation is applied within a transaction with an isolation level such
  6343. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  6344. // or updated by the mutation.
  6345. func (m *UserMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
  6346. switch {
  6347. case m.op.Is(OpUpdateOne | OpDeleteOne):
  6348. id, exists := m.ID()
  6349. if exists {
  6350. return []uuid.UUID{id}, nil
  6351. }
  6352. fallthrough
  6353. case m.op.Is(OpUpdate | OpDelete):
  6354. return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
  6355. default:
  6356. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  6357. }
  6358. }
  6359. // SetCreatedAt sets the "created_at" field.
  6360. func (m *UserMutation) SetCreatedAt(t time.Time) {
  6361. m.created_at = &t
  6362. }
  6363. // CreatedAt returns the value of the "created_at" field in the mutation.
  6364. func (m *UserMutation) CreatedAt() (r time.Time, exists bool) {
  6365. v := m.created_at
  6366. if v == nil {
  6367. return
  6368. }
  6369. return *v, true
  6370. }
  6371. // OldCreatedAt returns the old "created_at" field's value of the User entity.
  6372. // If the User object wasn't provided to the builder, the object is fetched from the database.
  6373. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6374. func (m *UserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  6375. if !m.op.Is(OpUpdateOne) {
  6376. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  6377. }
  6378. if m.id == nil || m.oldValue == nil {
  6379. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  6380. }
  6381. oldValue, err := m.oldValue(ctx)
  6382. if err != nil {
  6383. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  6384. }
  6385. return oldValue.CreatedAt, nil
  6386. }
  6387. // ResetCreatedAt resets all changes to the "created_at" field.
  6388. func (m *UserMutation) ResetCreatedAt() {
  6389. m.created_at = nil
  6390. }
  6391. // SetUpdatedAt sets the "updated_at" field.
  6392. func (m *UserMutation) SetUpdatedAt(t time.Time) {
  6393. m.updated_at = &t
  6394. }
  6395. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  6396. func (m *UserMutation) UpdatedAt() (r time.Time, exists bool) {
  6397. v := m.updated_at
  6398. if v == nil {
  6399. return
  6400. }
  6401. return *v, true
  6402. }
  6403. // OldUpdatedAt returns the old "updated_at" field's value of the User entity.
  6404. // If the User object wasn't provided to the builder, the object is fetched from the database.
  6405. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6406. func (m *UserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  6407. if !m.op.Is(OpUpdateOne) {
  6408. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  6409. }
  6410. if m.id == nil || m.oldValue == nil {
  6411. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  6412. }
  6413. oldValue, err := m.oldValue(ctx)
  6414. if err != nil {
  6415. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  6416. }
  6417. return oldValue.UpdatedAt, nil
  6418. }
  6419. // ResetUpdatedAt resets all changes to the "updated_at" field.
  6420. func (m *UserMutation) ResetUpdatedAt() {
  6421. m.updated_at = nil
  6422. }
  6423. // SetDeletedAt sets the "deleted_at" field.
  6424. func (m *UserMutation) SetDeletedAt(t time.Time) {
  6425. m.deleted_at = &t
  6426. }
  6427. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  6428. func (m *UserMutation) DeletedAt() (r time.Time, exists bool) {
  6429. v := m.deleted_at
  6430. if v == nil {
  6431. return
  6432. }
  6433. return *v, true
  6434. }
  6435. // OldDeletedAt returns the old "deleted_at" field's value of the User entity.
  6436. // If the User object wasn't provided to the builder, the object is fetched from the database.
  6437. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6438. func (m *UserMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
  6439. if !m.op.Is(OpUpdateOne) {
  6440. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  6441. }
  6442. if m.id == nil || m.oldValue == nil {
  6443. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  6444. }
  6445. oldValue, err := m.oldValue(ctx)
  6446. if err != nil {
  6447. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  6448. }
  6449. return oldValue.DeletedAt, nil
  6450. }
  6451. // ClearDeletedAt clears the value of the "deleted_at" field.
  6452. func (m *UserMutation) ClearDeletedAt() {
  6453. m.deleted_at = nil
  6454. m.clearedFields[user.FieldDeletedAt] = struct{}{}
  6455. }
  6456. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  6457. func (m *UserMutation) DeletedAtCleared() bool {
  6458. _, ok := m.clearedFields[user.FieldDeletedAt]
  6459. return ok
  6460. }
  6461. // ResetDeletedAt resets all changes to the "deleted_at" field.
  6462. func (m *UserMutation) ResetDeletedAt() {
  6463. m.deleted_at = nil
  6464. delete(m.clearedFields, user.FieldDeletedAt)
  6465. }
  6466. // SetPhoneNumber sets the "phone_number" field.
  6467. func (m *UserMutation) SetPhoneNumber(s string) {
  6468. m.phone_number = &s
  6469. }
  6470. // PhoneNumber returns the value of the "phone_number" field in the mutation.
  6471. func (m *UserMutation) PhoneNumber() (r string, exists bool) {
  6472. v := m.phone_number
  6473. if v == nil {
  6474. return
  6475. }
  6476. return *v, true
  6477. }
  6478. // OldPhoneNumber returns the old "phone_number" field's value of the User entity.
  6479. // If the User object wasn't provided to the builder, the object is fetched from the database.
  6480. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6481. func (m *UserMutation) OldPhoneNumber(ctx context.Context) (v *string, err error) {
  6482. if !m.op.Is(OpUpdateOne) {
  6483. return v, errors.New("OldPhoneNumber is only allowed on UpdateOne operations")
  6484. }
  6485. if m.id == nil || m.oldValue == nil {
  6486. return v, errors.New("OldPhoneNumber requires an ID field in the mutation")
  6487. }
  6488. oldValue, err := m.oldValue(ctx)
  6489. if err != nil {
  6490. return v, fmt.Errorf("querying old value for OldPhoneNumber: %w", err)
  6491. }
  6492. return oldValue.PhoneNumber, nil
  6493. }
  6494. // ClearPhoneNumber clears the value of the "phone_number" field.
  6495. func (m *UserMutation) ClearPhoneNumber() {
  6496. m.phone_number = nil
  6497. m.clearedFields[user.FieldPhoneNumber] = struct{}{}
  6498. }
  6499. // PhoneNumberCleared returns if the "phone_number" field was cleared in this mutation.
  6500. func (m *UserMutation) PhoneNumberCleared() bool {
  6501. _, ok := m.clearedFields[user.FieldPhoneNumber]
  6502. return ok
  6503. }
  6504. // ResetPhoneNumber resets all changes to the "phone_number" field.
  6505. func (m *UserMutation) ResetPhoneNumber() {
  6506. m.phone_number = nil
  6507. delete(m.clearedFields, user.FieldPhoneNumber)
  6508. }
  6509. // SetAreaCode sets the "area_code" field.
  6510. func (m *UserMutation) SetAreaCode(s string) {
  6511. m.area_code = &s
  6512. }
  6513. // AreaCode returns the value of the "area_code" field in the mutation.
  6514. func (m *UserMutation) AreaCode() (r string, exists bool) {
  6515. v := m.area_code
  6516. if v == nil {
  6517. return
  6518. }
  6519. return *v, true
  6520. }
  6521. // OldAreaCode returns the old "area_code" field's value of the User entity.
  6522. // If the User object wasn't provided to the builder, the object is fetched from the database.
  6523. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6524. func (m *UserMutation) OldAreaCode(ctx context.Context) (v *string, err error) {
  6525. if !m.op.Is(OpUpdateOne) {
  6526. return v, errors.New("OldAreaCode is only allowed on UpdateOne operations")
  6527. }
  6528. if m.id == nil || m.oldValue == nil {
  6529. return v, errors.New("OldAreaCode requires an ID field in the mutation")
  6530. }
  6531. oldValue, err := m.oldValue(ctx)
  6532. if err != nil {
  6533. return v, fmt.Errorf("querying old value for OldAreaCode: %w", err)
  6534. }
  6535. return oldValue.AreaCode, nil
  6536. }
  6537. // ClearAreaCode clears the value of the "area_code" field.
  6538. func (m *UserMutation) ClearAreaCode() {
  6539. m.area_code = nil
  6540. m.clearedFields[user.FieldAreaCode] = struct{}{}
  6541. }
  6542. // AreaCodeCleared returns if the "area_code" field was cleared in this mutation.
  6543. func (m *UserMutation) AreaCodeCleared() bool {
  6544. _, ok := m.clearedFields[user.FieldAreaCode]
  6545. return ok
  6546. }
  6547. // ResetAreaCode resets all changes to the "area_code" field.
  6548. func (m *UserMutation) ResetAreaCode() {
  6549. m.area_code = nil
  6550. delete(m.clearedFields, user.FieldAreaCode)
  6551. }
  6552. // SetEmail sets the "email" field.
  6553. func (m *UserMutation) SetEmail(s string) {
  6554. m.email = &s
  6555. }
  6556. // Email returns the value of the "email" field in the mutation.
  6557. func (m *UserMutation) Email() (r string, exists bool) {
  6558. v := m.email
  6559. if v == nil {
  6560. return
  6561. }
  6562. return *v, true
  6563. }
  6564. // OldEmail returns the old "email" field's value of the User entity.
  6565. // If the User object wasn't provided to the builder, the object is fetched from the database.
  6566. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6567. func (m *UserMutation) OldEmail(ctx context.Context) (v *string, err error) {
  6568. if !m.op.Is(OpUpdateOne) {
  6569. return v, errors.New("OldEmail is only allowed on UpdateOne operations")
  6570. }
  6571. if m.id == nil || m.oldValue == nil {
  6572. return v, errors.New("OldEmail requires an ID field in the mutation")
  6573. }
  6574. oldValue, err := m.oldValue(ctx)
  6575. if err != nil {
  6576. return v, fmt.Errorf("querying old value for OldEmail: %w", err)
  6577. }
  6578. return oldValue.Email, nil
  6579. }
  6580. // ClearEmail clears the value of the "email" field.
  6581. func (m *UserMutation) ClearEmail() {
  6582. m.email = nil
  6583. m.clearedFields[user.FieldEmail] = struct{}{}
  6584. }
  6585. // EmailCleared returns if the "email" field was cleared in this mutation.
  6586. func (m *UserMutation) EmailCleared() bool {
  6587. _, ok := m.clearedFields[user.FieldEmail]
  6588. return ok
  6589. }
  6590. // ResetEmail resets all changes to the "email" field.
  6591. func (m *UserMutation) ResetEmail() {
  6592. m.email = nil
  6593. delete(m.clearedFields, user.FieldEmail)
  6594. }
  6595. // SetPassword sets the "password" field.
  6596. func (m *UserMutation) SetPassword(s string) {
  6597. m.password = &s
  6598. }
  6599. // Password returns the value of the "password" field in the mutation.
  6600. func (m *UserMutation) Password() (r string, exists bool) {
  6601. v := m.password
  6602. if v == nil {
  6603. return
  6604. }
  6605. return *v, true
  6606. }
  6607. // OldPassword returns the old "password" field's value of the User entity.
  6608. // If the User object wasn't provided to the builder, the object is fetched from the database.
  6609. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6610. func (m *UserMutation) OldPassword(ctx context.Context) (v *string, err error) {
  6611. if !m.op.Is(OpUpdateOne) {
  6612. return v, errors.New("OldPassword is only allowed on UpdateOne operations")
  6613. }
  6614. if m.id == nil || m.oldValue == nil {
  6615. return v, errors.New("OldPassword requires an ID field in the mutation")
  6616. }
  6617. oldValue, err := m.oldValue(ctx)
  6618. if err != nil {
  6619. return v, fmt.Errorf("querying old value for OldPassword: %w", err)
  6620. }
  6621. return oldValue.Password, nil
  6622. }
  6623. // ClearPassword clears the value of the "password" field.
  6624. func (m *UserMutation) ClearPassword() {
  6625. m.password = nil
  6626. m.clearedFields[user.FieldPassword] = struct{}{}
  6627. }
  6628. // PasswordCleared returns if the "password" field was cleared in this mutation.
  6629. func (m *UserMutation) PasswordCleared() bool {
  6630. _, ok := m.clearedFields[user.FieldPassword]
  6631. return ok
  6632. }
  6633. // ResetPassword resets all changes to the "password" field.
  6634. func (m *UserMutation) ResetPassword() {
  6635. m.password = nil
  6636. delete(m.clearedFields, user.FieldPassword)
  6637. }
  6638. // SetIsRegistered sets the "is_registered" field.
  6639. func (m *UserMutation) SetIsRegistered(b bool) {
  6640. m.is_registered = &b
  6641. }
  6642. // IsRegistered returns the value of the "is_registered" field in the mutation.
  6643. func (m *UserMutation) IsRegistered() (r bool, exists bool) {
  6644. v := m.is_registered
  6645. if v == nil {
  6646. return
  6647. }
  6648. return *v, true
  6649. }
  6650. // OldIsRegistered returns the old "is_registered" field's value of the User entity.
  6651. // If the User object wasn't provided to the builder, the object is fetched from the database.
  6652. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6653. func (m *UserMutation) OldIsRegistered(ctx context.Context) (v bool, err error) {
  6654. if !m.op.Is(OpUpdateOne) {
  6655. return v, errors.New("OldIsRegistered is only allowed on UpdateOne operations")
  6656. }
  6657. if m.id == nil || m.oldValue == nil {
  6658. return v, errors.New("OldIsRegistered requires an ID field in the mutation")
  6659. }
  6660. oldValue, err := m.oldValue(ctx)
  6661. if err != nil {
  6662. return v, fmt.Errorf("querying old value for OldIsRegistered: %w", err)
  6663. }
  6664. return oldValue.IsRegistered, nil
  6665. }
  6666. // ResetIsRegistered resets all changes to the "is_registered" field.
  6667. func (m *UserMutation) ResetIsRegistered() {
  6668. m.is_registered = nil
  6669. }
  6670. // AddUserRefIDs adds the "userRefs" edge to the ChildRef entity by ids.
  6671. func (m *UserMutation) AddUserRefIDs(ids ...int64) {
  6672. if m.userRefs == nil {
  6673. m.userRefs = make(map[int64]struct{})
  6674. }
  6675. for i := range ids {
  6676. m.userRefs[ids[i]] = struct{}{}
  6677. }
  6678. }
  6679. // ClearUserRefs clears the "userRefs" edge to the ChildRef entity.
  6680. func (m *UserMutation) ClearUserRefs() {
  6681. m.cleareduserRefs = true
  6682. }
  6683. // UserRefsCleared reports if the "userRefs" edge to the ChildRef entity was cleared.
  6684. func (m *UserMutation) UserRefsCleared() bool {
  6685. return m.cleareduserRefs
  6686. }
  6687. // RemoveUserRefIDs removes the "userRefs" edge to the ChildRef entity by IDs.
  6688. func (m *UserMutation) RemoveUserRefIDs(ids ...int64) {
  6689. if m.removeduserRefs == nil {
  6690. m.removeduserRefs = make(map[int64]struct{})
  6691. }
  6692. for i := range ids {
  6693. delete(m.userRefs, ids[i])
  6694. m.removeduserRefs[ids[i]] = struct{}{}
  6695. }
  6696. }
  6697. // RemovedUserRefs returns the removed IDs of the "userRefs" edge to the ChildRef entity.
  6698. func (m *UserMutation) RemovedUserRefsIDs() (ids []int64) {
  6699. for id := range m.removeduserRefs {
  6700. ids = append(ids, id)
  6701. }
  6702. return
  6703. }
  6704. // UserRefsIDs returns the "userRefs" edge IDs in the mutation.
  6705. func (m *UserMutation) UserRefsIDs() (ids []int64) {
  6706. for id := range m.userRefs {
  6707. ids = append(ids, id)
  6708. }
  6709. return
  6710. }
  6711. // ResetUserRefs resets all changes to the "userRefs" edge.
  6712. func (m *UserMutation) ResetUserRefs() {
  6713. m.userRefs = nil
  6714. m.cleareduserRefs = false
  6715. m.removeduserRefs = nil
  6716. }
  6717. // Where appends a list predicates to the UserMutation builder.
  6718. func (m *UserMutation) Where(ps ...predicate.User) {
  6719. m.predicates = append(m.predicates, ps...)
  6720. }
  6721. // WhereP appends storage-level predicates to the UserMutation builder. Using this method,
  6722. // users can use type-assertion to append predicates that do not depend on any generated package.
  6723. func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) {
  6724. p := make([]predicate.User, len(ps))
  6725. for i := range ps {
  6726. p[i] = ps[i]
  6727. }
  6728. m.Where(p...)
  6729. }
  6730. // Op returns the operation name.
  6731. func (m *UserMutation) Op() Op {
  6732. return m.op
  6733. }
  6734. // SetOp allows setting the mutation operation.
  6735. func (m *UserMutation) SetOp(op Op) {
  6736. m.op = op
  6737. }
  6738. // Type returns the node type of this mutation (User).
  6739. func (m *UserMutation) Type() string {
  6740. return m.typ
  6741. }
  6742. // Fields returns all fields that were changed during this mutation. Note that in
  6743. // order to get all numeric fields that were incremented/decremented, call
  6744. // AddedFields().
  6745. func (m *UserMutation) Fields() []string {
  6746. fields := make([]string, 0, 8)
  6747. if m.created_at != nil {
  6748. fields = append(fields, user.FieldCreatedAt)
  6749. }
  6750. if m.updated_at != nil {
  6751. fields = append(fields, user.FieldUpdatedAt)
  6752. }
  6753. if m.deleted_at != nil {
  6754. fields = append(fields, user.FieldDeletedAt)
  6755. }
  6756. if m.phone_number != nil {
  6757. fields = append(fields, user.FieldPhoneNumber)
  6758. }
  6759. if m.area_code != nil {
  6760. fields = append(fields, user.FieldAreaCode)
  6761. }
  6762. if m.email != nil {
  6763. fields = append(fields, user.FieldEmail)
  6764. }
  6765. if m.password != nil {
  6766. fields = append(fields, user.FieldPassword)
  6767. }
  6768. if m.is_registered != nil {
  6769. fields = append(fields, user.FieldIsRegistered)
  6770. }
  6771. return fields
  6772. }
  6773. // Field returns the value of a field with the given name. The second boolean
  6774. // return value indicates that this field was not set, or was not defined in the
  6775. // schema.
  6776. func (m *UserMutation) Field(name string) (ent.Value, bool) {
  6777. switch name {
  6778. case user.FieldCreatedAt:
  6779. return m.CreatedAt()
  6780. case user.FieldUpdatedAt:
  6781. return m.UpdatedAt()
  6782. case user.FieldDeletedAt:
  6783. return m.DeletedAt()
  6784. case user.FieldPhoneNumber:
  6785. return m.PhoneNumber()
  6786. case user.FieldAreaCode:
  6787. return m.AreaCode()
  6788. case user.FieldEmail:
  6789. return m.Email()
  6790. case user.FieldPassword:
  6791. return m.Password()
  6792. case user.FieldIsRegistered:
  6793. return m.IsRegistered()
  6794. }
  6795. return nil, false
  6796. }
  6797. // OldField returns the old value of the field from the database. An error is
  6798. // returned if the mutation operation is not UpdateOne, or the query to the
  6799. // database failed.
  6800. func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  6801. switch name {
  6802. case user.FieldCreatedAt:
  6803. return m.OldCreatedAt(ctx)
  6804. case user.FieldUpdatedAt:
  6805. return m.OldUpdatedAt(ctx)
  6806. case user.FieldDeletedAt:
  6807. return m.OldDeletedAt(ctx)
  6808. case user.FieldPhoneNumber:
  6809. return m.OldPhoneNumber(ctx)
  6810. case user.FieldAreaCode:
  6811. return m.OldAreaCode(ctx)
  6812. case user.FieldEmail:
  6813. return m.OldEmail(ctx)
  6814. case user.FieldPassword:
  6815. return m.OldPassword(ctx)
  6816. case user.FieldIsRegistered:
  6817. return m.OldIsRegistered(ctx)
  6818. }
  6819. return nil, fmt.Errorf("unknown User field %s", name)
  6820. }
  6821. // SetField sets the value of a field with the given name. It returns an error if
  6822. // the field is not defined in the schema, or if the type mismatched the field
  6823. // type.
  6824. func (m *UserMutation) SetField(name string, value ent.Value) error {
  6825. switch name {
  6826. case user.FieldCreatedAt:
  6827. v, ok := value.(time.Time)
  6828. if !ok {
  6829. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6830. }
  6831. m.SetCreatedAt(v)
  6832. return nil
  6833. case user.FieldUpdatedAt:
  6834. v, ok := value.(time.Time)
  6835. if !ok {
  6836. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6837. }
  6838. m.SetUpdatedAt(v)
  6839. return nil
  6840. case user.FieldDeletedAt:
  6841. v, ok := value.(time.Time)
  6842. if !ok {
  6843. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6844. }
  6845. m.SetDeletedAt(v)
  6846. return nil
  6847. case user.FieldPhoneNumber:
  6848. v, ok := value.(string)
  6849. if !ok {
  6850. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6851. }
  6852. m.SetPhoneNumber(v)
  6853. return nil
  6854. case user.FieldAreaCode:
  6855. v, ok := value.(string)
  6856. if !ok {
  6857. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6858. }
  6859. m.SetAreaCode(v)
  6860. return nil
  6861. case user.FieldEmail:
  6862. v, ok := value.(string)
  6863. if !ok {
  6864. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6865. }
  6866. m.SetEmail(v)
  6867. return nil
  6868. case user.FieldPassword:
  6869. v, ok := value.(string)
  6870. if !ok {
  6871. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6872. }
  6873. m.SetPassword(v)
  6874. return nil
  6875. case user.FieldIsRegistered:
  6876. v, ok := value.(bool)
  6877. if !ok {
  6878. return fmt.Errorf("unexpected type %T for field %s", value, name)
  6879. }
  6880. m.SetIsRegistered(v)
  6881. return nil
  6882. }
  6883. return fmt.Errorf("unknown User field %s", name)
  6884. }
  6885. // AddedFields returns all numeric fields that were incremented/decremented during
  6886. // this mutation.
  6887. func (m *UserMutation) AddedFields() []string {
  6888. return nil
  6889. }
  6890. // AddedField returns the numeric value that was incremented/decremented on a field
  6891. // with the given name. The second boolean return value indicates that this field
  6892. // was not set, or was not defined in the schema.
  6893. func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
  6894. return nil, false
  6895. }
  6896. // AddField adds the value to the field with the given name. It returns an error if
  6897. // the field is not defined in the schema, or if the type mismatched the field
  6898. // type.
  6899. func (m *UserMutation) AddField(name string, value ent.Value) error {
  6900. switch name {
  6901. }
  6902. return fmt.Errorf("unknown User numeric field %s", name)
  6903. }
  6904. // ClearedFields returns all nullable fields that were cleared during this
  6905. // mutation.
  6906. func (m *UserMutation) ClearedFields() []string {
  6907. var fields []string
  6908. if m.FieldCleared(user.FieldDeletedAt) {
  6909. fields = append(fields, user.FieldDeletedAt)
  6910. }
  6911. if m.FieldCleared(user.FieldPhoneNumber) {
  6912. fields = append(fields, user.FieldPhoneNumber)
  6913. }
  6914. if m.FieldCleared(user.FieldAreaCode) {
  6915. fields = append(fields, user.FieldAreaCode)
  6916. }
  6917. if m.FieldCleared(user.FieldEmail) {
  6918. fields = append(fields, user.FieldEmail)
  6919. }
  6920. if m.FieldCleared(user.FieldPassword) {
  6921. fields = append(fields, user.FieldPassword)
  6922. }
  6923. return fields
  6924. }
  6925. // FieldCleared returns a boolean indicating if a field with the given name was
  6926. // cleared in this mutation.
  6927. func (m *UserMutation) FieldCleared(name string) bool {
  6928. _, ok := m.clearedFields[name]
  6929. return ok
  6930. }
  6931. // ClearField clears the value of the field with the given name. It returns an
  6932. // error if the field is not defined in the schema.
  6933. func (m *UserMutation) ClearField(name string) error {
  6934. switch name {
  6935. case user.FieldDeletedAt:
  6936. m.ClearDeletedAt()
  6937. return nil
  6938. case user.FieldPhoneNumber:
  6939. m.ClearPhoneNumber()
  6940. return nil
  6941. case user.FieldAreaCode:
  6942. m.ClearAreaCode()
  6943. return nil
  6944. case user.FieldEmail:
  6945. m.ClearEmail()
  6946. return nil
  6947. case user.FieldPassword:
  6948. m.ClearPassword()
  6949. return nil
  6950. }
  6951. return fmt.Errorf("unknown User nullable field %s", name)
  6952. }
  6953. // ResetField resets all changes in the mutation for the field with the given name.
  6954. // It returns an error if the field is not defined in the schema.
  6955. func (m *UserMutation) ResetField(name string) error {
  6956. switch name {
  6957. case user.FieldCreatedAt:
  6958. m.ResetCreatedAt()
  6959. return nil
  6960. case user.FieldUpdatedAt:
  6961. m.ResetUpdatedAt()
  6962. return nil
  6963. case user.FieldDeletedAt:
  6964. m.ResetDeletedAt()
  6965. return nil
  6966. case user.FieldPhoneNumber:
  6967. m.ResetPhoneNumber()
  6968. return nil
  6969. case user.FieldAreaCode:
  6970. m.ResetAreaCode()
  6971. return nil
  6972. case user.FieldEmail:
  6973. m.ResetEmail()
  6974. return nil
  6975. case user.FieldPassword:
  6976. m.ResetPassword()
  6977. return nil
  6978. case user.FieldIsRegistered:
  6979. m.ResetIsRegistered()
  6980. return nil
  6981. }
  6982. return fmt.Errorf("unknown User field %s", name)
  6983. }
  6984. // AddedEdges returns all edge names that were set/added in this mutation.
  6985. func (m *UserMutation) AddedEdges() []string {
  6986. edges := make([]string, 0, 1)
  6987. if m.userRefs != nil {
  6988. edges = append(edges, user.EdgeUserRefs)
  6989. }
  6990. return edges
  6991. }
  6992. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  6993. // name in this mutation.
  6994. func (m *UserMutation) AddedIDs(name string) []ent.Value {
  6995. switch name {
  6996. case user.EdgeUserRefs:
  6997. ids := make([]ent.Value, 0, len(m.userRefs))
  6998. for id := range m.userRefs {
  6999. ids = append(ids, id)
  7000. }
  7001. return ids
  7002. }
  7003. return nil
  7004. }
  7005. // RemovedEdges returns all edge names that were removed in this mutation.
  7006. func (m *UserMutation) RemovedEdges() []string {
  7007. edges := make([]string, 0, 1)
  7008. if m.removeduserRefs != nil {
  7009. edges = append(edges, user.EdgeUserRefs)
  7010. }
  7011. return edges
  7012. }
  7013. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  7014. // the given name in this mutation.
  7015. func (m *UserMutation) RemovedIDs(name string) []ent.Value {
  7016. switch name {
  7017. case user.EdgeUserRefs:
  7018. ids := make([]ent.Value, 0, len(m.removeduserRefs))
  7019. for id := range m.removeduserRefs {
  7020. ids = append(ids, id)
  7021. }
  7022. return ids
  7023. }
  7024. return nil
  7025. }
  7026. // ClearedEdges returns all edge names that were cleared in this mutation.
  7027. func (m *UserMutation) ClearedEdges() []string {
  7028. edges := make([]string, 0, 1)
  7029. if m.cleareduserRefs {
  7030. edges = append(edges, user.EdgeUserRefs)
  7031. }
  7032. return edges
  7033. }
  7034. // EdgeCleared returns a boolean which indicates if the edge with the given name
  7035. // was cleared in this mutation.
  7036. func (m *UserMutation) EdgeCleared(name string) bool {
  7037. switch name {
  7038. case user.EdgeUserRefs:
  7039. return m.cleareduserRefs
  7040. }
  7041. return false
  7042. }
  7043. // ClearEdge clears the value of the edge with the given name. It returns an error
  7044. // if that edge is not defined in the schema.
  7045. func (m *UserMutation) ClearEdge(name string) error {
  7046. switch name {
  7047. }
  7048. return fmt.Errorf("unknown User unique edge %s", name)
  7049. }
  7050. // ResetEdge resets all changes to the edge with the given name in this mutation.
  7051. // It returns an error if the edge is not defined in the schema.
  7052. func (m *UserMutation) ResetEdge(name string) error {
  7053. switch name {
  7054. case user.EdgeUserRefs:
  7055. m.ResetUserRefs()
  7056. return nil
  7057. }
  7058. return fmt.Errorf("unknown User edge %s", name)
  7059. }