sequelize.d.ts 223 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040
  1. // Type definitions for Sequelize 3.4.1
  2. // Project: http://sequelizejs.com
  3. // Definitions by: samuelneff <https://github.com/samuelneff>, Peter Harris <https://github.com/codeanimal>, Ivan Drinchev <https://github.com/drinchev>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5. // Based on original work by: samuelneff <https://github.com/samuelneff/sequelize-auto-ts/blob/master/lib/sequelize.d.ts>
  6. /// <reference path="../lodash/lodash.d.ts" />
  7. /// <reference path="../bluebird/bluebird.d.ts" />
  8. /// <reference path="../validator/validator.d.ts" />
  9. declare module "sequelize" {
  10. module sequelize {
  11. //
  12. // Associations
  13. // ~~~~~~~~~~~~~~
  14. //
  15. // https://github.com/sequelize/sequelize/tree/v3.4.1/lib/associations
  16. //
  17. /**
  18. * The options for the getAssociation mixin of the belongsTo association.
  19. * @see BelongsToGetAssociationMixin
  20. */
  21. interface BelongsToGetAssociationMixinOptions {
  22. /**
  23. * Apply a scope on the related model, or remove its default scope by passing false.
  24. */
  25. scope?: string | boolean;
  26. }
  27. /**
  28. * The getAssociation mixin applied to models with belongsTo.
  29. * An example of usage is as follows:
  30. *
  31. * ```js
  32. *
  33. * User.belongsTo(Role);
  34. *
  35. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttrib>, UserAttrib {
  36. * getRole: Sequelize.BelongsToGetAssociationMixin<RoleInstance>;
  37. * // setRole...
  38. * // createRole...
  39. * }
  40. * ```
  41. *
  42. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to/
  43. * @see Instance
  44. */
  45. interface BelongsToGetAssociationMixin<TInstance> {
  46. /**
  47. * Get the associated instance.
  48. * @param options The options to use when getting the association.
  49. */
  50. (options?: BelongsToGetAssociationMixinOptions): Promise<TInstance>
  51. }
  52. /**
  53. * The options for the setAssociation mixin of the belongsTo association.
  54. * @see BelongsToSetAssociationMixin
  55. */
  56. interface BelongsToSetAssociationMixinOptions {
  57. /**
  58. * Skip saving this after setting the foreign key if false.
  59. */
  60. save?: boolean;
  61. }
  62. /**
  63. * The setAssociation mixin applied to models with belongsTo.
  64. * An example of usage is as follows:
  65. *
  66. * ```js
  67. *
  68. * User.belongsTo(Role);
  69. *
  70. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  71. * // getRole...
  72. * setRole: Sequelize.BelongsToSetAssociationMixin<RoleInstance, RoleId>;
  73. * // createRole...
  74. * }
  75. * ```
  76. *
  77. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to/
  78. * @see Instance
  79. */
  80. interface BelongsToSetAssociationMixin<TInstance, TInstancePrimaryKey> {
  81. /**
  82. * Set the associated instance.
  83. * @param newAssociation An instance or the primary key of an instance to associate with this. Pass null or undefined to remove the association.
  84. * @param options the options passed to `this.save`.
  85. */
  86. (
  87. newAssociation?: TInstance | TInstancePrimaryKey,
  88. options?: BelongsToSetAssociationMixinOptions | InstanceSaveOptions
  89. ): Promise<void>
  90. }
  91. /**
  92. * The options for the createAssociation mixin of the belongsTo association.
  93. * @see BelongsToCreateAssociationMixin
  94. */
  95. interface BelongsToCreateAssociationMixinOptions { }
  96. /**
  97. * The createAssociation mixin applied to models with belongsTo.
  98. * An example of usage is as follows:
  99. *
  100. * ```js
  101. *
  102. * User.belongsTo(Role);
  103. *
  104. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  105. * // getRole...
  106. * // setRole...
  107. * createRole: Sequelize.BelongsToCreateAssociationMixin<RoleAttributes>;
  108. * }
  109. * ```
  110. *
  111. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to/
  112. * @see Instance
  113. */
  114. interface BelongsToCreateAssociationMixin<TAttributes> {
  115. /**
  116. * Create a new instance of the associated model and associate it with this.
  117. * @param values The values used to create the association.
  118. * @param options The options passed to `target.create` and `setAssociation`.
  119. */
  120. (
  121. values?: TAttributes,
  122. options?: BelongsToCreateAssociationMixinOptions | CreateOptions | BelongsToSetAssociationMixinOptions
  123. ): Promise<void>
  124. }
  125. /**
  126. * The options for the getAssociation mixin of the hasOne association.
  127. * @see HasOneGetAssociationMixin
  128. */
  129. interface HasOneGetAssociationMixinOptions {
  130. /**
  131. * Apply a scope on the related model, or remove its default scope by passing false.
  132. */
  133. scope?: string | boolean;
  134. }
  135. /**
  136. * The getAssociation mixin applied to models with hasOne.
  137. * An example of usage is as follows:
  138. *
  139. * ```js
  140. *
  141. * User.hasOne(Role);
  142. *
  143. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttrib>, UserAttrib {
  144. * getRole: Sequelize.HasOneGetAssociationMixin<RoleInstance>;
  145. * // setRole...
  146. * // createRole...
  147. * }
  148. * ```
  149. *
  150. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-one/
  151. * @see Instance
  152. */
  153. interface HasOneGetAssociationMixin<TInstance> {
  154. /**
  155. * Get the associated instance.
  156. * @param options The options to use when getting the association.
  157. */
  158. (options?: HasOneGetAssociationMixinOptions): Promise<TInstance>
  159. }
  160. /**
  161. * The options for the setAssociation mixin of the hasOne association.
  162. * @see HasOneSetAssociationMixin
  163. */
  164. interface HasOneSetAssociationMixinOptions {
  165. /**
  166. * Skip saving this after setting the foreign key if false.
  167. */
  168. save?: boolean;
  169. }
  170. /**
  171. * The setAssociation mixin applied to models with hasOne.
  172. * An example of usage is as follows:
  173. *
  174. * ```js
  175. *
  176. * User.hasOne(Role);
  177. *
  178. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  179. * // getRole...
  180. * setRole: Sequelize.HasOneSetAssociationMixin<RoleInstance, RoleId>;
  181. * // createRole...
  182. * }
  183. * ```
  184. *
  185. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-one/
  186. * @see Instance
  187. */
  188. interface HasOneSetAssociationMixin<TInstance, TInstancePrimaryKey> {
  189. /**
  190. * Set the associated instance.
  191. * @param newAssociation An instance or the primary key of an instance to associate with this. Pass null or undefined to remove the association.
  192. * @param options The options passed to `getAssocation` and `target.save`.
  193. */
  194. (
  195. newAssociation?: TInstance | TInstancePrimaryKey,
  196. options?: HasOneSetAssociationMixinOptions | HasOneGetAssociationMixinOptions | InstanceSaveOptions
  197. ): Promise<void>
  198. }
  199. /**
  200. * The options for the createAssociation mixin of the hasOne association.
  201. * @see HasOneCreateAssociationMixin
  202. */
  203. interface HasOneCreateAssociationMixinOptions { }
  204. /**
  205. * The createAssociation mixin applied to models with hasOne.
  206. * An example of usage is as follows:
  207. *
  208. * ```js
  209. *
  210. * User.hasOne(Role);
  211. *
  212. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  213. * // getRole...
  214. * // setRole...
  215. * createRole: Sequelize.HasOneCreateAssociationMixin<RoleAttributes>;
  216. * }
  217. * ```
  218. *
  219. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-one/
  220. * @see Instance
  221. */
  222. interface HasOneCreateAssociationMixin<TAttributes> {
  223. /**
  224. * Create a new instance of the associated model and associate it with this.
  225. * @param values The values used to create the association.
  226. * @param options The options passed to `target.create` and `setAssociation`.
  227. */
  228. (
  229. values?: TAttributes,
  230. options?: HasOneCreateAssociationMixinOptions | HasOneSetAssociationMixinOptions | CreateOptions
  231. ): Promise<void>
  232. }
  233. /**
  234. * The options for the getAssociations mixin of the hasMany association.
  235. * @see HasManyGetAssociationsMixin
  236. */
  237. interface HasManyGetAssociationsMixinOptions {
  238. /**
  239. * An optional where clause to limit the associated models.
  240. */
  241. where?: WhereOptions;
  242. /**
  243. * Apply a scope on the related model, or remove its default scope by passing false.
  244. */
  245. scope?: string | boolean;
  246. }
  247. /**
  248. * The getAssociations mixin applied to models with hasMany.
  249. * An example of usage is as follows:
  250. *
  251. * ```js
  252. *
  253. * User.hasMany(Role);
  254. *
  255. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  256. * getRoles: Sequelize.HasManyGetAssociationsMixin<RoleInstance>;
  257. * // setRoles...
  258. * // addRoles...
  259. * // addRole...
  260. * // createRole...
  261. * // removeRole...
  262. * // removeRoles...
  263. * // hasRole...
  264. * // hasRoles...
  265. * // countRoles...
  266. * }
  267. * ```
  268. *
  269. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  270. * @see Instance
  271. */
  272. interface HasManyGetAssociationsMixin<TInstance> {
  273. /**
  274. * Get everything currently associated with this, using an optional where clause.
  275. * @param options The options to use when getting the associations.
  276. */
  277. (options?: HasManyGetAssociationsMixinOptions): Promise<TInstance[]>
  278. }
  279. /**
  280. * The options for the setAssociations mixin of the hasMany association.
  281. * @see HasManySetAssociationsMixin
  282. */
  283. interface HasManySetAssociationsMixinOptions {
  284. /**
  285. * Run validation for the join model.
  286. */
  287. validate?: boolean;
  288. }
  289. /**
  290. * The setAssociations mixin applied to models with hasMany.
  291. * An example of usage is as follows:
  292. *
  293. * ```js
  294. *
  295. * User.hasMany(Role);
  296. *
  297. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  298. * // getRoles...
  299. * setRoles: Sequelize.HasManySetAssociationsMixin<RoleInstance, RoleId>;
  300. * // addRoles...
  301. * // addRole...
  302. * // createRole...
  303. * // removeRole...
  304. * // removeRoles...
  305. * // hasRole...
  306. * // hasRoles...
  307. * // countRoles...
  308. * }
  309. * ```
  310. *
  311. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  312. * @see Instance
  313. */
  314. interface HasManySetAssociationsMixin<TInstance, TInstancePrimaryKey> {
  315. /**
  316. * Set the associated models by passing an array of instances or their primary keys.
  317. * Everything that it not in the passed array will be un-associated.
  318. * @param newAssociations An array of instances or primary key of instances to associate with this. Pass null or undefined to remove all associations.
  319. * @param options The options passed to `target.findAll` and `update`.
  320. */
  321. (
  322. newAssociations?: Array<TInstance | TInstancePrimaryKey>,
  323. options?: HasManySetAssociationsMixinOptions | FindOptions | InstanceUpdateOptions
  324. ): Promise<void>
  325. }
  326. /**
  327. * The options for the addAssociations mixin of the hasMany association.
  328. * @see HasManyAddAssociationsMixin
  329. */
  330. interface HasManyAddAssociationsMixinOptions {
  331. /**
  332. * Run validation for the join model.
  333. */
  334. validate?: boolean;
  335. }
  336. /**
  337. * The addAssociations mixin applied to models with hasMany.
  338. * An example of usage is as follows:
  339. *
  340. * ```js
  341. *
  342. * User.hasMany(Role);
  343. *
  344. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  345. * // getRoles...
  346. * // setRoles...
  347. * addRoles: Sequelize.HasManyAddAssociationsMixin<RoleInstance, RoleId>;
  348. * // addRole...
  349. * // createRole...
  350. * // removeRole...
  351. * // removeRoles...
  352. * // hasRole...
  353. * // hasRoles...
  354. * // countRoles...
  355. * }
  356. * ```
  357. *
  358. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  359. * @see Instance
  360. */
  361. interface HasManyAddAssociationsMixin<TInstance, TInstancePrimaryKey> {
  362. /**
  363. * Associate several instances with this.
  364. * @param newAssociations An array of instances or primary key of instances to associate with this.
  365. * @param options The options passed to `target.update`.
  366. */
  367. (
  368. newAssociations?: Array<TInstance | TInstancePrimaryKey>,
  369. options?: HasManyAddAssociationsMixinOptions | InstanceUpdateOptions
  370. ): Promise<void>
  371. }
  372. /**
  373. * The options for the addAssociation mixin of the hasMany association.
  374. * @see HasManyAddAssociationMixin
  375. */
  376. interface HasManyAddAssociationMixinOptions {
  377. /**
  378. * Run validation for the join model.
  379. */
  380. validate?: boolean;
  381. }
  382. /**
  383. * The addAssociation mixin applied to models with hasMany.
  384. * An example of usage is as follows:
  385. *
  386. * ```js
  387. *
  388. * User.hasMany(Role);
  389. *
  390. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  391. * // getRoles...
  392. * // setRoles...
  393. * // addRoles...
  394. * addRole: Sequelize.HasManyAddAssociationMixin<RoleInstance, RoleId>;
  395. * // createRole...
  396. * // removeRole...
  397. * // removeRoles...
  398. * // hasRole...
  399. * // hasRoles...
  400. * // countRoles...
  401. * }
  402. * ```
  403. *
  404. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  405. * @see Instance
  406. */
  407. interface HasManyAddAssociationMixin<TInstance, TInstancePrimaryKey> {
  408. /**
  409. * Associate an instance with this.
  410. * @param newAssociation An instance or the primary key of an instance to associate with this.
  411. * @param options The options passed to `target.update`.
  412. */
  413. (
  414. newAssociation?: TInstance | TInstancePrimaryKey,
  415. options?: HasManyAddAssociationMixinOptions | InstanceUpdateOptions
  416. ): Promise<void>
  417. }
  418. /**
  419. * The options for the createAssociation mixin of the hasMany association.
  420. * @see HasManyCreateAssociationMixin
  421. */
  422. interface HasManyCreateAssociationMixinOptions { }
  423. /**
  424. * The createAssociation mixin applied to models with hasMany.
  425. * An example of usage is as follows:
  426. *
  427. * ```js
  428. *
  429. * User.hasMany(Role);
  430. *
  431. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  432. * // getRoles...
  433. * // setRoles...
  434. * // addRoles...
  435. * // addRole...
  436. * createRole: Sequelize.HasManyCreateAssociationMixin<RoleAttributes>;
  437. * // removeRole...
  438. * // removeRoles...
  439. * // hasRole...
  440. * // hasRoles...
  441. * // countRoles...
  442. * }
  443. * ```
  444. *
  445. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  446. * @see Instance
  447. */
  448. interface HasManyCreateAssociationMixin<TAttributes> {
  449. /**
  450. * Create a new instance of the associated model and associate it with this.
  451. * @param values The values used to create the association.
  452. * @param options The options to use when creating the association.
  453. */
  454. (
  455. values?: TAttributes,
  456. options?: HasManyCreateAssociationMixinOptions | CreateOptions
  457. ): Promise<void>
  458. }
  459. /**
  460. * The options for the removeAssociation mixin of the hasMany association.
  461. * @see HasManyRemoveAssociationMixin
  462. */
  463. interface HasManyRemoveAssociationMixinOptions { }
  464. /**
  465. * The removeAssociation mixin applied to models with hasMany.
  466. * An example of usage is as follows:
  467. *
  468. * ```js
  469. *
  470. * User.hasMany(Role);
  471. *
  472. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  473. * // getRoles...
  474. * // setRoles...
  475. * // addRoles...
  476. * // addRole...
  477. * // createRole...
  478. * removeRole: Sequelize.HasManyRemoveAssociationMixin<RoleInstance, RoleId>;
  479. * // removeRoles...
  480. * // hasRole...
  481. * // hasRoles...
  482. * // countRoles...
  483. * }
  484. * ```
  485. *
  486. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  487. * @see Instance
  488. */
  489. interface HasManyRemoveAssociationMixin<TInstance, TInstancePrimaryKey> {
  490. /**
  491. * Un-associate the instance.
  492. * @param oldAssociated The instance or the primary key of the instance to un-associate.
  493. * @param options The options passed to `target.update`.
  494. */
  495. (
  496. oldAssociated?: TInstance | TInstancePrimaryKey,
  497. options?: HasManyRemoveAssociationMixinOptions | InstanceUpdateOptions
  498. ): Promise<void>
  499. }
  500. /**
  501. * The options for the removeAssociations mixin of the hasMany association.
  502. * @see HasManyRemoveAssociationsMixin
  503. */
  504. interface HasManyRemoveAssociationsMixinOptions { }
  505. /**
  506. * The removeAssociations mixin applied to models with hasMany.
  507. * An example of usage is as follows:
  508. *
  509. * ```js
  510. *
  511. * User.hasMany(Role);
  512. *
  513. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  514. * // getRoles...
  515. * // setRoles...
  516. * // addRoles...
  517. * // addRole...
  518. * // createRole...
  519. * // removeRole...
  520. * removeRoles: Sequelize.HasManyRemoveAssociationsMixin<RoleInstance, RoleId>;
  521. * // hasRole...
  522. * // hasRoles...
  523. * // countRoles...
  524. * }
  525. * ```
  526. *
  527. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  528. * @see Instance
  529. */
  530. interface HasManyRemoveAssociationsMixin<TInstance, TInstancePrimaryKey> {
  531. /**
  532. * Un-associate several instances.
  533. * @param oldAssociated An array of instances or primary key of instances to un-associate.
  534. * @param options The options passed to `target.update`.
  535. */
  536. (
  537. oldAssociateds?: Array<TInstance | TInstancePrimaryKey>,
  538. options?: HasManyRemoveAssociationsMixinOptions | InstanceUpdateOptions
  539. ): Promise<void>
  540. }
  541. /**
  542. * The options for the hasAssociation mixin of the hasMany association.
  543. * @see HasManyHasAssociationMixin
  544. */
  545. interface HasManyHasAssociationMixinOptions { }
  546. /**
  547. * The hasAssociation mixin applied to models with hasMany.
  548. * An example of usage is as follows:
  549. *
  550. * ```js
  551. *
  552. * User.hasMany(Role);
  553. *
  554. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  555. * // getRoles...
  556. * // setRoles...
  557. * // addRoles...
  558. * // addRole...
  559. * // createRole...
  560. * // removeRole...
  561. * // removeRoles...
  562. * hasRole: Sequelize.HasManyHasAssociationMixin<RoleInstance, RoleId>;
  563. * // hasRoles...
  564. * // countRoles...
  565. * }
  566. * ```
  567. *
  568. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  569. * @see Instance
  570. */
  571. interface HasManyHasAssociationMixin<TInstance, TInstancePrimaryKey> {
  572. /**
  573. * Check if an instance is associated with this.
  574. * @param target The instance or the primary key of the instance to check.
  575. * @param options The options passed to `getAssociations`.
  576. */
  577. (
  578. target: TInstance | TInstancePrimaryKey,
  579. options?: HasManyHasAssociationMixinOptions | HasManyGetAssociationsMixinOptions
  580. ): Promise<boolean>
  581. }
  582. /**
  583. * The options for the hasAssociations mixin of the hasMany association.
  584. * @see HasManyHasAssociationsMixin
  585. */
  586. interface HasManyHasAssociationsMixinOptions { }
  587. /**
  588. * The removeAssociations mixin applied to models with hasMany.
  589. * An example of usage is as follows:
  590. *
  591. * ```js
  592. *
  593. * User.hasMany(Role);
  594. *
  595. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  596. * // getRoles...
  597. * // setRoles...
  598. * // addRoles...
  599. * // addRole...
  600. * // createRole...
  601. * // removeRole...
  602. * // removeRoles
  603. * // hasRole...
  604. * hasRoles: Sequelize.HasManyHasAssociationsMixin<RoleInstance, RoleId>;
  605. * // countRoles...
  606. * }
  607. * ```
  608. *
  609. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  610. * @see Instance
  611. */
  612. interface HasManyHasAssociationsMixin<TInstance, TInstancePrimaryKey> {
  613. /**
  614. * Check if all instances are associated with this.
  615. * @param targets An array of instances or primary key of instances to check.
  616. * @param options The options passed to `getAssociations`.
  617. */
  618. (
  619. targets: Array<TInstance | TInstancePrimaryKey>,
  620. options?: HasManyHasAssociationsMixinOptions | HasManyGetAssociationsMixinOptions
  621. ): Promise<boolean>
  622. }
  623. /**
  624. * The options for the countAssociations mixin of the hasMany association.
  625. * @see HasManyCountAssociationsMixin
  626. */
  627. interface HasManyCountAssociationsMixinOptions {
  628. /**
  629. * An optional where clause to limit the associated models.
  630. */
  631. where?: WhereOptions;
  632. /**
  633. * Apply a scope on the related model, or remove its default scope by passing false.
  634. */
  635. scope?: string | boolean;
  636. }
  637. /**
  638. * The countAssociations mixin applied to models with hasMany.
  639. * An example of usage is as follows:
  640. *
  641. * ```js
  642. *
  643. * User.hasMany(Role);
  644. *
  645. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  646. * // getRoles...
  647. * // setRoles...
  648. * // addRoles...
  649. * // addRole...
  650. * // createRole...
  651. * // removeRole...
  652. * // removeRoles...
  653. * // hasRole...
  654. * // hasRoles...
  655. * countRoles: Sequelize.HasManyCountAssociationsMixin;
  656. * }
  657. * ```
  658. *
  659. * @see http://docs.sequelizejs.com/en/latest/api/associations/has-many/
  660. * @see Instance
  661. */
  662. interface HasManyCountAssociationsMixin {
  663. /**
  664. * Count everything currently associated with this, using an optional where clause.
  665. * @param options The options to use when counting the associations.
  666. */
  667. (options?: HasManyCountAssociationsMixinOptions): Promise<number>
  668. }
  669. /**
  670. * The options for the getAssociations mixin of the belongsToMany association.
  671. * @see BelongsToManyGetAssociationsMixin
  672. */
  673. interface BelongsToManyGetAssociationsMixinOptions {
  674. /**
  675. * An optional where clause to limit the associated models.
  676. */
  677. where?: WhereOptions;
  678. /**
  679. * Apply a scope on the related model, or remove its default scope by passing false.
  680. */
  681. scope?: string | boolean;
  682. }
  683. /**
  684. * The getAssociations mixin applied to models with belongsToMany.
  685. * An example of usage is as follows:
  686. *
  687. * ```js
  688. *
  689. * User.belongsToMany(Role, { through: UserRole });
  690. *
  691. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  692. * getRoles: Sequelize.BelongsToManyGetAssociationsMixin<RoleInstance>;
  693. * // setRoles...
  694. * // addRoles...
  695. * // addRole...
  696. * // createRole...
  697. * // removeRole...
  698. * // removeRoles...
  699. * // hasRole...
  700. * // hasRoles...
  701. * // countRoles...
  702. * }
  703. * ```
  704. *
  705. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  706. * @see Instance
  707. */
  708. interface BelongsToManyGetAssociationsMixin<TInstance> {
  709. /**
  710. * Get everything currently associated with this, using an optional where clause.
  711. * @param options The options to use when getting the associations.
  712. */
  713. (options?: BelongsToManyGetAssociationsMixinOptions): Promise<TInstance[]>
  714. }
  715. /**
  716. * The options for the setAssociations mixin of the belongsToMany association.
  717. * @see BelongsToManySetAssociationsMixin
  718. */
  719. interface BelongsToManySetAssociationsMixinOptions {
  720. /**
  721. * Run validation for the join model.
  722. */
  723. validate?: boolean;
  724. }
  725. /**
  726. * The setAssociations mixin applied to models with belongsToMany.
  727. * An example of usage is as follows:
  728. *
  729. * ```js
  730. *
  731. * User.belongsToMany(Role, { through: UserRole });
  732. *
  733. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  734. * // getRoles...
  735. * setRoles: Sequelize.BelongsToManySetAssociationsMixin<RoleInstance, RoleId, UserRoleAttributes>;
  736. * // addRoles...
  737. * // addRole...
  738. * // createRole...
  739. * // removeRole...
  740. * // removeRoles...
  741. * // hasRole...
  742. * // hasRoles...
  743. * // countRoles...
  744. * }
  745. * ```
  746. *
  747. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  748. * @see Instance
  749. */
  750. interface BelongsToManySetAssociationsMixin<TInstance, TInstancePrimaryKey, TJoinTableAttributes> {
  751. /**
  752. * Set the associated models by passing an array of instances or their primary keys.
  753. * Everything that it not in the passed array will be un-associated.
  754. * @param newAssociations An array of instances or primary key of instances to associate with this. Pass null or undefined to remove all associations.
  755. * @param options The options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table.
  756. */
  757. (
  758. newAssociations?: Array<TInstance | TInstancePrimaryKey>,
  759. options?: BelongsToManySetAssociationsMixinOptions | FindOptions | BulkCreateOptions | InstanceUpdateOptions | InstanceDestroyOptions | TJoinTableAttributes
  760. ): Promise<void>
  761. }
  762. /**
  763. * The options for the addAssociations mixin of the belongsToMany association.
  764. * @see BelongsToManyAddAssociationsMixin
  765. */
  766. interface BelongsToManyAddAssociationsMixinOptions {
  767. /**
  768. * Run validation for the join model.
  769. */
  770. validate?: boolean;
  771. }
  772. /**
  773. * The addAssociations mixin applied to models with belongsToMany.
  774. * An example of usage is as follows:
  775. *
  776. * ```js
  777. *
  778. * User.belongsToMany(Role, { through: UserRole });
  779. *
  780. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  781. * // getRoles...
  782. * // setRoles...
  783. * addRoles: Sequelize.BelongsToManyAddAssociationsMixin<RoleInstance, RoleId, UserRoleAttributes>;
  784. * // addRole...
  785. * // createRole...
  786. * // removeRole...
  787. * // removeRoles...
  788. * // hasRole...
  789. * // hasRoles...
  790. * // countRoles...
  791. * }
  792. * ```
  793. *
  794. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  795. * @see Instance
  796. */
  797. interface BelongsToManyAddAssociationsMixin<TInstance, TInstancePrimaryKey, TJoinTableAttributes> {
  798. /**
  799. * Associate several instances with this.
  800. * @param newAssociations An array of instances or primary key of instances to associate with this.
  801. * @param options The options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table.
  802. */
  803. (
  804. newAssociations?: Array<TInstance | TInstancePrimaryKey>,
  805. options?: BelongsToManyAddAssociationsMixinOptions | FindOptions | BulkCreateOptions | InstanceUpdateOptions | InstanceDestroyOptions | TJoinTableAttributes
  806. ): Promise<void>
  807. }
  808. /**
  809. * The options for the addAssociation mixin of the belongsToMany association.
  810. * @see BelongsToManyAddAssociationMixin
  811. */
  812. interface BelongsToManyAddAssociationMixinOptions {
  813. /**
  814. * Run validation for the join model.
  815. */
  816. validate?: boolean;
  817. }
  818. /**
  819. * The addAssociation mixin applied to models with belongsToMany.
  820. * An example of usage is as follows:
  821. *
  822. * ```js
  823. *
  824. * User.belongsToMany(Role, { through: UserRole });
  825. *
  826. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  827. * // getRoles...
  828. * // setRoles...
  829. * // addRoles...
  830. * addRole: Sequelize.BelongsToManyAddAssociationMixin<RoleInstance, RoleId, UserRoleAttributes>;
  831. * // createRole...
  832. * // removeRole...
  833. * // removeRoles...
  834. * // hasRole...
  835. * // hasRoles...
  836. * // countRoles...
  837. * }
  838. * ```
  839. *
  840. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  841. * @see Instance
  842. */
  843. interface BelongsToManyAddAssociationMixin<TInstance, TInstancePrimaryKey, TJoinTableAttributes> {
  844. /**
  845. * Associate an instance with this.
  846. * @param newAssociation An instance or the primary key of an instance to associate with this.
  847. * @param options The options passed to `through.findAll`, `bulkCreate`, `update` and `destroy`. Can also hold additional attributes for the join table.
  848. */
  849. (
  850. newAssociation?: TInstance | TInstancePrimaryKey,
  851. options?: BelongsToManyAddAssociationMixinOptions | FindOptions | BulkCreateOptions | InstanceUpdateOptions | InstanceDestroyOptions | TJoinTableAttributes
  852. ): Promise<void>
  853. }
  854. /**
  855. * The options for the createAssociation mixin of the belongsToMany association.
  856. * @see BelongsToManyCreateAssociationMixin
  857. */
  858. interface BelongsToManyCreateAssociationMixinOptions { }
  859. /**
  860. * The createAssociation mixin applied to models with belongsToMany.
  861. * An example of usage is as follows:
  862. *
  863. * ```js
  864. *
  865. * User.belongsToMany(Role, { through: UserRole });
  866. *
  867. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  868. * // getRoles...
  869. * // setRoles...
  870. * // addRoles...
  871. * // addRole...
  872. * createRole: Sequelize.BelongsToManyCreateAssociationMixin<RoleAttributes, UserRoleAttributes>;
  873. * // removeRole...
  874. * // removeRoles...
  875. * // hasRole...
  876. * // hasRoles...
  877. * // countRoles...
  878. * }
  879. * ```
  880. *
  881. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  882. * @see Instance
  883. */
  884. interface BelongsToManyCreateAssociationMixin<TAttributes, TJoinTableAttributes> {
  885. /**
  886. * Create a new instance of the associated model and associate it with this.
  887. * @param values The values used to create the association.
  888. * @param options Options passed to `create` and `add`. Can also hold additional attributes for the join table.
  889. */
  890. (
  891. values?: TAttributes,
  892. options?: BelongsToManyCreateAssociationMixinOptions | CreateOptions | TJoinTableAttributes
  893. ): Promise<void>
  894. }
  895. /**
  896. * The options for the removeAssociation mixin of the belongsToMany association.
  897. * @see BelongsToManyRemoveAssociationMixin
  898. */
  899. interface BelongsToManyRemoveAssociationMixinOptions { }
  900. /**
  901. * The removeAssociation mixin applied to models with belongsToMany.
  902. * An example of usage is as follows:
  903. *
  904. * ```js
  905. *
  906. * User.belongsToMany(Role, { through: UserRole });
  907. *
  908. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  909. * // getRoles...
  910. * // setRoles...
  911. * // addRoles...
  912. * // addRole...
  913. * // createRole...
  914. * removeRole: Sequelize.BelongsToManyRemoveAssociationMixin<RoleInstance, RoleId>;
  915. * // removeRoles...
  916. * // hasRole...
  917. * // hasRoles...
  918. * // countRoles...
  919. * }
  920. * ```
  921. *
  922. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  923. * @see Instance
  924. */
  925. interface BelongsToManyRemoveAssociationMixin<TInstance, TInstancePrimaryKey> {
  926. /**
  927. * Un-associate the instance.
  928. * @param oldAssociated The instance or the primary key of the instance to un-associate.
  929. * @param options The options passed to `through.destroy`.
  930. */
  931. (
  932. oldAssociated?: TInstance | TInstancePrimaryKey,
  933. options?: BelongsToManyRemoveAssociationMixinOptions | InstanceDestroyOptions
  934. ): Promise<void>
  935. }
  936. /**
  937. * The options for the removeAssociations mixin of the belongsToMany association.
  938. * @see BelongsToManyRemoveAssociationsMixin
  939. */
  940. interface BelongsToManyRemoveAssociationsMixinOptions { }
  941. /**
  942. * The removeAssociations mixin applied to models with belongsToMany.
  943. * An example of usage is as follows:
  944. *
  945. * ```js
  946. *
  947. * User.belongsToMany(Role, { through: UserRole });
  948. *
  949. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  950. * // getRoles...
  951. * // setRoles...
  952. * // addRoles...
  953. * // addRole...
  954. * // createRole...
  955. * // removeRole...
  956. * removeRoles: Sequelize.BelongsToManyRemoveAssociationsMixin<RoleInstance, RoleId>;
  957. * // hasRole...
  958. * // hasRoles...
  959. * // countRoles...
  960. * }
  961. * ```
  962. *
  963. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  964. * @see Instance
  965. */
  966. interface BelongsToManyRemoveAssociationsMixin<TInstance, TInstancePrimaryKey> {
  967. /**
  968. * Un-associate several instances.
  969. * @param oldAssociated An array of instances or primary key of instances to un-associate.
  970. * @param options The options passed to `through.destroy`.
  971. */
  972. (
  973. oldAssociateds?: Array<TInstance | TInstancePrimaryKey>,
  974. options?: BelongsToManyRemoveAssociationsMixinOptions | InstanceDestroyOptions
  975. ): Promise<void>
  976. }
  977. /**
  978. * The options for the hasAssociation mixin of the belongsToMany association.
  979. * @see BelongsToManyHasAssociationMixin
  980. */
  981. interface BelongsToManyHasAssociationMixinOptions { }
  982. /**
  983. * The hasAssociation mixin applied to models with belongsToMany.
  984. * An example of usage is as follows:
  985. *
  986. * ```js
  987. *
  988. * User.belongsToMany(Role, { through: UserRole });
  989. *
  990. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  991. * // getRoles...
  992. * // setRoles...
  993. * // addRoles...
  994. * // addRole...
  995. * // createRole...
  996. * // removeRole...
  997. * // removeRoles...
  998. * hasRole: Sequelize.BelongsToManyHasAssociationMixin<RoleInstance, RoleId>;
  999. * // hasRoles...
  1000. * // countRoles...
  1001. * }
  1002. * ```
  1003. *
  1004. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  1005. * @see Instance
  1006. */
  1007. interface BelongsToManyHasAssociationMixin<TInstance, TInstancePrimaryKey> {
  1008. /**
  1009. * Check if an instance is associated with this.
  1010. * @param target The instance or the primary key of the instance to check.
  1011. * @param options The options passed to `getAssociations`.
  1012. */
  1013. (
  1014. target: TInstance | TInstancePrimaryKey,
  1015. options?: BelongsToManyHasAssociationMixinOptions | BelongsToManyGetAssociationsMixinOptions
  1016. ): Promise<boolean>
  1017. }
  1018. /**
  1019. * The options for the hasAssociations mixin of the belongsToMany association.
  1020. * @see BelongsToManyHasAssociationsMixin
  1021. */
  1022. interface BelongsToManyHasAssociationsMixinOptions { }
  1023. /**
  1024. * The removeAssociations mixin applied to models with belongsToMany.
  1025. * An example of usage is as follows:
  1026. *
  1027. * ```js
  1028. *
  1029. * User.belongsToMany(Role, { through: UserRole });
  1030. *
  1031. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  1032. * // getRoles...
  1033. * // setRoles...
  1034. * // addRoles...
  1035. * // addRole...
  1036. * // createRole...
  1037. * // removeRole...
  1038. * // removeRoles
  1039. * // hasRole...
  1040. * hasRoles: Sequelize.BelongsToManyHasAssociationsMixin<RoleInstance, RoleId>;
  1041. * // countRoles...
  1042. * }
  1043. * ```
  1044. *
  1045. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  1046. * @see Instance
  1047. */
  1048. interface BelongsToManyHasAssociationsMixin<TInstance, TInstancePrimaryKey> {
  1049. /**
  1050. * Check if all instances are associated with this.
  1051. * @param targets An array of instances or primary key of instances to check.
  1052. * @param options The options passed to `getAssociations`.
  1053. */
  1054. (
  1055. targets: Array<TInstance | TInstancePrimaryKey>,
  1056. options?: BelongsToManyHasAssociationsMixinOptions | BelongsToManyGetAssociationsMixinOptions
  1057. ): Promise<boolean>
  1058. }
  1059. /**
  1060. * The options for the countAssociations mixin of the belongsToMany association.
  1061. * @see BelongsToManyCountAssociationsMixin
  1062. */
  1063. interface BelongsToManyCountAssociationsMixinOptions {
  1064. /**
  1065. * An optional where clause to limit the associated models.
  1066. */
  1067. where?: WhereOptions;
  1068. /**
  1069. * Apply a scope on the related model, or remove its default scope by passing false.
  1070. */
  1071. scope?: string | boolean;
  1072. }
  1073. /**
  1074. * The countAssociations mixin applied to models with belongsToMany.
  1075. * An example of usage is as follows:
  1076. *
  1077. * ```js
  1078. *
  1079. * User.belongsToMany(Role, { through: UserRole });
  1080. *
  1081. * interface UserInstance extends Sequelize.Instance<UserInstance, UserAttributes>, UserAttributes {
  1082. * // getRoles...
  1083. * // setRoles...
  1084. * // addRoles...
  1085. * // addRole...
  1086. * // createRole...
  1087. * // removeRole...
  1088. * // removeRoles...
  1089. * // hasRole...
  1090. * // hasRoles...
  1091. * countRoles: Sequelize.BelongsToManyCountAssociationsMixin;
  1092. * }
  1093. * ```
  1094. *
  1095. * @see http://docs.sequelizejs.com/en/latest/api/associations/belongs-to-many/
  1096. * @see Instance
  1097. */
  1098. interface BelongsToManyCountAssociationsMixin {
  1099. /**
  1100. * Count everything currently associated with this, using an optional where clause.
  1101. * @param options The options to use when counting the associations.
  1102. */
  1103. (options?: BelongsToManyCountAssociationsMixinOptions): Promise<number>
  1104. }
  1105. /**
  1106. * Foreign Key Options
  1107. *
  1108. * @see AssociationOptions
  1109. */
  1110. interface AssociationForeignKeyOptions extends ColumnOptions {
  1111. /**
  1112. * Attribute name for the relation
  1113. */
  1114. name? : string;
  1115. }
  1116. /**
  1117. * Options provided when associating models
  1118. *
  1119. * @see Association class
  1120. */
  1121. interface AssociationOptions {
  1122. /**
  1123. * Set to true to run before-/afterDestroy hooks when an associated model is deleted because of a cascade.
  1124. * For example if `User.hasOne(Profile, {onDelete: 'cascade', hooks:true})`, the before-/afterDestroy hooks
  1125. * for profile will be called when a user is deleted. Otherwise the profile will be deleted without invoking
  1126. * any hooks.
  1127. *
  1128. * Defaults to false
  1129. */
  1130. hooks?: boolean;
  1131. /**
  1132. * The alias of this model, in singular form. See also the `name` option passed to `sequelize.define`. If
  1133. * you create multiple associations between the same tables, you should provide an alias to be able to
  1134. * distinguish between them. If you provide an alias when creating the assocition, you should provide the
  1135. * same alias when eager loading and when getting assocated models. Defaults to the singularized name of
  1136. * target
  1137. */
  1138. as?: string | { singular: string, plural: string };
  1139. /**
  1140. * The name of the foreign key in the target table or an object representing the type definition for the
  1141. * foreign column (see `Sequelize.define` for syntax). When using an object, you can add a `name` property
  1142. * to set the name of the column. Defaults to the name of source + primary key of source
  1143. */
  1144. foreignKey?: string | AssociationForeignKeyOptions;
  1145. /**
  1146. * What happens when delete occurs.
  1147. *
  1148. * Cascade if this is a n:m, and set null if it is a 1:m
  1149. *
  1150. * Defaults to 'SET NULL' or 'CASCADE'
  1151. */
  1152. onDelete?: string;
  1153. /**
  1154. * What happens when update occurs
  1155. *
  1156. * Defaults to 'CASCADE'
  1157. */
  1158. onUpdate?: string;
  1159. /**
  1160. * Should on update and on delete constraints be enabled on the foreign key.
  1161. */
  1162. constraints?: boolean;
  1163. foreignKeyConstraint?: boolean;
  1164. }
  1165. /**
  1166. * Options for Association Scope
  1167. *
  1168. * @see AssociationOptionsManyToMany
  1169. */
  1170. interface AssociationScope {
  1171. /**
  1172. * The name of the column that will be used for the associated scope and it's value
  1173. */
  1174. [scopeName: string] : any;
  1175. }
  1176. /**
  1177. * Options provided for many-to-many relationships
  1178. *
  1179. * @see AssociationOptionsHasMany
  1180. * @see AssociationOptionsBelongsToMany
  1181. */
  1182. interface AssociationOptionsManyToMany extends AssociationOptions {
  1183. /**
  1184. * A key/value set that will be used for association create and find defaults on the target.
  1185. * (sqlite not supported for N:M)
  1186. */
  1187. scope? : AssociationScope;
  1188. }
  1189. /**
  1190. * Options provided when associating models with hasOne relationship
  1191. *
  1192. * @see Association class hasOne method
  1193. */
  1194. interface AssociationOptionsHasOne extends AssociationOptions {
  1195. /**
  1196. * A string or a data type to represent the identifier in the table
  1197. */
  1198. keyType?: DataTypeAbstract;
  1199. }
  1200. /**
  1201. * Options provided when associating models with belongsTo relationship
  1202. *
  1203. * @see Association class belongsTo method
  1204. */
  1205. interface AssociationOptionsBelongsTo extends AssociationOptions {
  1206. /**
  1207. * The name of the field to use as the key for the association in the target table. Defaults to the primary
  1208. * key of the target table
  1209. */
  1210. targetKey? : string;
  1211. /**
  1212. * A string or a data type to represent the identifier in the table
  1213. */
  1214. keyType?: DataTypeAbstract;
  1215. }
  1216. /**
  1217. * Options provided when associating models with hasMany relationship
  1218. *
  1219. * @see Association class hasMany method
  1220. */
  1221. interface AssociationOptionsHasMany extends AssociationOptionsManyToMany {
  1222. /**
  1223. * A string or a data type to represent the identifier in the table
  1224. */
  1225. keyType?: DataTypeAbstract;
  1226. }
  1227. /**
  1228. * Options provided when associating models with belongsToMany relationship
  1229. *
  1230. * @see Association class belongsToMany method
  1231. */
  1232. interface AssociationOptionsBelongsToMany extends AssociationOptionsManyToMany {
  1233. /**
  1234. * The name of the table that is used to join source and target in n:m associations. Can also be a
  1235. * sequelize
  1236. * model if you want to define the junction table yourself and add extra attributes to it.
  1237. *
  1238. * In 3.4.1 version of Sequelize, hasMany's use of through gives an error, and on the other hand through
  1239. * option for belongsToMany has been made required.
  1240. *
  1241. * @see https://github.com/sequelize/sequelize/blob/v3.4.1/lib/associations/has-many.js
  1242. * @see https://github.com/sequelize/sequelize/blob/v3.4.1/lib/associations/belongs-to-many.js
  1243. */
  1244. through : Model<any, any> | string | ThroughOptions;
  1245. /**
  1246. * The name of the foreign key in the join table (representing the target model) or an object representing
  1247. * the type definition for the other column (see `Sequelize.define` for syntax). When using an object, you
  1248. * can add a `name` property to set the name of the colum. Defaults to the name of target + primary key of
  1249. * target
  1250. */
  1251. otherKey? : string | AssociationForeignKeyOptions;
  1252. }
  1253. /**
  1254. * Used for a association table in n:m associations.
  1255. *
  1256. * @see AssociationOptionsBelongsToMany
  1257. */
  1258. interface ThroughOptions {
  1259. /**
  1260. * The model used to join both sides of the N:M association.
  1261. */
  1262. model : Model<any, any>;
  1263. /**
  1264. * A key/value set that will be used for association create and find defaults on the through model.
  1265. * (Remember to add the attributes to the through model)
  1266. */
  1267. scope? : AssociationScope;
  1268. /**
  1269. * If true a unique key will be generated from the foreign keys used (might want to turn this off and create
  1270. * specific unique keys when using scopes)
  1271. *
  1272. * Defaults to true
  1273. */
  1274. unique? : boolean;
  1275. }
  1276. /**
  1277. * Creating assocations in sequelize is done by calling one of the belongsTo / hasOne / hasMany functions on a
  1278. * model (the source), and providing another model as the first argument to the function (the target).
  1279. *
  1280. * * hasOne - adds a foreign key to target
  1281. * * belongsTo - add a foreign key to source
  1282. * * hasMany - adds a foreign key to target, unless you also specify that target hasMany source, in which case
  1283. * a
  1284. * junction table is created with sourceId and targetId
  1285. *
  1286. * Creating an association will add a foreign key constraint to the attributes. All associations use `CASCADE`
  1287. * on update and `SET NULL` on delete, except for n:m, which also uses `CASCADE` on delete.
  1288. *
  1289. * When creating associations, you can provide an alias, via the `as` option. This is useful if the same model
  1290. * is associated twice, or you want your association to be called something other than the name of the target
  1291. * model.
  1292. *
  1293. * As an example, consider the case where users have many pictures, one of which is their profile picture. All
  1294. * pictures have a `userId`, but in addition the user model also has a `profilePictureId`, to be able to easily
  1295. * load the user's profile picture.
  1296. *
  1297. * ```js
  1298. * User.hasMany(Picture)
  1299. * User.belongsTo(Picture, { as: 'ProfilePicture', constraints: false })
  1300. *
  1301. * user.getPictures() // gets you all pictures
  1302. * user.getProfilePicture() // gets you only the profile picture
  1303. *
  1304. * User.findAll({
  1305. * where: ...,
  1306. * include: [
  1307. * { model: Picture }, // load all pictures
  1308. * { model: Picture, as: 'ProfilePicture' }, // load the profile picture. Notice that the spelling must be
  1309. * the exact same as the one in the association
  1310. * ]
  1311. * })
  1312. * ```
  1313. * To get full control over the foreign key column added by sequelize, you can use the `foreignKey` option. It
  1314. * can either be a string, that specifies the name, or and object type definition,
  1315. * equivalent to those passed to `sequelize.define`.
  1316. *
  1317. * ```js
  1318. * User.hasMany(Picture, { foreignKey: 'uid' })
  1319. * ```
  1320. *
  1321. * The foreign key column in Picture will now be called `uid` instead of the default `userId`.
  1322. *
  1323. * ```js
  1324. * User.hasMany(Picture, {
  1325. * foreignKey: {
  1326. * name: 'uid',
  1327. * allowNull: false
  1328. * }
  1329. * })
  1330. * ```
  1331. *
  1332. * This specifies that the `uid` column can not be null. In most cases this will already be covered by the
  1333. * foreign key costraints, which sequelize creates automatically, but can be useful in case where the foreign
  1334. * keys are disabled, e.g. due to circular references (see `constraints: false` below).
  1335. *
  1336. * When fetching associated models, you can limit your query to only load some models. These queries are
  1337. * written
  1338. * in the same way as queries to `find`/`findAll`. To only get pictures in JPG, you can do:
  1339. *
  1340. * ```js
  1341. * user.getPictures({
  1342. * where: {
  1343. * format: 'jpg'
  1344. * }
  1345. * })
  1346. * ```
  1347. *
  1348. * There are several ways to update and add new assoications. Continuing with our example of users and
  1349. * pictures:
  1350. * ```js
  1351. * user.addPicture(p) // Add a single picture
  1352. * user.setPictures([p1, p2]) // Associate user with ONLY these two picture, all other associations will be
  1353. * deleted user.addPictures([p1, p2]) // Associate user with these two pictures, but don't touch any current
  1354. * associations
  1355. * ```
  1356. *
  1357. * You don't have to pass in a complete object to the association functions, if your associated model has a
  1358. * single primary key:
  1359. *
  1360. * ```js
  1361. * user.addPicture(req.query.pid) // Here pid is just an integer, representing the primary key of the picture
  1362. * ```
  1363. *
  1364. * In the example above we have specified that a user belongs to his profile picture. Conceptually, this might
  1365. * not make sense, but since we want to add the foreign key to the user model this is the way to do it.
  1366. *
  1367. * Note how we also specified `constraints: false` for profile picture. This is because we add a foreign key
  1368. * from user to picture (profilePictureId), and from picture to user (userId). If we were to add foreign keys
  1369. * to both, it would create a cyclic dependency, and sequelize would not know which table to create first,
  1370. * since user depends on picture, and picture depends on user. These kinds of problems are detected by
  1371. * sequelize before the models are synced to the database, and you will get an error along the lines of `Error:
  1372. * Cyclic dependency found. 'users' is dependent of itself`. If you encounter this, you should either disable
  1373. * some constraints, or rethink your associations completely.
  1374. *
  1375. * @see Sequelize.Model
  1376. */
  1377. interface Associations {
  1378. /**
  1379. * Creates an association between this (the source) and the provided target. The foreign key is added
  1380. * on the target.
  1381. *
  1382. * Example: `User.hasOne(Profile)`. This will add userId to the profile table.
  1383. *
  1384. * @param target The model that will be associated with hasOne relationship
  1385. * @param options Options for the association
  1386. */
  1387. hasOne( target : Model<any, any>, options? : AssociationOptionsHasOne ): void;
  1388. /**
  1389. * Creates an association between this (the source) and the provided target. The foreign key is added on the
  1390. * source.
  1391. *
  1392. * Example: `Profile.belongsTo(User)`. This will add userId to the profile table.
  1393. *
  1394. * @param target The model that will be associated with hasOne relationship
  1395. * @param options Options for the association
  1396. */
  1397. belongsTo( target : Model<any, any>, options? : AssociationOptionsBelongsTo ) : void;
  1398. /**
  1399. * Create an association that is either 1:m or n:m.
  1400. *
  1401. * ```js
  1402. * // Create a 1:m association between user and project
  1403. * User.hasMany(Project)
  1404. * ```
  1405. * ```js
  1406. * // Create a n:m association between user and project
  1407. * User.hasMany(Project)
  1408. * Project.hasMany(User)
  1409. * ```
  1410. * By default, the name of the join table will be source+target, so in this case projectsusers. This can be
  1411. * overridden by providing either a string or a Model as `through` in the options. If you use a through
  1412. * model with custom attributes, these attributes can be set when adding / setting new associations in two
  1413. * ways. Consider users and projects from before with a join table that stores whether the project has been
  1414. * started yet:
  1415. * ```js
  1416. * var UserProjects = sequelize.define('userprojects', {
  1417. * started: Sequelize.BOOLEAN
  1418. * })
  1419. * User.hasMany(Project, { through: UserProjects })
  1420. * Project.hasMany(User, { through: UserProjects })
  1421. * ```
  1422. * ```js
  1423. * jan.addProject(homework, { started: false }) // The homework project is not started yet
  1424. * jan.setProjects([makedinner, doshopping], { started: true}) // Both shopping and dinner have been
  1425. * started
  1426. * ```
  1427. *
  1428. * If you want to set several target instances, but with different attributes you have to set the
  1429. * attributes on the instance, using a property with the name of the through model:
  1430. *
  1431. * ```js
  1432. * p1.userprojects {
  1433. * started: true
  1434. * }
  1435. * user.setProjects([p1, p2], {started: false}) // The default value is false, but p1 overrides that.
  1436. * ```
  1437. *
  1438. * Similarily, when fetching through a join table with custom attributes, these attributes will be
  1439. * available as an object with the name of the through model.
  1440. * ```js
  1441. * user.getProjects().then(function (projects) {
  1442. * var p1 = projects[0]
  1443. * p1.userprojects.started // Is this project started yet?
  1444. * })
  1445. * ```
  1446. *
  1447. * @param target The model that will be associated with hasOne relationship
  1448. * @param options Options for the association
  1449. */
  1450. hasMany( target : Model<any, any>, options? : AssociationOptionsHasMany ) : void;
  1451. /**
  1452. * Create an N:M association with a join table
  1453. *
  1454. * ```js
  1455. * User.belongsToMany(Project)
  1456. * Project.belongsToMany(User)
  1457. * ```
  1458. * By default, the name of the join table will be source+target, so in this case projectsusers. This can be
  1459. * overridden by providing either a string or a Model as `through` in the options.
  1460. *
  1461. * If you use a through model with custom attributes, these attributes can be set when adding / setting new
  1462. * associations in two ways. Consider users and projects from before with a join table that stores whether
  1463. * the project has been started yet:
  1464. * ```js
  1465. * var UserProjects = sequelize.define('userprojects', {
  1466. * started: Sequelize.BOOLEAN
  1467. * })
  1468. * User.belongsToMany(Project, { through: UserProjects })
  1469. * Project.belongsToMany(User, { through: UserProjects })
  1470. * ```
  1471. * ```js
  1472. * jan.addProject(homework, { started: false }) // The homework project is not started yet
  1473. * jan.setProjects([makedinner, doshopping], { started: true}) // Both shopping and dinner has been started
  1474. * ```
  1475. *
  1476. * If you want to set several target instances, but with different attributes you have to set the
  1477. * attributes on the instance, using a property with the name of the through model:
  1478. *
  1479. * ```js
  1480. * p1.userprojects {
  1481. * started: true
  1482. * }
  1483. * user.setProjects([p1, p2], {started: false}) // The default value is false, but p1 overrides that.
  1484. * ```
  1485. *
  1486. * Similarily, when fetching through a join table with custom attributes, these attributes will be
  1487. * available as an object with the name of the through model.
  1488. * ```js
  1489. * user.getProjects().then(function (projects) {
  1490. * var p1 = projects[0]
  1491. * p1.userprojects.started // Is this project started yet?
  1492. * })
  1493. * ```
  1494. *
  1495. * @param target The model that will be associated with hasOne relationship
  1496. * @param options Options for the association
  1497. *
  1498. */
  1499. belongsToMany( target : Model<any, any>, options : AssociationOptionsBelongsToMany ) : void;
  1500. }
  1501. //
  1502. // DataTypes
  1503. // ~~~~~~~~~~~
  1504. //
  1505. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/data-types.js
  1506. //
  1507. /**
  1508. * Abstract DataType interface. Use this if you want to create an interface that has a value any of the
  1509. * DataTypes that Sequelize supports.
  1510. */
  1511. interface DataTypeAbstract {
  1512. /**
  1513. * Although this is not needed for the definitions itself, we want to make sure that DataTypeAbstract is not
  1514. * something than can be evaluated to an empty object.
  1515. */
  1516. dialectTypes : string;
  1517. }
  1518. interface DataTypeAbstractString<T> extends DataTypeAbstract {
  1519. /**
  1520. * A variable length string. Default length 255
  1521. */
  1522. ( options? : { length: number } ) : T;
  1523. ( length : number ) : T;
  1524. /**
  1525. * Property BINARY for the type
  1526. */
  1527. BINARY : T;
  1528. }
  1529. interface DataTypeString extends DataTypeAbstractString<DataTypeString> { }
  1530. interface DataTypeChar extends DataTypeAbstractString<DataTypeChar> { }
  1531. interface DataTypeText extends DataTypeAbstract {
  1532. /**
  1533. * Length of the text field.
  1534. *
  1535. * Available lengths: `tiny`, `medium`, `long`
  1536. */
  1537. ( options? : { length: string } ) : DataTypeText;
  1538. ( length : string ) : DataTypeText;
  1539. }
  1540. interface DataTypeAbstractNumber<T> extends DataTypeAbstract {
  1541. UNSIGNED : T;
  1542. ZEROFILL : T;
  1543. }
  1544. interface DataTypeNumber extends DataTypeAbstractNumber<DataTypeNumber> { }
  1545. interface DataTypeInteger extends DataTypeAbstractNumber<DataTypeInteger> {
  1546. /**
  1547. * Length of the number field.
  1548. */
  1549. ( options? : { length: number } ) : DataTypeInteger;
  1550. ( length : number ) : DataTypeInteger;
  1551. }
  1552. interface DataTypeBigInt extends DataTypeAbstractNumber<DataTypeBigInt> {
  1553. /**
  1554. * Length of the number field.
  1555. */
  1556. ( options? : { length: number } ) : DataTypeBigInt;
  1557. ( length : number ) : DataTypeBigInt;
  1558. }
  1559. interface DataTypeFloat extends DataTypeAbstractNumber<DataTypeFloat> {
  1560. /**
  1561. * Length of the number field and decimals of the float
  1562. */
  1563. ( options? : { length: number, decimals?: number } ) : DataTypeFloat;
  1564. ( length : number, decimals? : number ) : DataTypeFloat;
  1565. }
  1566. interface DataTypeReal extends DataTypeAbstractNumber<DataTypeReal> {
  1567. /**
  1568. * Length of the number field and decimals of the real
  1569. */
  1570. ( options? : { length: number, decimals?: number } ) : DataTypeReal;
  1571. ( length : number, decimals? : number ) : DataTypeReal;
  1572. }
  1573. interface DataTypeDouble extends DataTypeAbstractNumber<DataTypeDouble> {
  1574. /**
  1575. * Length of the number field and decimals of the real
  1576. */
  1577. ( options? : { length: number, decimals?: number } ) : DataTypeDouble;
  1578. ( length : number, decimals? : number ) : DataTypeDouble;
  1579. }
  1580. interface DataTypeDecimal extends DataTypeAbstractNumber<DataTypeDecimal> {
  1581. /**
  1582. * Precision and scale for the decimal number
  1583. */
  1584. ( options? : { precision: number, scale?: number } ) : DataTypeDecimal;
  1585. ( precision : number, scale? : number ) : DataTypeDecimal;
  1586. }
  1587. interface DataTypeBoolean extends DataTypeAbstract { }
  1588. interface DataTypeTime extends DataTypeAbstract { }
  1589. interface DataTypeDate extends DataTypeAbstract { }
  1590. interface DataTypeDateOnly extends DataTypeAbstract { }
  1591. interface DataTypeHStore extends DataTypeAbstract { }
  1592. interface DataTypeJSONType extends DataTypeAbstract { }
  1593. interface DataTypeJSONB extends DataTypeAbstract { }
  1594. interface DataTypeNow extends DataTypeAbstract { }
  1595. interface DataTypeBlob extends DataTypeAbstract {
  1596. /**
  1597. * Length of the blob field.
  1598. *
  1599. * Available lengths: `tiny`, `medium`, `long`
  1600. */
  1601. ( options? : { length: string } ) : DataTypeBlob;
  1602. ( length : string ) : DataTypeBlob;
  1603. }
  1604. interface DataTypeRange extends DataTypeAbstract {
  1605. /**
  1606. * Range field for Postgre
  1607. *
  1608. * Accepts subtype any of the ranges
  1609. */
  1610. ( options? : { subtype: DataTypeAbstract } ) : DataTypeRange;
  1611. ( subtype : DataTypeAbstract ) : DataTypeRange;
  1612. }
  1613. interface DataTypeUUID extends DataTypeAbstract { }
  1614. interface DataTypeUUIDv1 extends DataTypeAbstract { }
  1615. interface DataTypeUUIDv4 extends DataTypeAbstract { }
  1616. interface DataTypeVirtual extends DataTypeAbstract { }
  1617. interface DataTypeEnum extends DataTypeAbstract {
  1618. /**
  1619. * Enum field
  1620. *
  1621. * Accepts values
  1622. */
  1623. ( options? : { values: string | string[] } ) : DataTypeEnum;
  1624. ( values : string | string[] ) : DataTypeEnum;
  1625. ( ...args : string[] ) : DataTypeEnum;
  1626. }
  1627. interface DataTypeArray extends DataTypeAbstract {
  1628. /**
  1629. * Array field for Postgre
  1630. *
  1631. * Accepts type any of the DataTypes
  1632. */
  1633. ( options : { type: DataTypeAbstract } ) : DataTypeArray;
  1634. ( type : DataTypeAbstract ) : DataTypeArray;
  1635. }
  1636. interface DataTypeGeometry extends DataTypeAbstract {
  1637. /**
  1638. * Geometry field for Postgres
  1639. */
  1640. ( type : string, srid? : number ) : DataTypeGeometry;
  1641. }
  1642. /**
  1643. * A convenience class holding commonly used data types. The datatypes are used when definining a new model
  1644. * using
  1645. * `Sequelize.define`, like this:
  1646. *
  1647. * ```js
  1648. * sequelize.define('model', {
  1649. * column: DataTypes.INTEGER
  1650. * })
  1651. * ```
  1652. * When defining a model you can just as easily pass a string as type, but often using the types defined here
  1653. * is
  1654. * beneficial. For example, using `DataTypes.BLOB`, mean that that column will be returned as an instance of
  1655. * `Buffer` when being fetched by sequelize.
  1656. *
  1657. * Some data types have special properties that can be accessed in order to change the data type.
  1658. * For example, to get an unsigned integer with zerofill you can do `DataTypes.INTEGER.UNSIGNED.ZEROFILL`.
  1659. * The order you access the properties in do not matter, so `DataTypes.INTEGER.ZEROFILL.UNSIGNED` is fine as
  1660. * well. The available properties are listed under each data type.
  1661. *
  1662. * To provide a length for the data type, you can invoke it like a function: `INTEGER(2)`
  1663. *
  1664. * Three of the values provided here (`NOW`, `UUIDV1` and `UUIDV4`) are special default values, that should not
  1665. * be used to define types. Instead they are used as shorthands for defining default values. For example, to
  1666. * get a uuid field with a default value generated following v1 of the UUID standard:
  1667. *
  1668. * ```js
  1669. * sequelize.define('model', {
  1670. * uuid: {
  1671. * type: DataTypes.UUID,
  1672. * defaultValue: DataTypes.UUIDV1,
  1673. * primaryKey: true
  1674. * }
  1675. * })
  1676. * ```
  1677. */
  1678. interface DataTypes {
  1679. ABSTRACT : DataTypeAbstract;
  1680. STRING : DataTypeString;
  1681. CHAR : DataTypeChar;
  1682. TEXT : DataTypeText;
  1683. NUMBER : DataTypeNumber;
  1684. INTEGER : DataTypeInteger;
  1685. BIGINT : DataTypeBigInt;
  1686. FLOAT : DataTypeFloat;
  1687. TIME : DataTypeTime;
  1688. DATE : DataTypeDate;
  1689. DATEONLY: DataTypeDateOnly;
  1690. BOOLEAN: DataTypeBoolean;
  1691. NOW: DataTypeNow;
  1692. BLOB: DataTypeBlob;
  1693. DECIMAL: DataTypeDecimal;
  1694. NUMERIC: DataTypeDecimal;
  1695. UUID: DataTypeUUID;
  1696. UUIDV1: DataTypeUUIDv1;
  1697. UUIDV4: DataTypeUUIDv4;
  1698. HSTORE: DataTypeHStore;
  1699. JSON: DataTypeJSONType;
  1700. JSONB: DataTypeJSONB;
  1701. VIRTUAL: DataTypeVirtual;
  1702. ARRAY: DataTypeArray;
  1703. NONE: DataTypeVirtual;
  1704. ENUM: DataTypeEnum;
  1705. RANGE: DataTypeRange;
  1706. REAL: DataTypeReal;
  1707. DOUBLE: DataTypeDouble,
  1708. 'DOUBLE PRECISION': DataTypeDouble,
  1709. GEOMETRY: DataTypeGeometry
  1710. }
  1711. //
  1712. // Deferrable
  1713. // ~~~~~~~~~~~~
  1714. //
  1715. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/deferrable.js
  1716. //
  1717. /**
  1718. * Abstract Deferrable interface. Use this if you want to create an interface that has a value any of the
  1719. * Deferrables that Sequelize supports.
  1720. */
  1721. interface DeferrableAbstract {
  1722. /**
  1723. * Although this is not needed for the definitions itself, we want to make sure that DeferrableAbstract is
  1724. * not something than can be evaluated to an empty object.
  1725. */
  1726. toString() : string;
  1727. toSql() : string;
  1728. }
  1729. interface DeferrableInitiallyDeferred extends DeferrableAbstract {
  1730. /**
  1731. * A property that will defer constraints checks to the end of transactions.
  1732. */
  1733. () : DeferrableInitiallyDeferred;
  1734. }
  1735. interface DeferrableInitiallyImmediate extends DeferrableAbstract {
  1736. /**
  1737. * A property that will trigger the constraint checks immediately
  1738. */
  1739. () : DeferrableInitiallyImmediate;
  1740. }
  1741. interface DeferrableNot extends DeferrableAbstract {
  1742. /**
  1743. * A property that will set the constraints to not deferred. This is the default in PostgreSQL and it make
  1744. * it impossible to dynamically defer the constraints within a transaction.
  1745. */
  1746. () : DeferrableNot;
  1747. }
  1748. interface DeferrableSetDeferred extends DeferrableAbstract {
  1749. /**
  1750. * A property that will trigger an additional query at the beginning of a
  1751. * transaction which sets the constraints to deferred.
  1752. *
  1753. * @param constraints An array of constraint names. Will defer all constraints by default.
  1754. */
  1755. ( constraints : Array<string> ) : DeferrableSetDeferred;
  1756. }
  1757. interface DeferrableSetImmediate extends DeferrableAbstract {
  1758. /**
  1759. * A property that will trigger an additional query at the beginning of a
  1760. * transaction which sets the constraints to immediately.
  1761. *
  1762. * @param constraints An array of constraint names. Will defer all constraints by default.
  1763. */
  1764. ( constraints : Array<string> ) : DeferrableSetImmediate;
  1765. }
  1766. /**
  1767. * A collection of properties related to deferrable constraints. It can be used to
  1768. * make foreign key constraints deferrable and to set the constaints within a
  1769. * transaction. This is only supported in PostgreSQL.
  1770. *
  1771. * The foreign keys can be configured like this. It will create a foreign key
  1772. * that will check the constraints immediately when the data was inserted.
  1773. *
  1774. * ```js
  1775. * sequelize.define('Model', {
  1776. * foreign_id: {
  1777. * type: Sequelize.INTEGER,
  1778. * references: {
  1779. * model: OtherModel,
  1780. * key: 'id',
  1781. * deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE
  1782. * }
  1783. * }
  1784. * });
  1785. * ```
  1786. *
  1787. * The constraints can be configured in a transaction like this. It will
  1788. * trigger a query once the transaction has been started and set the constraints
  1789. * to be checked at the very end of the transaction.
  1790. *
  1791. * ```js
  1792. * sequelize.transaction({
  1793. * deferrable: Sequelize.Deferrable.SET_DEFERRED
  1794. * });
  1795. * ```
  1796. */
  1797. interface Deferrable {
  1798. INITIALLY_DEFERRED: DeferrableInitiallyDeferred;
  1799. INITIALLY_IMMEDIATE: DeferrableInitiallyImmediate;
  1800. NOT: DeferrableNot;
  1801. SET_DEFERRED: DeferrableSetDeferred;
  1802. SET_IMMEDIATE: DeferrableSetImmediate
  1803. }
  1804. //
  1805. // Errors
  1806. // ~~~~~~~~
  1807. //
  1808. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/errors.js
  1809. //
  1810. /**
  1811. * The Base Error all Sequelize Errors inherit from.
  1812. */
  1813. interface BaseError extends ErrorConstructor { }
  1814. interface ValidationError extends BaseError {
  1815. /**
  1816. * Validation Error. Thrown when the sequelize validation has failed. The error contains an `errors`
  1817. * property, which is an array with 1 or more ValidationErrorItems, one for each validation that failed.
  1818. *
  1819. * @param message Error message
  1820. * @param errors Array of ValidationErrorItem objects describing the validation errors
  1821. */
  1822. new ( message : string, errors? : Array<ValidationErrorItem> ) : ValidationError;
  1823. /**
  1824. * Gets all validation error items for the path / field specified.
  1825. *
  1826. * @param path The path to be checked for error items
  1827. */
  1828. get( path : string ) : Array<ValidationErrorItem>;
  1829. }
  1830. interface ValidationErrorItem extends BaseError {
  1831. /**
  1832. * Validation Error Item
  1833. * Instances of this class are included in the `ValidationError.errors` property.
  1834. *
  1835. * @param message An error message
  1836. * @param type The type of the validation error
  1837. * @param path The field that triggered the validation error
  1838. * @param value The value that generated the error
  1839. */
  1840. new ( message : string, type : string, path : string, value : string ) : ValidationErrorItem;
  1841. }
  1842. interface DatabaseError extends BaseError {
  1843. /**
  1844. * A base class for all database related errors.
  1845. */
  1846. new ( parent : Error ) : DatabaseError;
  1847. }
  1848. interface TimeoutError extends DatabaseError {
  1849. /**
  1850. * Thrown when a database query times out because of a deadlock
  1851. */
  1852. new ( parent : Error ) : TimeoutError;
  1853. }
  1854. interface UniqueConstraintError extends DatabaseError {
  1855. /**
  1856. * Thrown when a unique constraint is violated in the database
  1857. */
  1858. new ( options : { parent? : Error, message? : string, errors? : Object } ) : UniqueConstraintError;
  1859. }
  1860. interface ForeignKeyConstraintError extends DatabaseError {
  1861. /**
  1862. * Thrown when a foreign key constraint is violated in the database
  1863. */
  1864. new ( options : { parent? : Error, message? : string, index? : string, fields? : Array<string>, table? : string } ) : ForeignKeyConstraintError;
  1865. }
  1866. interface ExclusionConstraintError extends DatabaseError {
  1867. /**
  1868. * Thrown when an exclusion constraint is violated in the database
  1869. */
  1870. new ( options : { parent? : Error, message? : string, constraint? : string, fields? : Array<string>, table? : string } ) : ExclusionConstraintError;
  1871. }
  1872. interface ConnectionError extends BaseError {
  1873. /**
  1874. * A base class for all connection related errors.
  1875. */
  1876. new ( parent : Error ) : ConnectionError;
  1877. }
  1878. interface ConnectionRefusedError extends ConnectionError {
  1879. /**
  1880. * Thrown when a connection to a database is refused
  1881. */
  1882. new ( parent : Error ) : ConnectionRefusedError;
  1883. }
  1884. interface AccessDeniedError extends ConnectionError {
  1885. /**
  1886. * Thrown when a connection to a database is refused due to insufficient privileges
  1887. */
  1888. new ( parent : Error ) : AccessDeniedError;
  1889. }
  1890. interface HostNotFoundError extends ConnectionError {
  1891. /**
  1892. * Thrown when a connection to a database has a hostname that was not found
  1893. */
  1894. new ( parent : Error ) : HostNotFoundError;
  1895. }
  1896. interface HostNotReachableError extends ConnectionError {
  1897. /**
  1898. * Thrown when a connection to a database has a hostname that was not reachable
  1899. */
  1900. new ( parent : Error ) : HostNotReachableError;
  1901. }
  1902. interface InvalidConnectionError extends ConnectionError {
  1903. /**
  1904. * Thrown when a connection to a database has invalid values for any of the connection parameters
  1905. */
  1906. new ( parent : Error ) : InvalidConnectionError;
  1907. }
  1908. interface ConnectionTimedOutError extends ConnectionError {
  1909. /**
  1910. * Thrown when a connection to a database times out
  1911. */
  1912. new ( parent : Error ) : ConnectionTimedOutError;
  1913. }
  1914. /**
  1915. * Sequelize provides a host of custom error classes, to allow you to do easier debugging. All of these errors
  1916. * are exposed on the sequelize object and the sequelize constructor. All sequelize errors inherit from the
  1917. * base JS error object.
  1918. */
  1919. interface Errors {
  1920. Error : BaseError;
  1921. ValidationError : ValidationError;
  1922. ValidationErrorItem : ValidationErrorItem;
  1923. DatabaseError : DatabaseError;
  1924. TimeoutError : TimeoutError;
  1925. UniqueConstraintError : UniqueConstraintError;
  1926. ExclusionConstraintError : ExclusionConstraintError;
  1927. ForeignKeyConstraintError : ForeignKeyConstraintError;
  1928. ConnectionError : ConnectionError;
  1929. ConnectionRefusedError : ConnectionRefusedError;
  1930. AccessDeniedError : AccessDeniedError;
  1931. HostNotFoundError : HostNotFoundError;
  1932. HostNotReachableError : HostNotReachableError;
  1933. InvalidConnectionError : InvalidConnectionError;
  1934. ConnectionTimedOutError : ConnectionTimedOutError;
  1935. }
  1936. //
  1937. // Hooks
  1938. // ~~~~~~~
  1939. //
  1940. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/hooks.js
  1941. //
  1942. /**
  1943. * Options for Sequelize.define. We mostly duplicate the Hooks here, since there is no way to combine the two
  1944. * interfaces.
  1945. *
  1946. * beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy, beforeBulkUpdate, beforeCreate,
  1947. * beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, afterBulkCreate, afterBulkDestroy and
  1948. * afterBulkUpdate.
  1949. */
  1950. interface HooksDefineOptions<TInstance> {
  1951. beforeValidate? : ( instance : TInstance, options : Object, fn? : Function ) => any;
  1952. afterValidate? : ( instance : TInstance, options : Object, fn? : Function ) => any;
  1953. beforeCreate? : ( attributes : TInstance, options : Object, fn? : Function ) => any;
  1954. afterCreate? : ( attributes : TInstance, options : Object, fn? : Function ) => any;
  1955. beforeDestroy? : ( instance : TInstance, options : Object, fn? : Function ) => any;
  1956. beforeDelete? : ( instance : TInstance, options : Object, fn? : Function ) => any;
  1957. afterDestroy? : ( instance : TInstance, options : Object, fn? : Function ) => any;
  1958. afterDelete? : ( instance : TInstance, options : Object, fn? : Function ) => any;
  1959. beforeUpdate? : ( instance : TInstance, options : Object, fn? : Function ) => any;
  1960. afterUpdate? : ( instance : TInstance, options : Object, fn? : Function ) => any;
  1961. beforeBulkCreate? : ( instances : Array<TInstance>, options : Object, fn? : Function ) => any;
  1962. afterBulkCreate? : ( instances : Array<TInstance>, options : Object, fn? : Function ) => any;
  1963. beforeBulkDestroy? : ( options : Object, fn? : Function ) => any;
  1964. beforeBulkDelete? : ( options : Object, fn? : Function ) => any;
  1965. afterBulkDestroy? : ( options : Object, fn? : Function ) => any;
  1966. afterBulkDelete? : ( options : Object, fn? : Function ) => any;
  1967. beforeBulkUpdate? : ( options : Object, fn? : Function ) => any;
  1968. afterBulkUpdate? : ( options : Object, fn? : Function ) => any;
  1969. beforeFind? : ( options : Object, fn? : Function ) => any;
  1970. beforeFindAfterExpandIncludeAll? : ( options : Object, fn? : Function ) => any;
  1971. beforeFindAfterOptions? : ( options : Object, fn? : Function ) => any;
  1972. afterFind? : ( instancesOrInstance : Array<TInstance> | TInstance, options : Object,
  1973. fn? : Function ) => any;
  1974. }
  1975. /**
  1976. * Hooks are function that are called before and after (bulk-) creation/updating/deletion and validation.
  1977. * Hooks can be added to you models in three ways:
  1978. *
  1979. * 1. By specifying them as options in `sequelize.define`
  1980. * 2. By calling `hook()` with a string and your hook handler function
  1981. * 3. By calling the function with the same name as the hook you want
  1982. *
  1983. * ```js
  1984. * // Method 1
  1985. * sequelize.define(name, { attributes }, {
  1986. * hooks: {
  1987. * beforeBulkCreate: function () {
  1988. * // can be a single function
  1989. * },
  1990. * beforeValidate: [
  1991. * function () {},
  1992. * function() {} // Or an array of several
  1993. * ]
  1994. * }
  1995. * })
  1996. *
  1997. * // Method 2
  1998. * Model.hook('afterDestroy', function () {})
  1999. *
  2000. * // Method 3
  2001. * Model.afterBulkUpdate(function () {})
  2002. * ```
  2003. *
  2004. * @see Sequelize.define
  2005. */
  2006. interface Hooks<TInstance> {
  2007. /**
  2008. * Add a hook to the model
  2009. *
  2010. * @param hookType
  2011. * @param name Provide a name for the hook function. It can be used to remove the hook later or to order
  2012. * hooks based on some sort of priority system in the future.
  2013. * @param fn The hook function
  2014. *
  2015. * @alias hook
  2016. */
  2017. addHook( hookType : string, name : string, fn : Function ) : Hooks<TInstance>;
  2018. addHook( hookType : string, fn : Function ) : Hooks<TInstance>;
  2019. hook( hookType : string, name : string, fn : Function ) : Hooks<TInstance>;
  2020. hook( hookType : string, fn : Function ) : Hooks<TInstance>;
  2021. /**
  2022. * Remove hook from the model
  2023. *
  2024. * @param hookType
  2025. * @param name
  2026. */
  2027. removeHook( hookType : string, name : string ) : Hooks<TInstance>;
  2028. /**
  2029. * Check whether the mode has any hooks of this type
  2030. *
  2031. * @param hookType
  2032. *
  2033. * @alias hasHooks
  2034. */
  2035. hasHook( hookType : string ) : boolean;
  2036. hasHooks( hookType : string ) : boolean;
  2037. /**
  2038. * A hook that is run before validation
  2039. *
  2040. * @param name
  2041. * @param fn A callback function that is called with instance, options
  2042. */
  2043. beforeValidate( name : string,
  2044. fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2045. beforeValidate( fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2046. /**
  2047. * A hook that is run after validation
  2048. *
  2049. * @param name
  2050. * @param fn A callback function that is called with instance, options
  2051. */
  2052. afterValidate( name : string,
  2053. fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2054. afterValidate( fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2055. /**
  2056. * A hook that is run before creating a single instance
  2057. *
  2058. * @param name
  2059. * @param fn A callback function that is called with attributes, options
  2060. */
  2061. beforeCreate( name : string,
  2062. fn : ( attributes : TInstance, options : Object, fn? : Function ) => void ): void;
  2063. beforeCreate( fn : ( attributes : TInstance, options : Object, fn? : Function ) => void ): void;
  2064. /**
  2065. * A hook that is run after creating a single instance
  2066. *
  2067. * @param name
  2068. * @param fn A callback function that is called with attributes, options
  2069. */
  2070. afterCreate( name : string,
  2071. fn : ( attributes : TInstance, options : Object, fn? : Function ) => void ): void;
  2072. afterCreate( fn : ( attributes : TInstance, options : Object, fn? : Function ) => void ): void;
  2073. /**
  2074. * A hook that is run before destroying a single instance
  2075. *
  2076. * @param name
  2077. * @param fn A callback function that is called with instance, options
  2078. * @alias beforeDelete
  2079. */
  2080. beforeDestroy( name : string,
  2081. fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2082. beforeDestroy( fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2083. beforeDelete( name : string,
  2084. fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2085. beforeDelete( fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2086. /**
  2087. * A hook that is run after destroying a single instance
  2088. *
  2089. * @param name
  2090. * @param fn A callback function that is called with instance, options
  2091. * @alias afterDelete
  2092. */
  2093. afterDestroy( name : string,
  2094. fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2095. afterDestroy( fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2096. afterDelete( name : string, fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2097. afterDelete( fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2098. /**
  2099. * A hook that is run before updating a single instance
  2100. *
  2101. * @param name
  2102. * @param fn A callback function that is called with instance, options
  2103. */
  2104. beforeUpdate( name : string,
  2105. fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2106. beforeUpdate( fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2107. /**
  2108. * A hook that is run after updating a single instance
  2109. *
  2110. * @param name
  2111. * @param fn A callback function that is called with instance, options
  2112. */
  2113. afterUpdate( name : string, fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2114. afterUpdate( fn : ( instance : TInstance, options : Object, fn? : Function ) => void ): void;
  2115. /**
  2116. * A hook that is run before creating instances in bulk
  2117. *
  2118. * @param name
  2119. * @param fn A callback function that is called with instances, options
  2120. */
  2121. beforeBulkCreate( name : string,
  2122. fn : ( instances : Array<TInstance>, options : Object, fn? : Function ) => void ): void;
  2123. beforeBulkCreate( fn : ( instances : Array<TInstance>, options : Object, fn? : Function ) => void ): void;
  2124. /**
  2125. * A hook that is run after creating instances in bulk
  2126. *
  2127. * @param name
  2128. * @param fn A callback function that is called with instances, options
  2129. * @name afterBulkCreate
  2130. */
  2131. afterBulkCreate( name : string,
  2132. fn : ( instances : Array<TInstance>, options : Object, fn? : Function ) => void ): void;
  2133. afterBulkCreate( fn : ( instances : Array<TInstance>, options : Object, fn? : Function ) => void ): void;
  2134. /**
  2135. * A hook that is run before destroying instances in bulk
  2136. *
  2137. * @param name
  2138. * @param fn A callback function that is called with options
  2139. *
  2140. * @alias beforeBulkDelete
  2141. */
  2142. beforeBulkDestroy( name : string, fn : ( options : Object, fn? : Function ) => void ): void;
  2143. beforeBulkDestroy( fn : ( options : Object, fn? : Function ) => void ): void;
  2144. beforeBulkDelete( name : string, fn : ( options : Object, fn? : Function ) => void ): void;
  2145. beforeBulkDelete( fn : ( options : Object, fn? : Function ) => void ): void;
  2146. /**
  2147. * A hook that is run after destroying instances in bulk
  2148. *
  2149. * @param name
  2150. * @param fn A callback function that is called with options
  2151. *
  2152. * @alias afterBulkDelete
  2153. */
  2154. afterBulkDestroy( name : string, fn : ( options : Object, fn? : Function ) => void ): void;
  2155. afterBulkDestroy( fn : ( options : Object, fn? : Function ) => void ): void;
  2156. afterBulkDelete( name : string, fn : ( options : Object, fn? : Function ) => void ): void;
  2157. afterBulkDelete( fn : ( options : Object, fn? : Function ) => void ): void;
  2158. /**
  2159. * A hook that is run after updating instances in bulk
  2160. *
  2161. * @param name
  2162. * @param fn A callback function that is called with options
  2163. */
  2164. beforeBulkUpdate( name : string, fn : ( options : Object, fn? : Function ) => void ): void;
  2165. beforeBulkUpdate( fn : ( options : Object, fn? : Function ) => void ): void;
  2166. /**
  2167. * A hook that is run after updating instances in bulk
  2168. *
  2169. * @param name
  2170. * @param fn A callback function that is called with options
  2171. */
  2172. afterBulkUpdate( name : string, fn : ( options : Object, fn? : Function ) => void ): void;
  2173. afterBulkUpdate( fn : ( options : Object, fn? : Function ) => void ): void;
  2174. /**
  2175. * A hook that is run before a find (select) query
  2176. *
  2177. * @param name
  2178. * @param fn A callback function that is called with options
  2179. */
  2180. beforeFind( name : string, fn : ( options : Object, fn? : Function ) => void ): void;
  2181. beforeFind( fn : ( options : Object, fn? : Function ) => void ): void;
  2182. /**
  2183. * A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded
  2184. *
  2185. * @param name
  2186. * @param fn A callback function that is called with options
  2187. */
  2188. beforeFindAfterExpandIncludeAll( name : string,
  2189. fn : ( options : Object, fn? : Function ) => void ): void;
  2190. beforeFindAfterExpandIncludeAll( fn : ( options : Object, fn? : Function ) => void ): void;
  2191. /**
  2192. * A hook that is run before a find (select) query, after all option parsing is complete
  2193. *
  2194. * @param name
  2195. * @param fn A callback function that is called with options
  2196. */
  2197. beforeFindAfterOptions( name : string, fn : ( options : Object, fn? : Function ) => void ): void;
  2198. beforeFindAfterOptions( fn : ( options : Object, fn? : Function ) => void ): void;
  2199. /**
  2200. * A hook that is run after a find (select) query
  2201. *
  2202. * @param name
  2203. * @param fn A callback function that is called with instance(s), options
  2204. */
  2205. afterFind( name : string,
  2206. fn : ( instancesOrInstance : Array<TInstance> | TInstance, options : Object,
  2207. fn? : Function ) => void ): void;
  2208. afterFind( fn : ( instancesOrInstance : Array<TInstance> | TInstance, options : Object,
  2209. fn? : Function ) => void ): void;
  2210. /**
  2211. * A hook that is run before a define call
  2212. *
  2213. * @param name
  2214. * @param fn A callback function that is called with attributes, options
  2215. */
  2216. beforeDefine( name : string, fn : ( attributes : DefineAttributes, options : Object ) => void ): void;
  2217. beforeDefine( fn : ( attributes : DefineAttributes, options : Object ) => void ): void;
  2218. /**
  2219. * A hook that is run after a define call
  2220. *
  2221. * @param name
  2222. * @param fn A callback function that is called with factory
  2223. */
  2224. afterDefine( name : string, fn : ( model : Model<TInstance, any> ) => void ): void;
  2225. afterDefine( fn : ( model : Model<TInstance, any> ) => void ): void;
  2226. /**
  2227. * A hook that is run before Sequelize() call
  2228. *
  2229. * @param name
  2230. * @param fn A callback function that is called with config, options
  2231. */
  2232. beforeInit( name : string, fn : ( config : Object, options : Object ) => void ): void;
  2233. beforeInit( fn : ( config : Object, options : Object ) => void ): void;
  2234. /**
  2235. * A hook that is run after Sequelize() call
  2236. *
  2237. * @param name
  2238. * @param fn A callback function that is called with sequelize
  2239. */
  2240. afterInit( name : string, fn : ( sequelize : Sequelize ) => void ): void;
  2241. afterInit( fn : ( sequelize : Sequelize ) => void ): void;
  2242. }
  2243. //
  2244. // Instance
  2245. // ~~~~~~~~~~
  2246. //
  2247. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/instance.js
  2248. //
  2249. /**
  2250. * Options used for Instance.increment method
  2251. */
  2252. interface InstanceIncrementDecrementOptions {
  2253. /**
  2254. * The number to increment by
  2255. *
  2256. * Defaults to 1
  2257. */
  2258. by? : number;
  2259. /**
  2260. * A function that gets executed while running the query to log the sql.
  2261. */
  2262. logging? : boolean | Function;
  2263. /**
  2264. * Transaction to run query under
  2265. */
  2266. transaction? : Transaction;
  2267. /**
  2268. * A hash of attributes to describe your search. See above for examples.
  2269. */
  2270. where? : WhereOptions | Array<col | and | or | string>;
  2271. }
  2272. /**
  2273. * Options used for Instance.restore method
  2274. */
  2275. interface InstanceRestoreOptions {
  2276. /**
  2277. * A function that gets executed while running the query to log the sql.
  2278. */
  2279. logging? : boolean | Function;
  2280. /**
  2281. * Transaction to run query under
  2282. */
  2283. transaction? : Transaction;
  2284. }
  2285. /**
  2286. * Options used for Instance.destroy method
  2287. */
  2288. interface InstanceDestroyOptions {
  2289. /**
  2290. * If set to true, paranoid models will actually be deleted
  2291. */
  2292. force? : boolean;
  2293. /**
  2294. * A function that gets executed while running the query to log the sql.
  2295. */
  2296. logging? : boolean | Function;
  2297. /**
  2298. * Transaction to run the query in
  2299. */
  2300. transaction? : Transaction;
  2301. }
  2302. /**
  2303. * Options used for Instance.update method
  2304. */
  2305. interface InstanceUpdateOptions extends InstanceSaveOptions, InstanceSetOptions {
  2306. /**
  2307. * A hash of attributes to describe your search. See above for examples.
  2308. */
  2309. where? : WhereOptions | Array<col | and | or | string>;
  2310. }
  2311. /**
  2312. * Options used for Instance.set method
  2313. */
  2314. interface InstanceSetOptions {
  2315. /**
  2316. * If set to true, field and virtual setters will be ignored
  2317. */
  2318. raw? : boolean;
  2319. /**
  2320. * Clear all previously set data values
  2321. */
  2322. reset? : boolean;
  2323. }
  2324. /**
  2325. * Options used for Instance.save method
  2326. */
  2327. interface InstanceSaveOptions {
  2328. /**
  2329. * An optional array of strings, representing database columns. If fields is provided, only those columns
  2330. * will be validated and saved.
  2331. */
  2332. fields? : Array<string>;
  2333. /**
  2334. * If true, the updatedAt timestamp will not be updated.
  2335. *
  2336. * Defaults to false
  2337. */
  2338. silent? : boolean;
  2339. /**
  2340. * If false, validations won't be run.
  2341. *
  2342. * Defaults to true
  2343. */
  2344. validate? : boolean;
  2345. /**
  2346. * A function that gets executed while running the query to log the sql.
  2347. */
  2348. logging? : boolean | Function;
  2349. /**
  2350. * Transaction to run the query in
  2351. */
  2352. transaction? : Transaction;
  2353. }
  2354. /**
  2355. * This class represents an single instance, a database row. You might see it referred to as both Instance and
  2356. * instance. You should not instantiate the Instance class directly, instead you access it using the finder and
  2357. * creation methods on the model.
  2358. *
  2359. * Instance instances operate with the concept of a `dataValues` property, which stores the actual values
  2360. * represented by the instance. By default, the values from dataValues can also be accessed directly from the
  2361. * Instance, that is:
  2362. * ```js
  2363. * instance.field
  2364. * // is the same as
  2365. * instance.get('field')
  2366. * // is the same as
  2367. * instance.getDataValue('field')
  2368. * ```
  2369. * However, if getters and/or setters are defined for `field` they will be invoked, instead of returning the
  2370. * value from `dataValues`. Accessing properties directly or using `get` is preferred for regular use,
  2371. * `getDataValue` should only be used for custom getters.
  2372. *
  2373. * @see Sequelize.define for more information about getters and setters
  2374. */
  2375. interface Instance<TInstance, TAttributes> {
  2376. /**
  2377. * Returns true if this instance has not yet been persisted to the database
  2378. */
  2379. isNewRecord : boolean;
  2380. /**
  2381. * Returns the Model the instance was created from.
  2382. *
  2383. * @see Model
  2384. */
  2385. Model : Model<TInstance, TAttributes>;
  2386. /**
  2387. * A reference to the sequelize instance
  2388. */
  2389. sequelize : Sequelize;
  2390. /**
  2391. * Get an object representing the query for this instance, use with `options.where`
  2392. */
  2393. where() : Object;
  2394. /**
  2395. * Get the value of the underlying data value
  2396. */
  2397. getDataValue( key : string ) : any;
  2398. /**
  2399. * Update the underlying data value
  2400. */
  2401. setDataValue( key : string, value : any ) : void;
  2402. /**
  2403. * If no key is given, returns all values of the instance, also invoking virtual getters.
  2404. *
  2405. * If key is given and a field or virtual getter is present for the key it will call that getter - else it
  2406. * will return the value for key.
  2407. *
  2408. * @param options.plain If set to true, included instances will be returned as plain objects
  2409. */
  2410. get( key : string, options? : { plain? : boolean, clone? : boolean } ) : any;
  2411. get( options? : { plain? : boolean, clone? : boolean } ) : TAttributes;
  2412. /**
  2413. * Set is used to update values on the instance (the sequelize representation of the instance that is,
  2414. * remember that nothing will be persisted before you actually call `save`). In its most basic form `set`
  2415. * will update a value stored in the underlying `dataValues` object. However, if a custom setter function
  2416. * is defined for the key, that function will be called instead. To bypass the setter, you can pass `raw:
  2417. * true` in the options object.
  2418. *
  2419. * If set is called with an object, it will loop over the object, and call set recursively for each key,
  2420. * value pair. If you set raw to true, the underlying dataValues will either be set directly to the object
  2421. * passed, or used to extend dataValues, if dataValues already contain values.
  2422. *
  2423. * When set is called, the previous value of the field is stored and sets a changed flag(see `changed`).
  2424. *
  2425. * Set can also be used to build instances for associations, if you have values for those.
  2426. * When using set with associations you need to make sure the property key matches the alias of the
  2427. * association while also making sure that the proper include options have been set (from .build() or
  2428. * .find())
  2429. *
  2430. * If called with a dot.seperated key on a JSON/JSONB attribute it will set the value nested and flag the
  2431. * entire object as changed.
  2432. *
  2433. * @param options.raw If set to true, field and virtual setters will be ignored
  2434. * @param options.reset Clear all previously set data values
  2435. */
  2436. set( key : string, value : any, options? : InstanceSetOptions ) : TInstance;
  2437. set( keys : Object, options? : InstanceSetOptions ) : TInstance;
  2438. setAttributes( key : string, value : any, options? : InstanceSetOptions ) : TInstance;
  2439. setAttributes( keys : Object, options? : InstanceSetOptions ) : TInstance;
  2440. /**
  2441. * If changed is called with a string it will return a boolean indicating whether the value of that key in
  2442. * `dataValues` is different from the value in `_previousDataValues`.
  2443. *
  2444. * If changed is called without an argument, it will return an array of keys that have changed.
  2445. *
  2446. * If changed is called without an argument and no keys have changed, it will return `false`.
  2447. */
  2448. changed( key : string ) : boolean;
  2449. changed() : boolean | Array<string>;
  2450. /**
  2451. * Returns the previous value for key from `_previousDataValues`.
  2452. */
  2453. previous( key : string ) : any;
  2454. /**
  2455. * Validate this instance, and if the validation passes, persist it to the database.
  2456. *
  2457. * On success, the callback will be called with this instance. On validation error, the callback will be
  2458. * called with an instance of `Sequelize.ValidationError`. This error will have a property for each of the
  2459. * fields for which validation failed, with the error message for that field.
  2460. */
  2461. save( options? : InstanceSaveOptions ) : Promise<TInstance>;
  2462. /**
  2463. * Refresh the current instance in-place, i.e. update the object with current data from the DB and return
  2464. * the same object. This is different from doing a `find(Instance.id)`, because that would create and
  2465. * return a new instance. With this method, all references to the Instance are updated with the new data
  2466. * and no new objects are created.
  2467. */
  2468. reload( options? : FindOptions ) : Promise<TInstance>;
  2469. /**
  2470. * Validate the attribute of this instance according to validation rules set in the model definition.
  2471. *
  2472. * Emits null if and only if validation successful; otherwise an Error instance containing
  2473. * { field name : [error msgs] } entries.
  2474. *
  2475. * @param options.skip An array of strings. All properties that are in this array will not be validated
  2476. */
  2477. validate( options? : { skip?: Array<string> } ) : Promise<void>;
  2478. /**
  2479. * This is the same as calling `set` and then calling `save`.
  2480. */
  2481. update( key : string, value : any, options? : InstanceUpdateOptions ) : Promise<TInstance>;
  2482. update( keys : Object, options? : InstanceUpdateOptions ) : Promise<TInstance>;
  2483. updateAttributes( key : string, value : any, options? : InstanceUpdateOptions ) : Promise<TInstance>;
  2484. updateAttributes( keys : Object, options? : InstanceUpdateOptions ) : Promise<TInstance>;
  2485. /**
  2486. * Destroy the row corresponding to this instance. Depending on your setting for paranoid, the row will
  2487. * either be completely deleted, or have its deletedAt timestamp set to the current time.
  2488. */
  2489. destroy( options? : InstanceDestroyOptions ) : Promise<void>;
  2490. /**
  2491. * Restore the row corresponding to this instance. Only available for paranoid models.
  2492. */
  2493. restore( options? : InstanceRestoreOptions ) : Promise<void>;
  2494. /**
  2495. * Increment the value of one or more columns. This is done in the database, which means it does not use
  2496. * the values currently stored on the Instance. The increment is done using a
  2497. * ```sql
  2498. * SET column = column + X
  2499. * ```
  2500. * query. To get the correct value after an increment into the Instance you should do a reload.
  2501. *
  2502. *```js
  2503. * instance.increment('number') // increment number by 1
  2504. * instance.increment(['number', 'count'], { by: 2 }) // increment number and count by 2
  2505. * instance.increment({ answer: 42, tries: 1}, { by: 2 }) // increment answer by 42, and tries by 1.
  2506. * // `by` is ignored, since each column has its own
  2507. * // value
  2508. * ```
  2509. *
  2510. * @param fields If a string is provided, that column is incremented by the value of `by` given in options.
  2511. * If an array is provided, the same is true for each column.
  2512. * If and object is provided, each column is incremented by the value given.
  2513. */
  2514. increment( fields : string | Array<string> | Object,
  2515. options? : InstanceIncrementDecrementOptions ) : Promise<TInstance>;
  2516. /**
  2517. * Decrement the value of one or more columns. This is done in the database, which means it does not use
  2518. * the values currently stored on the Instance. The decrement is done using a
  2519. * ```sql
  2520. * SET column = column - X
  2521. * ```
  2522. * query. To get the correct value after an decrement into the Instance you should do a reload.
  2523. *
  2524. * ```js
  2525. * instance.decrement('number') // decrement number by 1
  2526. * instance.decrement(['number', 'count'], { by: 2 }) // decrement number and count by 2
  2527. * instance.decrement({ answer: 42, tries: 1}, { by: 2 }) // decrement answer by 42, and tries by 1.
  2528. * // `by` is ignored, since each column has its own
  2529. * // value
  2530. * ```
  2531. *
  2532. * @param fields If a string is provided, that column is decremented by the value of `by` given in options.
  2533. * If an array is provided, the same is true for each column.
  2534. * If and object is provided, each column is decremented by the value given
  2535. */
  2536. decrement( fields : string | Array<string> | Object,
  2537. options? : InstanceIncrementDecrementOptions ) : Promise<TInstance>;
  2538. /**
  2539. * Check whether all values of this and `other` Instance are the same
  2540. */
  2541. equals( other : Instance<any, any> ) : boolean;
  2542. /**
  2543. * Check if this is eqaul to one of `others` by calling equals
  2544. */
  2545. equalsOneOf( others : Array<Instance<any, any>> ) : boolean;
  2546. /**
  2547. * Convert the instance to a JSON representation. Proxies to calling `get` with no keys. This means get all
  2548. * values gotten from the DB, and apply all custom getters.
  2549. */
  2550. toJSON() : TAttributes;
  2551. }
  2552. //
  2553. // Model
  2554. // ~~~~~~~
  2555. //
  2556. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/model.js
  2557. //
  2558. /**
  2559. * Options to pass to Model on drop
  2560. */
  2561. interface DropOptions {
  2562. /**
  2563. * Also drop all objects depending on this table, such as views. Only works in postgres
  2564. */
  2565. cascade?: boolean;
  2566. /**
  2567. * A function that gets executed while running the query to log the sql.
  2568. */
  2569. logging?: boolean | Function;
  2570. }
  2571. /**
  2572. * Schema Options provided for applying a schema to a model
  2573. */
  2574. interface SchemaOptions {
  2575. /**
  2576. * The character(s) that separates the schema name from the table name
  2577. */
  2578. schemaDelimeter? : string,
  2579. /**
  2580. * A function that gets executed while running the query to log the sql.
  2581. */
  2582. logging? : Function | boolean
  2583. }
  2584. /**
  2585. * Scope Options for Model.scope
  2586. */
  2587. interface ScopeOptions {
  2588. /**
  2589. * The scope(s) to apply. Scopes can either be passed as consecutive arguments, or as an array of arguments.
  2590. * To apply simple scopes and scope functions with no arguments, pass them as strings. For scope function,
  2591. * pass an object, with a `method` property. The value can either be a string, if the method does not take
  2592. * any arguments, or an array, where the first element is the name of the method, and consecutive elements
  2593. * are arguments to that method. Pass null to remove all scopes, including the default.
  2594. */
  2595. method : string | Array<any>;
  2596. }
  2597. /**
  2598. * Where Complex nested query
  2599. */
  2600. interface WhereNested {
  2601. $and : Array<WhereOptions | WhereLogic>;
  2602. $or : Array<WhereOptions | WhereLogic>;
  2603. }
  2604. /**
  2605. * Nested where Postgre Statement
  2606. */
  2607. interface WherePGStatement {
  2608. $any : Array<string | number>;
  2609. $all : Array<string | number>;
  2610. }
  2611. /**
  2612. * Where Geometry Options
  2613. */
  2614. interface WhereGeometryOptions {
  2615. type: string;
  2616. coordinates: Array<Array<number> | number>;
  2617. }
  2618. /**
  2619. * Logic of where statement
  2620. */
  2621. interface WhereLogic {
  2622. $ne : string | number | WhereLogic;
  2623. $in : Array<string | number> | literal;
  2624. $not : boolean | string | number | WhereOptions;
  2625. $notIn : Array<string | number> | literal;
  2626. $gte : number | string | Date;
  2627. $gt : number | string | Date;
  2628. $lte : number | string | Date;
  2629. $lt : number | string | Date;
  2630. $like : string | WherePGStatement;
  2631. $iLike : string | WherePGStatement;
  2632. $ilike : string | WherePGStatement;
  2633. $notLike : string | WherePGStatement;
  2634. $notILike : string | WherePGStatement;
  2635. $between : [number, number];
  2636. ".." : [number, number];
  2637. $notBetween: [number, number];
  2638. "!.." : [number, number];
  2639. $overlap : [number, number];
  2640. "&&" : [number, number];
  2641. $contains: any;
  2642. "@>": any;
  2643. $contained: any;
  2644. "<@": any;
  2645. }
  2646. /**
  2647. * A hash of attributes to describe your search. See above for examples.
  2648. *
  2649. * We did put Object in the end, because there where query might be a JSON Blob. It cripples a bit the
  2650. * typesafety, but there is no way to pass the tests if we just remove it.
  2651. */
  2652. interface WhereOptions {
  2653. [field: string]: string | number | WhereLogic | WhereOptions | col | and | or | WhereGeometryOptions | Array<string | number> | Object;
  2654. }
  2655. /**
  2656. * Through options for Include Options
  2657. */
  2658. interface IncludeThroughOptions {
  2659. /**
  2660. * Filter on the join model for belongsToMany relations
  2661. */
  2662. where? : WhereOptions;
  2663. /**
  2664. * A list of attributes to select from the join model for belongsToMany relations
  2665. */
  2666. attributes? : Array<string>;
  2667. }
  2668. /**
  2669. * Association Object for Include Options
  2670. */
  2671. interface IncludeAssociation {
  2672. source: Model<any, any>;
  2673. target: Model<any, any>;
  2674. identifier: string;
  2675. }
  2676. /**
  2677. * Complex include options
  2678. */
  2679. interface IncludeOptions {
  2680. /**
  2681. * The model you want to eagerly load
  2682. */
  2683. model? : Model<any, any>;
  2684. /**
  2685. * The alias of the relation, in case the model you want to eagerly load is aliassed. For `hasOne` /
  2686. * `belongsTo`, this should be the singular name, and for `hasMany`, it should be the plural
  2687. */
  2688. as? : string;
  2689. /**
  2690. * The association you want to eagerly load. (This can be used instead of providing a model/as pair)
  2691. */
  2692. association? : IncludeAssociation;
  2693. /**
  2694. * Where clauses to apply to the child models. Note that this converts the eager load to an inner join,
  2695. * unless you explicitly set `required: false`
  2696. */
  2697. where? : WhereOptions;
  2698. /**
  2699. * A list of attributes to select from the child model
  2700. */
  2701. attributes? : Array<string>;
  2702. /**
  2703. * If true, converts to an inner join, which means that the parent model will only be loaded if it has any
  2704. * matching children. True if `include.where` is set, false otherwise.
  2705. */
  2706. required? : boolean;
  2707. /**
  2708. * Through Options
  2709. */
  2710. through? : IncludeThroughOptions;
  2711. /**
  2712. * Load further nested related models
  2713. */
  2714. include? : Array<Model<any, any> | IncludeOptions>;
  2715. }
  2716. /**
  2717. * Options that are passed to any model creating a SELECT query
  2718. *
  2719. * A hash of options to describe the scope of the search
  2720. */
  2721. interface FindOptions {
  2722. /**
  2723. * A hash of attributes to describe your search. See above for examples.
  2724. */
  2725. where? : WhereOptions | Array<col | and | or | string>;
  2726. /**
  2727. * A list of the attributes that you want to select. To rename an attribute, you can pass an array, with
  2728. * two elements - the first is the name of the attribute in the DB (or some kind of expression such as
  2729. * `Sequelize.literal`, `Sequelize.fn` and so on), and the second is the name you want the attribute to
  2730. * have in the returned instance
  2731. */
  2732. attributes? : Array<string | [string, string]>;
  2733. /**
  2734. * If true, only non-deleted records will be returned. If false, both deleted and non-deleted records will
  2735. * be returned. Only applies if `options.paranoid` is true for the model.
  2736. */
  2737. paranoid?: boolean;
  2738. /**
  2739. * A list of associations to eagerly load using a left join. Supported is either
  2740. * `{ include: [ Model1, Model2, ...]}` or `{ include: [{ model: Model1, as: 'Alias' }]}`.
  2741. * If your association are set up with an `as` (eg. `X.hasMany(Y, { as: 'Z }`, you need to specify Z in
  2742. * the as attribute when eager loading Y).
  2743. */
  2744. include?: Array<Model<any, any> | IncludeOptions>;
  2745. /**
  2746. * Specifies an ordering. If a string is provided, it will be escaped. Using an array, you can provide
  2747. * several columns / functions to order by. Each element can be further wrapped in a two-element array. The
  2748. * first element is the column / function to order by, the second is the direction. For example:
  2749. * `order: [['name', 'DESC']]`. In this way the column will be escaped, but the direction will not.
  2750. */
  2751. order?: string | col | literal | Array<string | number | Model<any, any> | { model : Model<any, any>, as? : string}> | Array<string | col | literal | Array<string | number | Model<any, any> | { model : Model<any, any>, as? : string}>>;
  2752. /**
  2753. * Limit the results
  2754. */
  2755. limit?: number;
  2756. /**
  2757. * Skip the results;
  2758. */
  2759. offset?: number;
  2760. /**
  2761. * Transaction to run query under
  2762. */
  2763. transaction? : Transaction;
  2764. /**
  2765. * Lock the selected rows. Possible options are transaction.LOCK.UPDATE and transaction.LOCK.SHARE.
  2766. * Postgres also supports transaction.LOCK.KEY_SHARE, transaction.LOCK.NO_KEY_UPDATE and specific model
  2767. * locks with joins. See [transaction.LOCK for an example](transaction#lock)
  2768. */
  2769. lock? : string | { level: string, of: Model<any, any> };
  2770. /**
  2771. * Return raw result. See sequelize.query for more information.
  2772. */
  2773. raw? : boolean;
  2774. /**
  2775. * A function that gets executed while running the query to log the sql.
  2776. */
  2777. logging? : boolean | Function;
  2778. /**
  2779. * having ?!?
  2780. */
  2781. having? : WhereOptions;
  2782. }
  2783. /**
  2784. * Options for Model.count method
  2785. */
  2786. interface CountOptions {
  2787. /**
  2788. * A hash of search attributes.
  2789. */
  2790. where? : WhereOptions | Array<string>;
  2791. /**
  2792. * Include options. See `find` for details
  2793. */
  2794. include?: Array<Model<any, any> | IncludeOptions>;
  2795. /**
  2796. * Apply COUNT(DISTINCT(col))
  2797. */
  2798. distinct? : boolean;
  2799. /**
  2800. * Used in conjustion with `group`
  2801. */
  2802. attributes? : Array<string | [string, string]>;
  2803. /**
  2804. * For creating complex counts. Will return multiple rows as needed.
  2805. *
  2806. * TODO: Check?
  2807. */
  2808. group? : Object;
  2809. /**
  2810. * A function that gets executed while running the query to log the sql.
  2811. */
  2812. logging? : boolean | Function;
  2813. transaction?: Transaction;
  2814. }
  2815. /**
  2816. * Options for Model.build method
  2817. */
  2818. interface BuildOptions {
  2819. /**
  2820. * If set to true, values will ignore field and virtual setters.
  2821. */
  2822. raw? : boolean;
  2823. /**
  2824. * Is this record new
  2825. */
  2826. isNewRecord? : boolean;
  2827. /**
  2828. * an array of include options - Used to build prefetched/included model instances. See `set`
  2829. *
  2830. * TODO: See set
  2831. */
  2832. include? : Array<Model<any, any> | IncludeOptions>;
  2833. }
  2834. /**
  2835. * Options for Model.create method
  2836. */
  2837. interface CreateOptions extends BuildOptions {
  2838. /**
  2839. * If set, only columns matching those in fields will be saved
  2840. */
  2841. fields? : Array<string>;
  2842. /**
  2843. * On Duplicate
  2844. */
  2845. onDuplicate? : string;
  2846. /**
  2847. * Transaction to run query under
  2848. */
  2849. transaction? : Transaction;
  2850. /**
  2851. * A function that gets executed while running the query to log the sql.
  2852. */
  2853. logging? : boolean | Function;
  2854. silent? : boolean;
  2855. returning? : boolean;
  2856. }
  2857. /**
  2858. * Options for Model.findOrInitialize method
  2859. */
  2860. interface FindOrInitializeOptions<TAttributes> {
  2861. /**
  2862. * A hash of search attributes.
  2863. */
  2864. where : string | WhereOptions;
  2865. /**
  2866. * Default values to use if building a new instance
  2867. */
  2868. defaults? : TAttributes;
  2869. /**
  2870. * Transaction to run query under
  2871. */
  2872. transaction? : Transaction;
  2873. /**
  2874. * A function that gets executed while running the query to log the sql.
  2875. */
  2876. logging? : boolean | Function;
  2877. }
  2878. /**
  2879. * Options for Model.upsert method
  2880. */
  2881. interface UpsertOptions {
  2882. /**
  2883. * Run validations before the row is inserted
  2884. */
  2885. validate? : boolean;
  2886. /**
  2887. * The fields to insert / update. Defaults to all fields
  2888. */
  2889. fields? : Array<string>;
  2890. /**
  2891. * A function that gets executed while running the query to log the sql.
  2892. */
  2893. logging? : boolean | Function;
  2894. }
  2895. /**
  2896. * Options for Model.bulkCreate method
  2897. */
  2898. interface BulkCreateOptions {
  2899. /**
  2900. * Fields to insert (defaults to all fields)
  2901. */
  2902. fields? : Array<string>;
  2903. /**
  2904. * Should each row be subject to validation before it is inserted. The whole insert will fail if one row
  2905. * fails validation
  2906. */
  2907. validate? : boolean;
  2908. /**
  2909. * Run before / after bulk create hooks?
  2910. */
  2911. hooks? : boolean;
  2912. /**
  2913. * Run before / after create hooks for each individual Instance? BulkCreate hooks will still be run if
  2914. * options.hooks is true.
  2915. */
  2916. individualHooks? : boolean;
  2917. /**
  2918. * Ignore duplicate values for primary keys? (not supported by postgres)
  2919. *
  2920. * Defaults to false
  2921. */
  2922. ignoreDuplicates? : boolean;
  2923. /**
  2924. * Fields to update if row key already exists (on duplicate key update)? (only supported by mysql &
  2925. * mariadb). By default, all fields are updated.
  2926. */
  2927. updateOnDuplicate? : Array<string>;
  2928. /**
  2929. * Transaction to run query under
  2930. */
  2931. transaction? : Transaction;
  2932. /**
  2933. * A function that gets executed while running the query to log the sql.
  2934. */
  2935. logging? : boolean | Function;
  2936. }
  2937. /**
  2938. * The options passed to Model.destroy in addition to truncate
  2939. */
  2940. interface TruncateOptions {
  2941. /**
  2942. * Transaction to run query under
  2943. */
  2944. transaction? : Transaction;
  2945. /**
  2946. * Only used in conjuction with TRUNCATE. Truncates all tables that have foreign-key references to the
  2947. * named table, or to any tables added to the group due to CASCADE.
  2948. *
  2949. * Defaults to false;
  2950. */
  2951. cascade? : boolean;
  2952. /**
  2953. * A function that gets executed while running the query to log the sql.
  2954. */
  2955. logging? : boolean | Function;
  2956. }
  2957. /**
  2958. * Options used for Model.destroy
  2959. */
  2960. interface DestroyOptions extends TruncateOptions {
  2961. /**
  2962. * Filter the destroy
  2963. */
  2964. where? : WhereOptions;
  2965. /**
  2966. * Run before / after bulk destroy hooks?
  2967. */
  2968. hooks? : boolean;
  2969. /**
  2970. * If set to true, destroy will SELECT all records matching the where parameter and will execute before /
  2971. * after destroy hooks on each row
  2972. */
  2973. individualHooks? : boolean;
  2974. /**
  2975. * How many rows to delete
  2976. */
  2977. limit? : number;
  2978. /**
  2979. * Delete instead of setting deletedAt to current timestamp (only applicable if `paranoid` is enabled)
  2980. */
  2981. force? : boolean;
  2982. /**
  2983. * If set to true, dialects that support it will use TRUNCATE instead of DELETE FROM. If a table is
  2984. * truncated the where and limit options are ignored
  2985. */
  2986. truncate? : boolean;
  2987. }
  2988. /**
  2989. * Options for Model.restore
  2990. */
  2991. interface RestoreOptions {
  2992. /**
  2993. * Filter the restore
  2994. */
  2995. where? : WhereOptions;
  2996. /**
  2997. * Run before / after bulk restore hooks?
  2998. */
  2999. hooks? : boolean;
  3000. /**
  3001. * If set to true, restore will find all records within the where parameter and will execute before / after
  3002. * bulkRestore hooks on each row
  3003. */
  3004. individualHooks? : boolean;
  3005. /**
  3006. * How many rows to undelete
  3007. */
  3008. limit? : number;
  3009. /**
  3010. * A function that gets executed while running the query to log the sql.
  3011. */
  3012. logging? : boolean | Function;
  3013. /**
  3014. * Transaction to run query under
  3015. */
  3016. transaction? : Transaction;
  3017. }
  3018. /**
  3019. * Options used for Model.update
  3020. */
  3021. interface UpdateOptions {
  3022. /**
  3023. * Options to describe the scope of the search.
  3024. */
  3025. where: WhereOptions;
  3026. /**
  3027. * Fields to update (defaults to all fields)
  3028. */
  3029. fields? : Array<string>;
  3030. /**
  3031. * Should each row be subject to validation before it is inserted. The whole insert will fail if one row
  3032. * fails validation.
  3033. *
  3034. * Defaults to true
  3035. */
  3036. validate? : boolean;
  3037. /**
  3038. * Run before / after bulk update hooks?
  3039. *
  3040. * Defaults to true
  3041. */
  3042. hooks? : boolean;
  3043. /**
  3044. * Whether or not to update the side effects of any virtual setters.
  3045. *
  3046. * Defaults to true
  3047. */
  3048. sideEffects? : boolean;
  3049. /**
  3050. * Run before / after update hooks?. If true, this will execute a SELECT followed by individual UPDATEs.
  3051. * A select is needed, because the row data needs to be passed to the hooks
  3052. *
  3053. * Defaults to false
  3054. */
  3055. individualHooks? : boolean;
  3056. /**
  3057. * Return the affected rows (only for postgres)
  3058. */
  3059. returning? : boolean;
  3060. /**
  3061. * How many rows to update (only for mysql and mariadb)
  3062. */
  3063. limit? : number;
  3064. /**
  3065. * A function that gets executed while running the query to log the sql.
  3066. */
  3067. logging? : boolean | Function;
  3068. /**
  3069. * Transaction to run query under
  3070. */
  3071. transaction? : Transaction;
  3072. }
  3073. /**
  3074. * Options used for Model.aggregate
  3075. */
  3076. interface AggregateOptions extends QueryOptions {
  3077. /**
  3078. * A hash of search attributes.
  3079. */
  3080. where?: WhereOptions;
  3081. /**
  3082. * The type of the result. If `field` is a field in this Model, the default will be the type of that field,
  3083. * otherwise defaults to float.
  3084. */
  3085. dataType? : DataTypeAbstract | string;
  3086. /**
  3087. * Applies DISTINCT to the field being aggregated over
  3088. */
  3089. distinct? : boolean;
  3090. }
  3091. /**
  3092. * A Model represents a table in the database. Sometimes you might also see it referred to as model, or simply
  3093. * as factory. This class should _not_ be instantiated directly, it is created using `sequelize.define`, and
  3094. * already created models can be loaded using `sequelize.import`
  3095. */
  3096. interface Model<TInstance, TAttributes> extends Hooks<TInstance>, Associations {
  3097. /**
  3098. * The Instance class
  3099. */
  3100. Instance() : Instance<TInstance, TAttributes>;
  3101. /**
  3102. * Remove attribute from model definition
  3103. *
  3104. * @param attribute
  3105. */
  3106. removeAttribute( attribute : string ) : void;
  3107. /**
  3108. * Sync this Model to the DB, that is create the table. Upon success, the callback will be called with the
  3109. * model instance (this)
  3110. */
  3111. sync( options? : SyncOptions ) : Promise<Model<TInstance, TAttributes>>;
  3112. /**
  3113. * Drop the table represented by this Model
  3114. *
  3115. * @param options
  3116. */
  3117. drop( options? : DropOptions ) : Promise<void>;
  3118. /**
  3119. * Apply a schema to this model. For postgres, this will actually place the schema in front of the table
  3120. * name
  3121. * - `"schema"."tableName"`, while the schema will be prepended to the table name for mysql and
  3122. * sqlite - `'schema.tablename'`.
  3123. *
  3124. * @param schema The name of the schema
  3125. * @param options
  3126. */
  3127. schema( schema : string, options? : SchemaOptions ) : Model<TInstance, TAttributes>;
  3128. /**
  3129. * Get the tablename of the model, taking schema into account. The method will return The name as a string
  3130. * if the model has no schema, or an object with `tableName`, `schema` and `delimiter` properties.
  3131. *
  3132. * @param options The hash of options from any query. You can use one model to access tables with matching
  3133. * schemas by overriding `getTableName` and using custom key/values to alter the name of the table.
  3134. * (eg.
  3135. * subscribers_1, subscribers_2)
  3136. * @param options.logging=false A function that gets executed while running the query to log the sql.
  3137. */
  3138. getTableName( options? : { logging : Function } ) : string | Object;
  3139. /**
  3140. * Apply a scope created in `define` to the model. First let's look at how to create scopes:
  3141. * ```js
  3142. * var Model = sequelize.define('model', attributes, {
  3143. * defaultScope: {
  3144. * where: {
  3145. * username: 'dan'
  3146. * },
  3147. * limit: 12
  3148. * },
  3149. * scopes: {
  3150. * isALie: {
  3151. * where: {
  3152. * stuff: 'cake'
  3153. * }
  3154. * },
  3155. * complexFunction: function(email, accessLevel) {
  3156. * return {
  3157. * where: {
  3158. * email: {
  3159. * $like: email
  3160. * },
  3161. * accesss_level {
  3162. * $gte: accessLevel
  3163. * }
  3164. * }
  3165. * }
  3166. * }
  3167. * }
  3168. * })
  3169. * ```
  3170. * Now, since you defined a default scope, every time you do Model.find, the default scope is appended to
  3171. * your query. Here's a couple of examples:
  3172. * ```js
  3173. * Model.findAll() // WHERE username = 'dan'
  3174. * Model.findAll({ where: { age: { gt: 12 } } }) // WHERE age > 12 AND username = 'dan'
  3175. * ```
  3176. *
  3177. * To invoke scope functions you can do:
  3178. * ```js
  3179. * Model.scope({ method: ['complexFunction' 'dan@sequelize.com', 42]}).findAll()
  3180. * // WHERE email like 'dan@sequelize.com%' AND access_level >= 42
  3181. * ```
  3182. *
  3183. * @return Model A reference to the model, with the scope(s) applied. Calling scope again on the returned
  3184. * model will clear the previous scope.
  3185. */
  3186. scope( options? : string | Array<string> | ScopeOptions | WhereOptions ) : Model<TInstance, TAttributes>;
  3187. /**
  3188. * Search for multiple instances.
  3189. *
  3190. * __Simple search using AND and =__
  3191. * ```js
  3192. * Model.findAll({
  3193. * where: {
  3194. * attr1: 42,
  3195. * attr2: 'cake'
  3196. * }
  3197. * })
  3198. * ```
  3199. * ```sql
  3200. * WHERE attr1 = 42 AND attr2 = 'cake'
  3201. *```
  3202. *
  3203. * __Using greater than, less than etc.__
  3204. * ```js
  3205. *
  3206. * Model.findAll({
  3207. * where: {
  3208. * attr1: {
  3209. * gt: 50
  3210. * },
  3211. * attr2: {
  3212. * lte: 45
  3213. * },
  3214. * attr3: {
  3215. * in: [1,2,3]
  3216. * },
  3217. * attr4: {
  3218. * ne: 5
  3219. * }
  3220. * }
  3221. * })
  3222. * ```
  3223. * ```sql
  3224. * WHERE attr1 > 50 AND attr2 <= 45 AND attr3 IN (1,2,3) AND attr4 != 5
  3225. * ```
  3226. * Possible options are: `$ne, $in, $not, $notIn, $gte, $gt, $lte, $lt, $like, $ilike/$iLike, $notLike,
  3227. * $notILike, '..'/$between, '!..'/$notBetween, '&&'/$overlap, '@>'/$contains, '<@'/$contained`
  3228. *
  3229. * __Queries using OR__
  3230. * ```js
  3231. * Model.findAll({
  3232. * where: Sequelize.and(
  3233. * { name: 'a project' },
  3234. * Sequelize.or(
  3235. * { id: [1,2,3] },
  3236. * { id: { gt: 10 } }
  3237. * )
  3238. * )
  3239. * })
  3240. * ```
  3241. * ```sql
  3242. * WHERE name = 'a project' AND (id` IN (1,2,3) OR id > 10)
  3243. * ```
  3244. *
  3245. * The success listener is called with an array of instances if the query succeeds.
  3246. *
  3247. * @see {Sequelize#query}
  3248. */
  3249. findAll( options? : FindOptions ) : Promise<Array<TInstance>>;
  3250. all( optionz? : FindOptions ) : Promise<Array<TInstance>>;
  3251. /**
  3252. * Search for a single instance by its primary key. This applies LIMIT 1, so the listener will
  3253. * always be called with a single instance.
  3254. */
  3255. findById( identifier? : number | string, options? : FindOptions ) : Promise<TInstance>;
  3256. findByPrimary( identifier? : number | string, options? : FindOptions ) : Promise<TInstance>;
  3257. /**
  3258. * Search for a single instance. This applies LIMIT 1, so the listener will always be called with a single
  3259. * instance.
  3260. */
  3261. findOne( options? : FindOptions ) : Promise<TInstance>;
  3262. find( optionz? : FindOptions ) : Promise<TInstance>;
  3263. /**
  3264. * Run an aggregation method on the specified field
  3265. *
  3266. * @param field The field to aggregate over. Can be a field name or *
  3267. * @param aggregateFunction The function to use for aggregation, e.g. sum, max etc.
  3268. * @param options Query options. See sequelize.query for full options
  3269. * @return Returns the aggregate result cast to `options.dataType`, unless `options.plain` is false, in
  3270. * which case the complete data result is returned.
  3271. */
  3272. aggregate( field : string, aggregateFunction : Function, options? : AggregateOptions ) : Promise<Object>;
  3273. /**
  3274. * Count the number of records matching the provided where clause.
  3275. *
  3276. * If you provide an `include` option, the number of matching associations will be counted instead.
  3277. */
  3278. count( options? : CountOptions ) : Promise<number>;
  3279. /**
  3280. * Find all the rows matching your query, within a specified offset / limit, and get the total number of
  3281. * rows matching your query. This is very usefull for paging
  3282. *
  3283. * ```js
  3284. * Model.findAndCountAll({
  3285. * where: ...,
  3286. * limit: 12,
  3287. * offset: 12
  3288. * }).then(function (result) {
  3289. * ...
  3290. * })
  3291. * ```
  3292. * In the above example, `result.rows` will contain rows 13 through 24, while `result.count` will return
  3293. * the
  3294. * total number of rows that matched your query.
  3295. *
  3296. * When you add includes, only those which are required (either because they have a where clause, or
  3297. * because
  3298. * `required` is explicitly set to true on the include) will be added to the count part.
  3299. *
  3300. * Suppose you want to find all users who have a profile attached:
  3301. * ```js
  3302. * User.findAndCountAll({
  3303. * include: [
  3304. * { model: Profile, required: true}
  3305. * ],
  3306. * limit 3
  3307. * });
  3308. * ```
  3309. * Because the include for `Profile` has `required` set it will result in an inner join, and only the users
  3310. * who have a profile will be counted. If we remove `required` from the include, both users with and
  3311. * without
  3312. * profiles will be counted
  3313. */
  3314. findAndCount( options? : FindOptions ) : Promise<{ rows : Array<TInstance>, count : number }>;
  3315. findAndCountAll( options? : FindOptions ) : Promise<{ rows : Array<TInstance>, count : number }>;
  3316. /**
  3317. * Find the maximum value of field
  3318. */
  3319. max( field : string, options? : AggregateOptions ) : Promise<any>;
  3320. /**
  3321. * Find the minimum value of field
  3322. */
  3323. min( field : string, options? : AggregateOptions ) : Promise<any>;
  3324. /**
  3325. * Find the sum of field
  3326. */
  3327. sum( field : string, options? : AggregateOptions ) : Promise<number>;
  3328. /**
  3329. * Builds a new model instance. Values is an object of key value pairs, must be defined but can be empty.
  3330. */
  3331. build( record? : TAttributes, options? : BuildOptions ) : TInstance;
  3332. /**
  3333. * Undocumented bulkBuild
  3334. */
  3335. bulkBuild( records : Array<TAttributes>, options? : BuildOptions ) : Array<TInstance>;
  3336. /**
  3337. * Builds a new model instance and calls save on it.
  3338. */
  3339. create( values? : TAttributes, options? : CreateOptions ) : Promise<TInstance>;
  3340. /**
  3341. * Find a row that matches the query, or build (but don't save) the row if none is found.
  3342. * The successfull result of the promise will be (instance, initialized) - Make sure to use .spread()
  3343. */
  3344. findOrInitialize( options : FindOrInitializeOptions<TAttributes> ) : Promise<TInstance>;
  3345. findOrBuild( options : FindOrInitializeOptions<TAttributes> ) : Promise<TInstance>;
  3346. /**
  3347. * Find a row that matches the query, or build and save the row if none is found
  3348. * The successful result of the promise will be (instance, created) - Make sure to use .spread()
  3349. *
  3350. * If no transaction is passed in the `options` object, a new transaction will be created internally, to
  3351. * prevent the race condition where a matching row is created by another connection after the find but
  3352. * before the insert call. However, it is not always possible to handle this case in SQLite, specifically
  3353. * if one transaction inserts and another tries to select before the first one has comitted. In this case,
  3354. * an instance of sequelize.TimeoutError will be thrown instead. If a transaction is created, a savepoint
  3355. * will be created instead, and any unique constraint violation will be handled internally.
  3356. */
  3357. findOrCreate( options : FindOrInitializeOptions<TAttributes> ) : Promise<TInstance>;
  3358. /**
  3359. * Insert or update a single row. An update will be executed if a row which matches the supplied values on
  3360. * either the primary key or a unique key is found. Note that the unique index must be defined in your
  3361. * sequelize model and not just in the table. Otherwise you may experience a unique constraint violation,
  3362. * because sequelize fails to identify the row that should be updated.
  3363. *
  3364. * **Implementation details:**
  3365. *
  3366. * * MySQL - Implemented as a single query `INSERT values ON DUPLICATE KEY UPDATE values`
  3367. * * PostgreSQL - Implemented as a temporary function with exception handling: INSERT EXCEPTION WHEN
  3368. * unique_constraint UPDATE
  3369. * * SQLite - Implemented as two queries `INSERT; UPDATE`. This means that the update is executed
  3370. * regardless
  3371. * of whether the row already existed or not
  3372. *
  3373. * **Note** that SQLite returns undefined for created, no matter if the row was created or updated. This is
  3374. * because SQLite always runs INSERT OR IGNORE + UPDATE, in a single query, so there is no way to know
  3375. * whether the row was inserted or not.
  3376. */
  3377. upsert( values : TAttributes, options? : UpsertOptions ) : Promise<boolean>;
  3378. insertOrUpdate( values : TAttributes, options? : UpsertOptions ) : Promise<boolean>;
  3379. /**
  3380. * Create and insert multiple instances in bulk.
  3381. *
  3382. * The success handler is passed an array of instances, but please notice that these may not completely
  3383. * represent the state of the rows in the DB. This is because MySQL and SQLite do not make it easy to
  3384. * obtain
  3385. * back automatically generated IDs and other default values in a way that can be mapped to multiple
  3386. * records. To obtain Instances for the newly created values, you will need to query for them again.
  3387. *
  3388. * @param records List of objects (key/value pairs) to create instances from
  3389. */
  3390. bulkCreate( records : Array<TAttributes>, options? : BulkCreateOptions ) : Promise<Array<TInstance>>;
  3391. /**
  3392. * Truncate all instances of the model. This is a convenient method for Model.destroy({ truncate: true }).
  3393. */
  3394. truncate( options? : TruncateOptions ) : Promise<void>;
  3395. /**
  3396. * Delete multiple instances, or set their deletedAt timestamp to the current time if `paranoid` is enabled.
  3397. *
  3398. * @return Promise<number> The number of destroyed rows
  3399. */
  3400. destroy( options? : DestroyOptions ) : Promise<number>;
  3401. /**
  3402. * Restore multiple instances if `paranoid` is enabled.
  3403. */
  3404. restore( options? : RestoreOptions ) : Promise<void>;
  3405. /**
  3406. * Update multiple instances that match the where options. The promise returns an array with one or two
  3407. * elements. The first element is always the number of affected rows, while the second element is the actual
  3408. * affected rows (only supported in postgres with `options.returning` true.)
  3409. */
  3410. update( values : TAttributes, options : UpdateOptions ) : Promise<[number, Array<TInstance>]>;
  3411. /**
  3412. * Run a describe query on the table. The result will be return to the listener as a hash of attributes and
  3413. * their types.
  3414. */
  3415. describe() : Promise<Object>;
  3416. /**
  3417. * Unscope the model
  3418. */
  3419. unscoped() : Model<TInstance, TAttributes>;
  3420. }
  3421. //
  3422. // Query Interface
  3423. // ~~~~~~~~~~~~~~~~~
  3424. //
  3425. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/query-interface.js
  3426. //
  3427. /**
  3428. * Most of the methods accept options and use only the logger property of the options. That's why the most used
  3429. * interface type for options in a method is separated here as another interface.
  3430. */
  3431. interface QueryInterfaceOptions {
  3432. /**
  3433. * A function that gets executed while running the query to log the sql.
  3434. */
  3435. logging? : boolean | Function;
  3436. }
  3437. /**
  3438. * The interface that Sequelize uses to talk to all databases.
  3439. *
  3440. * This interface is available through sequelize.QueryInterface. It should not be commonly used, but it's
  3441. * referenced anyway, so it can be used.
  3442. */
  3443. interface QueryInterface {
  3444. /**
  3445. * Returns the dialect-specific sql generator.
  3446. *
  3447. * We don't have a definition for the QueryGenerator, because I doubt it is commonly in use separately.
  3448. */
  3449. QueryGenerator: any;
  3450. /**
  3451. * Queries the schema (table list).
  3452. *
  3453. * @param schema The schema to query. Applies only to Postgres.
  3454. */
  3455. createSchema( schema? : string, options? : QueryInterfaceOptions ): Promise<void>;
  3456. /**
  3457. * Drops the specified schema (table).
  3458. *
  3459. * @param schema The schema to query. Applies only to Postgres.
  3460. */
  3461. dropSchema( schema? : string, options? : QueryInterfaceOptions ): Promise<void>;
  3462. /**
  3463. * Drops all tables.
  3464. */
  3465. dropAllSchemas( options? : QueryInterfaceOptions ): Promise<void>;
  3466. /**
  3467. * Queries all table names in the database.
  3468. *
  3469. * @param options
  3470. */
  3471. showAllSchemas( options? : QueryOptions ): Promise<Object>;
  3472. /**
  3473. * Return database version
  3474. */
  3475. databaseVersion( options? : QueryInterfaceOptions ) : Promise<string>;
  3476. /**
  3477. * Creates a table with specified attributes.
  3478. *
  3479. * @param tableName Name of table to create
  3480. * @param attributes Hash of attributes, key is attribute name, value is data type
  3481. * @param options Query options.
  3482. */
  3483. createTable( tableName : string | { schema? : string, tableName? : string }, attributes : DefineAttributes,
  3484. options? : QueryOptions ): Promise<void>;
  3485. /**
  3486. * Drops the specified table.
  3487. *
  3488. * @param tableName Table name.
  3489. * @param options Query options, particularly "force".
  3490. */
  3491. dropTable( tableName : string, options? : QueryOptions ): Promise<void>;
  3492. /**
  3493. * Drops all tables.
  3494. *
  3495. * @param options
  3496. */
  3497. dropAllTables( options? : QueryOptions ): Promise<void>;
  3498. /**
  3499. * Drops all defined enums
  3500. *
  3501. * @param options
  3502. */
  3503. dropAllEnums( options? : QueryOptions ): Promise<void>;
  3504. /**
  3505. * Renames a table
  3506. */
  3507. renameTable( before : string, after : string, options? : QueryInterfaceOptions ) : Promise<void>;
  3508. /**
  3509. * Returns all tables
  3510. */
  3511. showAllTables( options? : QueryOptions ) : Promise<Array<string>>;
  3512. /**
  3513. * Describe a table
  3514. */
  3515. describeTable( tableName : string | { schema? : string, tableName? : string },
  3516. options? : string | { schema? : string, schemaDelimeter? : string, logging? : boolean | Function } ) : Promise<Object>;
  3517. /**
  3518. * Adds a new column to a table
  3519. */
  3520. addColumn( table : string, key : string, attribute : DefineAttributeColumnOptions | DataTypeAbstract,
  3521. options? : QueryInterfaceOptions ) : Promise<void>;
  3522. /**
  3523. * Removes a column from a table
  3524. */
  3525. removeColumn( table : string, attribute : string, options? : QueryInterfaceOptions ) : Promise<void>;
  3526. /**
  3527. * Changes a column
  3528. */
  3529. changeColumn( tableName : string | { schema? : string, tableName? : string }, attributeName : string,
  3530. dataTypeOrOptions? : string | DataTypeAbstract | DefineAttributeColumnOptions,
  3531. options? : QueryInterfaceOptions ) : Promise<void>;
  3532. /**
  3533. * Renames a column
  3534. */
  3535. renameColumn( tableName : string | { schema? : string, tableName? : string }, attrNameBefore : string,
  3536. attrNameAfter : string,
  3537. options? : QueryInterfaceOptions ) : Promise<void>;
  3538. /**
  3539. * Adds a new index to a table
  3540. */
  3541. addIndex( tableName : string | Object, attributes : Array<string>, options? : QueryOptions,
  3542. rawTablename? : string ) : Promise<void>;
  3543. /**
  3544. * Shows the index of a table
  3545. */
  3546. showIndex( tableName : string | Object, options? : QueryOptions ) : Promise<Object>;
  3547. /**
  3548. * Put a name to an index
  3549. */
  3550. nameIndexes( indexes : Array<string>, rawTablename : string ) : Promise<void>;
  3551. /**
  3552. * Returns all foreign key constraints of a table
  3553. */
  3554. getForeignKeysForTables( tableNames : string, options? : QueryInterfaceOptions ) : Promise<Object>;
  3555. /**
  3556. * Removes an index of a table
  3557. */
  3558. removeIndex( tableName : string, indexNameOrAttributes : Array<string> | string,
  3559. options? : QueryInterfaceOptions ) : Promise<void>;
  3560. /**
  3561. * Inserts a new record
  3562. */
  3563. insert( instance : Instance<any, any>, tableName : string, values : Object,
  3564. options? : QueryOptions ) : Promise<Object>;
  3565. /**
  3566. * Inserts or Updates a record in the database
  3567. */
  3568. upsert( tableName : string, values : Object, updateValues : Object, model : Model<any, any>,
  3569. options? : QueryOptions ) : Promise<Object>;
  3570. /**
  3571. * Inserts multiple records at once
  3572. */
  3573. bulkInsert( tableName : string, records : Array<Object>, options? : QueryOptions,
  3574. attributes? : Array<string> | string ) : Promise<Object>;
  3575. /**
  3576. * Updates a row
  3577. */
  3578. update( instance : Instance<any, any>, tableName : string, values : Object, identifier : Object,
  3579. options? : QueryOptions ) : Promise<Object>;
  3580. /**
  3581. * Updates multiple rows at once
  3582. */
  3583. bulkUpdate( tableName : string, values : Object, identifier : Object, options? : QueryOptions,
  3584. attributes? : Array<string> | string ) : Promise<Object>;
  3585. /**
  3586. * Deletes a row
  3587. */
  3588. "delete"( instance : Instance<any, any>, tableName : string, identifier : Object,
  3589. options? : QueryOptions ) : Promise<Object>;
  3590. /**
  3591. * Deletes multiple rows at once
  3592. */
  3593. bulkDelete( tableName : string, identifier : Object, options? : QueryOptions,
  3594. model? : Model<any, any> ) : Promise<Object>;
  3595. /**
  3596. * Returns selected rows
  3597. */
  3598. select( model : Model<any, any>, tableName : string, options? : QueryOptions ) : Promise<Array<Object>>;
  3599. /**
  3600. * Increments a row value
  3601. */
  3602. increment( instance : Instance<any, any>, tableName : string, values : Object, identifier : Object,
  3603. options? : QueryOptions ) : Promise<Object>;
  3604. /**
  3605. * Selects raw without parsing the string into an object
  3606. */
  3607. rawSelect( tableName : string, options : QueryOptions, attributeSelector : string | Array<string>,
  3608. model? : Model<any, any> ) : Promise<Array<string>>;
  3609. /**
  3610. * Postgres only. Creates a trigger on specified table to call the specified function with supplied
  3611. * parameters.
  3612. */
  3613. createTrigger( tableName : string, triggerName : string, timingType : string, fireOnArray : Array<any>,
  3614. functionName : string, functionParams : Array<any>, optionsArray : Array<string>,
  3615. options? : QueryInterfaceOptions ): Promise<void>;
  3616. /**
  3617. * Postgres only. Drops the specified trigger.
  3618. */
  3619. dropTrigger( tableName : string, triggerName : string, options? : QueryInterfaceOptions ): Promise<void>;
  3620. /**
  3621. * Postgres only. Renames a trigger
  3622. */
  3623. renameTrigger( tableName : string, oldTriggerName : string, newTriggerName : string,
  3624. options? : QueryInterfaceOptions ) : Promise<void>;
  3625. /**
  3626. * Postgres only. Create a function
  3627. */
  3628. createFunction( functionName : string, params : Array<any>, returnType : string, language : string,
  3629. body : string, options? : QueryOptions ) : Promise<void>;
  3630. /**
  3631. * Postgres only. Drops a function
  3632. */
  3633. dropFunction( functionName : string, params : Array<any>,
  3634. options? : QueryInterfaceOptions ) : Promise<void>;
  3635. /**
  3636. * Postgres only. Rename a function
  3637. */
  3638. renameFunction( oldFunctionName : string, params : Array<any>, newFunctionName : string,
  3639. options? : QueryInterfaceOptions ) : Promise<void>;
  3640. /**
  3641. * Escape an identifier (e.g. a table or attribute name). If force is true, the identifier will be quoted
  3642. * even if the `quoteIdentifiers` option is false.
  3643. */
  3644. quoteIdentifier( identifier : string, force : boolean ) : string;
  3645. /**
  3646. * Escape a table name
  3647. */
  3648. quoteTable( identifier : string ) : string;
  3649. /**
  3650. * Split an identifier into .-separated tokens and quote each part. If force is true, the identifier will be
  3651. * quoted even if the `quoteIdentifiers` option is false.
  3652. */
  3653. quoteIdentifiers( identifiers : string, force : boolean ) : string;
  3654. /**
  3655. * Escape a value (e.g. a string, number or date)
  3656. */
  3657. escape( value? : string | number | Date ) : string;
  3658. /**
  3659. * Set option for autocommit of a transaction
  3660. */
  3661. setAutocommit( transaction : Transaction, value : boolean, options? : QueryOptions ) : Promise<void>;
  3662. /**
  3663. * Set the isolation level of a transaction
  3664. */
  3665. setIsolationLevel( transaction : Transaction, value : string, options? : QueryOptions ) : Promise<void>;
  3666. /**
  3667. * Begin a new transaction
  3668. */
  3669. startTransaction( transaction : Transaction, options? : QueryOptions ) : Promise<void>;
  3670. /**
  3671. * Defer constraints
  3672. */
  3673. deferConstraints( transaction : Transaction, options? : QueryOptions ) : Promise<void>;
  3674. /**
  3675. * Commit an already started transaction
  3676. */
  3677. commitTransaction( transaction : Transaction, options? : QueryOptions ) : Promise<void>;
  3678. /**
  3679. * Rollback ( revert ) a transaction that has'nt been commited
  3680. */
  3681. rollbackTransaction( transaction : Transaction, options? : QueryOptions ) : Promise<void>;
  3682. }
  3683. //
  3684. // Query Types
  3685. // ~~~~~~~~~~~~~
  3686. //
  3687. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/query-types.js
  3688. //
  3689. interface QueryTypes {
  3690. SELECT: string // 'SELECT'
  3691. INSERT: string // 'INSERT'
  3692. UPDATE: string // 'UPDATE'
  3693. BULKUPDATE: string // 'BULKUPDATE'
  3694. BULKDELETE: string // 'BULKDELETE'
  3695. DELETE: string // 'DELETE'
  3696. UPSERT: string // 'UPSERT'
  3697. VERSION: string // 'VERSION'
  3698. SHOWTABLES: string // 'SHOWTABLES'
  3699. SHOWINDEXES: string // 'SHOWINDEXES'
  3700. DESCRIBE: string // 'DESCRIBE'
  3701. RAW: string // 'RAW'
  3702. FOREIGNKEYS: string // 'FOREIGNKEYS'
  3703. }
  3704. //
  3705. // Sequelize
  3706. // ~~~~~~~~~~~
  3707. //
  3708. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/sequelize.js
  3709. //
  3710. /**
  3711. * General column options
  3712. *
  3713. * @see Define
  3714. * @see AssociationForeignKeyOptions
  3715. */
  3716. interface ColumnOptions {
  3717. /**
  3718. * If false, the column will have a NOT NULL constraint, and a not null validation will be run before an
  3719. * instance is saved.
  3720. */
  3721. allowNull?: boolean;
  3722. /**
  3723. * If set, sequelize will map the attribute name to a different name in the database
  3724. */
  3725. field? : string;
  3726. /**
  3727. * A literal default value, a JavaScript function, or an SQL function (see `sequelize.fn`)
  3728. */
  3729. defaultValue?: any;
  3730. }
  3731. /**
  3732. * References options for the column's attributes
  3733. *
  3734. * @see AttributeColumnOptions
  3735. */
  3736. interface DefineAttributeColumnReferencesOptions {
  3737. /**
  3738. * If this column references another table, provide it here as a Model, or a string
  3739. */
  3740. model?: string | Model<any, any>;
  3741. /**
  3742. * The column of the foreign table that this column references
  3743. */
  3744. key? : string;
  3745. /**
  3746. * When to check for the foreign key constraing
  3747. *
  3748. * PostgreSQL only
  3749. */
  3750. deferrable? : Deferrable;
  3751. }
  3752. /**
  3753. * Column options for the model schema attributes
  3754. *
  3755. * @see Attributes
  3756. */
  3757. interface DefineAttributeColumnOptions extends ColumnOptions {
  3758. /**
  3759. * A string or a data type
  3760. */
  3761. type: string | DataTypeAbstract;
  3762. /**
  3763. * If true, the column will get a unique constraint. If a string is provided, the column will be part of a
  3764. * composite unique index. If multiple columns have the same string, they will be part of the same unique
  3765. * index
  3766. */
  3767. unique?: boolean | string | { name: string, msg: string };
  3768. /**
  3769. * Primary key flag
  3770. */
  3771. primaryKey?: boolean;
  3772. /**
  3773. * Is this field an auto increment field
  3774. */
  3775. autoIncrement?: boolean;
  3776. /**
  3777. * Comment for the database
  3778. */
  3779. comment?: string;
  3780. /**
  3781. * An object with reference configurations
  3782. */
  3783. references? : DefineAttributeColumnReferencesOptions;
  3784. /**
  3785. * What should happen when the referenced key is updated. One of CASCADE, RESTRICT, SET DEFAULT, SET NULL or
  3786. * NO ACTION
  3787. */
  3788. onUpdate? : string;
  3789. /**
  3790. * What should happen when the referenced key is deleted. One of CASCADE, RESTRICT, SET DEFAULT, SET NULL or
  3791. * NO ACTION
  3792. */
  3793. onDelete? : string;
  3794. /**
  3795. * Provide a custom getter for this column. Use `this.getDataValue(String)` to manipulate the underlying
  3796. * values.
  3797. */
  3798. get? : () => any;
  3799. /**
  3800. * Provide a custom setter for this column. Use `this.setDataValue(String, Value)` to manipulate the
  3801. * underlying values.
  3802. */
  3803. set? : ( val : any ) => void;
  3804. /**
  3805. * An object of validations to execute for this column every time the model is saved. Can be either the
  3806. * name of a validation provided by validator.js, a validation function provided by extending validator.js
  3807. * (see the
  3808. * `DAOValidator` property for more details), or a custom validation function. Custom validation functions
  3809. * are called with the value of the field, and can possibly take a second callback argument, to signal that
  3810. * they are asynchronous. If the validator is sync, it should throw in the case of a failed validation, it
  3811. * it is async, the callback should be called with the error text.
  3812. */
  3813. validate? : DefineValidateOptions;
  3814. /**
  3815. * Usage in object notation
  3816. *
  3817. * ```js
  3818. * sequelize.define('model', {
  3819. * states: {
  3820. * type: Sequelize.ENUM,
  3821. * values: ['active', 'pending', 'deleted']
  3822. * }
  3823. * })
  3824. * ```
  3825. */
  3826. values? : Array<string>;
  3827. }
  3828. /**
  3829. * Interface for Attributes provided for a column
  3830. *
  3831. * @see Sequelize.define
  3832. */
  3833. interface DefineAttributes {
  3834. /**
  3835. * The description of a database column
  3836. */
  3837. [name : string] : string | DataTypeAbstract | DefineAttributeColumnOptions;
  3838. }
  3839. /**
  3840. * Interface for query options
  3841. *
  3842. * @see Options
  3843. */
  3844. interface QueryOptions {
  3845. /**
  3846. * If true, sequelize will not try to format the results of the query, or build an instance of a model from
  3847. * the result
  3848. */
  3849. raw?: boolean;
  3850. /**
  3851. * The transaction that the query should be executed under
  3852. */
  3853. transaction?: Transaction;
  3854. /**
  3855. * The type of query you are executing. The query type affects how results are formatted before they are
  3856. * passed back. The type is a string, but `Sequelize.QueryTypes` is provided as convenience shortcuts.
  3857. */
  3858. type?: string;
  3859. /**
  3860. * If true, transforms objects with `.` separated property names into nested objects using
  3861. * [dottie.js](https://github.com/mickhansen/dottie.js). For example { 'user.username': 'john' } becomes
  3862. * { user: { username: 'john' }}. When `nest` is true, the query type is assumed to be `'SELECT'`,
  3863. * unless otherwise specified
  3864. *
  3865. * Defaults to false
  3866. */
  3867. nest?: boolean;
  3868. /**
  3869. * Sets the query type to `SELECT` and return a single row
  3870. */
  3871. plain?: boolean;
  3872. /**
  3873. * Either an object of named parameter replacements in the format `:param` or an array of unnamed
  3874. * replacements to replace `?` in your SQL.
  3875. */
  3876. replacements? : Object | Array<string>;
  3877. /**
  3878. * Force the query to use the write pool, regardless of the query type.
  3879. *
  3880. * Defaults to false
  3881. */
  3882. useMaster? : boolean;
  3883. /**
  3884. * A function that gets executed while running the query to log the sql.
  3885. */
  3886. logging? : Function
  3887. /**
  3888. * A sequelize instance used to build the return instance
  3889. */
  3890. instance? : Instance<any, any>;
  3891. /**
  3892. * A sequelize model used to build the returned model instances (used to be called callee)
  3893. */
  3894. model? : Model<any, any>;
  3895. // TODO: force, cascade
  3896. }
  3897. /**
  3898. * Model validations, allow you to specify format/content/inheritance validations for each attribute of the
  3899. * model.
  3900. *
  3901. * Validations are automatically run on create, update and save. You can also call validate() to manually
  3902. * validate an instance.
  3903. *
  3904. * The validations are implemented by validator.js.
  3905. */
  3906. interface DefineValidateOptions {
  3907. /**
  3908. * is: ["^[a-z]+$",'i'] // will only allow letters
  3909. * is: /^[a-z]+$/i // same as the previous example using real RegExp
  3910. */
  3911. is?: string | Array<string | RegExp> | RegExp | { msg: string, args : string | Array<string | RegExp> | RegExp };
  3912. /**
  3913. * not: ["[a-z]",'i'] // will not allow letters
  3914. */
  3915. not?: string | Array<string | RegExp> | RegExp | { msg: string, args : string | Array<string | RegExp> | RegExp };
  3916. /**
  3917. * checks for email format (foo@bar.com)
  3918. */
  3919. isEmail?: boolean | { msg: string };
  3920. /**
  3921. * checks for url format (http://foo.com)
  3922. */
  3923. isUrl?: boolean | { msg: string };
  3924. /**
  3925. * checks for IPv4 (129.89.23.1) or IPv6 format
  3926. */
  3927. isIP?: boolean | { msg: string };
  3928. /**
  3929. * checks for IPv4 (129.89.23.1)
  3930. */
  3931. isIPv4?: boolean | { msg: string };
  3932. /**
  3933. * checks for IPv6 format
  3934. */
  3935. isIPv6?: boolean | { msg: string };
  3936. /**
  3937. * will only allow letters
  3938. */
  3939. isAlpha?: boolean | { msg: string };
  3940. /**
  3941. * will only allow alphanumeric characters, so "_abc" will fail
  3942. */
  3943. isAlphanumeric?: boolean | { msg: string };
  3944. /**
  3945. * will only allow numbers
  3946. */
  3947. isNumeric?: boolean | { msg: string };
  3948. /**
  3949. * checks for valid integers
  3950. */
  3951. isInt?: boolean | { msg: string };
  3952. /**
  3953. * checks for valid floating point numbers
  3954. */
  3955. isFloat?: boolean | { msg: string };
  3956. /**
  3957. * checks for any numbers
  3958. */
  3959. isDecimal?: boolean | { msg: string };
  3960. /**
  3961. * checks for lowercase
  3962. */
  3963. isLowercase?: boolean | { msg: string };
  3964. /**
  3965. * checks for uppercase
  3966. */
  3967. isUppercase?: boolean | { msg: string };
  3968. /**
  3969. * won't allow null
  3970. */
  3971. notNull?: boolean | { msg: string };
  3972. /**
  3973. * only allows null
  3974. */
  3975. isNull?: boolean | { msg: string };
  3976. /**
  3977. * don't allow empty strings
  3978. */
  3979. notEmpty?: boolean | { msg: string };
  3980. /**
  3981. * only allow a specific value
  3982. */
  3983. equals? : string | { msg: string };
  3984. /**
  3985. * force specific substrings
  3986. */
  3987. contains? : string | { msg: string };
  3988. /**
  3989. * check the value is not one of these
  3990. */
  3991. notIn? : Array<Array<string>> | { msg: string, args: Array<Array<string>> };
  3992. /**
  3993. * check the value is one of these
  3994. */
  3995. isIn? : Array<Array<string>> | { msg: string, args: Array<Array<string>> };
  3996. /**
  3997. * don't allow specific substrings
  3998. */
  3999. notContains? : Array<string> | string | { msg: string, args: Array<string> | string };
  4000. /**
  4001. * only allow values with length between 2 and 10
  4002. */
  4003. len?: [number, number] | { msg: string, args: [number, number] };
  4004. /**
  4005. * only allow uuids
  4006. */
  4007. isUUID?: number | { msg: string, args: number };
  4008. /**
  4009. * only allow date strings
  4010. */
  4011. isDate?: boolean | { msg: string, args: boolean };
  4012. /**
  4013. * only allow date strings after a specific date
  4014. */
  4015. isAfter?: string | { msg: string, args: string };
  4016. /**
  4017. * only allow date strings before a specific date
  4018. */
  4019. isBefore?: string | { msg: string, args: string };
  4020. /**
  4021. * only allow values
  4022. */
  4023. max?: number | { msg: string, args: number };
  4024. /**
  4025. * only allow values >= 23
  4026. */
  4027. min?: number | { msg: string, args: number };
  4028. /**
  4029. * only allow arrays
  4030. */
  4031. isArray?: boolean | { msg: string, args: boolean };
  4032. /**
  4033. * check for valid credit card numbers
  4034. */
  4035. isCreditCard?: boolean | { msg: string, args: boolean };
  4036. /**
  4037. * custom validations are also possible
  4038. *
  4039. * Implementation notes :
  4040. *
  4041. * We can't enforce any other method to be a function, so :
  4042. *
  4043. * ```typescript
  4044. * [name: string] : ( value : any ) => boolean;
  4045. * ```
  4046. *
  4047. * doesn't work in combination with the properties above
  4048. *
  4049. * @see https://github.com/Microsoft/TypeScript/issues/1889
  4050. */
  4051. [name: string] : any;
  4052. }
  4053. /**
  4054. * Interface for indexes property in DefineOptions
  4055. *
  4056. * @see DefineOptions
  4057. */
  4058. interface DefineIndexesOptions {
  4059. /**
  4060. * The name of the index. Defaults to model name + _ + fields concatenated
  4061. */
  4062. name? : string,
  4063. /**
  4064. * Index type. Only used by mysql. One of `UNIQUE`, `FULLTEXT` and `SPATIAL`
  4065. */
  4066. index? : string,
  4067. /**
  4068. * The method to create the index by (`USING` statement in SQL). BTREE and HASH are supported by mysql and
  4069. * postgres, and postgres additionally supports GIST and GIN.
  4070. */
  4071. method? : string,
  4072. /**
  4073. * Should the index by unique? Can also be triggered by setting type to `UNIQUE`
  4074. *
  4075. * Defaults to false
  4076. */
  4077. unique? : boolean,
  4078. /**
  4079. * PostgreSQL will build the index without taking any write locks. Postgres only
  4080. *
  4081. * Defaults to false
  4082. */
  4083. concurrently? : boolean,
  4084. /**
  4085. * An array of the fields to index. Each field can either be a string containing the name of the field,
  4086. * a sequelize object (e.g `sequelize.fn`), or an object with the following attributes: `attribute`
  4087. * (field name), `length` (create a prefix index of length chars), `order` (the direction the column
  4088. * should be sorted in), `collate` (the collation (sort order) for the column)
  4089. */
  4090. fields? : Array<string|{ attribute: string, length: number, order: string, collate: string }>
  4091. }
  4092. /**
  4093. * Interface for name property in DefineOptions
  4094. *
  4095. * @see DefineOptions
  4096. */
  4097. interface DefineNameOptions {
  4098. /**
  4099. * Singular model name
  4100. */
  4101. singular? : string,
  4102. /**
  4103. * Plural model name
  4104. */
  4105. plural? : string,
  4106. }
  4107. /**
  4108. * Interface for getterMethods in DefineOptions
  4109. *
  4110. * @see DefineOptions
  4111. */
  4112. interface DefineGetterMethodsOptions {
  4113. [name: string] : () => any;
  4114. }
  4115. /**
  4116. * Interface for setterMethods in DefineOptions
  4117. *
  4118. * @see DefineOptions
  4119. */
  4120. interface DefineSetterMethodsOptions {
  4121. [name: string] : ( val : any ) => void;
  4122. }
  4123. /**
  4124. * Interface for Define Scope Options
  4125. *
  4126. * @see DefineOptions
  4127. */
  4128. interface DefineScopeOptions {
  4129. /**
  4130. * Name of the scope and it's query
  4131. */
  4132. [scopeName: string] : FindOptions | Function;
  4133. }
  4134. /**
  4135. * Options for model definition
  4136. *
  4137. * @see Sequelize.define
  4138. */
  4139. interface DefineOptions<TInstance> {
  4140. /**
  4141. * Define the default search scope to use for this model. Scopes have the same form as the options passed to
  4142. * find / findAll.
  4143. */
  4144. defaultScope?: FindOptions;
  4145. /**
  4146. * More scopes, defined in the same way as defaultScope above. See `Model.scope` for more information about
  4147. * how scopes are defined, and what you can do with them
  4148. */
  4149. scopes?: DefineScopeOptions;
  4150. /**
  4151. * Don't persits null values. This means that all columns with null values will not be saved.
  4152. */
  4153. omitNull?: boolean;
  4154. /**
  4155. * Adds createdAt and updatedAt timestamps to the model. Default true.
  4156. */
  4157. timestamps?: boolean;
  4158. /**
  4159. * Calling destroy will not delete the model, but instead set a deletedAt timestamp if this is true. Needs
  4160. * timestamps=true to work. Default false.
  4161. */
  4162. paranoid?: boolean;
  4163. /**
  4164. * Converts all camelCased columns to underscored if true. Default false.
  4165. */
  4166. underscored?: boolean;
  4167. /**
  4168. * Converts camelCased model names to underscored tablenames if true. Default false.
  4169. */
  4170. underscoredAll?: boolean;
  4171. /**
  4172. * If freezeTableName is true, sequelize will not try to alter the DAO name to get the table name.
  4173. * Otherwise, the dao name will be pluralized. Default false.
  4174. */
  4175. freezeTableName?: boolean;
  4176. /**
  4177. * An object with two attributes, `singular` and `plural`, which are used when this model is associated to
  4178. * others.
  4179. */
  4180. name?: DefineNameOptions;
  4181. /**
  4182. * Indexes for the provided database table
  4183. */
  4184. indexes? : Array<DefineIndexesOptions>;
  4185. /**
  4186. * Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps
  4187. * must be true. Not affected by underscored setting.
  4188. */
  4189. createdAt? : string | boolean;
  4190. /**
  4191. * Override the name of the deletedAt column if a string is provided, or disable it if false. Timestamps
  4192. * must be true. Not affected by underscored setting.
  4193. */
  4194. deletedAt? : string | boolean;
  4195. /**
  4196. * Override the name of the updatedAt column if a string is provided, or disable it if false. Timestamps
  4197. * must be true. Not affected by underscored setting.
  4198. */
  4199. updatedAt? : string | boolean;
  4200. /**
  4201. * Defaults to pluralized model name, unless freezeTableName is true, in which case it uses model name
  4202. * verbatim
  4203. */
  4204. tableName? : string;
  4205. /**
  4206. * Provide getter functions that work like those defined per column. If you provide a getter method with
  4207. * the
  4208. * same name as a column, it will be used to access the value of that column. If you provide a name that
  4209. * does not match a column, this function will act as a virtual getter, that can fetch multiple other
  4210. * values
  4211. */
  4212. getterMethods? : DefineGetterMethodsOptions;
  4213. /**
  4214. * Provide setter functions that work like those defined per column. If you provide a setter method with
  4215. * the
  4216. * same name as a column, it will be used to update the value of that column. If you provide a name that
  4217. * does not match a column, this function will act as a virtual setter, that can act on and set other
  4218. * values, but will not be persisted
  4219. */
  4220. setterMethods? : DefineSetterMethodsOptions;
  4221. /**
  4222. * Provide functions that are added to each instance (DAO). If you override methods provided by sequelize,
  4223. * you can access the original method using `this.constructor.super_.prototype`, e.g.
  4224. * `this.constructor.super_.prototype.toJSON.apply(this, arguments)`
  4225. */
  4226. instanceMethods? : Object;
  4227. /**
  4228. * Provide functions that are added to the model (Model). If you override methods provided by sequelize,
  4229. * you can access the original method using `this.constructor.prototype`, e.g.
  4230. * `this.constructor.prototype.find.apply(this, arguments)`
  4231. */
  4232. classMethods? : Object;
  4233. schema? : string;
  4234. /**
  4235. * You can also change the database engine, e.g. to MyISAM. InnoDB is the default.
  4236. */
  4237. engine? : string;
  4238. charset? : string;
  4239. /**
  4240. * Finaly you can specify a comment for the table in MySQL and PG
  4241. */
  4242. comment? : string;
  4243. collate? : string;
  4244. /**
  4245. * Set the initial AUTO_INCREMENT value for the table in MySQL.
  4246. */
  4247. initialAutoIncrement? : string;
  4248. /**
  4249. * An object of hook function that are called before and after certain lifecycle events.
  4250. * The possible hooks are: beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy,
  4251. * beforeBulkUpdate, beforeCreate, beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate,
  4252. * afterBulkCreate, afterBulkDestory and afterBulkUpdate. See Hooks for more information about hook
  4253. * functions and their signatures. Each property can either be a function, or an array of functions.
  4254. */
  4255. hooks? : HooksDefineOptions<TInstance>;
  4256. /**
  4257. * An object of model wide validations. Validations have access to all model values via `this`. If the
  4258. * validator function takes an argument, it is asumed to be async, and is called with a callback that
  4259. * accepts an optional error.
  4260. */
  4261. validate? : DefineValidateOptions;
  4262. }
  4263. /**
  4264. * Sync Options
  4265. *
  4266. * @see Sequelize.sync
  4267. */
  4268. interface SyncOptions {
  4269. /**
  4270. * If force is true, each DAO will do DROP TABLE IF EXISTS ..., before it tries to create its own table
  4271. */
  4272. force?: boolean;
  4273. /**
  4274. * Match a regex against the database name before syncing, a safety check for cases where force: true is
  4275. * used in tests but not live code
  4276. */
  4277. match?: RegExp;
  4278. /**
  4279. * A function that logs sql queries, or false for no logging
  4280. */
  4281. logging?: Function | boolean;
  4282. /**
  4283. * The schema that the tables should be created in. This can be overriden for each table in sequelize.define
  4284. */
  4285. schema?: string;
  4286. }
  4287. interface SetOptions { }
  4288. /**
  4289. * Connection Pool options
  4290. *
  4291. * @see Options
  4292. */
  4293. interface PoolOptions {
  4294. /**
  4295. * Maximum connections of the pool
  4296. */
  4297. maxConnections?: number;
  4298. /**
  4299. * Minimum connections of the pool
  4300. */
  4301. minConnections?: number;
  4302. /**
  4303. * The maximum time, in milliseconds, that a connection can be idle before being released.
  4304. */
  4305. maxIdleTime?: number;
  4306. /**
  4307. * A function that validates a connection. Called with client. The default function checks that client is an
  4308. * object, and that its state is not disconnected.
  4309. */
  4310. validateConnection?: ( client? : any ) => boolean;
  4311. }
  4312. /**
  4313. * Interface for replication Options in the sequelize constructor
  4314. *
  4315. * @see Options
  4316. */
  4317. interface ReplicationOptions {
  4318. read?: {
  4319. host?: string,
  4320. port?: string | number,
  4321. username?: string,
  4322. password?: string,
  4323. database?: string
  4324. }
  4325. write?: {
  4326. host?: string,
  4327. port?: string | number,
  4328. username?: string,
  4329. password?: string,
  4330. database?: string
  4331. }
  4332. }
  4333. /**
  4334. * Options for the constructor of Sequelize main class
  4335. */
  4336. interface Options {
  4337. /**
  4338. * The dialect of the database you are connecting to. One of mysql, postgres, sqlite, mariadb and mssql.
  4339. *
  4340. * Defaults to 'mysql'
  4341. */
  4342. dialect?: string;
  4343. /**
  4344. * If specified, load the dialect library from this path. For example, if you want to use pg.js instead of
  4345. * pg when connecting to a pg database, you should specify 'pg.js' here
  4346. */
  4347. dialectModulePath?: string;
  4348. /**
  4349. * An object of additional options, which are passed directly to the connection library
  4350. */
  4351. dialectOptions? : Object;
  4352. /**
  4353. * Only used by sqlite.
  4354. *
  4355. * Defaults to ':memory:'
  4356. */
  4357. storage? : string;
  4358. /**
  4359. * The host of the relational database.
  4360. *
  4361. * Defaults to 'localhost'
  4362. */
  4363. host? : string;
  4364. /**
  4365. * The port of the relational database.
  4366. */
  4367. port? : number;
  4368. /**
  4369. * The protocol of the relational database.
  4370. *
  4371. * Defaults to 'tcp'
  4372. */
  4373. protocol? : string;
  4374. /**
  4375. * Default options for model definitions. See sequelize.define for options
  4376. */
  4377. define? : DefineOptions<any>;
  4378. /**
  4379. * Default options for sequelize.query
  4380. */
  4381. query? : QueryOptions;
  4382. /**
  4383. * Default options for sequelize.set
  4384. */
  4385. set? : SetOptions;
  4386. /**
  4387. * Default options for sequelize.sync
  4388. */
  4389. sync? : SyncOptions;
  4390. /**
  4391. * The timezone used when converting a date from the database into a JavaScript date. The timezone is also
  4392. * used to SET TIMEZONE when connecting to the server, to ensure that the result of NOW, CURRENT_TIMESTAMP
  4393. * and other time related functions have in the right timezone. For best cross platform performance use the
  4394. * format
  4395. * +/-HH:MM. Will also accept string versions of timezones used by moment.js (e.g. 'America/Los_Angeles');
  4396. * this is useful to capture daylight savings time changes.
  4397. *
  4398. * Defaults to '+00:00'
  4399. */
  4400. timezone? : string;
  4401. /**
  4402. * A function that gets executed everytime Sequelize would log something.
  4403. *
  4404. * Defaults to console.log
  4405. */
  4406. logging? : boolean | Function;
  4407. /**
  4408. * A flag that defines if null values should be passed to SQL queries or not.
  4409. *
  4410. * Defaults to false
  4411. */
  4412. omitNull? : boolean;
  4413. /**
  4414. * A flag that defines if native library shall be used or not. Currently only has an effect for postgres
  4415. *
  4416. * Defaults to false
  4417. */
  4418. native? : boolean;
  4419. /**
  4420. * Use read / write replication. To enable replication, pass an object, with two properties, read and write.
  4421. * Write should be an object (a single server for handling writes), and read an array of object (several
  4422. * servers to handle reads). Each read/write server can have the following properties: `host`, `port`,
  4423. * `username`, `password`, `database`
  4424. *
  4425. * Defaults to false
  4426. */
  4427. replication? : ReplicationOptions;
  4428. /**
  4429. * Connection pool options
  4430. */
  4431. pool? : PoolOptions;
  4432. /**
  4433. * Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of
  4434. * them.
  4435. *
  4436. * Defaults to true
  4437. */
  4438. quoteIdentifiers? : boolean;
  4439. /**
  4440. * Set the default transaction isolation level. See `Sequelize.Transaction.ISOLATION_LEVELS` for possible
  4441. * options.
  4442. *
  4443. * Defaults to 'REPEATABLE_READ'
  4444. */
  4445. isolationLevel? : string;
  4446. }
  4447. /**
  4448. * Sequelize methods that are available both for the static and the instance class of Sequelize
  4449. */
  4450. interface SequelizeStaticAndInstance extends Errors {
  4451. /**
  4452. * A reference to sequelize utilities. Most users will not need to use these utils directly. However, you
  4453. * might want to use `Sequelize.Utils._`, which is a reference to the lodash library, if you don't already
  4454. * have it imported in your project.
  4455. */
  4456. Utils: Utils;
  4457. /**
  4458. * A modified version of bluebird promises, that allows listening for sql events
  4459. */
  4460. Promise: typeof Promise;
  4461. /**
  4462. * Available query types for use with `sequelize.query`
  4463. */
  4464. QueryTypes: QueryTypes;
  4465. /**
  4466. * Exposes the validator.js object, so you can extend it with custom validation functions.
  4467. * The validator is exposed both on the instance, and on the constructor.
  4468. */
  4469. Validator: Validator;
  4470. /**
  4471. * A Model represents a table in the database. Sometimes you might also see it referred to as model, or
  4472. * simply as factory. This class should not be instantiated directly, it is created using sequelize.define,
  4473. * and already created models can be loaded using sequelize.import
  4474. */
  4475. Model: Model<any, any>;
  4476. /**
  4477. * A reference to the sequelize transaction class. Use this to access isolationLevels when creating a
  4478. * transaction
  4479. */
  4480. Transaction : TransactionStatic;
  4481. /**
  4482. * A reference to the deferrable collection. Use this to access the different deferrable options.
  4483. */
  4484. Deferrable : Deferrable;
  4485. /**
  4486. * A reference to the sequelize instance class.
  4487. */
  4488. Instance : Instance<any, any>;
  4489. /**
  4490. * Creates a object representing a database function. This can be used in search queries, both in where and
  4491. * order parts, and as default values in column definitions. If you want to refer to columns in your
  4492. * function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and
  4493. * not a strings.
  4494. *
  4495. * Convert a user's username to upper case
  4496. * ```js
  4497. * instance.updateAttributes({
  4498. * username: self.sequelize.fn('upper', self.sequelize.col('username'))
  4499. * })
  4500. * ```
  4501. * @param fn The function you want to call
  4502. * @param args All further arguments will be passed as arguments to the function
  4503. */
  4504. fn( fn : string, ...args : any[] ) : fn;
  4505. /**
  4506. * Creates a object representing a column in the DB. This is often useful in conjunction with
  4507. * `sequelize.fn`, since raw string arguments to fn will be escaped.
  4508. *
  4509. * @param col The name of the column
  4510. */
  4511. col( col : string ) : col;
  4512. /**
  4513. * Creates a object representing a call to the cast function.
  4514. *
  4515. * @param val The value to cast
  4516. * @param type The type to cast it to
  4517. */
  4518. cast( val : any, type : string ) : cast;
  4519. /**
  4520. * Creates a object representing a literal, i.e. something that will not be escaped.
  4521. *
  4522. * @param val
  4523. */
  4524. literal( val : any ) : literal;
  4525. asIs( val : any ) : literal;
  4526. /**
  4527. * An AND query
  4528. *
  4529. * @param args Each argument will be joined by AND
  4530. */
  4531. and( ...args : Array<string | Object> ) : and;
  4532. /**
  4533. * An OR query
  4534. *
  4535. * @param args Each argument will be joined by OR
  4536. */
  4537. or( ...args : Array<string|Object> ) : or;
  4538. /**
  4539. * Creates an object representing nested where conditions for postgres's json data-type.
  4540. *
  4541. * @param conditionsOrPath A hash containing strings/numbers or other nested hash, a string using dot
  4542. * notation or a string using postgres json syntax.
  4543. * @param value An optional value to compare against. Produces a string of the form "<json path> =
  4544. * '<value>'".
  4545. */
  4546. json( conditionsOrPath : string | Object, value? : string | number | boolean ) : json;
  4547. /**
  4548. * A way of specifying attr = condition.
  4549. *
  4550. * The attr can either be an object taken from `Model.rawAttributes` (for example `Model.rawAttributes.id`
  4551. * or
  4552. * `Model.rawAttributes.name`). The attribute should be defined in your model definition. The attribute can
  4553. * also be an object from one of the sequelize utility functions (`sequelize.fn`, `sequelize.col` etc.)
  4554. *
  4555. * For string attributes, use the regular `{ where: { attr: something }}` syntax. If you don't want your
  4556. * string to be escaped, use `sequelize.literal`.
  4557. *
  4558. * @param attr The attribute, which can be either an attribute object from `Model.rawAttributes` or a
  4559. * sequelize object, for example an instance of `sequelize.fn`. For simple string attributes, use the
  4560. * POJO syntax
  4561. * @param comparator Comparator
  4562. * @param logic The condition. Can be both a simply type, or a further condition (`.or`, `.and`, `.literal`
  4563. * etc.)
  4564. */
  4565. where( attr : Object, comparator : string, logic : string | Object ) : where;
  4566. where( attr : Object, logic : string | Object ) : where;
  4567. condition( attr : Object, logic : string | Object ) : where;
  4568. }
  4569. /**
  4570. * Sequelize methods available only for the static class ( basically this is the constructor and some extends )
  4571. */
  4572. interface SequelizeStatic extends SequelizeStaticAndInstance, DataTypes {
  4573. /**
  4574. * Instantiate sequelize with name of database, username and password
  4575. *
  4576. * #### Example usage
  4577. *
  4578. * ```javascript
  4579. * // without password and options
  4580. * var sequelize = new Sequelize('database', 'username')
  4581. *
  4582. * // without options
  4583. * var sequelize = new Sequelize('database', 'username', 'password')
  4584. *
  4585. * // without password / with blank password
  4586. * var sequelize = new Sequelize('database', 'username', null, {})
  4587. *
  4588. * // with password and options
  4589. * var sequelize = new Sequelize('my_database', 'john', 'doe', {})
  4590. *
  4591. * // with uri (see below)
  4592. * var sequelize = new Sequelize('mysql://localhost:3306/database', {})
  4593. * ```
  4594. *
  4595. * @param database The name of the database
  4596. * @param username The username which is used to authenticate against the
  4597. * database.
  4598. * @param password The password which is used to authenticate against the
  4599. * database.
  4600. * @param options An object with options.
  4601. */
  4602. new ( database : string, username : string, password : string, options? : Options ) : Sequelize;
  4603. new ( database : string, username : string, options? : Options ) : Sequelize;
  4604. /**
  4605. * Instantiate sequelize with an URI
  4606. * @name Sequelize
  4607. * @constructor
  4608. *
  4609. * @param uri A full database URI
  4610. * @param options See above for possible options
  4611. */
  4612. new ( uri : string, options? : Options ) : Sequelize;
  4613. }
  4614. interface QueryOptionsTransactionRequired { }
  4615. /**
  4616. * This is the main class, the entry point to sequelize. To use it, you just need to
  4617. * import sequelize:
  4618. *
  4619. * ```js
  4620. * var Sequelize = require('sequelize');
  4621. * ```
  4622. *
  4623. * In addition to sequelize, the connection library for the dialect you want to use
  4624. * should also be installed in your project. You don't need to import it however, as
  4625. * sequelize will take care of that.
  4626. */
  4627. interface Sequelize extends SequelizeStaticAndInstance, Hooks<any> {
  4628. /**
  4629. * A reference to Sequelize constructor from sequelize. Useful for accessing DataTypes, Errors etc.
  4630. */
  4631. Sequelize: SequelizeStatic;
  4632. /**
  4633. * Returns the specified dialect.
  4634. */
  4635. getDialect() : string;
  4636. /**
  4637. * Returns an instance of QueryInterface.
  4638. */
  4639. getQueryInterface(): QueryInterface;
  4640. /**
  4641. * Define a new model, representing a table in the DB.
  4642. *
  4643. * The table columns are define by the hash that is given as the second argument. Each attribute of the
  4644. * hash
  4645. * represents a column. A short table definition might look like this:
  4646. *
  4647. * ```js
  4648. * sequelize.define('modelName', {
  4649. * columnA: {
  4650. * type: Sequelize.BOOLEAN,
  4651. * validate: {
  4652. * is: ["[a-z]",'i'], // will only allow letters
  4653. * max: 23, // only allow values <= 23
  4654. * isIn: {
  4655. * args: [['en', 'zh']],
  4656. * msg: "Must be English or Chinese"
  4657. * }
  4658. * },
  4659. * field: 'column_a'
  4660. * // Other attributes here
  4661. * },
  4662. * columnB: Sequelize.STRING,
  4663. * columnC: 'MY VERY OWN COLUMN TYPE'
  4664. * })
  4665. *
  4666. * sequelize.models.modelName // The model will now be available in models under the name given to define
  4667. * ```
  4668. *
  4669. * As shown above, column definitions can be either strings, a reference to one of the datatypes that are
  4670. * predefined on the Sequelize constructor, or an object that allows you to specify both the type of the
  4671. * column, and other attributes such as default values, foreign key constraints and custom setters and
  4672. * getters.
  4673. *
  4674. * For a list of possible data types, see
  4675. * http://docs.sequelizejs.com/en/latest/docs/models-definition/#data-types
  4676. *
  4677. * For more about getters and setters, see
  4678. * http://docs.sequelizejs.com/en/latest/docs/models-definition/#getters-setters
  4679. *
  4680. * For more about instance and class methods, see
  4681. * http://docs.sequelizejs.com/en/latest/docs/models-definition/#expansion-of-models
  4682. *
  4683. * For more about validation, see
  4684. * http://docs.sequelizejs.com/en/latest/docs/models-definition/#validations
  4685. *
  4686. * @param modelName The name of the model. The model will be stored in `sequelize.models` under this name
  4687. * @param attributes An object, where each attribute is a column of the table. Each column can be either a
  4688. * DataType, a string or a type-description object, with the properties described below:
  4689. * @param options These options are merged with the default define options provided to the Sequelize
  4690. * constructor
  4691. */
  4692. define<TInstance, TAttributes>( modelName : string, attributes : DefineAttributes,
  4693. options? : DefineOptions<TInstance> ) : Model<TInstance, TAttributes>;
  4694. /**
  4695. * Fetch a Model which is already defined
  4696. *
  4697. * @param modelName The name of a model defined with Sequelize.define
  4698. */
  4699. model<TInstance, TAttributes>( modelName : string ) : Model<TInstance, TAttributes>;
  4700. /**
  4701. * Checks whether a model with the given name is defined
  4702. *
  4703. * @param modelName The name of a model defined with Sequelize.define
  4704. */
  4705. isDefined( modelName : string ) : boolean;
  4706. /**
  4707. * Imports a model defined in another file
  4708. *
  4709. * Imported models are cached, so multiple calls to import with the same path will not load the file
  4710. * multiple times
  4711. *
  4712. * See https://github.com/sequelize/sequelize/blob/master/examples/using-multiple-model-files/Task.js for a
  4713. * short example of how to define your models in separate files so that they can be imported by
  4714. * sequelize.import
  4715. *
  4716. * @param path The path to the file that holds the model you want to import. If the part is relative, it
  4717. * will be resolved relatively to the calling file
  4718. */
  4719. import<TInstance, TAttributes>( path : string ) : Model<TInstance, TAttributes>;
  4720. /**
  4721. * Execute a query on the DB, with the posibility to bypass all the sequelize goodness.
  4722. *
  4723. * By default, the function will return two arguments: an array of results, and a metadata object,
  4724. * containing number of affected rows etc. Use `.spread` to access the results.
  4725. *
  4726. * If you are running a type of query where you don't need the metadata, for example a `SELECT` query, you
  4727. * can pass in a query type to make sequelize format the results:
  4728. *
  4729. * ```js
  4730. * sequelize.query('SELECT...').spread(function (results, metadata) {
  4731. * // Raw query - use spread
  4732. * });
  4733. *
  4734. * sequelize.query('SELECT...', { type: sequelize.QueryTypes.SELECT }).then(function (results) {
  4735. * // SELECT query - use then
  4736. * })
  4737. * ```
  4738. *
  4739. * @param sql
  4740. * @param options Query options
  4741. */
  4742. query( sql : string | { query: string, values: Array<any> }, options? : QueryOptions ) : Promise<any>;
  4743. /**
  4744. * Execute a query which would set an environment or user variable. The variables are set per connection,
  4745. * so this function needs a transaction.
  4746. *
  4747. * Only works for MySQL.
  4748. *
  4749. * @param variables Object with multiple variables.
  4750. * @param options Query options.
  4751. */
  4752. set( variables : Object, options : QueryOptionsTransactionRequired ) : Promise<any>;
  4753. /**
  4754. * Escape value.
  4755. *
  4756. * @param value Value that needs to be escaped
  4757. */
  4758. escape( value : string ) : string;
  4759. /**
  4760. * Create a new database schema.
  4761. *
  4762. * Note,that this is a schema in the
  4763. * [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
  4764. * not a database table. In mysql and sqlite, this command will do nothing.
  4765. *
  4766. * @param schema Name of the schema
  4767. * @param options Options supplied
  4768. * @param options.logging A function that logs sql queries, or false for no logging
  4769. */
  4770. createSchema( schema : string, options : { logging? : boolean | Function } ) : Promise<any>;
  4771. /**
  4772. * Show all defined schemas
  4773. *
  4774. * Note,that this is a schema in the
  4775. * [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
  4776. * not a database table. In mysql and sqlite, this will show all tables.
  4777. *
  4778. * @param options Options supplied
  4779. * @param options.logging A function that logs sql queries, or false for no logging
  4780. */
  4781. showAllSchemas( options : { logging? : boolean | Function } ) : Promise<any>;
  4782. /**
  4783. * Drop a single schema
  4784. *
  4785. * Note,that this is a schema in the
  4786. * [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
  4787. * not a database table. In mysql and sqlite, this drop a table matching the schema name
  4788. *
  4789. * @param schema Name of the schema
  4790. * @param options Options supplied
  4791. * @param options.logging A function that logs sql queries, or false for no logging
  4792. */
  4793. dropSchema( schema : string, options : { logging? : boolean | Function } ) : Promise<any>;
  4794. /**
  4795. * Drop all schemas
  4796. *
  4797. * Note,that this is a schema in the
  4798. * [postgres sense of the word](http://www.postgresql.org/docs/9.1/static/ddl-schemas.html),
  4799. * not a database table. In mysql and sqlite, this is the equivalent of drop all tables.
  4800. *
  4801. * @param options Options supplied
  4802. * @param options.logging A function that logs sql queries, or false for no logging
  4803. */
  4804. dropAllSchemas( options : { logging? : boolean | Function } ) : Promise<any>;
  4805. /**
  4806. * Sync all defined models to the DB.
  4807. *
  4808. * @param options Sync Options
  4809. */
  4810. sync( options? : SyncOptions ) : Promise<any>;
  4811. /**
  4812. * Truncate all tables defined through the sequelize models. This is done
  4813. * by calling Model.truncate() on each model.
  4814. *
  4815. * @param {object} [options] The options passed to Model.destroy in addition to truncate
  4816. * @param {Boolean|function} [options.transaction]
  4817. * @param {Boolean|function} [options.logging] A function that logs sql queries, or false for no logging
  4818. */
  4819. truncate( options? : DestroyOptions ) : Promise<any>;
  4820. /**
  4821. * Drop all tables defined through this sequelize instance. This is done by calling Model.drop on each model
  4822. * @see {Model#drop} for options
  4823. *
  4824. * @param options The options passed to each call to Model.drop
  4825. */
  4826. drop( options? : DropOptions ) : Promise<any>;
  4827. /**
  4828. * Test the connection by trying to authenticate
  4829. *
  4830. * @param options Query Options for authentication
  4831. */
  4832. authenticate( options? : QueryOptions ) : Promise<void>;
  4833. validate( options? : QueryOptions ) : Promise<void>;
  4834. /**
  4835. * Start a transaction. When using transactions, you should pass the transaction in the options argument
  4836. * in order for the query to happen under that transaction
  4837. *
  4838. * ```js
  4839. * sequelize.transaction().then(function (t) {
  4840. * return User.find(..., { transaction: t}).then(function (user) {
  4841. * return user.updateAttributes(..., { transaction: t});
  4842. * })
  4843. * .then(t.commit.bind(t))
  4844. * .catch(t.rollback.bind(t));
  4845. * })
  4846. * ```
  4847. *
  4848. * A syntax for automatically committing or rolling back based on the promise chain resolution is also
  4849. * supported:
  4850. *
  4851. * ```js
  4852. * sequelize.transaction(function (t) { // Note that we use a callback rather than a promise.then()
  4853. * return User.find(..., { transaction: t}).then(function (user) {
  4854. * return user.updateAttributes(..., { transaction: t});
  4855. * });
  4856. * }).then(function () {
  4857. * // Commited
  4858. * }).catch(function (err) {
  4859. * // Rolled back
  4860. * console.error(err);
  4861. * });
  4862. * ```
  4863. *
  4864. * If you have [CLS](https://github.com/othiym23/node-continuation-local-storage) enabled, the transaction
  4865. * will automatically be passed to any query that runs witin the callback. To enable CLS, add it do your
  4866. * project, create a namespace and set it on the sequelize constructor:
  4867. *
  4868. * ```js
  4869. * var cls = require('continuation-local-storage'),
  4870. * ns = cls.createNamespace('....');
  4871. * var Sequelize = require('sequelize');
  4872. * Sequelize.cls = ns;
  4873. * ```
  4874. * Note, that CLS is enabled for all sequelize instances, and all instances will share the same namespace
  4875. *
  4876. * @param options Transaction Options
  4877. * @param autoCallback Callback for the transaction
  4878. */
  4879. transaction( options : TransactionOptions,
  4880. autoCallback : ( t : Transaction ) => Promise<any> ) : Promise<any>;
  4881. transaction( autoCallback : ( t : Transaction ) => Promise<any> ) : Promise<any>;
  4882. transaction() : Promise<Transaction>;
  4883. /**
  4884. * Close all connections used by this sequelize instance, and free all references so the instance can be
  4885. * garbage collected.
  4886. *
  4887. * Normally this is done on process exit, so you only need to call this method if you are creating multiple
  4888. * instances, and want to garbage collect some of them.
  4889. */
  4890. close() : void;
  4891. /**
  4892. * Returns the database version
  4893. */
  4894. databaseVersion() : Promise<string>;
  4895. }
  4896. //
  4897. // Validator
  4898. // ~~~~~~~~~~~
  4899. /**
  4900. * Validator Interface
  4901. */
  4902. interface Validator extends IValidatorStatic {
  4903. notEmpty( str : string ) : boolean;
  4904. len( str : string, min : number, max : number ) : boolean;
  4905. isUrl( str : string ) : boolean;
  4906. isIPv6( str : string ) : boolean
  4907. isIPv4( str : string ) : boolean
  4908. notIn( str : string, values : Array<string> ) : boolean;
  4909. regex( str : string, pattern : string, modifiers : string ) : boolean;
  4910. notRegex( str : string, pattern : string, modifiers : string ) : boolean;
  4911. isDecimal( str : string ) : boolean;
  4912. min( str : string, val : number ) : boolean;
  4913. max( str : string, val : number ) : boolean;
  4914. not( str : string, pattern : string, modifiers : string ) : boolean;
  4915. contains( str : string, element : Array<string> ) : boolean;
  4916. notContains( str : string, element : Array<string> ) : boolean;
  4917. is( str : string, pattern : string, modifiers : string ) : boolean;
  4918. }
  4919. //
  4920. // Transaction
  4921. // ~~~~~~~~~~~~~
  4922. //
  4923. // https://github.com/sequelize/sequelize/blob/v3.4.1/lib/transaction.js
  4924. //
  4925. /**
  4926. * The transaction object is used to identify a running transaction. It is created by calling
  4927. * `Sequelize.transaction()`.
  4928. *
  4929. * To run a query under a transaction, you should pass the transaction in the options object.
  4930. */
  4931. interface Transaction {
  4932. /**
  4933. * Possible options for row locking. Used in conjuction with `find` calls:
  4934. *
  4935. * @see TransactionStatic
  4936. */
  4937. LOCK : TransactionLock;
  4938. /**
  4939. * Commit the transaction
  4940. */
  4941. commit() : Transaction;
  4942. /**
  4943. * Rollback (abort) the transaction
  4944. */
  4945. rollback() : Transaction;
  4946. }
  4947. /**
  4948. * The transaction static object
  4949. *
  4950. * @see Transaction
  4951. */
  4952. interface TransactionStatic {
  4953. /**
  4954. * Isolations levels can be set per-transaction by passing `options.isolationLevel` to
  4955. * `sequelize.transaction`. Default to `REPEATABLE_READ` but you can override the default isolation level
  4956. * by passing
  4957. * `options.isolationLevel` in `new Sequelize`.
  4958. *
  4959. * The possible isolations levels to use when starting a transaction:
  4960. *
  4961. * ```js
  4962. * {
  4963. * READ_UNCOMMITTED: "READ UNCOMMITTED",
  4964. * READ_COMMITTED: "READ COMMITTED",
  4965. * REPEATABLE_READ: "REPEATABLE READ",
  4966. * SERIALIZABLE: "SERIALIZABLE"
  4967. * }
  4968. * ```
  4969. *
  4970. * Pass in the desired level as the first argument:
  4971. *
  4972. * ```js
  4973. * return sequelize.transaction({
  4974. * isolationLevel: Sequelize.Transaction.SERIALIZABLE
  4975. * }, function (t) {
  4976. *
  4977. * // your transactions
  4978. *
  4979. * }).then(function(result) {
  4980. * // transaction has been committed. Do something after the commit if required.
  4981. * }).catch(function(err) {
  4982. * // do something with the err.
  4983. * });
  4984. * ```
  4985. *
  4986. * @see ISOLATION_LEVELS
  4987. */
  4988. ISOLATION_LEVELS : TransactionIsolationLevels;
  4989. /**
  4990. * Possible options for row locking. Used in conjuction with `find` calls:
  4991. *
  4992. * ```js
  4993. * t1 // is a transaction
  4994. * t1.LOCK.UPDATE,
  4995. * t1.LOCK.SHARE,
  4996. * t1.LOCK.KEY_SHARE, // Postgres 9.3+ only
  4997. * t1.LOCK.NO_KEY_UPDATE // Postgres 9.3+ only
  4998. * ```
  4999. *
  5000. * Usage:
  5001. * ```js
  5002. * t1 // is a transaction
  5003. * Model.findAll({
  5004. * where: ...,
  5005. * transaction: t1,
  5006. * lock: t1.LOCK...
  5007. * });
  5008. * ```
  5009. *
  5010. * Postgres also supports specific locks while eager loading by using OF:
  5011. * ```js
  5012. * UserModel.findAll({
  5013. * where: ...,
  5014. * include: [TaskModel, ...],
  5015. * transaction: t1,
  5016. * lock: {
  5017. * level: t1.LOCK...,
  5018. * of: UserModel
  5019. * }
  5020. * });
  5021. * ```
  5022. * UserModel will be locked but TaskModel won't!
  5023. */
  5024. LOCK : TransactionLock;
  5025. }
  5026. /**
  5027. * Isolations levels can be set per-transaction by passing `options.isolationLevel` to `sequelize.transaction`.
  5028. * Default to `REPEATABLE_READ` but you can override the default isolation level by passing
  5029. * `options.isolationLevel` in `new Sequelize`.
  5030. */
  5031. interface TransactionIsolationLevels {
  5032. READ_UNCOMMITTED: string; // 'READ UNCOMMITTED'
  5033. READ_COMMITTED: string; // 'READ COMMITTED'
  5034. REPEATABLE_READ: string; // 'REPEATABLE READ'
  5035. SERIALIZABLE: string; // 'SERIALIZABLE'
  5036. }
  5037. /**
  5038. * Possible options for row locking. Used in conjuction with `find` calls:
  5039. */
  5040. interface TransactionLock {
  5041. UPDATE: string; // 'UPDATE'
  5042. SHARE: string; // 'SHARE'
  5043. KEY_SHARE: string; // 'KEY SHARE'
  5044. NO_KEY_UPDATE: string; // 'NO KEY UPDATE'
  5045. }
  5046. /**
  5047. * Options provided when the transaction is created
  5048. *
  5049. * @see sequelize.transaction()
  5050. */
  5051. interface TransactionOptions {
  5052. autocommit?: boolean;
  5053. /**
  5054. * See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options
  5055. */
  5056. isolationLevel?: string;
  5057. /**
  5058. * A function that gets executed while running the query to log the sql.
  5059. */
  5060. logging?: Function;
  5061. }
  5062. //
  5063. // Utils
  5064. // ~~~~~~~
  5065. interface fn {
  5066. clone : fnStatic;
  5067. }
  5068. interface fnStatic {
  5069. /**
  5070. * @param fn The function you want to call
  5071. * @param args All further arguments will be passed as arguments to the function
  5072. */
  5073. new ( fn : string, ...args : Array<any> ) : fn;
  5074. }
  5075. interface col {
  5076. col: string;
  5077. }
  5078. interface colStatic {
  5079. /**
  5080. * Creates a object representing a column in the DB. This is often useful in conjunction with
  5081. * `sequelize.fn`, since raw string arguments to fn will be escaped.
  5082. * @see {Sequelize#fn}
  5083. *
  5084. * @param col The name of the column
  5085. */
  5086. new ( col : string ) : col;
  5087. }
  5088. interface cast {
  5089. val: any;
  5090. type: string;
  5091. }
  5092. interface castStatic {
  5093. /**
  5094. * Creates a object representing a call to the cast function.
  5095. *
  5096. * @param val The value to cast
  5097. * @param type The type to cast it to
  5098. */
  5099. new ( val : any, type : string ) : cast;
  5100. }
  5101. interface literal {
  5102. val: any;
  5103. }
  5104. interface literalStatic {
  5105. /**
  5106. * Creates a object representing a literal, i.e. something that will not be escaped.
  5107. *
  5108. * @param val
  5109. */
  5110. new ( val : any ) : literal;
  5111. }
  5112. interface and {
  5113. args: Array<any>;
  5114. }
  5115. interface andStatic {
  5116. /**
  5117. * An AND query
  5118. *
  5119. * @param args Each argument will be joined by AND
  5120. */
  5121. new ( ...args : Array<string | Object> ) : and;
  5122. }
  5123. interface or {
  5124. args: Array<any>;
  5125. }
  5126. interface orStatic {
  5127. /**
  5128. * An OR query
  5129. * @see {Model#find}
  5130. *
  5131. * @param args Each argument will be joined by OR
  5132. */
  5133. new ( ...args : Array<String|Object> ) : or;
  5134. }
  5135. interface json {
  5136. conditions?: Object;
  5137. path? : string;
  5138. value? : string | number | boolean;
  5139. }
  5140. interface jsonStatic {
  5141. /**
  5142. * Creates an object representing nested where conditions for postgres's json data-type.
  5143. * @see {Model#find}
  5144. *
  5145. * @method json
  5146. * @param conditionsOrPath A hash containing strings/numbers or other nested hash, a string using dot
  5147. * notation or a string using postgres json syntax.
  5148. * @param value An optional value to compare against. Produces a string of the form "<json path> =
  5149. * '<value>'".
  5150. */
  5151. new ( conditionsOrPath : string | Object, value? : string | number | boolean ) : json;
  5152. }
  5153. interface where {
  5154. attribute : Object;
  5155. comparator? : string;
  5156. logic : string | Object;
  5157. }
  5158. interface whereStatic {
  5159. /**
  5160. * A way of specifying attr = condition.
  5161. *
  5162. * The attr can either be an object taken from `Model.rawAttributes` (for example `Model.rawAttributes.id`
  5163. * or
  5164. * `Model.rawAttributes.name`). The attribute should be defined in your model definition. The attribute can
  5165. * also be an object from one of the sequelize utility functions (`sequelize.fn`, `sequelize.col` etc.)
  5166. *
  5167. * For string attributes, use the regular `{ where: { attr: something }}` syntax. If you don't want your
  5168. * string to be escaped, use `sequelize.literal`.
  5169. *
  5170. * @param attr The attribute, which can be either an attribute object from `Model.rawAttributes` or a
  5171. * sequelize object, for example an instance of `sequelize.fn`. For simple string attributes, use the
  5172. * POJO syntax
  5173. * @param comparator Comparator
  5174. * @param logic The condition. Can be both a simply type, or a further condition (`.or`, `.and`, `.literal`
  5175. * etc.)
  5176. */
  5177. new ( attr : Object, comparator : string, logic : string | Object ) : where;
  5178. new ( attr : Object, logic : string | Object ) : where;
  5179. }
  5180. interface SequelizeLoDash extends _.LoDashStatic {
  5181. camelizeIf( str : string, condition : boolean ): string;
  5182. underscoredIf( str : string, condition : boolean ): string;
  5183. /**
  5184. * * Returns an array with some falsy values removed. The values null, "", undefined and NaN are considered
  5185. * falsey.
  5186. *
  5187. * @param arr Array to compact.
  5188. */
  5189. compactLite<T>( arr : Array<T> ): Array<T>;
  5190. matchesDots( dots : string | Array<string>, value : Object ) : ( item : Object ) => boolean;
  5191. }
  5192. interface Utils {
  5193. _ : SequelizeLoDash;
  5194. /**
  5195. * Same concept as _.merge, but don't overwrite properties that have already been assigned
  5196. */
  5197. mergeDefaults : typeof _.merge;
  5198. lowercaseFirst( str : string ): string;
  5199. uppercaseFirst( str : string ): string;
  5200. spliceStr( str : string, index : number, count : number, add : string ): string;
  5201. camelize( str : string ): string;
  5202. format( arr : Array<any>, dialect? : string ): string;
  5203. formatNamedParameters( sql : string, parameters : any, dialect? : string ): string;
  5204. cloneDeep<T extends Object>( obj : T, fn? : ( value : T ) => any ) : T;
  5205. mapOptionFieldNames<T extends Object>( options : T, Model : Model<any, any> ) : T;
  5206. mapValueFieldNames( dataValues : Object, fields : Array<string>, Model : Model<any, any> ) : Object;
  5207. argsArePrimaryKeys( args : Array<any>, primaryKeys : Object ) : boolean;
  5208. canTreatArrayAsAnd( arr : Array<any> ) : boolean;
  5209. combineTableNames( tableName1 : string, tableName2 : string ): string;
  5210. singularize( s : string ): string;
  5211. pluralize( s : string ): string;
  5212. removeCommentsFromFunctionString( s : string ): string;
  5213. toDefaultValue( value : DataTypeAbstract ): any;
  5214. toDefaultValue( value : () => DataTypeAbstract ): any;
  5215. /**
  5216. * Determine if the default value provided exists and can be described
  5217. * in a db schema using the DEFAULT directive.
  5218. */
  5219. defaultValueSchemable( value : any ) : boolean;
  5220. removeNullValuesFromHash( hash : Object, omitNull? : boolean, options? : Object ): any;
  5221. inherit( subClass : Object, superClass : Object ): Object;
  5222. stack(): string;
  5223. sliceArgs( args : Array<any>, begin? : number ) : Array<any>;
  5224. now( dialect : string ): Date;
  5225. tick( f : Function ): void;
  5226. addTicks( s : string, tickChar? : string ): string;
  5227. removeTicks( s : string, tickChar? : string ): string;
  5228. fn: fnStatic;
  5229. col: colStatic;
  5230. cast: castStatic;
  5231. literal: literalStatic;
  5232. and: andStatic;
  5233. or: orStatic;
  5234. json: jsonStatic;
  5235. where: whereStatic;
  5236. validateParameter( value : Object, expectation : Object, options? : Object ) : boolean;
  5237. formatReferences( obj : Object ) : Object;
  5238. Promise : typeof Promise;
  5239. }
  5240. }
  5241. var sequelize : sequelize.SequelizeStatic;
  5242. export = sequelize;
  5243. }