mutation.go 172 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "sync"
  8. "time"
  9. "wechat-api/ent/contact"
  10. "wechat-api/ent/label"
  11. "wechat-api/ent/labelrelationship"
  12. "wechat-api/ent/message"
  13. "wechat-api/ent/predicate"
  14. "wechat-api/ent/server"
  15. "wechat-api/ent/wx"
  16. "entgo.io/ent"
  17. "entgo.io/ent/dialect/sql"
  18. )
  19. const (
  20. // Operation types.
  21. OpCreate = ent.OpCreate
  22. OpDelete = ent.OpDelete
  23. OpDeleteOne = ent.OpDeleteOne
  24. OpUpdate = ent.OpUpdate
  25. OpUpdateOne = ent.OpUpdateOne
  26. // Node types.
  27. TypeContact = "Contact"
  28. TypeLabel = "Label"
  29. TypeLabelRelationship = "LabelRelationship"
  30. TypeMessage = "Message"
  31. TypeServer = "Server"
  32. TypeWx = "Wx"
  33. )
  34. // ContactMutation represents an operation that mutates the Contact nodes in the graph.
  35. type ContactMutation struct {
  36. config
  37. op Op
  38. typ string
  39. id *uint64
  40. created_at *time.Time
  41. updated_at *time.Time
  42. status *uint8
  43. addstatus *int8
  44. deleted_at *time.Time
  45. wx_wxid *string
  46. _type *int
  47. add_type *int
  48. wxid *string
  49. account *string
  50. nickname *string
  51. markname *string
  52. headimg *string
  53. sex *int
  54. addsex *int
  55. starrole *string
  56. dontseeit *int
  57. adddontseeit *int
  58. dontseeme *int
  59. adddontseeme *int
  60. lag *string
  61. gid *string
  62. gname *string
  63. v3 *string
  64. clearedFields map[string]struct{}
  65. contact_relationships map[uint64]struct{}
  66. removedcontact_relationships map[uint64]struct{}
  67. clearedcontact_relationships bool
  68. done bool
  69. oldValue func(context.Context) (*Contact, error)
  70. predicates []predicate.Contact
  71. }
  72. var _ ent.Mutation = (*ContactMutation)(nil)
  73. // contactOption allows management of the mutation configuration using functional options.
  74. type contactOption func(*ContactMutation)
  75. // newContactMutation creates new mutation for the Contact entity.
  76. func newContactMutation(c config, op Op, opts ...contactOption) *ContactMutation {
  77. m := &ContactMutation{
  78. config: c,
  79. op: op,
  80. typ: TypeContact,
  81. clearedFields: make(map[string]struct{}),
  82. }
  83. for _, opt := range opts {
  84. opt(m)
  85. }
  86. return m
  87. }
  88. // withContactID sets the ID field of the mutation.
  89. func withContactID(id uint64) contactOption {
  90. return func(m *ContactMutation) {
  91. var (
  92. err error
  93. once sync.Once
  94. value *Contact
  95. )
  96. m.oldValue = func(ctx context.Context) (*Contact, error) {
  97. once.Do(func() {
  98. if m.done {
  99. err = errors.New("querying old values post mutation is not allowed")
  100. } else {
  101. value, err = m.Client().Contact.Get(ctx, id)
  102. }
  103. })
  104. return value, err
  105. }
  106. m.id = &id
  107. }
  108. }
  109. // withContact sets the old Contact of the mutation.
  110. func withContact(node *Contact) contactOption {
  111. return func(m *ContactMutation) {
  112. m.oldValue = func(context.Context) (*Contact, error) {
  113. return node, nil
  114. }
  115. m.id = &node.ID
  116. }
  117. }
  118. // Client returns a new `ent.Client` from the mutation. If the mutation was
  119. // executed in a transaction (ent.Tx), a transactional client is returned.
  120. func (m ContactMutation) Client() *Client {
  121. client := &Client{config: m.config}
  122. client.init()
  123. return client
  124. }
  125. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  126. // it returns an error otherwise.
  127. func (m ContactMutation) Tx() (*Tx, error) {
  128. if _, ok := m.driver.(*txDriver); !ok {
  129. return nil, errors.New("ent: mutation is not running in a transaction")
  130. }
  131. tx := &Tx{config: m.config}
  132. tx.init()
  133. return tx, nil
  134. }
  135. // SetID sets the value of the id field. Note that this
  136. // operation is only accepted on creation of Contact entities.
  137. func (m *ContactMutation) SetID(id uint64) {
  138. m.id = &id
  139. }
  140. // ID returns the ID value in the mutation. Note that the ID is only available
  141. // if it was provided to the builder or after it was returned from the database.
  142. func (m *ContactMutation) ID() (id uint64, exists bool) {
  143. if m.id == nil {
  144. return
  145. }
  146. return *m.id, true
  147. }
  148. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  149. // That means, if the mutation is applied within a transaction with an isolation level such
  150. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  151. // or updated by the mutation.
  152. func (m *ContactMutation) IDs(ctx context.Context) ([]uint64, error) {
  153. switch {
  154. case m.op.Is(OpUpdateOne | OpDeleteOne):
  155. id, exists := m.ID()
  156. if exists {
  157. return []uint64{id}, nil
  158. }
  159. fallthrough
  160. case m.op.Is(OpUpdate | OpDelete):
  161. return m.Client().Contact.Query().Where(m.predicates...).IDs(ctx)
  162. default:
  163. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  164. }
  165. }
  166. // SetCreatedAt sets the "created_at" field.
  167. func (m *ContactMutation) SetCreatedAt(t time.Time) {
  168. m.created_at = &t
  169. }
  170. // CreatedAt returns the value of the "created_at" field in the mutation.
  171. func (m *ContactMutation) CreatedAt() (r time.Time, exists bool) {
  172. v := m.created_at
  173. if v == nil {
  174. return
  175. }
  176. return *v, true
  177. }
  178. // OldCreatedAt returns the old "created_at" field's value of the Contact entity.
  179. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  180. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  181. func (m *ContactMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  182. if !m.op.Is(OpUpdateOne) {
  183. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  184. }
  185. if m.id == nil || m.oldValue == nil {
  186. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  187. }
  188. oldValue, err := m.oldValue(ctx)
  189. if err != nil {
  190. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  191. }
  192. return oldValue.CreatedAt, nil
  193. }
  194. // ResetCreatedAt resets all changes to the "created_at" field.
  195. func (m *ContactMutation) ResetCreatedAt() {
  196. m.created_at = nil
  197. }
  198. // SetUpdatedAt sets the "updated_at" field.
  199. func (m *ContactMutation) SetUpdatedAt(t time.Time) {
  200. m.updated_at = &t
  201. }
  202. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  203. func (m *ContactMutation) UpdatedAt() (r time.Time, exists bool) {
  204. v := m.updated_at
  205. if v == nil {
  206. return
  207. }
  208. return *v, true
  209. }
  210. // OldUpdatedAt returns the old "updated_at" field's value of the Contact entity.
  211. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  212. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  213. func (m *ContactMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  214. if !m.op.Is(OpUpdateOne) {
  215. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  216. }
  217. if m.id == nil || m.oldValue == nil {
  218. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  219. }
  220. oldValue, err := m.oldValue(ctx)
  221. if err != nil {
  222. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  223. }
  224. return oldValue.UpdatedAt, nil
  225. }
  226. // ResetUpdatedAt resets all changes to the "updated_at" field.
  227. func (m *ContactMutation) ResetUpdatedAt() {
  228. m.updated_at = nil
  229. }
  230. // SetStatus sets the "status" field.
  231. func (m *ContactMutation) SetStatus(u uint8) {
  232. m.status = &u
  233. m.addstatus = nil
  234. }
  235. // Status returns the value of the "status" field in the mutation.
  236. func (m *ContactMutation) Status() (r uint8, exists bool) {
  237. v := m.status
  238. if v == nil {
  239. return
  240. }
  241. return *v, true
  242. }
  243. // OldStatus returns the old "status" field's value of the Contact entity.
  244. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  245. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  246. func (m *ContactMutation) OldStatus(ctx context.Context) (v uint8, err error) {
  247. if !m.op.Is(OpUpdateOne) {
  248. return v, errors.New("OldStatus is only allowed on UpdateOne operations")
  249. }
  250. if m.id == nil || m.oldValue == nil {
  251. return v, errors.New("OldStatus requires an ID field in the mutation")
  252. }
  253. oldValue, err := m.oldValue(ctx)
  254. if err != nil {
  255. return v, fmt.Errorf("querying old value for OldStatus: %w", err)
  256. }
  257. return oldValue.Status, nil
  258. }
  259. // AddStatus adds u to the "status" field.
  260. func (m *ContactMutation) AddStatus(u int8) {
  261. if m.addstatus != nil {
  262. *m.addstatus += u
  263. } else {
  264. m.addstatus = &u
  265. }
  266. }
  267. // AddedStatus returns the value that was added to the "status" field in this mutation.
  268. func (m *ContactMutation) AddedStatus() (r int8, exists bool) {
  269. v := m.addstatus
  270. if v == nil {
  271. return
  272. }
  273. return *v, true
  274. }
  275. // ClearStatus clears the value of the "status" field.
  276. func (m *ContactMutation) ClearStatus() {
  277. m.status = nil
  278. m.addstatus = nil
  279. m.clearedFields[contact.FieldStatus] = struct{}{}
  280. }
  281. // StatusCleared returns if the "status" field was cleared in this mutation.
  282. func (m *ContactMutation) StatusCleared() bool {
  283. _, ok := m.clearedFields[contact.FieldStatus]
  284. return ok
  285. }
  286. // ResetStatus resets all changes to the "status" field.
  287. func (m *ContactMutation) ResetStatus() {
  288. m.status = nil
  289. m.addstatus = nil
  290. delete(m.clearedFields, contact.FieldStatus)
  291. }
  292. // SetDeletedAt sets the "deleted_at" field.
  293. func (m *ContactMutation) SetDeletedAt(t time.Time) {
  294. m.deleted_at = &t
  295. }
  296. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  297. func (m *ContactMutation) DeletedAt() (r time.Time, exists bool) {
  298. v := m.deleted_at
  299. if v == nil {
  300. return
  301. }
  302. return *v, true
  303. }
  304. // OldDeletedAt returns the old "deleted_at" field's value of the Contact entity.
  305. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  306. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  307. func (m *ContactMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  308. if !m.op.Is(OpUpdateOne) {
  309. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  310. }
  311. if m.id == nil || m.oldValue == nil {
  312. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  313. }
  314. oldValue, err := m.oldValue(ctx)
  315. if err != nil {
  316. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  317. }
  318. return oldValue.DeletedAt, nil
  319. }
  320. // ClearDeletedAt clears the value of the "deleted_at" field.
  321. func (m *ContactMutation) ClearDeletedAt() {
  322. m.deleted_at = nil
  323. m.clearedFields[contact.FieldDeletedAt] = struct{}{}
  324. }
  325. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  326. func (m *ContactMutation) DeletedAtCleared() bool {
  327. _, ok := m.clearedFields[contact.FieldDeletedAt]
  328. return ok
  329. }
  330. // ResetDeletedAt resets all changes to the "deleted_at" field.
  331. func (m *ContactMutation) ResetDeletedAt() {
  332. m.deleted_at = nil
  333. delete(m.clearedFields, contact.FieldDeletedAt)
  334. }
  335. // SetWxWxid sets the "wx_wxid" field.
  336. func (m *ContactMutation) SetWxWxid(s string) {
  337. m.wx_wxid = &s
  338. }
  339. // WxWxid returns the value of the "wx_wxid" field in the mutation.
  340. func (m *ContactMutation) WxWxid() (r string, exists bool) {
  341. v := m.wx_wxid
  342. if v == nil {
  343. return
  344. }
  345. return *v, true
  346. }
  347. // OldWxWxid returns the old "wx_wxid" field's value of the Contact entity.
  348. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  349. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  350. func (m *ContactMutation) OldWxWxid(ctx context.Context) (v string, err error) {
  351. if !m.op.Is(OpUpdateOne) {
  352. return v, errors.New("OldWxWxid is only allowed on UpdateOne operations")
  353. }
  354. if m.id == nil || m.oldValue == nil {
  355. return v, errors.New("OldWxWxid requires an ID field in the mutation")
  356. }
  357. oldValue, err := m.oldValue(ctx)
  358. if err != nil {
  359. return v, fmt.Errorf("querying old value for OldWxWxid: %w", err)
  360. }
  361. return oldValue.WxWxid, nil
  362. }
  363. // ClearWxWxid clears the value of the "wx_wxid" field.
  364. func (m *ContactMutation) ClearWxWxid() {
  365. m.wx_wxid = nil
  366. m.clearedFields[contact.FieldWxWxid] = struct{}{}
  367. }
  368. // WxWxidCleared returns if the "wx_wxid" field was cleared in this mutation.
  369. func (m *ContactMutation) WxWxidCleared() bool {
  370. _, ok := m.clearedFields[contact.FieldWxWxid]
  371. return ok
  372. }
  373. // ResetWxWxid resets all changes to the "wx_wxid" field.
  374. func (m *ContactMutation) ResetWxWxid() {
  375. m.wx_wxid = nil
  376. delete(m.clearedFields, contact.FieldWxWxid)
  377. }
  378. // SetType sets the "type" field.
  379. func (m *ContactMutation) SetType(i int) {
  380. m._type = &i
  381. m.add_type = nil
  382. }
  383. // GetType returns the value of the "type" field in the mutation.
  384. func (m *ContactMutation) GetType() (r int, exists bool) {
  385. v := m._type
  386. if v == nil {
  387. return
  388. }
  389. return *v, true
  390. }
  391. // OldType returns the old "type" field's value of the Contact entity.
  392. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  393. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  394. func (m *ContactMutation) OldType(ctx context.Context) (v int, err error) {
  395. if !m.op.Is(OpUpdateOne) {
  396. return v, errors.New("OldType is only allowed on UpdateOne operations")
  397. }
  398. if m.id == nil || m.oldValue == nil {
  399. return v, errors.New("OldType requires an ID field in the mutation")
  400. }
  401. oldValue, err := m.oldValue(ctx)
  402. if err != nil {
  403. return v, fmt.Errorf("querying old value for OldType: %w", err)
  404. }
  405. return oldValue.Type, nil
  406. }
  407. // AddType adds i to the "type" field.
  408. func (m *ContactMutation) AddType(i int) {
  409. if m.add_type != nil {
  410. *m.add_type += i
  411. } else {
  412. m.add_type = &i
  413. }
  414. }
  415. // AddedType returns the value that was added to the "type" field in this mutation.
  416. func (m *ContactMutation) AddedType() (r int, exists bool) {
  417. v := m.add_type
  418. if v == nil {
  419. return
  420. }
  421. return *v, true
  422. }
  423. // ClearType clears the value of the "type" field.
  424. func (m *ContactMutation) ClearType() {
  425. m._type = nil
  426. m.add_type = nil
  427. m.clearedFields[contact.FieldType] = struct{}{}
  428. }
  429. // TypeCleared returns if the "type" field was cleared in this mutation.
  430. func (m *ContactMutation) TypeCleared() bool {
  431. _, ok := m.clearedFields[contact.FieldType]
  432. return ok
  433. }
  434. // ResetType resets all changes to the "type" field.
  435. func (m *ContactMutation) ResetType() {
  436. m._type = nil
  437. m.add_type = nil
  438. delete(m.clearedFields, contact.FieldType)
  439. }
  440. // SetWxid sets the "wxid" field.
  441. func (m *ContactMutation) SetWxid(s string) {
  442. m.wxid = &s
  443. }
  444. // Wxid returns the value of the "wxid" field in the mutation.
  445. func (m *ContactMutation) Wxid() (r string, exists bool) {
  446. v := m.wxid
  447. if v == nil {
  448. return
  449. }
  450. return *v, true
  451. }
  452. // OldWxid returns the old "wxid" field's value of the Contact entity.
  453. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  454. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  455. func (m *ContactMutation) OldWxid(ctx context.Context) (v string, err error) {
  456. if !m.op.Is(OpUpdateOne) {
  457. return v, errors.New("OldWxid is only allowed on UpdateOne operations")
  458. }
  459. if m.id == nil || m.oldValue == nil {
  460. return v, errors.New("OldWxid requires an ID field in the mutation")
  461. }
  462. oldValue, err := m.oldValue(ctx)
  463. if err != nil {
  464. return v, fmt.Errorf("querying old value for OldWxid: %w", err)
  465. }
  466. return oldValue.Wxid, nil
  467. }
  468. // ResetWxid resets all changes to the "wxid" field.
  469. func (m *ContactMutation) ResetWxid() {
  470. m.wxid = nil
  471. }
  472. // SetAccount sets the "account" field.
  473. func (m *ContactMutation) SetAccount(s string) {
  474. m.account = &s
  475. }
  476. // Account returns the value of the "account" field in the mutation.
  477. func (m *ContactMutation) Account() (r string, exists bool) {
  478. v := m.account
  479. if v == nil {
  480. return
  481. }
  482. return *v, true
  483. }
  484. // OldAccount returns the old "account" field's value of the Contact entity.
  485. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  486. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  487. func (m *ContactMutation) OldAccount(ctx context.Context) (v string, err error) {
  488. if !m.op.Is(OpUpdateOne) {
  489. return v, errors.New("OldAccount is only allowed on UpdateOne operations")
  490. }
  491. if m.id == nil || m.oldValue == nil {
  492. return v, errors.New("OldAccount requires an ID field in the mutation")
  493. }
  494. oldValue, err := m.oldValue(ctx)
  495. if err != nil {
  496. return v, fmt.Errorf("querying old value for OldAccount: %w", err)
  497. }
  498. return oldValue.Account, nil
  499. }
  500. // ResetAccount resets all changes to the "account" field.
  501. func (m *ContactMutation) ResetAccount() {
  502. m.account = nil
  503. }
  504. // SetNickname sets the "nickname" field.
  505. func (m *ContactMutation) SetNickname(s string) {
  506. m.nickname = &s
  507. }
  508. // Nickname returns the value of the "nickname" field in the mutation.
  509. func (m *ContactMutation) Nickname() (r string, exists bool) {
  510. v := m.nickname
  511. if v == nil {
  512. return
  513. }
  514. return *v, true
  515. }
  516. // OldNickname returns the old "nickname" field's value of the Contact entity.
  517. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  518. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  519. func (m *ContactMutation) OldNickname(ctx context.Context) (v string, err error) {
  520. if !m.op.Is(OpUpdateOne) {
  521. return v, errors.New("OldNickname is only allowed on UpdateOne operations")
  522. }
  523. if m.id == nil || m.oldValue == nil {
  524. return v, errors.New("OldNickname requires an ID field in the mutation")
  525. }
  526. oldValue, err := m.oldValue(ctx)
  527. if err != nil {
  528. return v, fmt.Errorf("querying old value for OldNickname: %w", err)
  529. }
  530. return oldValue.Nickname, nil
  531. }
  532. // ResetNickname resets all changes to the "nickname" field.
  533. func (m *ContactMutation) ResetNickname() {
  534. m.nickname = nil
  535. }
  536. // SetMarkname sets the "markname" field.
  537. func (m *ContactMutation) SetMarkname(s string) {
  538. m.markname = &s
  539. }
  540. // Markname returns the value of the "markname" field in the mutation.
  541. func (m *ContactMutation) Markname() (r string, exists bool) {
  542. v := m.markname
  543. if v == nil {
  544. return
  545. }
  546. return *v, true
  547. }
  548. // OldMarkname returns the old "markname" field's value of the Contact entity.
  549. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  550. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  551. func (m *ContactMutation) OldMarkname(ctx context.Context) (v string, err error) {
  552. if !m.op.Is(OpUpdateOne) {
  553. return v, errors.New("OldMarkname is only allowed on UpdateOne operations")
  554. }
  555. if m.id == nil || m.oldValue == nil {
  556. return v, errors.New("OldMarkname requires an ID field in the mutation")
  557. }
  558. oldValue, err := m.oldValue(ctx)
  559. if err != nil {
  560. return v, fmt.Errorf("querying old value for OldMarkname: %w", err)
  561. }
  562. return oldValue.Markname, nil
  563. }
  564. // ResetMarkname resets all changes to the "markname" field.
  565. func (m *ContactMutation) ResetMarkname() {
  566. m.markname = nil
  567. }
  568. // SetHeadimg sets the "headimg" field.
  569. func (m *ContactMutation) SetHeadimg(s string) {
  570. m.headimg = &s
  571. }
  572. // Headimg returns the value of the "headimg" field in the mutation.
  573. func (m *ContactMutation) Headimg() (r string, exists bool) {
  574. v := m.headimg
  575. if v == nil {
  576. return
  577. }
  578. return *v, true
  579. }
  580. // OldHeadimg returns the old "headimg" field's value of the Contact entity.
  581. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  582. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  583. func (m *ContactMutation) OldHeadimg(ctx context.Context) (v string, err error) {
  584. if !m.op.Is(OpUpdateOne) {
  585. return v, errors.New("OldHeadimg is only allowed on UpdateOne operations")
  586. }
  587. if m.id == nil || m.oldValue == nil {
  588. return v, errors.New("OldHeadimg requires an ID field in the mutation")
  589. }
  590. oldValue, err := m.oldValue(ctx)
  591. if err != nil {
  592. return v, fmt.Errorf("querying old value for OldHeadimg: %w", err)
  593. }
  594. return oldValue.Headimg, nil
  595. }
  596. // ResetHeadimg resets all changes to the "headimg" field.
  597. func (m *ContactMutation) ResetHeadimg() {
  598. m.headimg = nil
  599. }
  600. // SetSex sets the "sex" field.
  601. func (m *ContactMutation) SetSex(i int) {
  602. m.sex = &i
  603. m.addsex = nil
  604. }
  605. // Sex returns the value of the "sex" field in the mutation.
  606. func (m *ContactMutation) Sex() (r int, exists bool) {
  607. v := m.sex
  608. if v == nil {
  609. return
  610. }
  611. return *v, true
  612. }
  613. // OldSex returns the old "sex" field's value of the Contact entity.
  614. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  615. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  616. func (m *ContactMutation) OldSex(ctx context.Context) (v int, err error) {
  617. if !m.op.Is(OpUpdateOne) {
  618. return v, errors.New("OldSex is only allowed on UpdateOne operations")
  619. }
  620. if m.id == nil || m.oldValue == nil {
  621. return v, errors.New("OldSex requires an ID field in the mutation")
  622. }
  623. oldValue, err := m.oldValue(ctx)
  624. if err != nil {
  625. return v, fmt.Errorf("querying old value for OldSex: %w", err)
  626. }
  627. return oldValue.Sex, nil
  628. }
  629. // AddSex adds i to the "sex" field.
  630. func (m *ContactMutation) AddSex(i int) {
  631. if m.addsex != nil {
  632. *m.addsex += i
  633. } else {
  634. m.addsex = &i
  635. }
  636. }
  637. // AddedSex returns the value that was added to the "sex" field in this mutation.
  638. func (m *ContactMutation) AddedSex() (r int, exists bool) {
  639. v := m.addsex
  640. if v == nil {
  641. return
  642. }
  643. return *v, true
  644. }
  645. // ResetSex resets all changes to the "sex" field.
  646. func (m *ContactMutation) ResetSex() {
  647. m.sex = nil
  648. m.addsex = nil
  649. }
  650. // SetStarrole sets the "starrole" field.
  651. func (m *ContactMutation) SetStarrole(s string) {
  652. m.starrole = &s
  653. }
  654. // Starrole returns the value of the "starrole" field in the mutation.
  655. func (m *ContactMutation) Starrole() (r string, exists bool) {
  656. v := m.starrole
  657. if v == nil {
  658. return
  659. }
  660. return *v, true
  661. }
  662. // OldStarrole returns the old "starrole" field's value of the Contact entity.
  663. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  664. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  665. func (m *ContactMutation) OldStarrole(ctx context.Context) (v string, err error) {
  666. if !m.op.Is(OpUpdateOne) {
  667. return v, errors.New("OldStarrole is only allowed on UpdateOne operations")
  668. }
  669. if m.id == nil || m.oldValue == nil {
  670. return v, errors.New("OldStarrole requires an ID field in the mutation")
  671. }
  672. oldValue, err := m.oldValue(ctx)
  673. if err != nil {
  674. return v, fmt.Errorf("querying old value for OldStarrole: %w", err)
  675. }
  676. return oldValue.Starrole, nil
  677. }
  678. // ResetStarrole resets all changes to the "starrole" field.
  679. func (m *ContactMutation) ResetStarrole() {
  680. m.starrole = nil
  681. }
  682. // SetDontseeit sets the "dontseeit" field.
  683. func (m *ContactMutation) SetDontseeit(i int) {
  684. m.dontseeit = &i
  685. m.adddontseeit = nil
  686. }
  687. // Dontseeit returns the value of the "dontseeit" field in the mutation.
  688. func (m *ContactMutation) Dontseeit() (r int, exists bool) {
  689. v := m.dontseeit
  690. if v == nil {
  691. return
  692. }
  693. return *v, true
  694. }
  695. // OldDontseeit returns the old "dontseeit" field's value of the Contact entity.
  696. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  697. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  698. func (m *ContactMutation) OldDontseeit(ctx context.Context) (v int, err error) {
  699. if !m.op.Is(OpUpdateOne) {
  700. return v, errors.New("OldDontseeit is only allowed on UpdateOne operations")
  701. }
  702. if m.id == nil || m.oldValue == nil {
  703. return v, errors.New("OldDontseeit requires an ID field in the mutation")
  704. }
  705. oldValue, err := m.oldValue(ctx)
  706. if err != nil {
  707. return v, fmt.Errorf("querying old value for OldDontseeit: %w", err)
  708. }
  709. return oldValue.Dontseeit, nil
  710. }
  711. // AddDontseeit adds i to the "dontseeit" field.
  712. func (m *ContactMutation) AddDontseeit(i int) {
  713. if m.adddontseeit != nil {
  714. *m.adddontseeit += i
  715. } else {
  716. m.adddontseeit = &i
  717. }
  718. }
  719. // AddedDontseeit returns the value that was added to the "dontseeit" field in this mutation.
  720. func (m *ContactMutation) AddedDontseeit() (r int, exists bool) {
  721. v := m.adddontseeit
  722. if v == nil {
  723. return
  724. }
  725. return *v, true
  726. }
  727. // ResetDontseeit resets all changes to the "dontseeit" field.
  728. func (m *ContactMutation) ResetDontseeit() {
  729. m.dontseeit = nil
  730. m.adddontseeit = nil
  731. }
  732. // SetDontseeme sets the "dontseeme" field.
  733. func (m *ContactMutation) SetDontseeme(i int) {
  734. m.dontseeme = &i
  735. m.adddontseeme = nil
  736. }
  737. // Dontseeme returns the value of the "dontseeme" field in the mutation.
  738. func (m *ContactMutation) Dontseeme() (r int, exists bool) {
  739. v := m.dontseeme
  740. if v == nil {
  741. return
  742. }
  743. return *v, true
  744. }
  745. // OldDontseeme returns the old "dontseeme" field's value of the Contact entity.
  746. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  747. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  748. func (m *ContactMutation) OldDontseeme(ctx context.Context) (v int, err error) {
  749. if !m.op.Is(OpUpdateOne) {
  750. return v, errors.New("OldDontseeme is only allowed on UpdateOne operations")
  751. }
  752. if m.id == nil || m.oldValue == nil {
  753. return v, errors.New("OldDontseeme requires an ID field in the mutation")
  754. }
  755. oldValue, err := m.oldValue(ctx)
  756. if err != nil {
  757. return v, fmt.Errorf("querying old value for OldDontseeme: %w", err)
  758. }
  759. return oldValue.Dontseeme, nil
  760. }
  761. // AddDontseeme adds i to the "dontseeme" field.
  762. func (m *ContactMutation) AddDontseeme(i int) {
  763. if m.adddontseeme != nil {
  764. *m.adddontseeme += i
  765. } else {
  766. m.adddontseeme = &i
  767. }
  768. }
  769. // AddedDontseeme returns the value that was added to the "dontseeme" field in this mutation.
  770. func (m *ContactMutation) AddedDontseeme() (r int, exists bool) {
  771. v := m.adddontseeme
  772. if v == nil {
  773. return
  774. }
  775. return *v, true
  776. }
  777. // ResetDontseeme resets all changes to the "dontseeme" field.
  778. func (m *ContactMutation) ResetDontseeme() {
  779. m.dontseeme = nil
  780. m.adddontseeme = nil
  781. }
  782. // SetLag sets the "lag" field.
  783. func (m *ContactMutation) SetLag(s string) {
  784. m.lag = &s
  785. }
  786. // Lag returns the value of the "lag" field in the mutation.
  787. func (m *ContactMutation) Lag() (r string, exists bool) {
  788. v := m.lag
  789. if v == nil {
  790. return
  791. }
  792. return *v, true
  793. }
  794. // OldLag returns the old "lag" field's value of the Contact entity.
  795. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  796. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  797. func (m *ContactMutation) OldLag(ctx context.Context) (v string, err error) {
  798. if !m.op.Is(OpUpdateOne) {
  799. return v, errors.New("OldLag is only allowed on UpdateOne operations")
  800. }
  801. if m.id == nil || m.oldValue == nil {
  802. return v, errors.New("OldLag requires an ID field in the mutation")
  803. }
  804. oldValue, err := m.oldValue(ctx)
  805. if err != nil {
  806. return v, fmt.Errorf("querying old value for OldLag: %w", err)
  807. }
  808. return oldValue.Lag, nil
  809. }
  810. // ResetLag resets all changes to the "lag" field.
  811. func (m *ContactMutation) ResetLag() {
  812. m.lag = nil
  813. }
  814. // SetGid sets the "gid" field.
  815. func (m *ContactMutation) SetGid(s string) {
  816. m.gid = &s
  817. }
  818. // Gid returns the value of the "gid" field in the mutation.
  819. func (m *ContactMutation) Gid() (r string, exists bool) {
  820. v := m.gid
  821. if v == nil {
  822. return
  823. }
  824. return *v, true
  825. }
  826. // OldGid returns the old "gid" field's value of the Contact entity.
  827. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  828. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  829. func (m *ContactMutation) OldGid(ctx context.Context) (v string, err error) {
  830. if !m.op.Is(OpUpdateOne) {
  831. return v, errors.New("OldGid is only allowed on UpdateOne operations")
  832. }
  833. if m.id == nil || m.oldValue == nil {
  834. return v, errors.New("OldGid requires an ID field in the mutation")
  835. }
  836. oldValue, err := m.oldValue(ctx)
  837. if err != nil {
  838. return v, fmt.Errorf("querying old value for OldGid: %w", err)
  839. }
  840. return oldValue.Gid, nil
  841. }
  842. // ResetGid resets all changes to the "gid" field.
  843. func (m *ContactMutation) ResetGid() {
  844. m.gid = nil
  845. }
  846. // SetGname sets the "gname" field.
  847. func (m *ContactMutation) SetGname(s string) {
  848. m.gname = &s
  849. }
  850. // Gname returns the value of the "gname" field in the mutation.
  851. func (m *ContactMutation) Gname() (r string, exists bool) {
  852. v := m.gname
  853. if v == nil {
  854. return
  855. }
  856. return *v, true
  857. }
  858. // OldGname returns the old "gname" field's value of the Contact entity.
  859. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  860. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  861. func (m *ContactMutation) OldGname(ctx context.Context) (v string, err error) {
  862. if !m.op.Is(OpUpdateOne) {
  863. return v, errors.New("OldGname is only allowed on UpdateOne operations")
  864. }
  865. if m.id == nil || m.oldValue == nil {
  866. return v, errors.New("OldGname requires an ID field in the mutation")
  867. }
  868. oldValue, err := m.oldValue(ctx)
  869. if err != nil {
  870. return v, fmt.Errorf("querying old value for OldGname: %w", err)
  871. }
  872. return oldValue.Gname, nil
  873. }
  874. // ResetGname resets all changes to the "gname" field.
  875. func (m *ContactMutation) ResetGname() {
  876. m.gname = nil
  877. }
  878. // SetV3 sets the "v3" field.
  879. func (m *ContactMutation) SetV3(s string) {
  880. m.v3 = &s
  881. }
  882. // V3 returns the value of the "v3" field in the mutation.
  883. func (m *ContactMutation) V3() (r string, exists bool) {
  884. v := m.v3
  885. if v == nil {
  886. return
  887. }
  888. return *v, true
  889. }
  890. // OldV3 returns the old "v3" field's value of the Contact entity.
  891. // If the Contact object wasn't provided to the builder, the object is fetched from the database.
  892. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  893. func (m *ContactMutation) OldV3(ctx context.Context) (v string, err error) {
  894. if !m.op.Is(OpUpdateOne) {
  895. return v, errors.New("OldV3 is only allowed on UpdateOne operations")
  896. }
  897. if m.id == nil || m.oldValue == nil {
  898. return v, errors.New("OldV3 requires an ID field in the mutation")
  899. }
  900. oldValue, err := m.oldValue(ctx)
  901. if err != nil {
  902. return v, fmt.Errorf("querying old value for OldV3: %w", err)
  903. }
  904. return oldValue.V3, nil
  905. }
  906. // ResetV3 resets all changes to the "v3" field.
  907. func (m *ContactMutation) ResetV3() {
  908. m.v3 = nil
  909. }
  910. // AddContactRelationshipIDs adds the "contact_relationships" edge to the LabelRelationship entity by ids.
  911. func (m *ContactMutation) AddContactRelationshipIDs(ids ...uint64) {
  912. if m.contact_relationships == nil {
  913. m.contact_relationships = make(map[uint64]struct{})
  914. }
  915. for i := range ids {
  916. m.contact_relationships[ids[i]] = struct{}{}
  917. }
  918. }
  919. // ClearContactRelationships clears the "contact_relationships" edge to the LabelRelationship entity.
  920. func (m *ContactMutation) ClearContactRelationships() {
  921. m.clearedcontact_relationships = true
  922. }
  923. // ContactRelationshipsCleared reports if the "contact_relationships" edge to the LabelRelationship entity was cleared.
  924. func (m *ContactMutation) ContactRelationshipsCleared() bool {
  925. return m.clearedcontact_relationships
  926. }
  927. // RemoveContactRelationshipIDs removes the "contact_relationships" edge to the LabelRelationship entity by IDs.
  928. func (m *ContactMutation) RemoveContactRelationshipIDs(ids ...uint64) {
  929. if m.removedcontact_relationships == nil {
  930. m.removedcontact_relationships = make(map[uint64]struct{})
  931. }
  932. for i := range ids {
  933. delete(m.contact_relationships, ids[i])
  934. m.removedcontact_relationships[ids[i]] = struct{}{}
  935. }
  936. }
  937. // RemovedContactRelationships returns the removed IDs of the "contact_relationships" edge to the LabelRelationship entity.
  938. func (m *ContactMutation) RemovedContactRelationshipsIDs() (ids []uint64) {
  939. for id := range m.removedcontact_relationships {
  940. ids = append(ids, id)
  941. }
  942. return
  943. }
  944. // ContactRelationshipsIDs returns the "contact_relationships" edge IDs in the mutation.
  945. func (m *ContactMutation) ContactRelationshipsIDs() (ids []uint64) {
  946. for id := range m.contact_relationships {
  947. ids = append(ids, id)
  948. }
  949. return
  950. }
  951. // ResetContactRelationships resets all changes to the "contact_relationships" edge.
  952. func (m *ContactMutation) ResetContactRelationships() {
  953. m.contact_relationships = nil
  954. m.clearedcontact_relationships = false
  955. m.removedcontact_relationships = nil
  956. }
  957. // Where appends a list predicates to the ContactMutation builder.
  958. func (m *ContactMutation) Where(ps ...predicate.Contact) {
  959. m.predicates = append(m.predicates, ps...)
  960. }
  961. // WhereP appends storage-level predicates to the ContactMutation builder. Using this method,
  962. // users can use type-assertion to append predicates that do not depend on any generated package.
  963. func (m *ContactMutation) WhereP(ps ...func(*sql.Selector)) {
  964. p := make([]predicate.Contact, len(ps))
  965. for i := range ps {
  966. p[i] = ps[i]
  967. }
  968. m.Where(p...)
  969. }
  970. // Op returns the operation name.
  971. func (m *ContactMutation) Op() Op {
  972. return m.op
  973. }
  974. // SetOp allows setting the mutation operation.
  975. func (m *ContactMutation) SetOp(op Op) {
  976. m.op = op
  977. }
  978. // Type returns the node type of this mutation (Contact).
  979. func (m *ContactMutation) Type() string {
  980. return m.typ
  981. }
  982. // Fields returns all fields that were changed during this mutation. Note that in
  983. // order to get all numeric fields that were incremented/decremented, call
  984. // AddedFields().
  985. func (m *ContactMutation) Fields() []string {
  986. fields := make([]string, 0, 19)
  987. if m.created_at != nil {
  988. fields = append(fields, contact.FieldCreatedAt)
  989. }
  990. if m.updated_at != nil {
  991. fields = append(fields, contact.FieldUpdatedAt)
  992. }
  993. if m.status != nil {
  994. fields = append(fields, contact.FieldStatus)
  995. }
  996. if m.deleted_at != nil {
  997. fields = append(fields, contact.FieldDeletedAt)
  998. }
  999. if m.wx_wxid != nil {
  1000. fields = append(fields, contact.FieldWxWxid)
  1001. }
  1002. if m._type != nil {
  1003. fields = append(fields, contact.FieldType)
  1004. }
  1005. if m.wxid != nil {
  1006. fields = append(fields, contact.FieldWxid)
  1007. }
  1008. if m.account != nil {
  1009. fields = append(fields, contact.FieldAccount)
  1010. }
  1011. if m.nickname != nil {
  1012. fields = append(fields, contact.FieldNickname)
  1013. }
  1014. if m.markname != nil {
  1015. fields = append(fields, contact.FieldMarkname)
  1016. }
  1017. if m.headimg != nil {
  1018. fields = append(fields, contact.FieldHeadimg)
  1019. }
  1020. if m.sex != nil {
  1021. fields = append(fields, contact.FieldSex)
  1022. }
  1023. if m.starrole != nil {
  1024. fields = append(fields, contact.FieldStarrole)
  1025. }
  1026. if m.dontseeit != nil {
  1027. fields = append(fields, contact.FieldDontseeit)
  1028. }
  1029. if m.dontseeme != nil {
  1030. fields = append(fields, contact.FieldDontseeme)
  1031. }
  1032. if m.lag != nil {
  1033. fields = append(fields, contact.FieldLag)
  1034. }
  1035. if m.gid != nil {
  1036. fields = append(fields, contact.FieldGid)
  1037. }
  1038. if m.gname != nil {
  1039. fields = append(fields, contact.FieldGname)
  1040. }
  1041. if m.v3 != nil {
  1042. fields = append(fields, contact.FieldV3)
  1043. }
  1044. return fields
  1045. }
  1046. // Field returns the value of a field with the given name. The second boolean
  1047. // return value indicates that this field was not set, or was not defined in the
  1048. // schema.
  1049. func (m *ContactMutation) Field(name string) (ent.Value, bool) {
  1050. switch name {
  1051. case contact.FieldCreatedAt:
  1052. return m.CreatedAt()
  1053. case contact.FieldUpdatedAt:
  1054. return m.UpdatedAt()
  1055. case contact.FieldStatus:
  1056. return m.Status()
  1057. case contact.FieldDeletedAt:
  1058. return m.DeletedAt()
  1059. case contact.FieldWxWxid:
  1060. return m.WxWxid()
  1061. case contact.FieldType:
  1062. return m.GetType()
  1063. case contact.FieldWxid:
  1064. return m.Wxid()
  1065. case contact.FieldAccount:
  1066. return m.Account()
  1067. case contact.FieldNickname:
  1068. return m.Nickname()
  1069. case contact.FieldMarkname:
  1070. return m.Markname()
  1071. case contact.FieldHeadimg:
  1072. return m.Headimg()
  1073. case contact.FieldSex:
  1074. return m.Sex()
  1075. case contact.FieldStarrole:
  1076. return m.Starrole()
  1077. case contact.FieldDontseeit:
  1078. return m.Dontseeit()
  1079. case contact.FieldDontseeme:
  1080. return m.Dontseeme()
  1081. case contact.FieldLag:
  1082. return m.Lag()
  1083. case contact.FieldGid:
  1084. return m.Gid()
  1085. case contact.FieldGname:
  1086. return m.Gname()
  1087. case contact.FieldV3:
  1088. return m.V3()
  1089. }
  1090. return nil, false
  1091. }
  1092. // OldField returns the old value of the field from the database. An error is
  1093. // returned if the mutation operation is not UpdateOne, or the query to the
  1094. // database failed.
  1095. func (m *ContactMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  1096. switch name {
  1097. case contact.FieldCreatedAt:
  1098. return m.OldCreatedAt(ctx)
  1099. case contact.FieldUpdatedAt:
  1100. return m.OldUpdatedAt(ctx)
  1101. case contact.FieldStatus:
  1102. return m.OldStatus(ctx)
  1103. case contact.FieldDeletedAt:
  1104. return m.OldDeletedAt(ctx)
  1105. case contact.FieldWxWxid:
  1106. return m.OldWxWxid(ctx)
  1107. case contact.FieldType:
  1108. return m.OldType(ctx)
  1109. case contact.FieldWxid:
  1110. return m.OldWxid(ctx)
  1111. case contact.FieldAccount:
  1112. return m.OldAccount(ctx)
  1113. case contact.FieldNickname:
  1114. return m.OldNickname(ctx)
  1115. case contact.FieldMarkname:
  1116. return m.OldMarkname(ctx)
  1117. case contact.FieldHeadimg:
  1118. return m.OldHeadimg(ctx)
  1119. case contact.FieldSex:
  1120. return m.OldSex(ctx)
  1121. case contact.FieldStarrole:
  1122. return m.OldStarrole(ctx)
  1123. case contact.FieldDontseeit:
  1124. return m.OldDontseeit(ctx)
  1125. case contact.FieldDontseeme:
  1126. return m.OldDontseeme(ctx)
  1127. case contact.FieldLag:
  1128. return m.OldLag(ctx)
  1129. case contact.FieldGid:
  1130. return m.OldGid(ctx)
  1131. case contact.FieldGname:
  1132. return m.OldGname(ctx)
  1133. case contact.FieldV3:
  1134. return m.OldV3(ctx)
  1135. }
  1136. return nil, fmt.Errorf("unknown Contact field %s", name)
  1137. }
  1138. // SetField sets the value of a field with the given name. It returns an error if
  1139. // the field is not defined in the schema, or if the type mismatched the field
  1140. // type.
  1141. func (m *ContactMutation) SetField(name string, value ent.Value) error {
  1142. switch name {
  1143. case contact.FieldCreatedAt:
  1144. v, ok := value.(time.Time)
  1145. if !ok {
  1146. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1147. }
  1148. m.SetCreatedAt(v)
  1149. return nil
  1150. case contact.FieldUpdatedAt:
  1151. v, ok := value.(time.Time)
  1152. if !ok {
  1153. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1154. }
  1155. m.SetUpdatedAt(v)
  1156. return nil
  1157. case contact.FieldStatus:
  1158. v, ok := value.(uint8)
  1159. if !ok {
  1160. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1161. }
  1162. m.SetStatus(v)
  1163. return nil
  1164. case contact.FieldDeletedAt:
  1165. v, ok := value.(time.Time)
  1166. if !ok {
  1167. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1168. }
  1169. m.SetDeletedAt(v)
  1170. return nil
  1171. case contact.FieldWxWxid:
  1172. v, ok := value.(string)
  1173. if !ok {
  1174. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1175. }
  1176. m.SetWxWxid(v)
  1177. return nil
  1178. case contact.FieldType:
  1179. v, ok := value.(int)
  1180. if !ok {
  1181. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1182. }
  1183. m.SetType(v)
  1184. return nil
  1185. case contact.FieldWxid:
  1186. v, ok := value.(string)
  1187. if !ok {
  1188. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1189. }
  1190. m.SetWxid(v)
  1191. return nil
  1192. case contact.FieldAccount:
  1193. v, ok := value.(string)
  1194. if !ok {
  1195. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1196. }
  1197. m.SetAccount(v)
  1198. return nil
  1199. case contact.FieldNickname:
  1200. v, ok := value.(string)
  1201. if !ok {
  1202. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1203. }
  1204. m.SetNickname(v)
  1205. return nil
  1206. case contact.FieldMarkname:
  1207. v, ok := value.(string)
  1208. if !ok {
  1209. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1210. }
  1211. m.SetMarkname(v)
  1212. return nil
  1213. case contact.FieldHeadimg:
  1214. v, ok := value.(string)
  1215. if !ok {
  1216. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1217. }
  1218. m.SetHeadimg(v)
  1219. return nil
  1220. case contact.FieldSex:
  1221. v, ok := value.(int)
  1222. if !ok {
  1223. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1224. }
  1225. m.SetSex(v)
  1226. return nil
  1227. case contact.FieldStarrole:
  1228. v, ok := value.(string)
  1229. if !ok {
  1230. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1231. }
  1232. m.SetStarrole(v)
  1233. return nil
  1234. case contact.FieldDontseeit:
  1235. v, ok := value.(int)
  1236. if !ok {
  1237. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1238. }
  1239. m.SetDontseeit(v)
  1240. return nil
  1241. case contact.FieldDontseeme:
  1242. v, ok := value.(int)
  1243. if !ok {
  1244. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1245. }
  1246. m.SetDontseeme(v)
  1247. return nil
  1248. case contact.FieldLag:
  1249. v, ok := value.(string)
  1250. if !ok {
  1251. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1252. }
  1253. m.SetLag(v)
  1254. return nil
  1255. case contact.FieldGid:
  1256. v, ok := value.(string)
  1257. if !ok {
  1258. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1259. }
  1260. m.SetGid(v)
  1261. return nil
  1262. case contact.FieldGname:
  1263. v, ok := value.(string)
  1264. if !ok {
  1265. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1266. }
  1267. m.SetGname(v)
  1268. return nil
  1269. case contact.FieldV3:
  1270. v, ok := value.(string)
  1271. if !ok {
  1272. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1273. }
  1274. m.SetV3(v)
  1275. return nil
  1276. }
  1277. return fmt.Errorf("unknown Contact field %s", name)
  1278. }
  1279. // AddedFields returns all numeric fields that were incremented/decremented during
  1280. // this mutation.
  1281. func (m *ContactMutation) AddedFields() []string {
  1282. var fields []string
  1283. if m.addstatus != nil {
  1284. fields = append(fields, contact.FieldStatus)
  1285. }
  1286. if m.add_type != nil {
  1287. fields = append(fields, contact.FieldType)
  1288. }
  1289. if m.addsex != nil {
  1290. fields = append(fields, contact.FieldSex)
  1291. }
  1292. if m.adddontseeit != nil {
  1293. fields = append(fields, contact.FieldDontseeit)
  1294. }
  1295. if m.adddontseeme != nil {
  1296. fields = append(fields, contact.FieldDontseeme)
  1297. }
  1298. return fields
  1299. }
  1300. // AddedField returns the numeric value that was incremented/decremented on a field
  1301. // with the given name. The second boolean return value indicates that this field
  1302. // was not set, or was not defined in the schema.
  1303. func (m *ContactMutation) AddedField(name string) (ent.Value, bool) {
  1304. switch name {
  1305. case contact.FieldStatus:
  1306. return m.AddedStatus()
  1307. case contact.FieldType:
  1308. return m.AddedType()
  1309. case contact.FieldSex:
  1310. return m.AddedSex()
  1311. case contact.FieldDontseeit:
  1312. return m.AddedDontseeit()
  1313. case contact.FieldDontseeme:
  1314. return m.AddedDontseeme()
  1315. }
  1316. return nil, false
  1317. }
  1318. // AddField adds the value to the field with the given name. It returns an error if
  1319. // the field is not defined in the schema, or if the type mismatched the field
  1320. // type.
  1321. func (m *ContactMutation) AddField(name string, value ent.Value) error {
  1322. switch name {
  1323. case contact.FieldStatus:
  1324. v, ok := value.(int8)
  1325. if !ok {
  1326. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1327. }
  1328. m.AddStatus(v)
  1329. return nil
  1330. case contact.FieldType:
  1331. v, ok := value.(int)
  1332. if !ok {
  1333. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1334. }
  1335. m.AddType(v)
  1336. return nil
  1337. case contact.FieldSex:
  1338. v, ok := value.(int)
  1339. if !ok {
  1340. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1341. }
  1342. m.AddSex(v)
  1343. return nil
  1344. case contact.FieldDontseeit:
  1345. v, ok := value.(int)
  1346. if !ok {
  1347. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1348. }
  1349. m.AddDontseeit(v)
  1350. return nil
  1351. case contact.FieldDontseeme:
  1352. v, ok := value.(int)
  1353. if !ok {
  1354. return fmt.Errorf("unexpected type %T for field %s", value, name)
  1355. }
  1356. m.AddDontseeme(v)
  1357. return nil
  1358. }
  1359. return fmt.Errorf("unknown Contact numeric field %s", name)
  1360. }
  1361. // ClearedFields returns all nullable fields that were cleared during this
  1362. // mutation.
  1363. func (m *ContactMutation) ClearedFields() []string {
  1364. var fields []string
  1365. if m.FieldCleared(contact.FieldStatus) {
  1366. fields = append(fields, contact.FieldStatus)
  1367. }
  1368. if m.FieldCleared(contact.FieldDeletedAt) {
  1369. fields = append(fields, contact.FieldDeletedAt)
  1370. }
  1371. if m.FieldCleared(contact.FieldWxWxid) {
  1372. fields = append(fields, contact.FieldWxWxid)
  1373. }
  1374. if m.FieldCleared(contact.FieldType) {
  1375. fields = append(fields, contact.FieldType)
  1376. }
  1377. return fields
  1378. }
  1379. // FieldCleared returns a boolean indicating if a field with the given name was
  1380. // cleared in this mutation.
  1381. func (m *ContactMutation) FieldCleared(name string) bool {
  1382. _, ok := m.clearedFields[name]
  1383. return ok
  1384. }
  1385. // ClearField clears the value of the field with the given name. It returns an
  1386. // error if the field is not defined in the schema.
  1387. func (m *ContactMutation) ClearField(name string) error {
  1388. switch name {
  1389. case contact.FieldStatus:
  1390. m.ClearStatus()
  1391. return nil
  1392. case contact.FieldDeletedAt:
  1393. m.ClearDeletedAt()
  1394. return nil
  1395. case contact.FieldWxWxid:
  1396. m.ClearWxWxid()
  1397. return nil
  1398. case contact.FieldType:
  1399. m.ClearType()
  1400. return nil
  1401. }
  1402. return fmt.Errorf("unknown Contact nullable field %s", name)
  1403. }
  1404. // ResetField resets all changes in the mutation for the field with the given name.
  1405. // It returns an error if the field is not defined in the schema.
  1406. func (m *ContactMutation) ResetField(name string) error {
  1407. switch name {
  1408. case contact.FieldCreatedAt:
  1409. m.ResetCreatedAt()
  1410. return nil
  1411. case contact.FieldUpdatedAt:
  1412. m.ResetUpdatedAt()
  1413. return nil
  1414. case contact.FieldStatus:
  1415. m.ResetStatus()
  1416. return nil
  1417. case contact.FieldDeletedAt:
  1418. m.ResetDeletedAt()
  1419. return nil
  1420. case contact.FieldWxWxid:
  1421. m.ResetWxWxid()
  1422. return nil
  1423. case contact.FieldType:
  1424. m.ResetType()
  1425. return nil
  1426. case contact.FieldWxid:
  1427. m.ResetWxid()
  1428. return nil
  1429. case contact.FieldAccount:
  1430. m.ResetAccount()
  1431. return nil
  1432. case contact.FieldNickname:
  1433. m.ResetNickname()
  1434. return nil
  1435. case contact.FieldMarkname:
  1436. m.ResetMarkname()
  1437. return nil
  1438. case contact.FieldHeadimg:
  1439. m.ResetHeadimg()
  1440. return nil
  1441. case contact.FieldSex:
  1442. m.ResetSex()
  1443. return nil
  1444. case contact.FieldStarrole:
  1445. m.ResetStarrole()
  1446. return nil
  1447. case contact.FieldDontseeit:
  1448. m.ResetDontseeit()
  1449. return nil
  1450. case contact.FieldDontseeme:
  1451. m.ResetDontseeme()
  1452. return nil
  1453. case contact.FieldLag:
  1454. m.ResetLag()
  1455. return nil
  1456. case contact.FieldGid:
  1457. m.ResetGid()
  1458. return nil
  1459. case contact.FieldGname:
  1460. m.ResetGname()
  1461. return nil
  1462. case contact.FieldV3:
  1463. m.ResetV3()
  1464. return nil
  1465. }
  1466. return fmt.Errorf("unknown Contact field %s", name)
  1467. }
  1468. // AddedEdges returns all edge names that were set/added in this mutation.
  1469. func (m *ContactMutation) AddedEdges() []string {
  1470. edges := make([]string, 0, 1)
  1471. if m.contact_relationships != nil {
  1472. edges = append(edges, contact.EdgeContactRelationships)
  1473. }
  1474. return edges
  1475. }
  1476. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  1477. // name in this mutation.
  1478. func (m *ContactMutation) AddedIDs(name string) []ent.Value {
  1479. switch name {
  1480. case contact.EdgeContactRelationships:
  1481. ids := make([]ent.Value, 0, len(m.contact_relationships))
  1482. for id := range m.contact_relationships {
  1483. ids = append(ids, id)
  1484. }
  1485. return ids
  1486. }
  1487. return nil
  1488. }
  1489. // RemovedEdges returns all edge names that were removed in this mutation.
  1490. func (m *ContactMutation) RemovedEdges() []string {
  1491. edges := make([]string, 0, 1)
  1492. if m.removedcontact_relationships != nil {
  1493. edges = append(edges, contact.EdgeContactRelationships)
  1494. }
  1495. return edges
  1496. }
  1497. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  1498. // the given name in this mutation.
  1499. func (m *ContactMutation) RemovedIDs(name string) []ent.Value {
  1500. switch name {
  1501. case contact.EdgeContactRelationships:
  1502. ids := make([]ent.Value, 0, len(m.removedcontact_relationships))
  1503. for id := range m.removedcontact_relationships {
  1504. ids = append(ids, id)
  1505. }
  1506. return ids
  1507. }
  1508. return nil
  1509. }
  1510. // ClearedEdges returns all edge names that were cleared in this mutation.
  1511. func (m *ContactMutation) ClearedEdges() []string {
  1512. edges := make([]string, 0, 1)
  1513. if m.clearedcontact_relationships {
  1514. edges = append(edges, contact.EdgeContactRelationships)
  1515. }
  1516. return edges
  1517. }
  1518. // EdgeCleared returns a boolean which indicates if the edge with the given name
  1519. // was cleared in this mutation.
  1520. func (m *ContactMutation) EdgeCleared(name string) bool {
  1521. switch name {
  1522. case contact.EdgeContactRelationships:
  1523. return m.clearedcontact_relationships
  1524. }
  1525. return false
  1526. }
  1527. // ClearEdge clears the value of the edge with the given name. It returns an error
  1528. // if that edge is not defined in the schema.
  1529. func (m *ContactMutation) ClearEdge(name string) error {
  1530. switch name {
  1531. }
  1532. return fmt.Errorf("unknown Contact unique edge %s", name)
  1533. }
  1534. // ResetEdge resets all changes to the edge with the given name in this mutation.
  1535. // It returns an error if the edge is not defined in the schema.
  1536. func (m *ContactMutation) ResetEdge(name string) error {
  1537. switch name {
  1538. case contact.EdgeContactRelationships:
  1539. m.ResetContactRelationships()
  1540. return nil
  1541. }
  1542. return fmt.Errorf("unknown Contact edge %s", name)
  1543. }
  1544. // LabelMutation represents an operation that mutates the Label nodes in the graph.
  1545. type LabelMutation struct {
  1546. config
  1547. op Op
  1548. typ string
  1549. id *uint64
  1550. created_at *time.Time
  1551. updated_at *time.Time
  1552. status *uint8
  1553. addstatus *int8
  1554. deleted_at *time.Time
  1555. _type *int
  1556. add_type *int
  1557. name *string
  1558. from *int
  1559. addfrom *int
  1560. mode *int
  1561. addmode *int
  1562. conditions *string
  1563. clearedFields map[string]struct{}
  1564. label_relationships map[uint64]struct{}
  1565. removedlabel_relationships map[uint64]struct{}
  1566. clearedlabel_relationships bool
  1567. done bool
  1568. oldValue func(context.Context) (*Label, error)
  1569. predicates []predicate.Label
  1570. }
  1571. var _ ent.Mutation = (*LabelMutation)(nil)
  1572. // labelOption allows management of the mutation configuration using functional options.
  1573. type labelOption func(*LabelMutation)
  1574. // newLabelMutation creates new mutation for the Label entity.
  1575. func newLabelMutation(c config, op Op, opts ...labelOption) *LabelMutation {
  1576. m := &LabelMutation{
  1577. config: c,
  1578. op: op,
  1579. typ: TypeLabel,
  1580. clearedFields: make(map[string]struct{}),
  1581. }
  1582. for _, opt := range opts {
  1583. opt(m)
  1584. }
  1585. return m
  1586. }
  1587. // withLabelID sets the ID field of the mutation.
  1588. func withLabelID(id uint64) labelOption {
  1589. return func(m *LabelMutation) {
  1590. var (
  1591. err error
  1592. once sync.Once
  1593. value *Label
  1594. )
  1595. m.oldValue = func(ctx context.Context) (*Label, error) {
  1596. once.Do(func() {
  1597. if m.done {
  1598. err = errors.New("querying old values post mutation is not allowed")
  1599. } else {
  1600. value, err = m.Client().Label.Get(ctx, id)
  1601. }
  1602. })
  1603. return value, err
  1604. }
  1605. m.id = &id
  1606. }
  1607. }
  1608. // withLabel sets the old Label of the mutation.
  1609. func withLabel(node *Label) labelOption {
  1610. return func(m *LabelMutation) {
  1611. m.oldValue = func(context.Context) (*Label, error) {
  1612. return node, nil
  1613. }
  1614. m.id = &node.ID
  1615. }
  1616. }
  1617. // Client returns a new `ent.Client` from the mutation. If the mutation was
  1618. // executed in a transaction (ent.Tx), a transactional client is returned.
  1619. func (m LabelMutation) Client() *Client {
  1620. client := &Client{config: m.config}
  1621. client.init()
  1622. return client
  1623. }
  1624. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  1625. // it returns an error otherwise.
  1626. func (m LabelMutation) Tx() (*Tx, error) {
  1627. if _, ok := m.driver.(*txDriver); !ok {
  1628. return nil, errors.New("ent: mutation is not running in a transaction")
  1629. }
  1630. tx := &Tx{config: m.config}
  1631. tx.init()
  1632. return tx, nil
  1633. }
  1634. // SetID sets the value of the id field. Note that this
  1635. // operation is only accepted on creation of Label entities.
  1636. func (m *LabelMutation) SetID(id uint64) {
  1637. m.id = &id
  1638. }
  1639. // ID returns the ID value in the mutation. Note that the ID is only available
  1640. // if it was provided to the builder or after it was returned from the database.
  1641. func (m *LabelMutation) ID() (id uint64, exists bool) {
  1642. if m.id == nil {
  1643. return
  1644. }
  1645. return *m.id, true
  1646. }
  1647. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  1648. // That means, if the mutation is applied within a transaction with an isolation level such
  1649. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  1650. // or updated by the mutation.
  1651. func (m *LabelMutation) IDs(ctx context.Context) ([]uint64, error) {
  1652. switch {
  1653. case m.op.Is(OpUpdateOne | OpDeleteOne):
  1654. id, exists := m.ID()
  1655. if exists {
  1656. return []uint64{id}, nil
  1657. }
  1658. fallthrough
  1659. case m.op.Is(OpUpdate | OpDelete):
  1660. return m.Client().Label.Query().Where(m.predicates...).IDs(ctx)
  1661. default:
  1662. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  1663. }
  1664. }
  1665. // SetCreatedAt sets the "created_at" field.
  1666. func (m *LabelMutation) SetCreatedAt(t time.Time) {
  1667. m.created_at = &t
  1668. }
  1669. // CreatedAt returns the value of the "created_at" field in the mutation.
  1670. func (m *LabelMutation) CreatedAt() (r time.Time, exists bool) {
  1671. v := m.created_at
  1672. if v == nil {
  1673. return
  1674. }
  1675. return *v, true
  1676. }
  1677. // OldCreatedAt returns the old "created_at" field's value of the Label entity.
  1678. // If the Label object wasn't provided to the builder, the object is fetched from the database.
  1679. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1680. func (m *LabelMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  1681. if !m.op.Is(OpUpdateOne) {
  1682. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  1683. }
  1684. if m.id == nil || m.oldValue == nil {
  1685. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  1686. }
  1687. oldValue, err := m.oldValue(ctx)
  1688. if err != nil {
  1689. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  1690. }
  1691. return oldValue.CreatedAt, nil
  1692. }
  1693. // ResetCreatedAt resets all changes to the "created_at" field.
  1694. func (m *LabelMutation) ResetCreatedAt() {
  1695. m.created_at = nil
  1696. }
  1697. // SetUpdatedAt sets the "updated_at" field.
  1698. func (m *LabelMutation) SetUpdatedAt(t time.Time) {
  1699. m.updated_at = &t
  1700. }
  1701. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  1702. func (m *LabelMutation) UpdatedAt() (r time.Time, exists bool) {
  1703. v := m.updated_at
  1704. if v == nil {
  1705. return
  1706. }
  1707. return *v, true
  1708. }
  1709. // OldUpdatedAt returns the old "updated_at" field's value of the Label entity.
  1710. // If the Label object wasn't provided to the builder, the object is fetched from the database.
  1711. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1712. func (m *LabelMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  1713. if !m.op.Is(OpUpdateOne) {
  1714. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  1715. }
  1716. if m.id == nil || m.oldValue == nil {
  1717. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  1718. }
  1719. oldValue, err := m.oldValue(ctx)
  1720. if err != nil {
  1721. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  1722. }
  1723. return oldValue.UpdatedAt, nil
  1724. }
  1725. // ResetUpdatedAt resets all changes to the "updated_at" field.
  1726. func (m *LabelMutation) ResetUpdatedAt() {
  1727. m.updated_at = nil
  1728. }
  1729. // SetStatus sets the "status" field.
  1730. func (m *LabelMutation) SetStatus(u uint8) {
  1731. m.status = &u
  1732. m.addstatus = nil
  1733. }
  1734. // Status returns the value of the "status" field in the mutation.
  1735. func (m *LabelMutation) Status() (r uint8, exists bool) {
  1736. v := m.status
  1737. if v == nil {
  1738. return
  1739. }
  1740. return *v, true
  1741. }
  1742. // OldStatus returns the old "status" field's value of the Label entity.
  1743. // If the Label object wasn't provided to the builder, the object is fetched from the database.
  1744. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1745. func (m *LabelMutation) OldStatus(ctx context.Context) (v uint8, err error) {
  1746. if !m.op.Is(OpUpdateOne) {
  1747. return v, errors.New("OldStatus is only allowed on UpdateOne operations")
  1748. }
  1749. if m.id == nil || m.oldValue == nil {
  1750. return v, errors.New("OldStatus requires an ID field in the mutation")
  1751. }
  1752. oldValue, err := m.oldValue(ctx)
  1753. if err != nil {
  1754. return v, fmt.Errorf("querying old value for OldStatus: %w", err)
  1755. }
  1756. return oldValue.Status, nil
  1757. }
  1758. // AddStatus adds u to the "status" field.
  1759. func (m *LabelMutation) AddStatus(u int8) {
  1760. if m.addstatus != nil {
  1761. *m.addstatus += u
  1762. } else {
  1763. m.addstatus = &u
  1764. }
  1765. }
  1766. // AddedStatus returns the value that was added to the "status" field in this mutation.
  1767. func (m *LabelMutation) AddedStatus() (r int8, exists bool) {
  1768. v := m.addstatus
  1769. if v == nil {
  1770. return
  1771. }
  1772. return *v, true
  1773. }
  1774. // ClearStatus clears the value of the "status" field.
  1775. func (m *LabelMutation) ClearStatus() {
  1776. m.status = nil
  1777. m.addstatus = nil
  1778. m.clearedFields[label.FieldStatus] = struct{}{}
  1779. }
  1780. // StatusCleared returns if the "status" field was cleared in this mutation.
  1781. func (m *LabelMutation) StatusCleared() bool {
  1782. _, ok := m.clearedFields[label.FieldStatus]
  1783. return ok
  1784. }
  1785. // ResetStatus resets all changes to the "status" field.
  1786. func (m *LabelMutation) ResetStatus() {
  1787. m.status = nil
  1788. m.addstatus = nil
  1789. delete(m.clearedFields, label.FieldStatus)
  1790. }
  1791. // SetDeletedAt sets the "deleted_at" field.
  1792. func (m *LabelMutation) SetDeletedAt(t time.Time) {
  1793. m.deleted_at = &t
  1794. }
  1795. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  1796. func (m *LabelMutation) DeletedAt() (r time.Time, exists bool) {
  1797. v := m.deleted_at
  1798. if v == nil {
  1799. return
  1800. }
  1801. return *v, true
  1802. }
  1803. // OldDeletedAt returns the old "deleted_at" field's value of the Label entity.
  1804. // If the Label object wasn't provided to the builder, the object is fetched from the database.
  1805. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1806. func (m *LabelMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  1807. if !m.op.Is(OpUpdateOne) {
  1808. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  1809. }
  1810. if m.id == nil || m.oldValue == nil {
  1811. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  1812. }
  1813. oldValue, err := m.oldValue(ctx)
  1814. if err != nil {
  1815. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  1816. }
  1817. return oldValue.DeletedAt, nil
  1818. }
  1819. // ClearDeletedAt clears the value of the "deleted_at" field.
  1820. func (m *LabelMutation) ClearDeletedAt() {
  1821. m.deleted_at = nil
  1822. m.clearedFields[label.FieldDeletedAt] = struct{}{}
  1823. }
  1824. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  1825. func (m *LabelMutation) DeletedAtCleared() bool {
  1826. _, ok := m.clearedFields[label.FieldDeletedAt]
  1827. return ok
  1828. }
  1829. // ResetDeletedAt resets all changes to the "deleted_at" field.
  1830. func (m *LabelMutation) ResetDeletedAt() {
  1831. m.deleted_at = nil
  1832. delete(m.clearedFields, label.FieldDeletedAt)
  1833. }
  1834. // SetType sets the "type" field.
  1835. func (m *LabelMutation) SetType(i int) {
  1836. m._type = &i
  1837. m.add_type = nil
  1838. }
  1839. // GetType returns the value of the "type" field in the mutation.
  1840. func (m *LabelMutation) GetType() (r int, exists bool) {
  1841. v := m._type
  1842. if v == nil {
  1843. return
  1844. }
  1845. return *v, true
  1846. }
  1847. // OldType returns the old "type" field's value of the Label entity.
  1848. // If the Label object wasn't provided to the builder, the object is fetched from the database.
  1849. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1850. func (m *LabelMutation) OldType(ctx context.Context) (v int, err error) {
  1851. if !m.op.Is(OpUpdateOne) {
  1852. return v, errors.New("OldType is only allowed on UpdateOne operations")
  1853. }
  1854. if m.id == nil || m.oldValue == nil {
  1855. return v, errors.New("OldType requires an ID field in the mutation")
  1856. }
  1857. oldValue, err := m.oldValue(ctx)
  1858. if err != nil {
  1859. return v, fmt.Errorf("querying old value for OldType: %w", err)
  1860. }
  1861. return oldValue.Type, nil
  1862. }
  1863. // AddType adds i to the "type" field.
  1864. func (m *LabelMutation) AddType(i int) {
  1865. if m.add_type != nil {
  1866. *m.add_type += i
  1867. } else {
  1868. m.add_type = &i
  1869. }
  1870. }
  1871. // AddedType returns the value that was added to the "type" field in this mutation.
  1872. func (m *LabelMutation) AddedType() (r int, exists bool) {
  1873. v := m.add_type
  1874. if v == nil {
  1875. return
  1876. }
  1877. return *v, true
  1878. }
  1879. // ResetType resets all changes to the "type" field.
  1880. func (m *LabelMutation) ResetType() {
  1881. m._type = nil
  1882. m.add_type = nil
  1883. }
  1884. // SetName sets the "name" field.
  1885. func (m *LabelMutation) SetName(s string) {
  1886. m.name = &s
  1887. }
  1888. // Name returns the value of the "name" field in the mutation.
  1889. func (m *LabelMutation) Name() (r string, exists bool) {
  1890. v := m.name
  1891. if v == nil {
  1892. return
  1893. }
  1894. return *v, true
  1895. }
  1896. // OldName returns the old "name" field's value of the Label entity.
  1897. // If the Label object wasn't provided to the builder, the object is fetched from the database.
  1898. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1899. func (m *LabelMutation) OldName(ctx context.Context) (v string, err error) {
  1900. if !m.op.Is(OpUpdateOne) {
  1901. return v, errors.New("OldName is only allowed on UpdateOne operations")
  1902. }
  1903. if m.id == nil || m.oldValue == nil {
  1904. return v, errors.New("OldName requires an ID field in the mutation")
  1905. }
  1906. oldValue, err := m.oldValue(ctx)
  1907. if err != nil {
  1908. return v, fmt.Errorf("querying old value for OldName: %w", err)
  1909. }
  1910. return oldValue.Name, nil
  1911. }
  1912. // ResetName resets all changes to the "name" field.
  1913. func (m *LabelMutation) ResetName() {
  1914. m.name = nil
  1915. }
  1916. // SetFrom sets the "from" field.
  1917. func (m *LabelMutation) SetFrom(i int) {
  1918. m.from = &i
  1919. m.addfrom = nil
  1920. }
  1921. // From returns the value of the "from" field in the mutation.
  1922. func (m *LabelMutation) From() (r int, exists bool) {
  1923. v := m.from
  1924. if v == nil {
  1925. return
  1926. }
  1927. return *v, true
  1928. }
  1929. // OldFrom returns the old "from" field's value of the Label entity.
  1930. // If the Label object wasn't provided to the builder, the object is fetched from the database.
  1931. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1932. func (m *LabelMutation) OldFrom(ctx context.Context) (v int, err error) {
  1933. if !m.op.Is(OpUpdateOne) {
  1934. return v, errors.New("OldFrom is only allowed on UpdateOne operations")
  1935. }
  1936. if m.id == nil || m.oldValue == nil {
  1937. return v, errors.New("OldFrom requires an ID field in the mutation")
  1938. }
  1939. oldValue, err := m.oldValue(ctx)
  1940. if err != nil {
  1941. return v, fmt.Errorf("querying old value for OldFrom: %w", err)
  1942. }
  1943. return oldValue.From, nil
  1944. }
  1945. // AddFrom adds i to the "from" field.
  1946. func (m *LabelMutation) AddFrom(i int) {
  1947. if m.addfrom != nil {
  1948. *m.addfrom += i
  1949. } else {
  1950. m.addfrom = &i
  1951. }
  1952. }
  1953. // AddedFrom returns the value that was added to the "from" field in this mutation.
  1954. func (m *LabelMutation) AddedFrom() (r int, exists bool) {
  1955. v := m.addfrom
  1956. if v == nil {
  1957. return
  1958. }
  1959. return *v, true
  1960. }
  1961. // ResetFrom resets all changes to the "from" field.
  1962. func (m *LabelMutation) ResetFrom() {
  1963. m.from = nil
  1964. m.addfrom = nil
  1965. }
  1966. // SetMode sets the "mode" field.
  1967. func (m *LabelMutation) SetMode(i int) {
  1968. m.mode = &i
  1969. m.addmode = nil
  1970. }
  1971. // Mode returns the value of the "mode" field in the mutation.
  1972. func (m *LabelMutation) Mode() (r int, exists bool) {
  1973. v := m.mode
  1974. if v == nil {
  1975. return
  1976. }
  1977. return *v, true
  1978. }
  1979. // OldMode returns the old "mode" field's value of the Label entity.
  1980. // If the Label object wasn't provided to the builder, the object is fetched from the database.
  1981. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1982. func (m *LabelMutation) OldMode(ctx context.Context) (v int, err error) {
  1983. if !m.op.Is(OpUpdateOne) {
  1984. return v, errors.New("OldMode is only allowed on UpdateOne operations")
  1985. }
  1986. if m.id == nil || m.oldValue == nil {
  1987. return v, errors.New("OldMode requires an ID field in the mutation")
  1988. }
  1989. oldValue, err := m.oldValue(ctx)
  1990. if err != nil {
  1991. return v, fmt.Errorf("querying old value for OldMode: %w", err)
  1992. }
  1993. return oldValue.Mode, nil
  1994. }
  1995. // AddMode adds i to the "mode" field.
  1996. func (m *LabelMutation) AddMode(i int) {
  1997. if m.addmode != nil {
  1998. *m.addmode += i
  1999. } else {
  2000. m.addmode = &i
  2001. }
  2002. }
  2003. // AddedMode returns the value that was added to the "mode" field in this mutation.
  2004. func (m *LabelMutation) AddedMode() (r int, exists bool) {
  2005. v := m.addmode
  2006. if v == nil {
  2007. return
  2008. }
  2009. return *v, true
  2010. }
  2011. // ResetMode resets all changes to the "mode" field.
  2012. func (m *LabelMutation) ResetMode() {
  2013. m.mode = nil
  2014. m.addmode = nil
  2015. }
  2016. // SetConditions sets the "conditions" field.
  2017. func (m *LabelMutation) SetConditions(s string) {
  2018. m.conditions = &s
  2019. }
  2020. // Conditions returns the value of the "conditions" field in the mutation.
  2021. func (m *LabelMutation) Conditions() (r string, exists bool) {
  2022. v := m.conditions
  2023. if v == nil {
  2024. return
  2025. }
  2026. return *v, true
  2027. }
  2028. // OldConditions returns the old "conditions" field's value of the Label entity.
  2029. // If the Label object wasn't provided to the builder, the object is fetched from the database.
  2030. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2031. func (m *LabelMutation) OldConditions(ctx context.Context) (v string, err error) {
  2032. if !m.op.Is(OpUpdateOne) {
  2033. return v, errors.New("OldConditions is only allowed on UpdateOne operations")
  2034. }
  2035. if m.id == nil || m.oldValue == nil {
  2036. return v, errors.New("OldConditions requires an ID field in the mutation")
  2037. }
  2038. oldValue, err := m.oldValue(ctx)
  2039. if err != nil {
  2040. return v, fmt.Errorf("querying old value for OldConditions: %w", err)
  2041. }
  2042. return oldValue.Conditions, nil
  2043. }
  2044. // ClearConditions clears the value of the "conditions" field.
  2045. func (m *LabelMutation) ClearConditions() {
  2046. m.conditions = nil
  2047. m.clearedFields[label.FieldConditions] = struct{}{}
  2048. }
  2049. // ConditionsCleared returns if the "conditions" field was cleared in this mutation.
  2050. func (m *LabelMutation) ConditionsCleared() bool {
  2051. _, ok := m.clearedFields[label.FieldConditions]
  2052. return ok
  2053. }
  2054. // ResetConditions resets all changes to the "conditions" field.
  2055. func (m *LabelMutation) ResetConditions() {
  2056. m.conditions = nil
  2057. delete(m.clearedFields, label.FieldConditions)
  2058. }
  2059. // AddLabelRelationshipIDs adds the "label_relationships" edge to the LabelRelationship entity by ids.
  2060. func (m *LabelMutation) AddLabelRelationshipIDs(ids ...uint64) {
  2061. if m.label_relationships == nil {
  2062. m.label_relationships = make(map[uint64]struct{})
  2063. }
  2064. for i := range ids {
  2065. m.label_relationships[ids[i]] = struct{}{}
  2066. }
  2067. }
  2068. // ClearLabelRelationships clears the "label_relationships" edge to the LabelRelationship entity.
  2069. func (m *LabelMutation) ClearLabelRelationships() {
  2070. m.clearedlabel_relationships = true
  2071. }
  2072. // LabelRelationshipsCleared reports if the "label_relationships" edge to the LabelRelationship entity was cleared.
  2073. func (m *LabelMutation) LabelRelationshipsCleared() bool {
  2074. return m.clearedlabel_relationships
  2075. }
  2076. // RemoveLabelRelationshipIDs removes the "label_relationships" edge to the LabelRelationship entity by IDs.
  2077. func (m *LabelMutation) RemoveLabelRelationshipIDs(ids ...uint64) {
  2078. if m.removedlabel_relationships == nil {
  2079. m.removedlabel_relationships = make(map[uint64]struct{})
  2080. }
  2081. for i := range ids {
  2082. delete(m.label_relationships, ids[i])
  2083. m.removedlabel_relationships[ids[i]] = struct{}{}
  2084. }
  2085. }
  2086. // RemovedLabelRelationships returns the removed IDs of the "label_relationships" edge to the LabelRelationship entity.
  2087. func (m *LabelMutation) RemovedLabelRelationshipsIDs() (ids []uint64) {
  2088. for id := range m.removedlabel_relationships {
  2089. ids = append(ids, id)
  2090. }
  2091. return
  2092. }
  2093. // LabelRelationshipsIDs returns the "label_relationships" edge IDs in the mutation.
  2094. func (m *LabelMutation) LabelRelationshipsIDs() (ids []uint64) {
  2095. for id := range m.label_relationships {
  2096. ids = append(ids, id)
  2097. }
  2098. return
  2099. }
  2100. // ResetLabelRelationships resets all changes to the "label_relationships" edge.
  2101. func (m *LabelMutation) ResetLabelRelationships() {
  2102. m.label_relationships = nil
  2103. m.clearedlabel_relationships = false
  2104. m.removedlabel_relationships = nil
  2105. }
  2106. // Where appends a list predicates to the LabelMutation builder.
  2107. func (m *LabelMutation) Where(ps ...predicate.Label) {
  2108. m.predicates = append(m.predicates, ps...)
  2109. }
  2110. // WhereP appends storage-level predicates to the LabelMutation builder. Using this method,
  2111. // users can use type-assertion to append predicates that do not depend on any generated package.
  2112. func (m *LabelMutation) WhereP(ps ...func(*sql.Selector)) {
  2113. p := make([]predicate.Label, len(ps))
  2114. for i := range ps {
  2115. p[i] = ps[i]
  2116. }
  2117. m.Where(p...)
  2118. }
  2119. // Op returns the operation name.
  2120. func (m *LabelMutation) Op() Op {
  2121. return m.op
  2122. }
  2123. // SetOp allows setting the mutation operation.
  2124. func (m *LabelMutation) SetOp(op Op) {
  2125. m.op = op
  2126. }
  2127. // Type returns the node type of this mutation (Label).
  2128. func (m *LabelMutation) Type() string {
  2129. return m.typ
  2130. }
  2131. // Fields returns all fields that were changed during this mutation. Note that in
  2132. // order to get all numeric fields that were incremented/decremented, call
  2133. // AddedFields().
  2134. func (m *LabelMutation) Fields() []string {
  2135. fields := make([]string, 0, 9)
  2136. if m.created_at != nil {
  2137. fields = append(fields, label.FieldCreatedAt)
  2138. }
  2139. if m.updated_at != nil {
  2140. fields = append(fields, label.FieldUpdatedAt)
  2141. }
  2142. if m.status != nil {
  2143. fields = append(fields, label.FieldStatus)
  2144. }
  2145. if m.deleted_at != nil {
  2146. fields = append(fields, label.FieldDeletedAt)
  2147. }
  2148. if m._type != nil {
  2149. fields = append(fields, label.FieldType)
  2150. }
  2151. if m.name != nil {
  2152. fields = append(fields, label.FieldName)
  2153. }
  2154. if m.from != nil {
  2155. fields = append(fields, label.FieldFrom)
  2156. }
  2157. if m.mode != nil {
  2158. fields = append(fields, label.FieldMode)
  2159. }
  2160. if m.conditions != nil {
  2161. fields = append(fields, label.FieldConditions)
  2162. }
  2163. return fields
  2164. }
  2165. // Field returns the value of a field with the given name. The second boolean
  2166. // return value indicates that this field was not set, or was not defined in the
  2167. // schema.
  2168. func (m *LabelMutation) Field(name string) (ent.Value, bool) {
  2169. switch name {
  2170. case label.FieldCreatedAt:
  2171. return m.CreatedAt()
  2172. case label.FieldUpdatedAt:
  2173. return m.UpdatedAt()
  2174. case label.FieldStatus:
  2175. return m.Status()
  2176. case label.FieldDeletedAt:
  2177. return m.DeletedAt()
  2178. case label.FieldType:
  2179. return m.GetType()
  2180. case label.FieldName:
  2181. return m.Name()
  2182. case label.FieldFrom:
  2183. return m.From()
  2184. case label.FieldMode:
  2185. return m.Mode()
  2186. case label.FieldConditions:
  2187. return m.Conditions()
  2188. }
  2189. return nil, false
  2190. }
  2191. // OldField returns the old value of the field from the database. An error is
  2192. // returned if the mutation operation is not UpdateOne, or the query to the
  2193. // database failed.
  2194. func (m *LabelMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  2195. switch name {
  2196. case label.FieldCreatedAt:
  2197. return m.OldCreatedAt(ctx)
  2198. case label.FieldUpdatedAt:
  2199. return m.OldUpdatedAt(ctx)
  2200. case label.FieldStatus:
  2201. return m.OldStatus(ctx)
  2202. case label.FieldDeletedAt:
  2203. return m.OldDeletedAt(ctx)
  2204. case label.FieldType:
  2205. return m.OldType(ctx)
  2206. case label.FieldName:
  2207. return m.OldName(ctx)
  2208. case label.FieldFrom:
  2209. return m.OldFrom(ctx)
  2210. case label.FieldMode:
  2211. return m.OldMode(ctx)
  2212. case label.FieldConditions:
  2213. return m.OldConditions(ctx)
  2214. }
  2215. return nil, fmt.Errorf("unknown Label field %s", name)
  2216. }
  2217. // SetField sets the value of a field with the given name. It returns an error if
  2218. // the field is not defined in the schema, or if the type mismatched the field
  2219. // type.
  2220. func (m *LabelMutation) SetField(name string, value ent.Value) error {
  2221. switch name {
  2222. case label.FieldCreatedAt:
  2223. v, ok := value.(time.Time)
  2224. if !ok {
  2225. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2226. }
  2227. m.SetCreatedAt(v)
  2228. return nil
  2229. case label.FieldUpdatedAt:
  2230. v, ok := value.(time.Time)
  2231. if !ok {
  2232. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2233. }
  2234. m.SetUpdatedAt(v)
  2235. return nil
  2236. case label.FieldStatus:
  2237. v, ok := value.(uint8)
  2238. if !ok {
  2239. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2240. }
  2241. m.SetStatus(v)
  2242. return nil
  2243. case label.FieldDeletedAt:
  2244. v, ok := value.(time.Time)
  2245. if !ok {
  2246. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2247. }
  2248. m.SetDeletedAt(v)
  2249. return nil
  2250. case label.FieldType:
  2251. v, ok := value.(int)
  2252. if !ok {
  2253. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2254. }
  2255. m.SetType(v)
  2256. return nil
  2257. case label.FieldName:
  2258. v, ok := value.(string)
  2259. if !ok {
  2260. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2261. }
  2262. m.SetName(v)
  2263. return nil
  2264. case label.FieldFrom:
  2265. v, ok := value.(int)
  2266. if !ok {
  2267. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2268. }
  2269. m.SetFrom(v)
  2270. return nil
  2271. case label.FieldMode:
  2272. v, ok := value.(int)
  2273. if !ok {
  2274. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2275. }
  2276. m.SetMode(v)
  2277. return nil
  2278. case label.FieldConditions:
  2279. v, ok := value.(string)
  2280. if !ok {
  2281. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2282. }
  2283. m.SetConditions(v)
  2284. return nil
  2285. }
  2286. return fmt.Errorf("unknown Label field %s", name)
  2287. }
  2288. // AddedFields returns all numeric fields that were incremented/decremented during
  2289. // this mutation.
  2290. func (m *LabelMutation) AddedFields() []string {
  2291. var fields []string
  2292. if m.addstatus != nil {
  2293. fields = append(fields, label.FieldStatus)
  2294. }
  2295. if m.add_type != nil {
  2296. fields = append(fields, label.FieldType)
  2297. }
  2298. if m.addfrom != nil {
  2299. fields = append(fields, label.FieldFrom)
  2300. }
  2301. if m.addmode != nil {
  2302. fields = append(fields, label.FieldMode)
  2303. }
  2304. return fields
  2305. }
  2306. // AddedField returns the numeric value that was incremented/decremented on a field
  2307. // with the given name. The second boolean return value indicates that this field
  2308. // was not set, or was not defined in the schema.
  2309. func (m *LabelMutation) AddedField(name string) (ent.Value, bool) {
  2310. switch name {
  2311. case label.FieldStatus:
  2312. return m.AddedStatus()
  2313. case label.FieldType:
  2314. return m.AddedType()
  2315. case label.FieldFrom:
  2316. return m.AddedFrom()
  2317. case label.FieldMode:
  2318. return m.AddedMode()
  2319. }
  2320. return nil, false
  2321. }
  2322. // AddField adds the value to the field with the given name. It returns an error if
  2323. // the field is not defined in the schema, or if the type mismatched the field
  2324. // type.
  2325. func (m *LabelMutation) AddField(name string, value ent.Value) error {
  2326. switch name {
  2327. case label.FieldStatus:
  2328. v, ok := value.(int8)
  2329. if !ok {
  2330. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2331. }
  2332. m.AddStatus(v)
  2333. return nil
  2334. case label.FieldType:
  2335. v, ok := value.(int)
  2336. if !ok {
  2337. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2338. }
  2339. m.AddType(v)
  2340. return nil
  2341. case label.FieldFrom:
  2342. v, ok := value.(int)
  2343. if !ok {
  2344. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2345. }
  2346. m.AddFrom(v)
  2347. return nil
  2348. case label.FieldMode:
  2349. v, ok := value.(int)
  2350. if !ok {
  2351. return fmt.Errorf("unexpected type %T for field %s", value, name)
  2352. }
  2353. m.AddMode(v)
  2354. return nil
  2355. }
  2356. return fmt.Errorf("unknown Label numeric field %s", name)
  2357. }
  2358. // ClearedFields returns all nullable fields that were cleared during this
  2359. // mutation.
  2360. func (m *LabelMutation) ClearedFields() []string {
  2361. var fields []string
  2362. if m.FieldCleared(label.FieldStatus) {
  2363. fields = append(fields, label.FieldStatus)
  2364. }
  2365. if m.FieldCleared(label.FieldDeletedAt) {
  2366. fields = append(fields, label.FieldDeletedAt)
  2367. }
  2368. if m.FieldCleared(label.FieldConditions) {
  2369. fields = append(fields, label.FieldConditions)
  2370. }
  2371. return fields
  2372. }
  2373. // FieldCleared returns a boolean indicating if a field with the given name was
  2374. // cleared in this mutation.
  2375. func (m *LabelMutation) FieldCleared(name string) bool {
  2376. _, ok := m.clearedFields[name]
  2377. return ok
  2378. }
  2379. // ClearField clears the value of the field with the given name. It returns an
  2380. // error if the field is not defined in the schema.
  2381. func (m *LabelMutation) ClearField(name string) error {
  2382. switch name {
  2383. case label.FieldStatus:
  2384. m.ClearStatus()
  2385. return nil
  2386. case label.FieldDeletedAt:
  2387. m.ClearDeletedAt()
  2388. return nil
  2389. case label.FieldConditions:
  2390. m.ClearConditions()
  2391. return nil
  2392. }
  2393. return fmt.Errorf("unknown Label nullable field %s", name)
  2394. }
  2395. // ResetField resets all changes in the mutation for the field with the given name.
  2396. // It returns an error if the field is not defined in the schema.
  2397. func (m *LabelMutation) ResetField(name string) error {
  2398. switch name {
  2399. case label.FieldCreatedAt:
  2400. m.ResetCreatedAt()
  2401. return nil
  2402. case label.FieldUpdatedAt:
  2403. m.ResetUpdatedAt()
  2404. return nil
  2405. case label.FieldStatus:
  2406. m.ResetStatus()
  2407. return nil
  2408. case label.FieldDeletedAt:
  2409. m.ResetDeletedAt()
  2410. return nil
  2411. case label.FieldType:
  2412. m.ResetType()
  2413. return nil
  2414. case label.FieldName:
  2415. m.ResetName()
  2416. return nil
  2417. case label.FieldFrom:
  2418. m.ResetFrom()
  2419. return nil
  2420. case label.FieldMode:
  2421. m.ResetMode()
  2422. return nil
  2423. case label.FieldConditions:
  2424. m.ResetConditions()
  2425. return nil
  2426. }
  2427. return fmt.Errorf("unknown Label field %s", name)
  2428. }
  2429. // AddedEdges returns all edge names that were set/added in this mutation.
  2430. func (m *LabelMutation) AddedEdges() []string {
  2431. edges := make([]string, 0, 1)
  2432. if m.label_relationships != nil {
  2433. edges = append(edges, label.EdgeLabelRelationships)
  2434. }
  2435. return edges
  2436. }
  2437. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  2438. // name in this mutation.
  2439. func (m *LabelMutation) AddedIDs(name string) []ent.Value {
  2440. switch name {
  2441. case label.EdgeLabelRelationships:
  2442. ids := make([]ent.Value, 0, len(m.label_relationships))
  2443. for id := range m.label_relationships {
  2444. ids = append(ids, id)
  2445. }
  2446. return ids
  2447. }
  2448. return nil
  2449. }
  2450. // RemovedEdges returns all edge names that were removed in this mutation.
  2451. func (m *LabelMutation) RemovedEdges() []string {
  2452. edges := make([]string, 0, 1)
  2453. if m.removedlabel_relationships != nil {
  2454. edges = append(edges, label.EdgeLabelRelationships)
  2455. }
  2456. return edges
  2457. }
  2458. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  2459. // the given name in this mutation.
  2460. func (m *LabelMutation) RemovedIDs(name string) []ent.Value {
  2461. switch name {
  2462. case label.EdgeLabelRelationships:
  2463. ids := make([]ent.Value, 0, len(m.removedlabel_relationships))
  2464. for id := range m.removedlabel_relationships {
  2465. ids = append(ids, id)
  2466. }
  2467. return ids
  2468. }
  2469. return nil
  2470. }
  2471. // ClearedEdges returns all edge names that were cleared in this mutation.
  2472. func (m *LabelMutation) ClearedEdges() []string {
  2473. edges := make([]string, 0, 1)
  2474. if m.clearedlabel_relationships {
  2475. edges = append(edges, label.EdgeLabelRelationships)
  2476. }
  2477. return edges
  2478. }
  2479. // EdgeCleared returns a boolean which indicates if the edge with the given name
  2480. // was cleared in this mutation.
  2481. func (m *LabelMutation) EdgeCleared(name string) bool {
  2482. switch name {
  2483. case label.EdgeLabelRelationships:
  2484. return m.clearedlabel_relationships
  2485. }
  2486. return false
  2487. }
  2488. // ClearEdge clears the value of the edge with the given name. It returns an error
  2489. // if that edge is not defined in the schema.
  2490. func (m *LabelMutation) ClearEdge(name string) error {
  2491. switch name {
  2492. }
  2493. return fmt.Errorf("unknown Label unique edge %s", name)
  2494. }
  2495. // ResetEdge resets all changes to the edge with the given name in this mutation.
  2496. // It returns an error if the edge is not defined in the schema.
  2497. func (m *LabelMutation) ResetEdge(name string) error {
  2498. switch name {
  2499. case label.EdgeLabelRelationships:
  2500. m.ResetLabelRelationships()
  2501. return nil
  2502. }
  2503. return fmt.Errorf("unknown Label edge %s", name)
  2504. }
  2505. // LabelRelationshipMutation represents an operation that mutates the LabelRelationship nodes in the graph.
  2506. type LabelRelationshipMutation struct {
  2507. config
  2508. op Op
  2509. typ string
  2510. id *uint64
  2511. created_at *time.Time
  2512. updated_at *time.Time
  2513. status *uint8
  2514. addstatus *int8
  2515. deleted_at *time.Time
  2516. clearedFields map[string]struct{}
  2517. contacts *uint64
  2518. clearedcontacts bool
  2519. labels *uint64
  2520. clearedlabels bool
  2521. done bool
  2522. oldValue func(context.Context) (*LabelRelationship, error)
  2523. predicates []predicate.LabelRelationship
  2524. }
  2525. var _ ent.Mutation = (*LabelRelationshipMutation)(nil)
  2526. // labelrelationshipOption allows management of the mutation configuration using functional options.
  2527. type labelrelationshipOption func(*LabelRelationshipMutation)
  2528. // newLabelRelationshipMutation creates new mutation for the LabelRelationship entity.
  2529. func newLabelRelationshipMutation(c config, op Op, opts ...labelrelationshipOption) *LabelRelationshipMutation {
  2530. m := &LabelRelationshipMutation{
  2531. config: c,
  2532. op: op,
  2533. typ: TypeLabelRelationship,
  2534. clearedFields: make(map[string]struct{}),
  2535. }
  2536. for _, opt := range opts {
  2537. opt(m)
  2538. }
  2539. return m
  2540. }
  2541. // withLabelRelationshipID sets the ID field of the mutation.
  2542. func withLabelRelationshipID(id uint64) labelrelationshipOption {
  2543. return func(m *LabelRelationshipMutation) {
  2544. var (
  2545. err error
  2546. once sync.Once
  2547. value *LabelRelationship
  2548. )
  2549. m.oldValue = func(ctx context.Context) (*LabelRelationship, error) {
  2550. once.Do(func() {
  2551. if m.done {
  2552. err = errors.New("querying old values post mutation is not allowed")
  2553. } else {
  2554. value, err = m.Client().LabelRelationship.Get(ctx, id)
  2555. }
  2556. })
  2557. return value, err
  2558. }
  2559. m.id = &id
  2560. }
  2561. }
  2562. // withLabelRelationship sets the old LabelRelationship of the mutation.
  2563. func withLabelRelationship(node *LabelRelationship) labelrelationshipOption {
  2564. return func(m *LabelRelationshipMutation) {
  2565. m.oldValue = func(context.Context) (*LabelRelationship, error) {
  2566. return node, nil
  2567. }
  2568. m.id = &node.ID
  2569. }
  2570. }
  2571. // Client returns a new `ent.Client` from the mutation. If the mutation was
  2572. // executed in a transaction (ent.Tx), a transactional client is returned.
  2573. func (m LabelRelationshipMutation) Client() *Client {
  2574. client := &Client{config: m.config}
  2575. client.init()
  2576. return client
  2577. }
  2578. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  2579. // it returns an error otherwise.
  2580. func (m LabelRelationshipMutation) Tx() (*Tx, error) {
  2581. if _, ok := m.driver.(*txDriver); !ok {
  2582. return nil, errors.New("ent: mutation is not running in a transaction")
  2583. }
  2584. tx := &Tx{config: m.config}
  2585. tx.init()
  2586. return tx, nil
  2587. }
  2588. // SetID sets the value of the id field. Note that this
  2589. // operation is only accepted on creation of LabelRelationship entities.
  2590. func (m *LabelRelationshipMutation) SetID(id uint64) {
  2591. m.id = &id
  2592. }
  2593. // ID returns the ID value in the mutation. Note that the ID is only available
  2594. // if it was provided to the builder or after it was returned from the database.
  2595. func (m *LabelRelationshipMutation) ID() (id uint64, exists bool) {
  2596. if m.id == nil {
  2597. return
  2598. }
  2599. return *m.id, true
  2600. }
  2601. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  2602. // That means, if the mutation is applied within a transaction with an isolation level such
  2603. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  2604. // or updated by the mutation.
  2605. func (m *LabelRelationshipMutation) IDs(ctx context.Context) ([]uint64, error) {
  2606. switch {
  2607. case m.op.Is(OpUpdateOne | OpDeleteOne):
  2608. id, exists := m.ID()
  2609. if exists {
  2610. return []uint64{id}, nil
  2611. }
  2612. fallthrough
  2613. case m.op.Is(OpUpdate | OpDelete):
  2614. return m.Client().LabelRelationship.Query().Where(m.predicates...).IDs(ctx)
  2615. default:
  2616. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  2617. }
  2618. }
  2619. // SetCreatedAt sets the "created_at" field.
  2620. func (m *LabelRelationshipMutation) SetCreatedAt(t time.Time) {
  2621. m.created_at = &t
  2622. }
  2623. // CreatedAt returns the value of the "created_at" field in the mutation.
  2624. func (m *LabelRelationshipMutation) CreatedAt() (r time.Time, exists bool) {
  2625. v := m.created_at
  2626. if v == nil {
  2627. return
  2628. }
  2629. return *v, true
  2630. }
  2631. // OldCreatedAt returns the old "created_at" field's value of the LabelRelationship entity.
  2632. // If the LabelRelationship object wasn't provided to the builder, the object is fetched from the database.
  2633. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2634. func (m *LabelRelationshipMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  2635. if !m.op.Is(OpUpdateOne) {
  2636. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  2637. }
  2638. if m.id == nil || m.oldValue == nil {
  2639. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  2640. }
  2641. oldValue, err := m.oldValue(ctx)
  2642. if err != nil {
  2643. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  2644. }
  2645. return oldValue.CreatedAt, nil
  2646. }
  2647. // ResetCreatedAt resets all changes to the "created_at" field.
  2648. func (m *LabelRelationshipMutation) ResetCreatedAt() {
  2649. m.created_at = nil
  2650. }
  2651. // SetUpdatedAt sets the "updated_at" field.
  2652. func (m *LabelRelationshipMutation) SetUpdatedAt(t time.Time) {
  2653. m.updated_at = &t
  2654. }
  2655. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  2656. func (m *LabelRelationshipMutation) UpdatedAt() (r time.Time, exists bool) {
  2657. v := m.updated_at
  2658. if v == nil {
  2659. return
  2660. }
  2661. return *v, true
  2662. }
  2663. // OldUpdatedAt returns the old "updated_at" field's value of the LabelRelationship entity.
  2664. // If the LabelRelationship object wasn't provided to the builder, the object is fetched from the database.
  2665. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2666. func (m *LabelRelationshipMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  2667. if !m.op.Is(OpUpdateOne) {
  2668. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  2669. }
  2670. if m.id == nil || m.oldValue == nil {
  2671. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  2672. }
  2673. oldValue, err := m.oldValue(ctx)
  2674. if err != nil {
  2675. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  2676. }
  2677. return oldValue.UpdatedAt, nil
  2678. }
  2679. // ResetUpdatedAt resets all changes to the "updated_at" field.
  2680. func (m *LabelRelationshipMutation) ResetUpdatedAt() {
  2681. m.updated_at = nil
  2682. }
  2683. // SetStatus sets the "status" field.
  2684. func (m *LabelRelationshipMutation) SetStatus(u uint8) {
  2685. m.status = &u
  2686. m.addstatus = nil
  2687. }
  2688. // Status returns the value of the "status" field in the mutation.
  2689. func (m *LabelRelationshipMutation) Status() (r uint8, exists bool) {
  2690. v := m.status
  2691. if v == nil {
  2692. return
  2693. }
  2694. return *v, true
  2695. }
  2696. // OldStatus returns the old "status" field's value of the LabelRelationship entity.
  2697. // If the LabelRelationship object wasn't provided to the builder, the object is fetched from the database.
  2698. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2699. func (m *LabelRelationshipMutation) OldStatus(ctx context.Context) (v uint8, err error) {
  2700. if !m.op.Is(OpUpdateOne) {
  2701. return v, errors.New("OldStatus is only allowed on UpdateOne operations")
  2702. }
  2703. if m.id == nil || m.oldValue == nil {
  2704. return v, errors.New("OldStatus requires an ID field in the mutation")
  2705. }
  2706. oldValue, err := m.oldValue(ctx)
  2707. if err != nil {
  2708. return v, fmt.Errorf("querying old value for OldStatus: %w", err)
  2709. }
  2710. return oldValue.Status, nil
  2711. }
  2712. // AddStatus adds u to the "status" field.
  2713. func (m *LabelRelationshipMutation) AddStatus(u int8) {
  2714. if m.addstatus != nil {
  2715. *m.addstatus += u
  2716. } else {
  2717. m.addstatus = &u
  2718. }
  2719. }
  2720. // AddedStatus returns the value that was added to the "status" field in this mutation.
  2721. func (m *LabelRelationshipMutation) AddedStatus() (r int8, exists bool) {
  2722. v := m.addstatus
  2723. if v == nil {
  2724. return
  2725. }
  2726. return *v, true
  2727. }
  2728. // ClearStatus clears the value of the "status" field.
  2729. func (m *LabelRelationshipMutation) ClearStatus() {
  2730. m.status = nil
  2731. m.addstatus = nil
  2732. m.clearedFields[labelrelationship.FieldStatus] = struct{}{}
  2733. }
  2734. // StatusCleared returns if the "status" field was cleared in this mutation.
  2735. func (m *LabelRelationshipMutation) StatusCleared() bool {
  2736. _, ok := m.clearedFields[labelrelationship.FieldStatus]
  2737. return ok
  2738. }
  2739. // ResetStatus resets all changes to the "status" field.
  2740. func (m *LabelRelationshipMutation) ResetStatus() {
  2741. m.status = nil
  2742. m.addstatus = nil
  2743. delete(m.clearedFields, labelrelationship.FieldStatus)
  2744. }
  2745. // SetDeletedAt sets the "deleted_at" field.
  2746. func (m *LabelRelationshipMutation) SetDeletedAt(t time.Time) {
  2747. m.deleted_at = &t
  2748. }
  2749. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  2750. func (m *LabelRelationshipMutation) DeletedAt() (r time.Time, exists bool) {
  2751. v := m.deleted_at
  2752. if v == nil {
  2753. return
  2754. }
  2755. return *v, true
  2756. }
  2757. // OldDeletedAt returns the old "deleted_at" field's value of the LabelRelationship entity.
  2758. // If the LabelRelationship object wasn't provided to the builder, the object is fetched from the database.
  2759. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2760. func (m *LabelRelationshipMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  2761. if !m.op.Is(OpUpdateOne) {
  2762. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  2763. }
  2764. if m.id == nil || m.oldValue == nil {
  2765. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  2766. }
  2767. oldValue, err := m.oldValue(ctx)
  2768. if err != nil {
  2769. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  2770. }
  2771. return oldValue.DeletedAt, nil
  2772. }
  2773. // ClearDeletedAt clears the value of the "deleted_at" field.
  2774. func (m *LabelRelationshipMutation) ClearDeletedAt() {
  2775. m.deleted_at = nil
  2776. m.clearedFields[labelrelationship.FieldDeletedAt] = struct{}{}
  2777. }
  2778. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  2779. func (m *LabelRelationshipMutation) DeletedAtCleared() bool {
  2780. _, ok := m.clearedFields[labelrelationship.FieldDeletedAt]
  2781. return ok
  2782. }
  2783. // ResetDeletedAt resets all changes to the "deleted_at" field.
  2784. func (m *LabelRelationshipMutation) ResetDeletedAt() {
  2785. m.deleted_at = nil
  2786. delete(m.clearedFields, labelrelationship.FieldDeletedAt)
  2787. }
  2788. // SetLabelID sets the "label_id" field.
  2789. func (m *LabelRelationshipMutation) SetLabelID(u uint64) {
  2790. m.labels = &u
  2791. }
  2792. // LabelID returns the value of the "label_id" field in the mutation.
  2793. func (m *LabelRelationshipMutation) LabelID() (r uint64, exists bool) {
  2794. v := m.labels
  2795. if v == nil {
  2796. return
  2797. }
  2798. return *v, true
  2799. }
  2800. // OldLabelID returns the old "label_id" field's value of the LabelRelationship entity.
  2801. // If the LabelRelationship object wasn't provided to the builder, the object is fetched from the database.
  2802. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2803. func (m *LabelRelationshipMutation) OldLabelID(ctx context.Context) (v uint64, err error) {
  2804. if !m.op.Is(OpUpdateOne) {
  2805. return v, errors.New("OldLabelID is only allowed on UpdateOne operations")
  2806. }
  2807. if m.id == nil || m.oldValue == nil {
  2808. return v, errors.New("OldLabelID requires an ID field in the mutation")
  2809. }
  2810. oldValue, err := m.oldValue(ctx)
  2811. if err != nil {
  2812. return v, fmt.Errorf("querying old value for OldLabelID: %w", err)
  2813. }
  2814. return oldValue.LabelID, nil
  2815. }
  2816. // ResetLabelID resets all changes to the "label_id" field.
  2817. func (m *LabelRelationshipMutation) ResetLabelID() {
  2818. m.labels = nil
  2819. }
  2820. // SetContactID sets the "contact_id" field.
  2821. func (m *LabelRelationshipMutation) SetContactID(u uint64) {
  2822. m.contacts = &u
  2823. }
  2824. // ContactID returns the value of the "contact_id" field in the mutation.
  2825. func (m *LabelRelationshipMutation) ContactID() (r uint64, exists bool) {
  2826. v := m.contacts
  2827. if v == nil {
  2828. return
  2829. }
  2830. return *v, true
  2831. }
  2832. // OldContactID returns the old "contact_id" field's value of the LabelRelationship entity.
  2833. // If the LabelRelationship object wasn't provided to the builder, the object is fetched from the database.
  2834. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2835. func (m *LabelRelationshipMutation) OldContactID(ctx context.Context) (v uint64, err error) {
  2836. if !m.op.Is(OpUpdateOne) {
  2837. return v, errors.New("OldContactID is only allowed on UpdateOne operations")
  2838. }
  2839. if m.id == nil || m.oldValue == nil {
  2840. return v, errors.New("OldContactID requires an ID field in the mutation")
  2841. }
  2842. oldValue, err := m.oldValue(ctx)
  2843. if err != nil {
  2844. return v, fmt.Errorf("querying old value for OldContactID: %w", err)
  2845. }
  2846. return oldValue.ContactID, nil
  2847. }
  2848. // ResetContactID resets all changes to the "contact_id" field.
  2849. func (m *LabelRelationshipMutation) ResetContactID() {
  2850. m.contacts = nil
  2851. }
  2852. // SetContactsID sets the "contacts" edge to the Contact entity by id.
  2853. func (m *LabelRelationshipMutation) SetContactsID(id uint64) {
  2854. m.contacts = &id
  2855. }
  2856. // ClearContacts clears the "contacts" edge to the Contact entity.
  2857. func (m *LabelRelationshipMutation) ClearContacts() {
  2858. m.clearedcontacts = true
  2859. m.clearedFields[labelrelationship.FieldContactID] = struct{}{}
  2860. }
  2861. // ContactsCleared reports if the "contacts" edge to the Contact entity was cleared.
  2862. func (m *LabelRelationshipMutation) ContactsCleared() bool {
  2863. return m.clearedcontacts
  2864. }
  2865. // ContactsID returns the "contacts" edge ID in the mutation.
  2866. func (m *LabelRelationshipMutation) ContactsID() (id uint64, exists bool) {
  2867. if m.contacts != nil {
  2868. return *m.contacts, true
  2869. }
  2870. return
  2871. }
  2872. // ContactsIDs returns the "contacts" edge IDs in the mutation.
  2873. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  2874. // ContactsID instead. It exists only for internal usage by the builders.
  2875. func (m *LabelRelationshipMutation) ContactsIDs() (ids []uint64) {
  2876. if id := m.contacts; id != nil {
  2877. ids = append(ids, *id)
  2878. }
  2879. return
  2880. }
  2881. // ResetContacts resets all changes to the "contacts" edge.
  2882. func (m *LabelRelationshipMutation) ResetContacts() {
  2883. m.contacts = nil
  2884. m.clearedcontacts = false
  2885. }
  2886. // SetLabelsID sets the "labels" edge to the Label entity by id.
  2887. func (m *LabelRelationshipMutation) SetLabelsID(id uint64) {
  2888. m.labels = &id
  2889. }
  2890. // ClearLabels clears the "labels" edge to the Label entity.
  2891. func (m *LabelRelationshipMutation) ClearLabels() {
  2892. m.clearedlabels = true
  2893. m.clearedFields[labelrelationship.FieldLabelID] = struct{}{}
  2894. }
  2895. // LabelsCleared reports if the "labels" edge to the Label entity was cleared.
  2896. func (m *LabelRelationshipMutation) LabelsCleared() bool {
  2897. return m.clearedlabels
  2898. }
  2899. // LabelsID returns the "labels" edge ID in the mutation.
  2900. func (m *LabelRelationshipMutation) LabelsID() (id uint64, exists bool) {
  2901. if m.labels != nil {
  2902. return *m.labels, true
  2903. }
  2904. return
  2905. }
  2906. // LabelsIDs returns the "labels" edge IDs in the mutation.
  2907. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  2908. // LabelsID instead. It exists only for internal usage by the builders.
  2909. func (m *LabelRelationshipMutation) LabelsIDs() (ids []uint64) {
  2910. if id := m.labels; id != nil {
  2911. ids = append(ids, *id)
  2912. }
  2913. return
  2914. }
  2915. // ResetLabels resets all changes to the "labels" edge.
  2916. func (m *LabelRelationshipMutation) ResetLabels() {
  2917. m.labels = nil
  2918. m.clearedlabels = false
  2919. }
  2920. // Where appends a list predicates to the LabelRelationshipMutation builder.
  2921. func (m *LabelRelationshipMutation) Where(ps ...predicate.LabelRelationship) {
  2922. m.predicates = append(m.predicates, ps...)
  2923. }
  2924. // WhereP appends storage-level predicates to the LabelRelationshipMutation builder. Using this method,
  2925. // users can use type-assertion to append predicates that do not depend on any generated package.
  2926. func (m *LabelRelationshipMutation) WhereP(ps ...func(*sql.Selector)) {
  2927. p := make([]predicate.LabelRelationship, len(ps))
  2928. for i := range ps {
  2929. p[i] = ps[i]
  2930. }
  2931. m.Where(p...)
  2932. }
  2933. // Op returns the operation name.
  2934. func (m *LabelRelationshipMutation) Op() Op {
  2935. return m.op
  2936. }
  2937. // SetOp allows setting the mutation operation.
  2938. func (m *LabelRelationshipMutation) SetOp(op Op) {
  2939. m.op = op
  2940. }
  2941. // Type returns the node type of this mutation (LabelRelationship).
  2942. func (m *LabelRelationshipMutation) Type() string {
  2943. return m.typ
  2944. }
  2945. // Fields returns all fields that were changed during this mutation. Note that in
  2946. // order to get all numeric fields that were incremented/decremented, call
  2947. // AddedFields().
  2948. func (m *LabelRelationshipMutation) Fields() []string {
  2949. fields := make([]string, 0, 6)
  2950. if m.created_at != nil {
  2951. fields = append(fields, labelrelationship.FieldCreatedAt)
  2952. }
  2953. if m.updated_at != nil {
  2954. fields = append(fields, labelrelationship.FieldUpdatedAt)
  2955. }
  2956. if m.status != nil {
  2957. fields = append(fields, labelrelationship.FieldStatus)
  2958. }
  2959. if m.deleted_at != nil {
  2960. fields = append(fields, labelrelationship.FieldDeletedAt)
  2961. }
  2962. if m.labels != nil {
  2963. fields = append(fields, labelrelationship.FieldLabelID)
  2964. }
  2965. if m.contacts != nil {
  2966. fields = append(fields, labelrelationship.FieldContactID)
  2967. }
  2968. return fields
  2969. }
  2970. // Field returns the value of a field with the given name. The second boolean
  2971. // return value indicates that this field was not set, or was not defined in the
  2972. // schema.
  2973. func (m *LabelRelationshipMutation) Field(name string) (ent.Value, bool) {
  2974. switch name {
  2975. case labelrelationship.FieldCreatedAt:
  2976. return m.CreatedAt()
  2977. case labelrelationship.FieldUpdatedAt:
  2978. return m.UpdatedAt()
  2979. case labelrelationship.FieldStatus:
  2980. return m.Status()
  2981. case labelrelationship.FieldDeletedAt:
  2982. return m.DeletedAt()
  2983. case labelrelationship.FieldLabelID:
  2984. return m.LabelID()
  2985. case labelrelationship.FieldContactID:
  2986. return m.ContactID()
  2987. }
  2988. return nil, false
  2989. }
  2990. // OldField returns the old value of the field from the database. An error is
  2991. // returned if the mutation operation is not UpdateOne, or the query to the
  2992. // database failed.
  2993. func (m *LabelRelationshipMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  2994. switch name {
  2995. case labelrelationship.FieldCreatedAt:
  2996. return m.OldCreatedAt(ctx)
  2997. case labelrelationship.FieldUpdatedAt:
  2998. return m.OldUpdatedAt(ctx)
  2999. case labelrelationship.FieldStatus:
  3000. return m.OldStatus(ctx)
  3001. case labelrelationship.FieldDeletedAt:
  3002. return m.OldDeletedAt(ctx)
  3003. case labelrelationship.FieldLabelID:
  3004. return m.OldLabelID(ctx)
  3005. case labelrelationship.FieldContactID:
  3006. return m.OldContactID(ctx)
  3007. }
  3008. return nil, fmt.Errorf("unknown LabelRelationship field %s", name)
  3009. }
  3010. // SetField sets the value of a field with the given name. It returns an error if
  3011. // the field is not defined in the schema, or if the type mismatched the field
  3012. // type.
  3013. func (m *LabelRelationshipMutation) SetField(name string, value ent.Value) error {
  3014. switch name {
  3015. case labelrelationship.FieldCreatedAt:
  3016. v, ok := value.(time.Time)
  3017. if !ok {
  3018. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3019. }
  3020. m.SetCreatedAt(v)
  3021. return nil
  3022. case labelrelationship.FieldUpdatedAt:
  3023. v, ok := value.(time.Time)
  3024. if !ok {
  3025. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3026. }
  3027. m.SetUpdatedAt(v)
  3028. return nil
  3029. case labelrelationship.FieldStatus:
  3030. v, ok := value.(uint8)
  3031. if !ok {
  3032. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3033. }
  3034. m.SetStatus(v)
  3035. return nil
  3036. case labelrelationship.FieldDeletedAt:
  3037. v, ok := value.(time.Time)
  3038. if !ok {
  3039. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3040. }
  3041. m.SetDeletedAt(v)
  3042. return nil
  3043. case labelrelationship.FieldLabelID:
  3044. v, ok := value.(uint64)
  3045. if !ok {
  3046. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3047. }
  3048. m.SetLabelID(v)
  3049. return nil
  3050. case labelrelationship.FieldContactID:
  3051. v, ok := value.(uint64)
  3052. if !ok {
  3053. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3054. }
  3055. m.SetContactID(v)
  3056. return nil
  3057. }
  3058. return fmt.Errorf("unknown LabelRelationship field %s", name)
  3059. }
  3060. // AddedFields returns all numeric fields that were incremented/decremented during
  3061. // this mutation.
  3062. func (m *LabelRelationshipMutation) AddedFields() []string {
  3063. var fields []string
  3064. if m.addstatus != nil {
  3065. fields = append(fields, labelrelationship.FieldStatus)
  3066. }
  3067. return fields
  3068. }
  3069. // AddedField returns the numeric value that was incremented/decremented on a field
  3070. // with the given name. The second boolean return value indicates that this field
  3071. // was not set, or was not defined in the schema.
  3072. func (m *LabelRelationshipMutation) AddedField(name string) (ent.Value, bool) {
  3073. switch name {
  3074. case labelrelationship.FieldStatus:
  3075. return m.AddedStatus()
  3076. }
  3077. return nil, false
  3078. }
  3079. // AddField adds the value to the field with the given name. It returns an error if
  3080. // the field is not defined in the schema, or if the type mismatched the field
  3081. // type.
  3082. func (m *LabelRelationshipMutation) AddField(name string, value ent.Value) error {
  3083. switch name {
  3084. case labelrelationship.FieldStatus:
  3085. v, ok := value.(int8)
  3086. if !ok {
  3087. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3088. }
  3089. m.AddStatus(v)
  3090. return nil
  3091. }
  3092. return fmt.Errorf("unknown LabelRelationship numeric field %s", name)
  3093. }
  3094. // ClearedFields returns all nullable fields that were cleared during this
  3095. // mutation.
  3096. func (m *LabelRelationshipMutation) ClearedFields() []string {
  3097. var fields []string
  3098. if m.FieldCleared(labelrelationship.FieldStatus) {
  3099. fields = append(fields, labelrelationship.FieldStatus)
  3100. }
  3101. if m.FieldCleared(labelrelationship.FieldDeletedAt) {
  3102. fields = append(fields, labelrelationship.FieldDeletedAt)
  3103. }
  3104. return fields
  3105. }
  3106. // FieldCleared returns a boolean indicating if a field with the given name was
  3107. // cleared in this mutation.
  3108. func (m *LabelRelationshipMutation) FieldCleared(name string) bool {
  3109. _, ok := m.clearedFields[name]
  3110. return ok
  3111. }
  3112. // ClearField clears the value of the field with the given name. It returns an
  3113. // error if the field is not defined in the schema.
  3114. func (m *LabelRelationshipMutation) ClearField(name string) error {
  3115. switch name {
  3116. case labelrelationship.FieldStatus:
  3117. m.ClearStatus()
  3118. return nil
  3119. case labelrelationship.FieldDeletedAt:
  3120. m.ClearDeletedAt()
  3121. return nil
  3122. }
  3123. return fmt.Errorf("unknown LabelRelationship nullable field %s", name)
  3124. }
  3125. // ResetField resets all changes in the mutation for the field with the given name.
  3126. // It returns an error if the field is not defined in the schema.
  3127. func (m *LabelRelationshipMutation) ResetField(name string) error {
  3128. switch name {
  3129. case labelrelationship.FieldCreatedAt:
  3130. m.ResetCreatedAt()
  3131. return nil
  3132. case labelrelationship.FieldUpdatedAt:
  3133. m.ResetUpdatedAt()
  3134. return nil
  3135. case labelrelationship.FieldStatus:
  3136. m.ResetStatus()
  3137. return nil
  3138. case labelrelationship.FieldDeletedAt:
  3139. m.ResetDeletedAt()
  3140. return nil
  3141. case labelrelationship.FieldLabelID:
  3142. m.ResetLabelID()
  3143. return nil
  3144. case labelrelationship.FieldContactID:
  3145. m.ResetContactID()
  3146. return nil
  3147. }
  3148. return fmt.Errorf("unknown LabelRelationship field %s", name)
  3149. }
  3150. // AddedEdges returns all edge names that were set/added in this mutation.
  3151. func (m *LabelRelationshipMutation) AddedEdges() []string {
  3152. edges := make([]string, 0, 2)
  3153. if m.contacts != nil {
  3154. edges = append(edges, labelrelationship.EdgeContacts)
  3155. }
  3156. if m.labels != nil {
  3157. edges = append(edges, labelrelationship.EdgeLabels)
  3158. }
  3159. return edges
  3160. }
  3161. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  3162. // name in this mutation.
  3163. func (m *LabelRelationshipMutation) AddedIDs(name string) []ent.Value {
  3164. switch name {
  3165. case labelrelationship.EdgeContacts:
  3166. if id := m.contacts; id != nil {
  3167. return []ent.Value{*id}
  3168. }
  3169. case labelrelationship.EdgeLabels:
  3170. if id := m.labels; id != nil {
  3171. return []ent.Value{*id}
  3172. }
  3173. }
  3174. return nil
  3175. }
  3176. // RemovedEdges returns all edge names that were removed in this mutation.
  3177. func (m *LabelRelationshipMutation) RemovedEdges() []string {
  3178. edges := make([]string, 0, 2)
  3179. return edges
  3180. }
  3181. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  3182. // the given name in this mutation.
  3183. func (m *LabelRelationshipMutation) RemovedIDs(name string) []ent.Value {
  3184. return nil
  3185. }
  3186. // ClearedEdges returns all edge names that were cleared in this mutation.
  3187. func (m *LabelRelationshipMutation) ClearedEdges() []string {
  3188. edges := make([]string, 0, 2)
  3189. if m.clearedcontacts {
  3190. edges = append(edges, labelrelationship.EdgeContacts)
  3191. }
  3192. if m.clearedlabels {
  3193. edges = append(edges, labelrelationship.EdgeLabels)
  3194. }
  3195. return edges
  3196. }
  3197. // EdgeCleared returns a boolean which indicates if the edge with the given name
  3198. // was cleared in this mutation.
  3199. func (m *LabelRelationshipMutation) EdgeCleared(name string) bool {
  3200. switch name {
  3201. case labelrelationship.EdgeContacts:
  3202. return m.clearedcontacts
  3203. case labelrelationship.EdgeLabels:
  3204. return m.clearedlabels
  3205. }
  3206. return false
  3207. }
  3208. // ClearEdge clears the value of the edge with the given name. It returns an error
  3209. // if that edge is not defined in the schema.
  3210. func (m *LabelRelationshipMutation) ClearEdge(name string) error {
  3211. switch name {
  3212. case labelrelationship.EdgeContacts:
  3213. m.ClearContacts()
  3214. return nil
  3215. case labelrelationship.EdgeLabels:
  3216. m.ClearLabels()
  3217. return nil
  3218. }
  3219. return fmt.Errorf("unknown LabelRelationship unique edge %s", name)
  3220. }
  3221. // ResetEdge resets all changes to the edge with the given name in this mutation.
  3222. // It returns an error if the edge is not defined in the schema.
  3223. func (m *LabelRelationshipMutation) ResetEdge(name string) error {
  3224. switch name {
  3225. case labelrelationship.EdgeContacts:
  3226. m.ResetContacts()
  3227. return nil
  3228. case labelrelationship.EdgeLabels:
  3229. m.ResetLabels()
  3230. return nil
  3231. }
  3232. return fmt.Errorf("unknown LabelRelationship edge %s", name)
  3233. }
  3234. // MessageMutation represents an operation that mutates the Message nodes in the graph.
  3235. type MessageMutation struct {
  3236. config
  3237. op Op
  3238. typ string
  3239. id *int
  3240. wx_wxid *string
  3241. wxid *string
  3242. content *string
  3243. clearedFields map[string]struct{}
  3244. done bool
  3245. oldValue func(context.Context) (*Message, error)
  3246. predicates []predicate.Message
  3247. }
  3248. var _ ent.Mutation = (*MessageMutation)(nil)
  3249. // messageOption allows management of the mutation configuration using functional options.
  3250. type messageOption func(*MessageMutation)
  3251. // newMessageMutation creates new mutation for the Message entity.
  3252. func newMessageMutation(c config, op Op, opts ...messageOption) *MessageMutation {
  3253. m := &MessageMutation{
  3254. config: c,
  3255. op: op,
  3256. typ: TypeMessage,
  3257. clearedFields: make(map[string]struct{}),
  3258. }
  3259. for _, opt := range opts {
  3260. opt(m)
  3261. }
  3262. return m
  3263. }
  3264. // withMessageID sets the ID field of the mutation.
  3265. func withMessageID(id int) messageOption {
  3266. return func(m *MessageMutation) {
  3267. var (
  3268. err error
  3269. once sync.Once
  3270. value *Message
  3271. )
  3272. m.oldValue = func(ctx context.Context) (*Message, error) {
  3273. once.Do(func() {
  3274. if m.done {
  3275. err = errors.New("querying old values post mutation is not allowed")
  3276. } else {
  3277. value, err = m.Client().Message.Get(ctx, id)
  3278. }
  3279. })
  3280. return value, err
  3281. }
  3282. m.id = &id
  3283. }
  3284. }
  3285. // withMessage sets the old Message of the mutation.
  3286. func withMessage(node *Message) messageOption {
  3287. return func(m *MessageMutation) {
  3288. m.oldValue = func(context.Context) (*Message, error) {
  3289. return node, nil
  3290. }
  3291. m.id = &node.ID
  3292. }
  3293. }
  3294. // Client returns a new `ent.Client` from the mutation. If the mutation was
  3295. // executed in a transaction (ent.Tx), a transactional client is returned.
  3296. func (m MessageMutation) Client() *Client {
  3297. client := &Client{config: m.config}
  3298. client.init()
  3299. return client
  3300. }
  3301. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  3302. // it returns an error otherwise.
  3303. func (m MessageMutation) Tx() (*Tx, error) {
  3304. if _, ok := m.driver.(*txDriver); !ok {
  3305. return nil, errors.New("ent: mutation is not running in a transaction")
  3306. }
  3307. tx := &Tx{config: m.config}
  3308. tx.init()
  3309. return tx, nil
  3310. }
  3311. // ID returns the ID value in the mutation. Note that the ID is only available
  3312. // if it was provided to the builder or after it was returned from the database.
  3313. func (m *MessageMutation) ID() (id int, exists bool) {
  3314. if m.id == nil {
  3315. return
  3316. }
  3317. return *m.id, true
  3318. }
  3319. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  3320. // That means, if the mutation is applied within a transaction with an isolation level such
  3321. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  3322. // or updated by the mutation.
  3323. func (m *MessageMutation) IDs(ctx context.Context) ([]int, error) {
  3324. switch {
  3325. case m.op.Is(OpUpdateOne | OpDeleteOne):
  3326. id, exists := m.ID()
  3327. if exists {
  3328. return []int{id}, nil
  3329. }
  3330. fallthrough
  3331. case m.op.Is(OpUpdate | OpDelete):
  3332. return m.Client().Message.Query().Where(m.predicates...).IDs(ctx)
  3333. default:
  3334. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  3335. }
  3336. }
  3337. // SetWxWxid sets the "wx_wxid" field.
  3338. func (m *MessageMutation) SetWxWxid(s string) {
  3339. m.wx_wxid = &s
  3340. }
  3341. // WxWxid returns the value of the "wx_wxid" field in the mutation.
  3342. func (m *MessageMutation) WxWxid() (r string, exists bool) {
  3343. v := m.wx_wxid
  3344. if v == nil {
  3345. return
  3346. }
  3347. return *v, true
  3348. }
  3349. // OldWxWxid returns the old "wx_wxid" field's value of the Message entity.
  3350. // If the Message object wasn't provided to the builder, the object is fetched from the database.
  3351. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3352. func (m *MessageMutation) OldWxWxid(ctx context.Context) (v string, err error) {
  3353. if !m.op.Is(OpUpdateOne) {
  3354. return v, errors.New("OldWxWxid is only allowed on UpdateOne operations")
  3355. }
  3356. if m.id == nil || m.oldValue == nil {
  3357. return v, errors.New("OldWxWxid requires an ID field in the mutation")
  3358. }
  3359. oldValue, err := m.oldValue(ctx)
  3360. if err != nil {
  3361. return v, fmt.Errorf("querying old value for OldWxWxid: %w", err)
  3362. }
  3363. return oldValue.WxWxid, nil
  3364. }
  3365. // ClearWxWxid clears the value of the "wx_wxid" field.
  3366. func (m *MessageMutation) ClearWxWxid() {
  3367. m.wx_wxid = nil
  3368. m.clearedFields[message.FieldWxWxid] = struct{}{}
  3369. }
  3370. // WxWxidCleared returns if the "wx_wxid" field was cleared in this mutation.
  3371. func (m *MessageMutation) WxWxidCleared() bool {
  3372. _, ok := m.clearedFields[message.FieldWxWxid]
  3373. return ok
  3374. }
  3375. // ResetWxWxid resets all changes to the "wx_wxid" field.
  3376. func (m *MessageMutation) ResetWxWxid() {
  3377. m.wx_wxid = nil
  3378. delete(m.clearedFields, message.FieldWxWxid)
  3379. }
  3380. // SetWxid sets the "wxid" field.
  3381. func (m *MessageMutation) SetWxid(s string) {
  3382. m.wxid = &s
  3383. }
  3384. // Wxid returns the value of the "wxid" field in the mutation.
  3385. func (m *MessageMutation) Wxid() (r string, exists bool) {
  3386. v := m.wxid
  3387. if v == nil {
  3388. return
  3389. }
  3390. return *v, true
  3391. }
  3392. // OldWxid returns the old "wxid" field's value of the Message entity.
  3393. // If the Message object wasn't provided to the builder, the object is fetched from the database.
  3394. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3395. func (m *MessageMutation) OldWxid(ctx context.Context) (v string, err error) {
  3396. if !m.op.Is(OpUpdateOne) {
  3397. return v, errors.New("OldWxid is only allowed on UpdateOne operations")
  3398. }
  3399. if m.id == nil || m.oldValue == nil {
  3400. return v, errors.New("OldWxid requires an ID field in the mutation")
  3401. }
  3402. oldValue, err := m.oldValue(ctx)
  3403. if err != nil {
  3404. return v, fmt.Errorf("querying old value for OldWxid: %w", err)
  3405. }
  3406. return oldValue.Wxid, nil
  3407. }
  3408. // ResetWxid resets all changes to the "wxid" field.
  3409. func (m *MessageMutation) ResetWxid() {
  3410. m.wxid = nil
  3411. }
  3412. // SetContent sets the "content" field.
  3413. func (m *MessageMutation) SetContent(s string) {
  3414. m.content = &s
  3415. }
  3416. // Content returns the value of the "content" field in the mutation.
  3417. func (m *MessageMutation) Content() (r string, exists bool) {
  3418. v := m.content
  3419. if v == nil {
  3420. return
  3421. }
  3422. return *v, true
  3423. }
  3424. // OldContent returns the old "content" field's value of the Message entity.
  3425. // If the Message object wasn't provided to the builder, the object is fetched from the database.
  3426. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3427. func (m *MessageMutation) OldContent(ctx context.Context) (v string, err error) {
  3428. if !m.op.Is(OpUpdateOne) {
  3429. return v, errors.New("OldContent is only allowed on UpdateOne operations")
  3430. }
  3431. if m.id == nil || m.oldValue == nil {
  3432. return v, errors.New("OldContent requires an ID field in the mutation")
  3433. }
  3434. oldValue, err := m.oldValue(ctx)
  3435. if err != nil {
  3436. return v, fmt.Errorf("querying old value for OldContent: %w", err)
  3437. }
  3438. return oldValue.Content, nil
  3439. }
  3440. // ResetContent resets all changes to the "content" field.
  3441. func (m *MessageMutation) ResetContent() {
  3442. m.content = nil
  3443. }
  3444. // Where appends a list predicates to the MessageMutation builder.
  3445. func (m *MessageMutation) Where(ps ...predicate.Message) {
  3446. m.predicates = append(m.predicates, ps...)
  3447. }
  3448. // WhereP appends storage-level predicates to the MessageMutation builder. Using this method,
  3449. // users can use type-assertion to append predicates that do not depend on any generated package.
  3450. func (m *MessageMutation) WhereP(ps ...func(*sql.Selector)) {
  3451. p := make([]predicate.Message, len(ps))
  3452. for i := range ps {
  3453. p[i] = ps[i]
  3454. }
  3455. m.Where(p...)
  3456. }
  3457. // Op returns the operation name.
  3458. func (m *MessageMutation) Op() Op {
  3459. return m.op
  3460. }
  3461. // SetOp allows setting the mutation operation.
  3462. func (m *MessageMutation) SetOp(op Op) {
  3463. m.op = op
  3464. }
  3465. // Type returns the node type of this mutation (Message).
  3466. func (m *MessageMutation) Type() string {
  3467. return m.typ
  3468. }
  3469. // Fields returns all fields that were changed during this mutation. Note that in
  3470. // order to get all numeric fields that were incremented/decremented, call
  3471. // AddedFields().
  3472. func (m *MessageMutation) Fields() []string {
  3473. fields := make([]string, 0, 3)
  3474. if m.wx_wxid != nil {
  3475. fields = append(fields, message.FieldWxWxid)
  3476. }
  3477. if m.wxid != nil {
  3478. fields = append(fields, message.FieldWxid)
  3479. }
  3480. if m.content != nil {
  3481. fields = append(fields, message.FieldContent)
  3482. }
  3483. return fields
  3484. }
  3485. // Field returns the value of a field with the given name. The second boolean
  3486. // return value indicates that this field was not set, or was not defined in the
  3487. // schema.
  3488. func (m *MessageMutation) Field(name string) (ent.Value, bool) {
  3489. switch name {
  3490. case message.FieldWxWxid:
  3491. return m.WxWxid()
  3492. case message.FieldWxid:
  3493. return m.Wxid()
  3494. case message.FieldContent:
  3495. return m.Content()
  3496. }
  3497. return nil, false
  3498. }
  3499. // OldField returns the old value of the field from the database. An error is
  3500. // returned if the mutation operation is not UpdateOne, or the query to the
  3501. // database failed.
  3502. func (m *MessageMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  3503. switch name {
  3504. case message.FieldWxWxid:
  3505. return m.OldWxWxid(ctx)
  3506. case message.FieldWxid:
  3507. return m.OldWxid(ctx)
  3508. case message.FieldContent:
  3509. return m.OldContent(ctx)
  3510. }
  3511. return nil, fmt.Errorf("unknown Message field %s", name)
  3512. }
  3513. // SetField sets the value of a field with the given name. It returns an error if
  3514. // the field is not defined in the schema, or if the type mismatched the field
  3515. // type.
  3516. func (m *MessageMutation) SetField(name string, value ent.Value) error {
  3517. switch name {
  3518. case message.FieldWxWxid:
  3519. v, ok := value.(string)
  3520. if !ok {
  3521. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3522. }
  3523. m.SetWxWxid(v)
  3524. return nil
  3525. case message.FieldWxid:
  3526. v, ok := value.(string)
  3527. if !ok {
  3528. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3529. }
  3530. m.SetWxid(v)
  3531. return nil
  3532. case message.FieldContent:
  3533. v, ok := value.(string)
  3534. if !ok {
  3535. return fmt.Errorf("unexpected type %T for field %s", value, name)
  3536. }
  3537. m.SetContent(v)
  3538. return nil
  3539. }
  3540. return fmt.Errorf("unknown Message field %s", name)
  3541. }
  3542. // AddedFields returns all numeric fields that were incremented/decremented during
  3543. // this mutation.
  3544. func (m *MessageMutation) AddedFields() []string {
  3545. return nil
  3546. }
  3547. // AddedField returns the numeric value that was incremented/decremented on a field
  3548. // with the given name. The second boolean return value indicates that this field
  3549. // was not set, or was not defined in the schema.
  3550. func (m *MessageMutation) AddedField(name string) (ent.Value, bool) {
  3551. return nil, false
  3552. }
  3553. // AddField adds the value to the field with the given name. It returns an error if
  3554. // the field is not defined in the schema, or if the type mismatched the field
  3555. // type.
  3556. func (m *MessageMutation) AddField(name string, value ent.Value) error {
  3557. switch name {
  3558. }
  3559. return fmt.Errorf("unknown Message numeric field %s", name)
  3560. }
  3561. // ClearedFields returns all nullable fields that were cleared during this
  3562. // mutation.
  3563. func (m *MessageMutation) ClearedFields() []string {
  3564. var fields []string
  3565. if m.FieldCleared(message.FieldWxWxid) {
  3566. fields = append(fields, message.FieldWxWxid)
  3567. }
  3568. return fields
  3569. }
  3570. // FieldCleared returns a boolean indicating if a field with the given name was
  3571. // cleared in this mutation.
  3572. func (m *MessageMutation) FieldCleared(name string) bool {
  3573. _, ok := m.clearedFields[name]
  3574. return ok
  3575. }
  3576. // ClearField clears the value of the field with the given name. It returns an
  3577. // error if the field is not defined in the schema.
  3578. func (m *MessageMutation) ClearField(name string) error {
  3579. switch name {
  3580. case message.FieldWxWxid:
  3581. m.ClearWxWxid()
  3582. return nil
  3583. }
  3584. return fmt.Errorf("unknown Message nullable field %s", name)
  3585. }
  3586. // ResetField resets all changes in the mutation for the field with the given name.
  3587. // It returns an error if the field is not defined in the schema.
  3588. func (m *MessageMutation) ResetField(name string) error {
  3589. switch name {
  3590. case message.FieldWxWxid:
  3591. m.ResetWxWxid()
  3592. return nil
  3593. case message.FieldWxid:
  3594. m.ResetWxid()
  3595. return nil
  3596. case message.FieldContent:
  3597. m.ResetContent()
  3598. return nil
  3599. }
  3600. return fmt.Errorf("unknown Message field %s", name)
  3601. }
  3602. // AddedEdges returns all edge names that were set/added in this mutation.
  3603. func (m *MessageMutation) AddedEdges() []string {
  3604. edges := make([]string, 0, 0)
  3605. return edges
  3606. }
  3607. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  3608. // name in this mutation.
  3609. func (m *MessageMutation) AddedIDs(name string) []ent.Value {
  3610. return nil
  3611. }
  3612. // RemovedEdges returns all edge names that were removed in this mutation.
  3613. func (m *MessageMutation) RemovedEdges() []string {
  3614. edges := make([]string, 0, 0)
  3615. return edges
  3616. }
  3617. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  3618. // the given name in this mutation.
  3619. func (m *MessageMutation) RemovedIDs(name string) []ent.Value {
  3620. return nil
  3621. }
  3622. // ClearedEdges returns all edge names that were cleared in this mutation.
  3623. func (m *MessageMutation) ClearedEdges() []string {
  3624. edges := make([]string, 0, 0)
  3625. return edges
  3626. }
  3627. // EdgeCleared returns a boolean which indicates if the edge with the given name
  3628. // was cleared in this mutation.
  3629. func (m *MessageMutation) EdgeCleared(name string) bool {
  3630. return false
  3631. }
  3632. // ClearEdge clears the value of the edge with the given name. It returns an error
  3633. // if that edge is not defined in the schema.
  3634. func (m *MessageMutation) ClearEdge(name string) error {
  3635. return fmt.Errorf("unknown Message unique edge %s", name)
  3636. }
  3637. // ResetEdge resets all changes to the edge with the given name in this mutation.
  3638. // It returns an error if the edge is not defined in the schema.
  3639. func (m *MessageMutation) ResetEdge(name string) error {
  3640. return fmt.Errorf("unknown Message edge %s", name)
  3641. }
  3642. // ServerMutation represents an operation that mutates the Server nodes in the graph.
  3643. type ServerMutation struct {
  3644. config
  3645. op Op
  3646. typ string
  3647. id *uint64
  3648. created_at *time.Time
  3649. updated_at *time.Time
  3650. status *uint8
  3651. addstatus *int8
  3652. deleted_at *time.Time
  3653. name *string
  3654. public_ip *string
  3655. private_ip *string
  3656. admin_port *string
  3657. clearedFields map[string]struct{}
  3658. wxs map[uint64]struct{}
  3659. removedwxs map[uint64]struct{}
  3660. clearedwxs bool
  3661. done bool
  3662. oldValue func(context.Context) (*Server, error)
  3663. predicates []predicate.Server
  3664. }
  3665. var _ ent.Mutation = (*ServerMutation)(nil)
  3666. // serverOption allows management of the mutation configuration using functional options.
  3667. type serverOption func(*ServerMutation)
  3668. // newServerMutation creates new mutation for the Server entity.
  3669. func newServerMutation(c config, op Op, opts ...serverOption) *ServerMutation {
  3670. m := &ServerMutation{
  3671. config: c,
  3672. op: op,
  3673. typ: TypeServer,
  3674. clearedFields: make(map[string]struct{}),
  3675. }
  3676. for _, opt := range opts {
  3677. opt(m)
  3678. }
  3679. return m
  3680. }
  3681. // withServerID sets the ID field of the mutation.
  3682. func withServerID(id uint64) serverOption {
  3683. return func(m *ServerMutation) {
  3684. var (
  3685. err error
  3686. once sync.Once
  3687. value *Server
  3688. )
  3689. m.oldValue = func(ctx context.Context) (*Server, error) {
  3690. once.Do(func() {
  3691. if m.done {
  3692. err = errors.New("querying old values post mutation is not allowed")
  3693. } else {
  3694. value, err = m.Client().Server.Get(ctx, id)
  3695. }
  3696. })
  3697. return value, err
  3698. }
  3699. m.id = &id
  3700. }
  3701. }
  3702. // withServer sets the old Server of the mutation.
  3703. func withServer(node *Server) serverOption {
  3704. return func(m *ServerMutation) {
  3705. m.oldValue = func(context.Context) (*Server, error) {
  3706. return node, nil
  3707. }
  3708. m.id = &node.ID
  3709. }
  3710. }
  3711. // Client returns a new `ent.Client` from the mutation. If the mutation was
  3712. // executed in a transaction (ent.Tx), a transactional client is returned.
  3713. func (m ServerMutation) Client() *Client {
  3714. client := &Client{config: m.config}
  3715. client.init()
  3716. return client
  3717. }
  3718. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  3719. // it returns an error otherwise.
  3720. func (m ServerMutation) Tx() (*Tx, error) {
  3721. if _, ok := m.driver.(*txDriver); !ok {
  3722. return nil, errors.New("ent: mutation is not running in a transaction")
  3723. }
  3724. tx := &Tx{config: m.config}
  3725. tx.init()
  3726. return tx, nil
  3727. }
  3728. // SetID sets the value of the id field. Note that this
  3729. // operation is only accepted on creation of Server entities.
  3730. func (m *ServerMutation) SetID(id uint64) {
  3731. m.id = &id
  3732. }
  3733. // ID returns the ID value in the mutation. Note that the ID is only available
  3734. // if it was provided to the builder or after it was returned from the database.
  3735. func (m *ServerMutation) ID() (id uint64, exists bool) {
  3736. if m.id == nil {
  3737. return
  3738. }
  3739. return *m.id, true
  3740. }
  3741. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  3742. // That means, if the mutation is applied within a transaction with an isolation level such
  3743. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  3744. // or updated by the mutation.
  3745. func (m *ServerMutation) IDs(ctx context.Context) ([]uint64, error) {
  3746. switch {
  3747. case m.op.Is(OpUpdateOne | OpDeleteOne):
  3748. id, exists := m.ID()
  3749. if exists {
  3750. return []uint64{id}, nil
  3751. }
  3752. fallthrough
  3753. case m.op.Is(OpUpdate | OpDelete):
  3754. return m.Client().Server.Query().Where(m.predicates...).IDs(ctx)
  3755. default:
  3756. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  3757. }
  3758. }
  3759. // SetCreatedAt sets the "created_at" field.
  3760. func (m *ServerMutation) SetCreatedAt(t time.Time) {
  3761. m.created_at = &t
  3762. }
  3763. // CreatedAt returns the value of the "created_at" field in the mutation.
  3764. func (m *ServerMutation) CreatedAt() (r time.Time, exists bool) {
  3765. v := m.created_at
  3766. if v == nil {
  3767. return
  3768. }
  3769. return *v, true
  3770. }
  3771. // OldCreatedAt returns the old "created_at" field's value of the Server entity.
  3772. // If the Server object wasn't provided to the builder, the object is fetched from the database.
  3773. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3774. func (m *ServerMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  3775. if !m.op.Is(OpUpdateOne) {
  3776. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  3777. }
  3778. if m.id == nil || m.oldValue == nil {
  3779. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  3780. }
  3781. oldValue, err := m.oldValue(ctx)
  3782. if err != nil {
  3783. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  3784. }
  3785. return oldValue.CreatedAt, nil
  3786. }
  3787. // ResetCreatedAt resets all changes to the "created_at" field.
  3788. func (m *ServerMutation) ResetCreatedAt() {
  3789. m.created_at = nil
  3790. }
  3791. // SetUpdatedAt sets the "updated_at" field.
  3792. func (m *ServerMutation) SetUpdatedAt(t time.Time) {
  3793. m.updated_at = &t
  3794. }
  3795. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  3796. func (m *ServerMutation) UpdatedAt() (r time.Time, exists bool) {
  3797. v := m.updated_at
  3798. if v == nil {
  3799. return
  3800. }
  3801. return *v, true
  3802. }
  3803. // OldUpdatedAt returns the old "updated_at" field's value of the Server entity.
  3804. // If the Server object wasn't provided to the builder, the object is fetched from the database.
  3805. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3806. func (m *ServerMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  3807. if !m.op.Is(OpUpdateOne) {
  3808. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  3809. }
  3810. if m.id == nil || m.oldValue == nil {
  3811. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  3812. }
  3813. oldValue, err := m.oldValue(ctx)
  3814. if err != nil {
  3815. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  3816. }
  3817. return oldValue.UpdatedAt, nil
  3818. }
  3819. // ResetUpdatedAt resets all changes to the "updated_at" field.
  3820. func (m *ServerMutation) ResetUpdatedAt() {
  3821. m.updated_at = nil
  3822. }
  3823. // SetStatus sets the "status" field.
  3824. func (m *ServerMutation) SetStatus(u uint8) {
  3825. m.status = &u
  3826. m.addstatus = nil
  3827. }
  3828. // Status returns the value of the "status" field in the mutation.
  3829. func (m *ServerMutation) Status() (r uint8, exists bool) {
  3830. v := m.status
  3831. if v == nil {
  3832. return
  3833. }
  3834. return *v, true
  3835. }
  3836. // OldStatus returns the old "status" field's value of the Server entity.
  3837. // If the Server object wasn't provided to the builder, the object is fetched from the database.
  3838. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3839. func (m *ServerMutation) OldStatus(ctx context.Context) (v uint8, err error) {
  3840. if !m.op.Is(OpUpdateOne) {
  3841. return v, errors.New("OldStatus is only allowed on UpdateOne operations")
  3842. }
  3843. if m.id == nil || m.oldValue == nil {
  3844. return v, errors.New("OldStatus requires an ID field in the mutation")
  3845. }
  3846. oldValue, err := m.oldValue(ctx)
  3847. if err != nil {
  3848. return v, fmt.Errorf("querying old value for OldStatus: %w", err)
  3849. }
  3850. return oldValue.Status, nil
  3851. }
  3852. // AddStatus adds u to the "status" field.
  3853. func (m *ServerMutation) AddStatus(u int8) {
  3854. if m.addstatus != nil {
  3855. *m.addstatus += u
  3856. } else {
  3857. m.addstatus = &u
  3858. }
  3859. }
  3860. // AddedStatus returns the value that was added to the "status" field in this mutation.
  3861. func (m *ServerMutation) AddedStatus() (r int8, exists bool) {
  3862. v := m.addstatus
  3863. if v == nil {
  3864. return
  3865. }
  3866. return *v, true
  3867. }
  3868. // ClearStatus clears the value of the "status" field.
  3869. func (m *ServerMutation) ClearStatus() {
  3870. m.status = nil
  3871. m.addstatus = nil
  3872. m.clearedFields[server.FieldStatus] = struct{}{}
  3873. }
  3874. // StatusCleared returns if the "status" field was cleared in this mutation.
  3875. func (m *ServerMutation) StatusCleared() bool {
  3876. _, ok := m.clearedFields[server.FieldStatus]
  3877. return ok
  3878. }
  3879. // ResetStatus resets all changes to the "status" field.
  3880. func (m *ServerMutation) ResetStatus() {
  3881. m.status = nil
  3882. m.addstatus = nil
  3883. delete(m.clearedFields, server.FieldStatus)
  3884. }
  3885. // SetDeletedAt sets the "deleted_at" field.
  3886. func (m *ServerMutation) SetDeletedAt(t time.Time) {
  3887. m.deleted_at = &t
  3888. }
  3889. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  3890. func (m *ServerMutation) DeletedAt() (r time.Time, exists bool) {
  3891. v := m.deleted_at
  3892. if v == nil {
  3893. return
  3894. }
  3895. return *v, true
  3896. }
  3897. // OldDeletedAt returns the old "deleted_at" field's value of the Server entity.
  3898. // If the Server object wasn't provided to the builder, the object is fetched from the database.
  3899. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3900. func (m *ServerMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  3901. if !m.op.Is(OpUpdateOne) {
  3902. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  3903. }
  3904. if m.id == nil || m.oldValue == nil {
  3905. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  3906. }
  3907. oldValue, err := m.oldValue(ctx)
  3908. if err != nil {
  3909. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  3910. }
  3911. return oldValue.DeletedAt, nil
  3912. }
  3913. // ClearDeletedAt clears the value of the "deleted_at" field.
  3914. func (m *ServerMutation) ClearDeletedAt() {
  3915. m.deleted_at = nil
  3916. m.clearedFields[server.FieldDeletedAt] = struct{}{}
  3917. }
  3918. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  3919. func (m *ServerMutation) DeletedAtCleared() bool {
  3920. _, ok := m.clearedFields[server.FieldDeletedAt]
  3921. return ok
  3922. }
  3923. // ResetDeletedAt resets all changes to the "deleted_at" field.
  3924. func (m *ServerMutation) ResetDeletedAt() {
  3925. m.deleted_at = nil
  3926. delete(m.clearedFields, server.FieldDeletedAt)
  3927. }
  3928. // SetName sets the "name" field.
  3929. func (m *ServerMutation) SetName(s string) {
  3930. m.name = &s
  3931. }
  3932. // Name returns the value of the "name" field in the mutation.
  3933. func (m *ServerMutation) Name() (r string, exists bool) {
  3934. v := m.name
  3935. if v == nil {
  3936. return
  3937. }
  3938. return *v, true
  3939. }
  3940. // OldName returns the old "name" field's value of the Server entity.
  3941. // If the Server object wasn't provided to the builder, the object is fetched from the database.
  3942. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3943. func (m *ServerMutation) OldName(ctx context.Context) (v string, err error) {
  3944. if !m.op.Is(OpUpdateOne) {
  3945. return v, errors.New("OldName is only allowed on UpdateOne operations")
  3946. }
  3947. if m.id == nil || m.oldValue == nil {
  3948. return v, errors.New("OldName requires an ID field in the mutation")
  3949. }
  3950. oldValue, err := m.oldValue(ctx)
  3951. if err != nil {
  3952. return v, fmt.Errorf("querying old value for OldName: %w", err)
  3953. }
  3954. return oldValue.Name, nil
  3955. }
  3956. // ResetName resets all changes to the "name" field.
  3957. func (m *ServerMutation) ResetName() {
  3958. m.name = nil
  3959. }
  3960. // SetPublicIP sets the "public_ip" field.
  3961. func (m *ServerMutation) SetPublicIP(s string) {
  3962. m.public_ip = &s
  3963. }
  3964. // PublicIP returns the value of the "public_ip" field in the mutation.
  3965. func (m *ServerMutation) PublicIP() (r string, exists bool) {
  3966. v := m.public_ip
  3967. if v == nil {
  3968. return
  3969. }
  3970. return *v, true
  3971. }
  3972. // OldPublicIP returns the old "public_ip" field's value of the Server entity.
  3973. // If the Server object wasn't provided to the builder, the object is fetched from the database.
  3974. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3975. func (m *ServerMutation) OldPublicIP(ctx context.Context) (v string, err error) {
  3976. if !m.op.Is(OpUpdateOne) {
  3977. return v, errors.New("OldPublicIP is only allowed on UpdateOne operations")
  3978. }
  3979. if m.id == nil || m.oldValue == nil {
  3980. return v, errors.New("OldPublicIP requires an ID field in the mutation")
  3981. }
  3982. oldValue, err := m.oldValue(ctx)
  3983. if err != nil {
  3984. return v, fmt.Errorf("querying old value for OldPublicIP: %w", err)
  3985. }
  3986. return oldValue.PublicIP, nil
  3987. }
  3988. // ResetPublicIP resets all changes to the "public_ip" field.
  3989. func (m *ServerMutation) ResetPublicIP() {
  3990. m.public_ip = nil
  3991. }
  3992. // SetPrivateIP sets the "private_ip" field.
  3993. func (m *ServerMutation) SetPrivateIP(s string) {
  3994. m.private_ip = &s
  3995. }
  3996. // PrivateIP returns the value of the "private_ip" field in the mutation.
  3997. func (m *ServerMutation) PrivateIP() (r string, exists bool) {
  3998. v := m.private_ip
  3999. if v == nil {
  4000. return
  4001. }
  4002. return *v, true
  4003. }
  4004. // OldPrivateIP returns the old "private_ip" field's value of the Server entity.
  4005. // If the Server object wasn't provided to the builder, the object is fetched from the database.
  4006. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4007. func (m *ServerMutation) OldPrivateIP(ctx context.Context) (v string, err error) {
  4008. if !m.op.Is(OpUpdateOne) {
  4009. return v, errors.New("OldPrivateIP is only allowed on UpdateOne operations")
  4010. }
  4011. if m.id == nil || m.oldValue == nil {
  4012. return v, errors.New("OldPrivateIP requires an ID field in the mutation")
  4013. }
  4014. oldValue, err := m.oldValue(ctx)
  4015. if err != nil {
  4016. return v, fmt.Errorf("querying old value for OldPrivateIP: %w", err)
  4017. }
  4018. return oldValue.PrivateIP, nil
  4019. }
  4020. // ResetPrivateIP resets all changes to the "private_ip" field.
  4021. func (m *ServerMutation) ResetPrivateIP() {
  4022. m.private_ip = nil
  4023. }
  4024. // SetAdminPort sets the "admin_port" field.
  4025. func (m *ServerMutation) SetAdminPort(s string) {
  4026. m.admin_port = &s
  4027. }
  4028. // AdminPort returns the value of the "admin_port" field in the mutation.
  4029. func (m *ServerMutation) AdminPort() (r string, exists bool) {
  4030. v := m.admin_port
  4031. if v == nil {
  4032. return
  4033. }
  4034. return *v, true
  4035. }
  4036. // OldAdminPort returns the old "admin_port" field's value of the Server entity.
  4037. // If the Server object wasn't provided to the builder, the object is fetched from the database.
  4038. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4039. func (m *ServerMutation) OldAdminPort(ctx context.Context) (v string, err error) {
  4040. if !m.op.Is(OpUpdateOne) {
  4041. return v, errors.New("OldAdminPort is only allowed on UpdateOne operations")
  4042. }
  4043. if m.id == nil || m.oldValue == nil {
  4044. return v, errors.New("OldAdminPort requires an ID field in the mutation")
  4045. }
  4046. oldValue, err := m.oldValue(ctx)
  4047. if err != nil {
  4048. return v, fmt.Errorf("querying old value for OldAdminPort: %w", err)
  4049. }
  4050. return oldValue.AdminPort, nil
  4051. }
  4052. // ResetAdminPort resets all changes to the "admin_port" field.
  4053. func (m *ServerMutation) ResetAdminPort() {
  4054. m.admin_port = nil
  4055. }
  4056. // AddWxIDs adds the "wxs" edge to the Wx entity by ids.
  4057. func (m *ServerMutation) AddWxIDs(ids ...uint64) {
  4058. if m.wxs == nil {
  4059. m.wxs = make(map[uint64]struct{})
  4060. }
  4061. for i := range ids {
  4062. m.wxs[ids[i]] = struct{}{}
  4063. }
  4064. }
  4065. // ClearWxs clears the "wxs" edge to the Wx entity.
  4066. func (m *ServerMutation) ClearWxs() {
  4067. m.clearedwxs = true
  4068. }
  4069. // WxsCleared reports if the "wxs" edge to the Wx entity was cleared.
  4070. func (m *ServerMutation) WxsCleared() bool {
  4071. return m.clearedwxs
  4072. }
  4073. // RemoveWxIDs removes the "wxs" edge to the Wx entity by IDs.
  4074. func (m *ServerMutation) RemoveWxIDs(ids ...uint64) {
  4075. if m.removedwxs == nil {
  4076. m.removedwxs = make(map[uint64]struct{})
  4077. }
  4078. for i := range ids {
  4079. delete(m.wxs, ids[i])
  4080. m.removedwxs[ids[i]] = struct{}{}
  4081. }
  4082. }
  4083. // RemovedWxs returns the removed IDs of the "wxs" edge to the Wx entity.
  4084. func (m *ServerMutation) RemovedWxsIDs() (ids []uint64) {
  4085. for id := range m.removedwxs {
  4086. ids = append(ids, id)
  4087. }
  4088. return
  4089. }
  4090. // WxsIDs returns the "wxs" edge IDs in the mutation.
  4091. func (m *ServerMutation) WxsIDs() (ids []uint64) {
  4092. for id := range m.wxs {
  4093. ids = append(ids, id)
  4094. }
  4095. return
  4096. }
  4097. // ResetWxs resets all changes to the "wxs" edge.
  4098. func (m *ServerMutation) ResetWxs() {
  4099. m.wxs = nil
  4100. m.clearedwxs = false
  4101. m.removedwxs = nil
  4102. }
  4103. // Where appends a list predicates to the ServerMutation builder.
  4104. func (m *ServerMutation) Where(ps ...predicate.Server) {
  4105. m.predicates = append(m.predicates, ps...)
  4106. }
  4107. // WhereP appends storage-level predicates to the ServerMutation builder. Using this method,
  4108. // users can use type-assertion to append predicates that do not depend on any generated package.
  4109. func (m *ServerMutation) WhereP(ps ...func(*sql.Selector)) {
  4110. p := make([]predicate.Server, len(ps))
  4111. for i := range ps {
  4112. p[i] = ps[i]
  4113. }
  4114. m.Where(p...)
  4115. }
  4116. // Op returns the operation name.
  4117. func (m *ServerMutation) Op() Op {
  4118. return m.op
  4119. }
  4120. // SetOp allows setting the mutation operation.
  4121. func (m *ServerMutation) SetOp(op Op) {
  4122. m.op = op
  4123. }
  4124. // Type returns the node type of this mutation (Server).
  4125. func (m *ServerMutation) Type() string {
  4126. return m.typ
  4127. }
  4128. // Fields returns all fields that were changed during this mutation. Note that in
  4129. // order to get all numeric fields that were incremented/decremented, call
  4130. // AddedFields().
  4131. func (m *ServerMutation) Fields() []string {
  4132. fields := make([]string, 0, 8)
  4133. if m.created_at != nil {
  4134. fields = append(fields, server.FieldCreatedAt)
  4135. }
  4136. if m.updated_at != nil {
  4137. fields = append(fields, server.FieldUpdatedAt)
  4138. }
  4139. if m.status != nil {
  4140. fields = append(fields, server.FieldStatus)
  4141. }
  4142. if m.deleted_at != nil {
  4143. fields = append(fields, server.FieldDeletedAt)
  4144. }
  4145. if m.name != nil {
  4146. fields = append(fields, server.FieldName)
  4147. }
  4148. if m.public_ip != nil {
  4149. fields = append(fields, server.FieldPublicIP)
  4150. }
  4151. if m.private_ip != nil {
  4152. fields = append(fields, server.FieldPrivateIP)
  4153. }
  4154. if m.admin_port != nil {
  4155. fields = append(fields, server.FieldAdminPort)
  4156. }
  4157. return fields
  4158. }
  4159. // Field returns the value of a field with the given name. The second boolean
  4160. // return value indicates that this field was not set, or was not defined in the
  4161. // schema.
  4162. func (m *ServerMutation) Field(name string) (ent.Value, bool) {
  4163. switch name {
  4164. case server.FieldCreatedAt:
  4165. return m.CreatedAt()
  4166. case server.FieldUpdatedAt:
  4167. return m.UpdatedAt()
  4168. case server.FieldStatus:
  4169. return m.Status()
  4170. case server.FieldDeletedAt:
  4171. return m.DeletedAt()
  4172. case server.FieldName:
  4173. return m.Name()
  4174. case server.FieldPublicIP:
  4175. return m.PublicIP()
  4176. case server.FieldPrivateIP:
  4177. return m.PrivateIP()
  4178. case server.FieldAdminPort:
  4179. return m.AdminPort()
  4180. }
  4181. return nil, false
  4182. }
  4183. // OldField returns the old value of the field from the database. An error is
  4184. // returned if the mutation operation is not UpdateOne, or the query to the
  4185. // database failed.
  4186. func (m *ServerMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  4187. switch name {
  4188. case server.FieldCreatedAt:
  4189. return m.OldCreatedAt(ctx)
  4190. case server.FieldUpdatedAt:
  4191. return m.OldUpdatedAt(ctx)
  4192. case server.FieldStatus:
  4193. return m.OldStatus(ctx)
  4194. case server.FieldDeletedAt:
  4195. return m.OldDeletedAt(ctx)
  4196. case server.FieldName:
  4197. return m.OldName(ctx)
  4198. case server.FieldPublicIP:
  4199. return m.OldPublicIP(ctx)
  4200. case server.FieldPrivateIP:
  4201. return m.OldPrivateIP(ctx)
  4202. case server.FieldAdminPort:
  4203. return m.OldAdminPort(ctx)
  4204. }
  4205. return nil, fmt.Errorf("unknown Server field %s", name)
  4206. }
  4207. // SetField sets the value of a field with the given name. It returns an error if
  4208. // the field is not defined in the schema, or if the type mismatched the field
  4209. // type.
  4210. func (m *ServerMutation) SetField(name string, value ent.Value) error {
  4211. switch name {
  4212. case server.FieldCreatedAt:
  4213. v, ok := value.(time.Time)
  4214. if !ok {
  4215. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4216. }
  4217. m.SetCreatedAt(v)
  4218. return nil
  4219. case server.FieldUpdatedAt:
  4220. v, ok := value.(time.Time)
  4221. if !ok {
  4222. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4223. }
  4224. m.SetUpdatedAt(v)
  4225. return nil
  4226. case server.FieldStatus:
  4227. v, ok := value.(uint8)
  4228. if !ok {
  4229. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4230. }
  4231. m.SetStatus(v)
  4232. return nil
  4233. case server.FieldDeletedAt:
  4234. v, ok := value.(time.Time)
  4235. if !ok {
  4236. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4237. }
  4238. m.SetDeletedAt(v)
  4239. return nil
  4240. case server.FieldName:
  4241. v, ok := value.(string)
  4242. if !ok {
  4243. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4244. }
  4245. m.SetName(v)
  4246. return nil
  4247. case server.FieldPublicIP:
  4248. v, ok := value.(string)
  4249. if !ok {
  4250. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4251. }
  4252. m.SetPublicIP(v)
  4253. return nil
  4254. case server.FieldPrivateIP:
  4255. v, ok := value.(string)
  4256. if !ok {
  4257. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4258. }
  4259. m.SetPrivateIP(v)
  4260. return nil
  4261. case server.FieldAdminPort:
  4262. v, ok := value.(string)
  4263. if !ok {
  4264. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4265. }
  4266. m.SetAdminPort(v)
  4267. return nil
  4268. }
  4269. return fmt.Errorf("unknown Server field %s", name)
  4270. }
  4271. // AddedFields returns all numeric fields that were incremented/decremented during
  4272. // this mutation.
  4273. func (m *ServerMutation) AddedFields() []string {
  4274. var fields []string
  4275. if m.addstatus != nil {
  4276. fields = append(fields, server.FieldStatus)
  4277. }
  4278. return fields
  4279. }
  4280. // AddedField returns the numeric value that was incremented/decremented on a field
  4281. // with the given name. The second boolean return value indicates that this field
  4282. // was not set, or was not defined in the schema.
  4283. func (m *ServerMutation) AddedField(name string) (ent.Value, bool) {
  4284. switch name {
  4285. case server.FieldStatus:
  4286. return m.AddedStatus()
  4287. }
  4288. return nil, false
  4289. }
  4290. // AddField adds the value to the field with the given name. It returns an error if
  4291. // the field is not defined in the schema, or if the type mismatched the field
  4292. // type.
  4293. func (m *ServerMutation) AddField(name string, value ent.Value) error {
  4294. switch name {
  4295. case server.FieldStatus:
  4296. v, ok := value.(int8)
  4297. if !ok {
  4298. return fmt.Errorf("unexpected type %T for field %s", value, name)
  4299. }
  4300. m.AddStatus(v)
  4301. return nil
  4302. }
  4303. return fmt.Errorf("unknown Server numeric field %s", name)
  4304. }
  4305. // ClearedFields returns all nullable fields that were cleared during this
  4306. // mutation.
  4307. func (m *ServerMutation) ClearedFields() []string {
  4308. var fields []string
  4309. if m.FieldCleared(server.FieldStatus) {
  4310. fields = append(fields, server.FieldStatus)
  4311. }
  4312. if m.FieldCleared(server.FieldDeletedAt) {
  4313. fields = append(fields, server.FieldDeletedAt)
  4314. }
  4315. return fields
  4316. }
  4317. // FieldCleared returns a boolean indicating if a field with the given name was
  4318. // cleared in this mutation.
  4319. func (m *ServerMutation) FieldCleared(name string) bool {
  4320. _, ok := m.clearedFields[name]
  4321. return ok
  4322. }
  4323. // ClearField clears the value of the field with the given name. It returns an
  4324. // error if the field is not defined in the schema.
  4325. func (m *ServerMutation) ClearField(name string) error {
  4326. switch name {
  4327. case server.FieldStatus:
  4328. m.ClearStatus()
  4329. return nil
  4330. case server.FieldDeletedAt:
  4331. m.ClearDeletedAt()
  4332. return nil
  4333. }
  4334. return fmt.Errorf("unknown Server nullable field %s", name)
  4335. }
  4336. // ResetField resets all changes in the mutation for the field with the given name.
  4337. // It returns an error if the field is not defined in the schema.
  4338. func (m *ServerMutation) ResetField(name string) error {
  4339. switch name {
  4340. case server.FieldCreatedAt:
  4341. m.ResetCreatedAt()
  4342. return nil
  4343. case server.FieldUpdatedAt:
  4344. m.ResetUpdatedAt()
  4345. return nil
  4346. case server.FieldStatus:
  4347. m.ResetStatus()
  4348. return nil
  4349. case server.FieldDeletedAt:
  4350. m.ResetDeletedAt()
  4351. return nil
  4352. case server.FieldName:
  4353. m.ResetName()
  4354. return nil
  4355. case server.FieldPublicIP:
  4356. m.ResetPublicIP()
  4357. return nil
  4358. case server.FieldPrivateIP:
  4359. m.ResetPrivateIP()
  4360. return nil
  4361. case server.FieldAdminPort:
  4362. m.ResetAdminPort()
  4363. return nil
  4364. }
  4365. return fmt.Errorf("unknown Server field %s", name)
  4366. }
  4367. // AddedEdges returns all edge names that were set/added in this mutation.
  4368. func (m *ServerMutation) AddedEdges() []string {
  4369. edges := make([]string, 0, 1)
  4370. if m.wxs != nil {
  4371. edges = append(edges, server.EdgeWxs)
  4372. }
  4373. return edges
  4374. }
  4375. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  4376. // name in this mutation.
  4377. func (m *ServerMutation) AddedIDs(name string) []ent.Value {
  4378. switch name {
  4379. case server.EdgeWxs:
  4380. ids := make([]ent.Value, 0, len(m.wxs))
  4381. for id := range m.wxs {
  4382. ids = append(ids, id)
  4383. }
  4384. return ids
  4385. }
  4386. return nil
  4387. }
  4388. // RemovedEdges returns all edge names that were removed in this mutation.
  4389. func (m *ServerMutation) RemovedEdges() []string {
  4390. edges := make([]string, 0, 1)
  4391. if m.removedwxs != nil {
  4392. edges = append(edges, server.EdgeWxs)
  4393. }
  4394. return edges
  4395. }
  4396. // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  4397. // the given name in this mutation.
  4398. func (m *ServerMutation) RemovedIDs(name string) []ent.Value {
  4399. switch name {
  4400. case server.EdgeWxs:
  4401. ids := make([]ent.Value, 0, len(m.removedwxs))
  4402. for id := range m.removedwxs {
  4403. ids = append(ids, id)
  4404. }
  4405. return ids
  4406. }
  4407. return nil
  4408. }
  4409. // ClearedEdges returns all edge names that were cleared in this mutation.
  4410. func (m *ServerMutation) ClearedEdges() []string {
  4411. edges := make([]string, 0, 1)
  4412. if m.clearedwxs {
  4413. edges = append(edges, server.EdgeWxs)
  4414. }
  4415. return edges
  4416. }
  4417. // EdgeCleared returns a boolean which indicates if the edge with the given name
  4418. // was cleared in this mutation.
  4419. func (m *ServerMutation) EdgeCleared(name string) bool {
  4420. switch name {
  4421. case server.EdgeWxs:
  4422. return m.clearedwxs
  4423. }
  4424. return false
  4425. }
  4426. // ClearEdge clears the value of the edge with the given name. It returns an error
  4427. // if that edge is not defined in the schema.
  4428. func (m *ServerMutation) ClearEdge(name string) error {
  4429. switch name {
  4430. }
  4431. return fmt.Errorf("unknown Server unique edge %s", name)
  4432. }
  4433. // ResetEdge resets all changes to the edge with the given name in this mutation.
  4434. // It returns an error if the edge is not defined in the schema.
  4435. func (m *ServerMutation) ResetEdge(name string) error {
  4436. switch name {
  4437. case server.EdgeWxs:
  4438. m.ResetWxs()
  4439. return nil
  4440. }
  4441. return fmt.Errorf("unknown Server edge %s", name)
  4442. }
  4443. // WxMutation represents an operation that mutates the Wx nodes in the graph.
  4444. type WxMutation struct {
  4445. config
  4446. op Op
  4447. typ string
  4448. id *uint64
  4449. created_at *time.Time
  4450. updated_at *time.Time
  4451. status *uint8
  4452. addstatus *int8
  4453. deleted_at *time.Time
  4454. port *string
  4455. process_id *string
  4456. callback *string
  4457. wxid *string
  4458. account *string
  4459. nickname *string
  4460. tel *string
  4461. head_big *string
  4462. clearedFields map[string]struct{}
  4463. server *uint64
  4464. clearedserver bool
  4465. done bool
  4466. oldValue func(context.Context) (*Wx, error)
  4467. predicates []predicate.Wx
  4468. }
  4469. var _ ent.Mutation = (*WxMutation)(nil)
  4470. // wxOption allows management of the mutation configuration using functional options.
  4471. type wxOption func(*WxMutation)
  4472. // newWxMutation creates new mutation for the Wx entity.
  4473. func newWxMutation(c config, op Op, opts ...wxOption) *WxMutation {
  4474. m := &WxMutation{
  4475. config: c,
  4476. op: op,
  4477. typ: TypeWx,
  4478. clearedFields: make(map[string]struct{}),
  4479. }
  4480. for _, opt := range opts {
  4481. opt(m)
  4482. }
  4483. return m
  4484. }
  4485. // withWxID sets the ID field of the mutation.
  4486. func withWxID(id uint64) wxOption {
  4487. return func(m *WxMutation) {
  4488. var (
  4489. err error
  4490. once sync.Once
  4491. value *Wx
  4492. )
  4493. m.oldValue = func(ctx context.Context) (*Wx, error) {
  4494. once.Do(func() {
  4495. if m.done {
  4496. err = errors.New("querying old values post mutation is not allowed")
  4497. } else {
  4498. value, err = m.Client().Wx.Get(ctx, id)
  4499. }
  4500. })
  4501. return value, err
  4502. }
  4503. m.id = &id
  4504. }
  4505. }
  4506. // withWx sets the old Wx of the mutation.
  4507. func withWx(node *Wx) wxOption {
  4508. return func(m *WxMutation) {
  4509. m.oldValue = func(context.Context) (*Wx, error) {
  4510. return node, nil
  4511. }
  4512. m.id = &node.ID
  4513. }
  4514. }
  4515. // Client returns a new `ent.Client` from the mutation. If the mutation was
  4516. // executed in a transaction (ent.Tx), a transactional client is returned.
  4517. func (m WxMutation) Client() *Client {
  4518. client := &Client{config: m.config}
  4519. client.init()
  4520. return client
  4521. }
  4522. // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  4523. // it returns an error otherwise.
  4524. func (m WxMutation) Tx() (*Tx, error) {
  4525. if _, ok := m.driver.(*txDriver); !ok {
  4526. return nil, errors.New("ent: mutation is not running in a transaction")
  4527. }
  4528. tx := &Tx{config: m.config}
  4529. tx.init()
  4530. return tx, nil
  4531. }
  4532. // SetID sets the value of the id field. Note that this
  4533. // operation is only accepted on creation of Wx entities.
  4534. func (m *WxMutation) SetID(id uint64) {
  4535. m.id = &id
  4536. }
  4537. // ID returns the ID value in the mutation. Note that the ID is only available
  4538. // if it was provided to the builder or after it was returned from the database.
  4539. func (m *WxMutation) ID() (id uint64, exists bool) {
  4540. if m.id == nil {
  4541. return
  4542. }
  4543. return *m.id, true
  4544. }
  4545. // IDs queries the database and returns the entity ids that match the mutation's predicate.
  4546. // That means, if the mutation is applied within a transaction with an isolation level such
  4547. // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  4548. // or updated by the mutation.
  4549. func (m *WxMutation) IDs(ctx context.Context) ([]uint64, error) {
  4550. switch {
  4551. case m.op.Is(OpUpdateOne | OpDeleteOne):
  4552. id, exists := m.ID()
  4553. if exists {
  4554. return []uint64{id}, nil
  4555. }
  4556. fallthrough
  4557. case m.op.Is(OpUpdate | OpDelete):
  4558. return m.Client().Wx.Query().Where(m.predicates...).IDs(ctx)
  4559. default:
  4560. return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  4561. }
  4562. }
  4563. // SetCreatedAt sets the "created_at" field.
  4564. func (m *WxMutation) SetCreatedAt(t time.Time) {
  4565. m.created_at = &t
  4566. }
  4567. // CreatedAt returns the value of the "created_at" field in the mutation.
  4568. func (m *WxMutation) CreatedAt() (r time.Time, exists bool) {
  4569. v := m.created_at
  4570. if v == nil {
  4571. return
  4572. }
  4573. return *v, true
  4574. }
  4575. // OldCreatedAt returns the old "created_at" field's value of the Wx entity.
  4576. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4577. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4578. func (m *WxMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  4579. if !m.op.Is(OpUpdateOne) {
  4580. return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  4581. }
  4582. if m.id == nil || m.oldValue == nil {
  4583. return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  4584. }
  4585. oldValue, err := m.oldValue(ctx)
  4586. if err != nil {
  4587. return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  4588. }
  4589. return oldValue.CreatedAt, nil
  4590. }
  4591. // ResetCreatedAt resets all changes to the "created_at" field.
  4592. func (m *WxMutation) ResetCreatedAt() {
  4593. m.created_at = nil
  4594. }
  4595. // SetUpdatedAt sets the "updated_at" field.
  4596. func (m *WxMutation) SetUpdatedAt(t time.Time) {
  4597. m.updated_at = &t
  4598. }
  4599. // UpdatedAt returns the value of the "updated_at" field in the mutation.
  4600. func (m *WxMutation) UpdatedAt() (r time.Time, exists bool) {
  4601. v := m.updated_at
  4602. if v == nil {
  4603. return
  4604. }
  4605. return *v, true
  4606. }
  4607. // OldUpdatedAt returns the old "updated_at" field's value of the Wx entity.
  4608. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4609. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4610. func (m *WxMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  4611. if !m.op.Is(OpUpdateOne) {
  4612. return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  4613. }
  4614. if m.id == nil || m.oldValue == nil {
  4615. return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  4616. }
  4617. oldValue, err := m.oldValue(ctx)
  4618. if err != nil {
  4619. return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  4620. }
  4621. return oldValue.UpdatedAt, nil
  4622. }
  4623. // ResetUpdatedAt resets all changes to the "updated_at" field.
  4624. func (m *WxMutation) ResetUpdatedAt() {
  4625. m.updated_at = nil
  4626. }
  4627. // SetStatus sets the "status" field.
  4628. func (m *WxMutation) SetStatus(u uint8) {
  4629. m.status = &u
  4630. m.addstatus = nil
  4631. }
  4632. // Status returns the value of the "status" field in the mutation.
  4633. func (m *WxMutation) Status() (r uint8, exists bool) {
  4634. v := m.status
  4635. if v == nil {
  4636. return
  4637. }
  4638. return *v, true
  4639. }
  4640. // OldStatus returns the old "status" field's value of the Wx entity.
  4641. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4642. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4643. func (m *WxMutation) OldStatus(ctx context.Context) (v uint8, err error) {
  4644. if !m.op.Is(OpUpdateOne) {
  4645. return v, errors.New("OldStatus is only allowed on UpdateOne operations")
  4646. }
  4647. if m.id == nil || m.oldValue == nil {
  4648. return v, errors.New("OldStatus requires an ID field in the mutation")
  4649. }
  4650. oldValue, err := m.oldValue(ctx)
  4651. if err != nil {
  4652. return v, fmt.Errorf("querying old value for OldStatus: %w", err)
  4653. }
  4654. return oldValue.Status, nil
  4655. }
  4656. // AddStatus adds u to the "status" field.
  4657. func (m *WxMutation) AddStatus(u int8) {
  4658. if m.addstatus != nil {
  4659. *m.addstatus += u
  4660. } else {
  4661. m.addstatus = &u
  4662. }
  4663. }
  4664. // AddedStatus returns the value that was added to the "status" field in this mutation.
  4665. func (m *WxMutation) AddedStatus() (r int8, exists bool) {
  4666. v := m.addstatus
  4667. if v == nil {
  4668. return
  4669. }
  4670. return *v, true
  4671. }
  4672. // ClearStatus clears the value of the "status" field.
  4673. func (m *WxMutation) ClearStatus() {
  4674. m.status = nil
  4675. m.addstatus = nil
  4676. m.clearedFields[wx.FieldStatus] = struct{}{}
  4677. }
  4678. // StatusCleared returns if the "status" field was cleared in this mutation.
  4679. func (m *WxMutation) StatusCleared() bool {
  4680. _, ok := m.clearedFields[wx.FieldStatus]
  4681. return ok
  4682. }
  4683. // ResetStatus resets all changes to the "status" field.
  4684. func (m *WxMutation) ResetStatus() {
  4685. m.status = nil
  4686. m.addstatus = nil
  4687. delete(m.clearedFields, wx.FieldStatus)
  4688. }
  4689. // SetDeletedAt sets the "deleted_at" field.
  4690. func (m *WxMutation) SetDeletedAt(t time.Time) {
  4691. m.deleted_at = &t
  4692. }
  4693. // DeletedAt returns the value of the "deleted_at" field in the mutation.
  4694. func (m *WxMutation) DeletedAt() (r time.Time, exists bool) {
  4695. v := m.deleted_at
  4696. if v == nil {
  4697. return
  4698. }
  4699. return *v, true
  4700. }
  4701. // OldDeletedAt returns the old "deleted_at" field's value of the Wx entity.
  4702. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4703. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4704. func (m *WxMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  4705. if !m.op.Is(OpUpdateOne) {
  4706. return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  4707. }
  4708. if m.id == nil || m.oldValue == nil {
  4709. return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  4710. }
  4711. oldValue, err := m.oldValue(ctx)
  4712. if err != nil {
  4713. return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  4714. }
  4715. return oldValue.DeletedAt, nil
  4716. }
  4717. // ClearDeletedAt clears the value of the "deleted_at" field.
  4718. func (m *WxMutation) ClearDeletedAt() {
  4719. m.deleted_at = nil
  4720. m.clearedFields[wx.FieldDeletedAt] = struct{}{}
  4721. }
  4722. // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  4723. func (m *WxMutation) DeletedAtCleared() bool {
  4724. _, ok := m.clearedFields[wx.FieldDeletedAt]
  4725. return ok
  4726. }
  4727. // ResetDeletedAt resets all changes to the "deleted_at" field.
  4728. func (m *WxMutation) ResetDeletedAt() {
  4729. m.deleted_at = nil
  4730. delete(m.clearedFields, wx.FieldDeletedAt)
  4731. }
  4732. // SetServerID sets the "server_id" field.
  4733. func (m *WxMutation) SetServerID(u uint64) {
  4734. m.server = &u
  4735. }
  4736. // ServerID returns the value of the "server_id" field in the mutation.
  4737. func (m *WxMutation) ServerID() (r uint64, exists bool) {
  4738. v := m.server
  4739. if v == nil {
  4740. return
  4741. }
  4742. return *v, true
  4743. }
  4744. // OldServerID returns the old "server_id" field's value of the Wx entity.
  4745. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4746. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4747. func (m *WxMutation) OldServerID(ctx context.Context) (v uint64, err error) {
  4748. if !m.op.Is(OpUpdateOne) {
  4749. return v, errors.New("OldServerID is only allowed on UpdateOne operations")
  4750. }
  4751. if m.id == nil || m.oldValue == nil {
  4752. return v, errors.New("OldServerID requires an ID field in the mutation")
  4753. }
  4754. oldValue, err := m.oldValue(ctx)
  4755. if err != nil {
  4756. return v, fmt.Errorf("querying old value for OldServerID: %w", err)
  4757. }
  4758. return oldValue.ServerID, nil
  4759. }
  4760. // ClearServerID clears the value of the "server_id" field.
  4761. func (m *WxMutation) ClearServerID() {
  4762. m.server = nil
  4763. m.clearedFields[wx.FieldServerID] = struct{}{}
  4764. }
  4765. // ServerIDCleared returns if the "server_id" field was cleared in this mutation.
  4766. func (m *WxMutation) ServerIDCleared() bool {
  4767. _, ok := m.clearedFields[wx.FieldServerID]
  4768. return ok
  4769. }
  4770. // ResetServerID resets all changes to the "server_id" field.
  4771. func (m *WxMutation) ResetServerID() {
  4772. m.server = nil
  4773. delete(m.clearedFields, wx.FieldServerID)
  4774. }
  4775. // SetPort sets the "port" field.
  4776. func (m *WxMutation) SetPort(s string) {
  4777. m.port = &s
  4778. }
  4779. // Port returns the value of the "port" field in the mutation.
  4780. func (m *WxMutation) Port() (r string, exists bool) {
  4781. v := m.port
  4782. if v == nil {
  4783. return
  4784. }
  4785. return *v, true
  4786. }
  4787. // OldPort returns the old "port" field's value of the Wx entity.
  4788. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4789. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4790. func (m *WxMutation) OldPort(ctx context.Context) (v string, err error) {
  4791. if !m.op.Is(OpUpdateOne) {
  4792. return v, errors.New("OldPort is only allowed on UpdateOne operations")
  4793. }
  4794. if m.id == nil || m.oldValue == nil {
  4795. return v, errors.New("OldPort requires an ID field in the mutation")
  4796. }
  4797. oldValue, err := m.oldValue(ctx)
  4798. if err != nil {
  4799. return v, fmt.Errorf("querying old value for OldPort: %w", err)
  4800. }
  4801. return oldValue.Port, nil
  4802. }
  4803. // ResetPort resets all changes to the "port" field.
  4804. func (m *WxMutation) ResetPort() {
  4805. m.port = nil
  4806. }
  4807. // SetProcessID sets the "process_id" field.
  4808. func (m *WxMutation) SetProcessID(s string) {
  4809. m.process_id = &s
  4810. }
  4811. // ProcessID returns the value of the "process_id" field in the mutation.
  4812. func (m *WxMutation) ProcessID() (r string, exists bool) {
  4813. v := m.process_id
  4814. if v == nil {
  4815. return
  4816. }
  4817. return *v, true
  4818. }
  4819. // OldProcessID returns the old "process_id" field's value of the Wx entity.
  4820. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4821. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4822. func (m *WxMutation) OldProcessID(ctx context.Context) (v string, err error) {
  4823. if !m.op.Is(OpUpdateOne) {
  4824. return v, errors.New("OldProcessID is only allowed on UpdateOne operations")
  4825. }
  4826. if m.id == nil || m.oldValue == nil {
  4827. return v, errors.New("OldProcessID requires an ID field in the mutation")
  4828. }
  4829. oldValue, err := m.oldValue(ctx)
  4830. if err != nil {
  4831. return v, fmt.Errorf("querying old value for OldProcessID: %w", err)
  4832. }
  4833. return oldValue.ProcessID, nil
  4834. }
  4835. // ResetProcessID resets all changes to the "process_id" field.
  4836. func (m *WxMutation) ResetProcessID() {
  4837. m.process_id = nil
  4838. }
  4839. // SetCallback sets the "callback" field.
  4840. func (m *WxMutation) SetCallback(s string) {
  4841. m.callback = &s
  4842. }
  4843. // Callback returns the value of the "callback" field in the mutation.
  4844. func (m *WxMutation) Callback() (r string, exists bool) {
  4845. v := m.callback
  4846. if v == nil {
  4847. return
  4848. }
  4849. return *v, true
  4850. }
  4851. // OldCallback returns the old "callback" field's value of the Wx entity.
  4852. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4853. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4854. func (m *WxMutation) OldCallback(ctx context.Context) (v string, err error) {
  4855. if !m.op.Is(OpUpdateOne) {
  4856. return v, errors.New("OldCallback is only allowed on UpdateOne operations")
  4857. }
  4858. if m.id == nil || m.oldValue == nil {
  4859. return v, errors.New("OldCallback requires an ID field in the mutation")
  4860. }
  4861. oldValue, err := m.oldValue(ctx)
  4862. if err != nil {
  4863. return v, fmt.Errorf("querying old value for OldCallback: %w", err)
  4864. }
  4865. return oldValue.Callback, nil
  4866. }
  4867. // ResetCallback resets all changes to the "callback" field.
  4868. func (m *WxMutation) ResetCallback() {
  4869. m.callback = nil
  4870. }
  4871. // SetWxid sets the "wxid" field.
  4872. func (m *WxMutation) SetWxid(s string) {
  4873. m.wxid = &s
  4874. }
  4875. // Wxid returns the value of the "wxid" field in the mutation.
  4876. func (m *WxMutation) Wxid() (r string, exists bool) {
  4877. v := m.wxid
  4878. if v == nil {
  4879. return
  4880. }
  4881. return *v, true
  4882. }
  4883. // OldWxid returns the old "wxid" field's value of the Wx entity.
  4884. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4885. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4886. func (m *WxMutation) OldWxid(ctx context.Context) (v string, err error) {
  4887. if !m.op.Is(OpUpdateOne) {
  4888. return v, errors.New("OldWxid is only allowed on UpdateOne operations")
  4889. }
  4890. if m.id == nil || m.oldValue == nil {
  4891. return v, errors.New("OldWxid requires an ID field in the mutation")
  4892. }
  4893. oldValue, err := m.oldValue(ctx)
  4894. if err != nil {
  4895. return v, fmt.Errorf("querying old value for OldWxid: %w", err)
  4896. }
  4897. return oldValue.Wxid, nil
  4898. }
  4899. // ResetWxid resets all changes to the "wxid" field.
  4900. func (m *WxMutation) ResetWxid() {
  4901. m.wxid = nil
  4902. }
  4903. // SetAccount sets the "account" field.
  4904. func (m *WxMutation) SetAccount(s string) {
  4905. m.account = &s
  4906. }
  4907. // Account returns the value of the "account" field in the mutation.
  4908. func (m *WxMutation) Account() (r string, exists bool) {
  4909. v := m.account
  4910. if v == nil {
  4911. return
  4912. }
  4913. return *v, true
  4914. }
  4915. // OldAccount returns the old "account" field's value of the Wx entity.
  4916. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4917. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4918. func (m *WxMutation) OldAccount(ctx context.Context) (v string, err error) {
  4919. if !m.op.Is(OpUpdateOne) {
  4920. return v, errors.New("OldAccount is only allowed on UpdateOne operations")
  4921. }
  4922. if m.id == nil || m.oldValue == nil {
  4923. return v, errors.New("OldAccount requires an ID field in the mutation")
  4924. }
  4925. oldValue, err := m.oldValue(ctx)
  4926. if err != nil {
  4927. return v, fmt.Errorf("querying old value for OldAccount: %w", err)
  4928. }
  4929. return oldValue.Account, nil
  4930. }
  4931. // ResetAccount resets all changes to the "account" field.
  4932. func (m *WxMutation) ResetAccount() {
  4933. m.account = nil
  4934. }
  4935. // SetNickname sets the "nickname" field.
  4936. func (m *WxMutation) SetNickname(s string) {
  4937. m.nickname = &s
  4938. }
  4939. // Nickname returns the value of the "nickname" field in the mutation.
  4940. func (m *WxMutation) Nickname() (r string, exists bool) {
  4941. v := m.nickname
  4942. if v == nil {
  4943. return
  4944. }
  4945. return *v, true
  4946. }
  4947. // OldNickname returns the old "nickname" field's value of the Wx entity.
  4948. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4949. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4950. func (m *WxMutation) OldNickname(ctx context.Context) (v string, err error) {
  4951. if !m.op.Is(OpUpdateOne) {
  4952. return v, errors.New("OldNickname is only allowed on UpdateOne operations")
  4953. }
  4954. if m.id == nil || m.oldValue == nil {
  4955. return v, errors.New("OldNickname requires an ID field in the mutation")
  4956. }
  4957. oldValue, err := m.oldValue(ctx)
  4958. if err != nil {
  4959. return v, fmt.Errorf("querying old value for OldNickname: %w", err)
  4960. }
  4961. return oldValue.Nickname, nil
  4962. }
  4963. // ResetNickname resets all changes to the "nickname" field.
  4964. func (m *WxMutation) ResetNickname() {
  4965. m.nickname = nil
  4966. }
  4967. // SetTel sets the "tel" field.
  4968. func (m *WxMutation) SetTel(s string) {
  4969. m.tel = &s
  4970. }
  4971. // Tel returns the value of the "tel" field in the mutation.
  4972. func (m *WxMutation) Tel() (r string, exists bool) {
  4973. v := m.tel
  4974. if v == nil {
  4975. return
  4976. }
  4977. return *v, true
  4978. }
  4979. // OldTel returns the old "tel" field's value of the Wx entity.
  4980. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  4981. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4982. func (m *WxMutation) OldTel(ctx context.Context) (v string, err error) {
  4983. if !m.op.Is(OpUpdateOne) {
  4984. return v, errors.New("OldTel is only allowed on UpdateOne operations")
  4985. }
  4986. if m.id == nil || m.oldValue == nil {
  4987. return v, errors.New("OldTel requires an ID field in the mutation")
  4988. }
  4989. oldValue, err := m.oldValue(ctx)
  4990. if err != nil {
  4991. return v, fmt.Errorf("querying old value for OldTel: %w", err)
  4992. }
  4993. return oldValue.Tel, nil
  4994. }
  4995. // ResetTel resets all changes to the "tel" field.
  4996. func (m *WxMutation) ResetTel() {
  4997. m.tel = nil
  4998. }
  4999. // SetHeadBig sets the "head_big" field.
  5000. func (m *WxMutation) SetHeadBig(s string) {
  5001. m.head_big = &s
  5002. }
  5003. // HeadBig returns the value of the "head_big" field in the mutation.
  5004. func (m *WxMutation) HeadBig() (r string, exists bool) {
  5005. v := m.head_big
  5006. if v == nil {
  5007. return
  5008. }
  5009. return *v, true
  5010. }
  5011. // OldHeadBig returns the old "head_big" field's value of the Wx entity.
  5012. // If the Wx object wasn't provided to the builder, the object is fetched from the database.
  5013. // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5014. func (m *WxMutation) OldHeadBig(ctx context.Context) (v string, err error) {
  5015. if !m.op.Is(OpUpdateOne) {
  5016. return v, errors.New("OldHeadBig is only allowed on UpdateOne operations")
  5017. }
  5018. if m.id == nil || m.oldValue == nil {
  5019. return v, errors.New("OldHeadBig requires an ID field in the mutation")
  5020. }
  5021. oldValue, err := m.oldValue(ctx)
  5022. if err != nil {
  5023. return v, fmt.Errorf("querying old value for OldHeadBig: %w", err)
  5024. }
  5025. return oldValue.HeadBig, nil
  5026. }
  5027. // ResetHeadBig resets all changes to the "head_big" field.
  5028. func (m *WxMutation) ResetHeadBig() {
  5029. m.head_big = nil
  5030. }
  5031. // ClearServer clears the "server" edge to the Server entity.
  5032. func (m *WxMutation) ClearServer() {
  5033. m.clearedserver = true
  5034. m.clearedFields[wx.FieldServerID] = struct{}{}
  5035. }
  5036. // ServerCleared reports if the "server" edge to the Server entity was cleared.
  5037. func (m *WxMutation) ServerCleared() bool {
  5038. return m.ServerIDCleared() || m.clearedserver
  5039. }
  5040. // ServerIDs returns the "server" edge IDs in the mutation.
  5041. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  5042. // ServerID instead. It exists only for internal usage by the builders.
  5043. func (m *WxMutation) ServerIDs() (ids []uint64) {
  5044. if id := m.server; id != nil {
  5045. ids = append(ids, *id)
  5046. }
  5047. return
  5048. }
  5049. // ResetServer resets all changes to the "server" edge.
  5050. func (m *WxMutation) ResetServer() {
  5051. m.server = nil
  5052. m.clearedserver = false
  5053. }
  5054. // Where appends a list predicates to the WxMutation builder.
  5055. func (m *WxMutation) Where(ps ...predicate.Wx) {
  5056. m.predicates = append(m.predicates, ps...)
  5057. }
  5058. // WhereP appends storage-level predicates to the WxMutation builder. Using this method,
  5059. // users can use type-assertion to append predicates that do not depend on any generated package.
  5060. func (m *WxMutation) WhereP(ps ...func(*sql.Selector)) {
  5061. p := make([]predicate.Wx, len(ps))
  5062. for i := range ps {
  5063. p[i] = ps[i]
  5064. }
  5065. m.Where(p...)
  5066. }
  5067. // Op returns the operation name.
  5068. func (m *WxMutation) Op() Op {
  5069. return m.op
  5070. }
  5071. // SetOp allows setting the mutation operation.
  5072. func (m *WxMutation) SetOp(op Op) {
  5073. m.op = op
  5074. }
  5075. // Type returns the node type of this mutation (Wx).
  5076. func (m *WxMutation) Type() string {
  5077. return m.typ
  5078. }
  5079. // Fields returns all fields that were changed during this mutation. Note that in
  5080. // order to get all numeric fields that were incremented/decremented, call
  5081. // AddedFields().
  5082. func (m *WxMutation) Fields() []string {
  5083. fields := make([]string, 0, 13)
  5084. if m.created_at != nil {
  5085. fields = append(fields, wx.FieldCreatedAt)
  5086. }
  5087. if m.updated_at != nil {
  5088. fields = append(fields, wx.FieldUpdatedAt)
  5089. }
  5090. if m.status != nil {
  5091. fields = append(fields, wx.FieldStatus)
  5092. }
  5093. if m.deleted_at != nil {
  5094. fields = append(fields, wx.FieldDeletedAt)
  5095. }
  5096. if m.server != nil {
  5097. fields = append(fields, wx.FieldServerID)
  5098. }
  5099. if m.port != nil {
  5100. fields = append(fields, wx.FieldPort)
  5101. }
  5102. if m.process_id != nil {
  5103. fields = append(fields, wx.FieldProcessID)
  5104. }
  5105. if m.callback != nil {
  5106. fields = append(fields, wx.FieldCallback)
  5107. }
  5108. if m.wxid != nil {
  5109. fields = append(fields, wx.FieldWxid)
  5110. }
  5111. if m.account != nil {
  5112. fields = append(fields, wx.FieldAccount)
  5113. }
  5114. if m.nickname != nil {
  5115. fields = append(fields, wx.FieldNickname)
  5116. }
  5117. if m.tel != nil {
  5118. fields = append(fields, wx.FieldTel)
  5119. }
  5120. if m.head_big != nil {
  5121. fields = append(fields, wx.FieldHeadBig)
  5122. }
  5123. return fields
  5124. }
  5125. // Field returns the value of a field with the given name. The second boolean
  5126. // return value indicates that this field was not set, or was not defined in the
  5127. // schema.
  5128. func (m *WxMutation) Field(name string) (ent.Value, bool) {
  5129. switch name {
  5130. case wx.FieldCreatedAt:
  5131. return m.CreatedAt()
  5132. case wx.FieldUpdatedAt:
  5133. return m.UpdatedAt()
  5134. case wx.FieldStatus:
  5135. return m.Status()
  5136. case wx.FieldDeletedAt:
  5137. return m.DeletedAt()
  5138. case wx.FieldServerID:
  5139. return m.ServerID()
  5140. case wx.FieldPort:
  5141. return m.Port()
  5142. case wx.FieldProcessID:
  5143. return m.ProcessID()
  5144. case wx.FieldCallback:
  5145. return m.Callback()
  5146. case wx.FieldWxid:
  5147. return m.Wxid()
  5148. case wx.FieldAccount:
  5149. return m.Account()
  5150. case wx.FieldNickname:
  5151. return m.Nickname()
  5152. case wx.FieldTel:
  5153. return m.Tel()
  5154. case wx.FieldHeadBig:
  5155. return m.HeadBig()
  5156. }
  5157. return nil, false
  5158. }
  5159. // OldField returns the old value of the field from the database. An error is
  5160. // returned if the mutation operation is not UpdateOne, or the query to the
  5161. // database failed.
  5162. func (m *WxMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  5163. switch name {
  5164. case wx.FieldCreatedAt:
  5165. return m.OldCreatedAt(ctx)
  5166. case wx.FieldUpdatedAt:
  5167. return m.OldUpdatedAt(ctx)
  5168. case wx.FieldStatus:
  5169. return m.OldStatus(ctx)
  5170. case wx.FieldDeletedAt:
  5171. return m.OldDeletedAt(ctx)
  5172. case wx.FieldServerID:
  5173. return m.OldServerID(ctx)
  5174. case wx.FieldPort:
  5175. return m.OldPort(ctx)
  5176. case wx.FieldProcessID:
  5177. return m.OldProcessID(ctx)
  5178. case wx.FieldCallback:
  5179. return m.OldCallback(ctx)
  5180. case wx.FieldWxid:
  5181. return m.OldWxid(ctx)
  5182. case wx.FieldAccount:
  5183. return m.OldAccount(ctx)
  5184. case wx.FieldNickname:
  5185. return m.OldNickname(ctx)
  5186. case wx.FieldTel:
  5187. return m.OldTel(ctx)
  5188. case wx.FieldHeadBig:
  5189. return m.OldHeadBig(ctx)
  5190. }
  5191. return nil, fmt.Errorf("unknown Wx field %s", name)
  5192. }
  5193. // SetField sets the value of a field with the given name. It returns an error if
  5194. // the field is not defined in the schema, or if the type mismatched the field
  5195. // type.
  5196. func (m *WxMutation) SetField(name string, value ent.Value) error {
  5197. switch name {
  5198. case wx.FieldCreatedAt:
  5199. v, ok := value.(time.Time)
  5200. if !ok {
  5201. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5202. }
  5203. m.SetCreatedAt(v)
  5204. return nil
  5205. case wx.FieldUpdatedAt:
  5206. v, ok := value.(time.Time)
  5207. if !ok {
  5208. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5209. }
  5210. m.SetUpdatedAt(v)
  5211. return nil
  5212. case wx.FieldStatus:
  5213. v, ok := value.(uint8)
  5214. if !ok {
  5215. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5216. }
  5217. m.SetStatus(v)
  5218. return nil
  5219. case wx.FieldDeletedAt:
  5220. v, ok := value.(time.Time)
  5221. if !ok {
  5222. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5223. }
  5224. m.SetDeletedAt(v)
  5225. return nil
  5226. case wx.FieldServerID:
  5227. v, ok := value.(uint64)
  5228. if !ok {
  5229. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5230. }
  5231. m.SetServerID(v)
  5232. return nil
  5233. case wx.FieldPort:
  5234. v, ok := value.(string)
  5235. if !ok {
  5236. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5237. }
  5238. m.SetPort(v)
  5239. return nil
  5240. case wx.FieldProcessID:
  5241. v, ok := value.(string)
  5242. if !ok {
  5243. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5244. }
  5245. m.SetProcessID(v)
  5246. return nil
  5247. case wx.FieldCallback:
  5248. v, ok := value.(string)
  5249. if !ok {
  5250. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5251. }
  5252. m.SetCallback(v)
  5253. return nil
  5254. case wx.FieldWxid:
  5255. v, ok := value.(string)
  5256. if !ok {
  5257. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5258. }
  5259. m.SetWxid(v)
  5260. return nil
  5261. case wx.FieldAccount:
  5262. v, ok := value.(string)
  5263. if !ok {
  5264. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5265. }
  5266. m.SetAccount(v)
  5267. return nil
  5268. case wx.FieldNickname:
  5269. v, ok := value.(string)
  5270. if !ok {
  5271. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5272. }
  5273. m.SetNickname(v)
  5274. return nil
  5275. case wx.FieldTel:
  5276. v, ok := value.(string)
  5277. if !ok {
  5278. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5279. }
  5280. m.SetTel(v)
  5281. return nil
  5282. case wx.FieldHeadBig:
  5283. v, ok := value.(string)
  5284. if !ok {
  5285. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5286. }
  5287. m.SetHeadBig(v)
  5288. return nil
  5289. }
  5290. return fmt.Errorf("unknown Wx field %s", name)
  5291. }
  5292. // AddedFields returns all numeric fields that were incremented/decremented during
  5293. // this mutation.
  5294. func (m *WxMutation) AddedFields() []string {
  5295. var fields []string
  5296. if m.addstatus != nil {
  5297. fields = append(fields, wx.FieldStatus)
  5298. }
  5299. return fields
  5300. }
  5301. // AddedField returns the numeric value that was incremented/decremented on a field
  5302. // with the given name. The second boolean return value indicates that this field
  5303. // was not set, or was not defined in the schema.
  5304. func (m *WxMutation) AddedField(name string) (ent.Value, bool) {
  5305. switch name {
  5306. case wx.FieldStatus:
  5307. return m.AddedStatus()
  5308. }
  5309. return nil, false
  5310. }
  5311. // AddField adds the value to the field with the given name. It returns an error if
  5312. // the field is not defined in the schema, or if the type mismatched the field
  5313. // type.
  5314. func (m *WxMutation) AddField(name string, value ent.Value) error {
  5315. switch name {
  5316. case wx.FieldStatus:
  5317. v, ok := value.(int8)
  5318. if !ok {
  5319. return fmt.Errorf("unexpected type %T for field %s", value, name)
  5320. }
  5321. m.AddStatus(v)
  5322. return nil
  5323. }
  5324. return fmt.Errorf("unknown Wx numeric field %s", name)
  5325. }
  5326. // ClearedFields returns all nullable fields that were cleared during this
  5327. // mutation.
  5328. func (m *WxMutation) ClearedFields() []string {
  5329. var fields []string
  5330. if m.FieldCleared(wx.FieldStatus) {
  5331. fields = append(fields, wx.FieldStatus)
  5332. }
  5333. if m.FieldCleared(wx.FieldDeletedAt) {
  5334. fields = append(fields, wx.FieldDeletedAt)
  5335. }
  5336. if m.FieldCleared(wx.FieldServerID) {
  5337. fields = append(fields, wx.FieldServerID)
  5338. }
  5339. return fields
  5340. }
  5341. // FieldCleared returns a boolean indicating if a field with the given name was
  5342. // cleared in this mutation.
  5343. func (m *WxMutation) FieldCleared(name string) bool {
  5344. _, ok := m.clearedFields[name]
  5345. return ok
  5346. }
  5347. // ClearField clears the value of the field with the given name. It returns an
  5348. // error if the field is not defined in the schema.
  5349. func (m *WxMutation) ClearField(name string) error {
  5350. switch name {
  5351. case wx.FieldStatus:
  5352. m.ClearStatus()
  5353. return nil
  5354. case wx.FieldDeletedAt:
  5355. m.ClearDeletedAt()
  5356. return nil
  5357. case wx.FieldServerID:
  5358. m.ClearServerID()
  5359. return nil
  5360. }
  5361. return fmt.Errorf("unknown Wx nullable field %s", name)
  5362. }
  5363. // ResetField resets all changes in the mutation for the field with the given name.
  5364. // It returns an error if the field is not defined in the schema.
  5365. func (m *WxMutation) ResetField(name string) error {
  5366. switch name {
  5367. case wx.FieldCreatedAt:
  5368. m.ResetCreatedAt()
  5369. return nil
  5370. case wx.FieldUpdatedAt:
  5371. m.ResetUpdatedAt()
  5372. return nil
  5373. case wx.FieldStatus:
  5374. m.ResetStatus()
  5375. return nil
  5376. case wx.FieldDeletedAt:
  5377. m.ResetDeletedAt()
  5378. return nil
  5379. case wx.FieldServerID:
  5380. m.ResetServerID()
  5381. return nil
  5382. case wx.FieldPort:
  5383. m.ResetPort()
  5384. return nil
  5385. case wx.FieldProcessID:
  5386. m.ResetProcessID()
  5387. return nil
  5388. case wx.FieldCallback:
  5389. m.ResetCallback()
  5390. return nil
  5391. case wx.FieldWxid:
  5392. m.ResetWxid()
  5393. return nil
  5394. case wx.FieldAccount:
  5395. m.ResetAccount()
  5396. return nil
  5397. case wx.FieldNickname:
  5398. m.ResetNickname()
  5399. return nil
  5400. case wx.FieldTel:
  5401. m.ResetTel()
  5402. return nil
  5403. case wx.FieldHeadBig:
  5404. m.ResetHeadBig()
  5405. return nil
  5406. }
  5407. return fmt.Errorf("unknown Wx field %s", name)
  5408. }
  5409. // AddedEdges returns all edge names that were set/added in this mutation.
  5410. func (m *WxMutation) AddedEdges() []string {
  5411. edges := make([]string, 0, 1)
  5412. if m.server != nil {
  5413. edges = append(edges, wx.EdgeServer)
  5414. }
  5415. return edges
  5416. }
  5417. // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  5418. // name in this mutation.
  5419. func (m *WxMutation) AddedIDs(name string) []ent.Value {
  5420. switch name {
  5421. case wx.EdgeServer:
  5422. if id := m.server; id != nil {
  5423. return []ent.Value{*id}
  5424. }
  5425. }
  5426. return nil
  5427. }
  5428. // RemovedEdges returns all edge names that were removed in this mutation.
  5429. func (m *WxMutation) RemovedEdges() []string {
  5430. edges := make([]string, 0, 1)
  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 *WxMutation) RemovedIDs(name string) []ent.Value {
  5436. return nil
  5437. }
  5438. // ClearedEdges returns all edge names that were cleared in this mutation.
  5439. func (m *WxMutation) ClearedEdges() []string {
  5440. edges := make([]string, 0, 1)
  5441. if m.clearedserver {
  5442. edges = append(edges, wx.EdgeServer)
  5443. }
  5444. return edges
  5445. }
  5446. // EdgeCleared returns a boolean which indicates if the edge with the given name
  5447. // was cleared in this mutation.
  5448. func (m *WxMutation) EdgeCleared(name string) bool {
  5449. switch name {
  5450. case wx.EdgeServer:
  5451. return m.clearedserver
  5452. }
  5453. return false
  5454. }
  5455. // ClearEdge clears the value of the edge with the given name. It returns an error
  5456. // if that edge is not defined in the schema.
  5457. func (m *WxMutation) ClearEdge(name string) error {
  5458. switch name {
  5459. case wx.EdgeServer:
  5460. m.ClearServer()
  5461. return nil
  5462. }
  5463. return fmt.Errorf("unknown Wx unique edge %s", name)
  5464. }
  5465. // ResetEdge resets all changes to the edge with the given name in this mutation.
  5466. // It returns an error if the edge is not defined in the schema.
  5467. func (m *WxMutation) ResetEdge(name string) error {
  5468. switch name {
  5469. case wx.EdgeServer:
  5470. m.ResetServer()
  5471. return nil
  5472. }
  5473. return fmt.Errorf("unknown Wx edge %s", name)
  5474. }