[{"data":1,"prerenderedAt":1725},["ShallowReactive",2],{"navigation_docs":3,"-models-retrieving":69,"-models-retrieving-surround":1720},[4,20,60],{"title":5,"path":6,"stem":7,"children":8,"page":19},"Getting Started","/getting-started","1.getting-started",[9,14],{"title":10,"path":11,"stem":12,"icon":13},"Introduction","/getting-started/introduction","1.getting-started/1.introduction","i-lucide-house",{"title":15,"path":16,"stem":17,"icon":18},"Installation","/getting-started/installation","1.getting-started/2.installation","i-lucide-download",false,{"title":21,"path":22,"stem":23,"children":24,"page":19},"Models","/models","2.models",[25,30,35,40,45,50,55],{"title":26,"path":27,"stem":28,"icon":29},"Defining Models","/models/defining-models","2.models/1.defining-models","i-lucide-database",{"title":31,"path":32,"stem":33,"icon":34},"Retrieving Models","/models/retrieving","2.models/2.retrieving","i-lucide-database-search",{"title":36,"path":37,"stem":38,"icon":39},"Inserting & Updating Models","/models/inserting-and-updating","2.models/3.inserting-and-updating","i-lucide-between-horizontal-start",{"title":41,"path":42,"stem":43,"icon":44},"Deleting Models","/models/deleting","2.models/4.deleting","i-lucide-trash",{"title":46,"path":47,"stem":48,"icon":49},"Relationships","/models/relationships","2.models/5.relationships","i-lucide-share-2",{"title":51,"path":52,"stem":53,"icon":54},"Events","/models/events","2.models/6.events","i-lucide-bell",{"title":56,"path":57,"stem":58,"icon":59},"Migrations & Seeders","/models/migrations-and-seeders","2.models/7.migrations-and-seeders","i-lucide-wrench",{"title":61,"path":62,"stem":63,"children":64,"page":19},"Contributing","/contributing","3.contributing",[65],{"title":66,"path":67,"stem":68},"Local Development","/contributing/local-development","3.contributing/1.local-development",{"id":70,"title":31,"body":71,"description":1712,"extension":1713,"links":1714,"meta":1715,"navigation":1716,"path":32,"seo":1717,"stem":33,"__hash__":1719},"docs/2.models/2.retrieving.md",{"type":72,"value":73,"toc":1691},"minimark",[74,78,83,95,140,144,149,159,200,203,250,257,291,295,301,350,360,409,413,417,422,425,470,473,632,636,643,698,702,711,751,755,768,816,820,827,863,868,902,906,920,980,984,991,1039,1043,1063,1073,1077,1085,1272,1276,1285,1375,1379,1382,1554,1561,1687],[75,76,77],"p",{},"Once you have defined your models, you can use them to retrieve data from your database.",[79,80,82],"h2",{"id":81},"retrieving-all-models","Retrieving All Models",[75,84,85,86,90,91,94],{},"To retrieve all models from a table, you can use the ",[87,88,89],"code",{},"all"," or ",[87,92,93],{},"get"," methods directly on the class.",[96,97,102],"pre",{"className":98,"code":99,"language":100,"meta":101,"style":101},"language-ts shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","const users = await User.all();\n","ts","",[87,103,104],{"__ignoreMap":101},[105,106,109,113,117,121,125,128,131,134,137],"span",{"class":107,"line":108},"line",1,[105,110,112],{"class":111},"spNyl","const",[105,114,116],{"class":115},"sTEyZ"," users ",[105,118,120],{"class":119},"sMK4o","=",[105,122,124],{"class":123},"s7zQu"," await",[105,126,127],{"class":115}," User",[105,129,130],{"class":119},".",[105,132,89],{"class":133},"s2Zo4",[105,135,136],{"class":115},"()",[105,138,139],{"class":119},";\n",[79,141,143],{"id":142},"retrieving-single-models","Retrieving Single Models",[145,146,148],"h3",{"id":147},"find","Find",[75,150,151,152,154,155,158],{},"If you know the primary key of the model you want to retrieve, you can use the ",[87,153,147],{}," method. This method returns the model instance if found, or ",[87,156,157],{},"undefined"," otherwise.",[96,160,162],{"className":98,"code":161,"language":100,"meta":101,"style":101},"// Returns User | undefined\nconst user = await User.find(1);\n",[87,163,164,170],{"__ignoreMap":101},[105,165,166],{"class":107,"line":108},[105,167,169],{"class":168},"sHwdD","// Returns User | undefined\n",[105,171,173,175,178,180,182,184,186,188,191,195,198],{"class":107,"line":172},2,[105,174,112],{"class":111},[105,176,177],{"class":115}," user ",[105,179,120],{"class":119},[105,181,124],{"class":123},[105,183,127],{"class":115},[105,185,130],{"class":119},[105,187,147],{"class":133},[105,189,190],{"class":115},"(",[105,192,194],{"class":193},"sbssI","1",[105,196,197],{"class":115},")",[105,199,139],{"class":119},[75,201,202],{},"You can also pass an array of primary keys to retrieve multiple records.",[96,204,206],{"className":98,"code":205,"language":100,"meta":101,"style":101},"// Returns User[]\nconst users = await User.find([1, 2, 3]);\n",[87,207,208,213],{"__ignoreMap":101},[105,209,210],{"class":107,"line":108},[105,211,212],{"class":168},"// Returns User[]\n",[105,214,215,217,219,221,223,225,227,229,232,234,237,240,242,245,248],{"class":107,"line":172},[105,216,112],{"class":111},[105,218,116],{"class":115},[105,220,120],{"class":119},[105,222,124],{"class":123},[105,224,127],{"class":115},[105,226,130],{"class":119},[105,228,147],{"class":133},[105,230,231],{"class":115},"([",[105,233,194],{"class":193},[105,235,236],{"class":119},",",[105,238,239],{"class":193}," 2",[105,241,236],{"class":119},[105,243,244],{"class":193}," 3",[105,246,247],{"class":115},"])",[105,249,139],{"class":119},[75,251,252,253,256],{},"The ",[87,254,255],{},"findOrFail"," method works similarly but throws an error if the model is not found.",[96,258,260],{"className":98,"code":259,"language":100,"meta":101,"style":101},"// Returns User, Throws Error if not found\nconst user = await User.findOrFail(1);\n",[87,261,262,267],{"__ignoreMap":101},[105,263,264],{"class":107,"line":108},[105,265,266],{"class":168},"// Returns User, Throws Error if not found\n",[105,268,269,271,273,275,277,279,281,283,285,287,289],{"class":107,"line":172},[105,270,112],{"class":111},[105,272,177],{"class":115},[105,274,120],{"class":119},[105,276,124],{"class":123},[105,278,127],{"class":115},[105,280,130],{"class":119},[105,282,255],{"class":133},[105,284,190],{"class":115},[105,286,194],{"class":193},[105,288,197],{"class":115},[105,290,139],{"class":119},[145,292,294],{"id":293},"first","First",[75,296,297,298,300],{},"To retrieve the first record matching your query constraints, use the ",[87,299,293],{}," method.",[96,302,304],{"className":98,"code":303,"language":100,"meta":101,"style":101},"const user = await User.where(\"active\", true).first();\n",[87,305,306],{"__ignoreMap":101},[105,307,308,310,312,314,316,318,320,323,325,328,332,334,336,340,342,344,346,348],{"class":107,"line":108},[105,309,112],{"class":111},[105,311,177],{"class":115},[105,313,120],{"class":119},[105,315,124],{"class":123},[105,317,127],{"class":115},[105,319,130],{"class":119},[105,321,322],{"class":133},"where",[105,324,190],{"class":115},[105,326,327],{"class":119},"\"",[105,329,331],{"class":330},"sfazB","active",[105,333,327],{"class":119},[105,335,236],{"class":119},[105,337,339],{"class":338},"sfNiH"," true",[105,341,197],{"class":115},[105,343,130],{"class":119},[105,345,293],{"class":133},[105,347,136],{"class":115},[105,349,139],{"class":119},[75,351,352,353,355,356,359],{},"Just like ",[87,354,147],{},", there is a ",[87,357,358],{},"firstOrFail"," method that throws an error if no matching record is found.",[96,361,363],{"className":98,"code":362,"language":100,"meta":101,"style":101},"// Returns User, Throws Error if no active user is found\nconst activeUser = await User.where(\"active\", true).firstOrFail();\n",[87,364,365,370],{"__ignoreMap":101},[105,366,367],{"class":107,"line":108},[105,368,369],{"class":168},"// Returns User, Throws Error if no active user is found\n",[105,371,372,374,377,379,381,383,385,387,389,391,393,395,397,399,401,403,405,407],{"class":107,"line":172},[105,373,112],{"class":111},[105,375,376],{"class":115}," activeUser ",[105,378,120],{"class":119},[105,380,124],{"class":123},[105,382,127],{"class":115},[105,384,130],{"class":119},[105,386,322],{"class":133},[105,388,190],{"class":115},[105,390,327],{"class":119},[105,392,331],{"class":330},[105,394,327],{"class":119},[105,396,236],{"class":119},[105,398,339],{"class":338},[105,400,197],{"class":115},[105,402,130],{"class":119},[105,404,358],{"class":133},[105,406,136],{"class":115},[105,408,139],{"class":119},[79,410,412],{"id":411},"filtering-results","Filtering Results",[145,414,416],{"id":415},"where-clauses","Where Clauses",[75,418,419,420,300],{},"You can filter results using the ",[87,421,322],{},[75,423,424],{},"The most basic call requires two arguments: the name of the column and the value to match against.",[96,426,428],{"className":98,"code":427,"language":100,"meta":101,"style":101},"const user = await User.where(\"votes\", 100).get();\n",[87,429,430],{"__ignoreMap":101},[105,431,432,434,436,438,440,442,444,446,448,450,453,455,457,460,462,464,466,468],{"class":107,"line":108},[105,433,112],{"class":111},[105,435,177],{"class":115},[105,437,120],{"class":119},[105,439,124],{"class":123},[105,441,127],{"class":115},[105,443,130],{"class":119},[105,445,322],{"class":133},[105,447,190],{"class":115},[105,449,327],{"class":119},[105,451,452],{"class":330},"votes",[105,454,327],{"class":119},[105,456,236],{"class":119},[105,458,459],{"class":193}," 100",[105,461,197],{"class":115},[105,463,130],{"class":119},[105,465,93],{"class":133},[105,467,136],{"class":115},[105,469,139],{"class":119},[75,471,472],{},"You may also pass a comparison operator as the second argument and the value as the third argument.",[96,474,476],{"className":98,"code":475,"language":100,"meta":101,"style":101},"const user = await User.where(\"votes\", \"=\", 100).get();\n\nconst user = await User.where(\"votes\", \">=\", 100).get();\n\nconst user = await User.where(\"votes\", \"\u003C>\", 100).get();\n",[87,477,478,525,531,579,584],{"__ignoreMap":101},[105,479,480,482,484,486,488,490,492,494,496,498,500,502,504,507,509,511,513,515,517,519,521,523],{"class":107,"line":108},[105,481,112],{"class":111},[105,483,177],{"class":115},[105,485,120],{"class":119},[105,487,124],{"class":123},[105,489,127],{"class":115},[105,491,130],{"class":119},[105,493,322],{"class":133},[105,495,190],{"class":115},[105,497,327],{"class":119},[105,499,452],{"class":330},[105,501,327],{"class":119},[105,503,236],{"class":119},[105,505,506],{"class":119}," \"",[105,508,120],{"class":330},[105,510,327],{"class":119},[105,512,236],{"class":119},[105,514,459],{"class":193},[105,516,197],{"class":115},[105,518,130],{"class":119},[105,520,93],{"class":133},[105,522,136],{"class":115},[105,524,139],{"class":119},[105,526,527],{"class":107,"line":172},[105,528,530],{"emptyLinePlaceholder":529},true,"\n",[105,532,534,536,538,540,542,544,546,548,550,552,554,556,558,560,563,565,567,569,571,573,575,577],{"class":107,"line":533},3,[105,535,112],{"class":111},[105,537,177],{"class":115},[105,539,120],{"class":119},[105,541,124],{"class":123},[105,543,127],{"class":115},[105,545,130],{"class":119},[105,547,322],{"class":133},[105,549,190],{"class":115},[105,551,327],{"class":119},[105,553,452],{"class":330},[105,555,327],{"class":119},[105,557,236],{"class":119},[105,559,506],{"class":119},[105,561,562],{"class":330},">=",[105,564,327],{"class":119},[105,566,236],{"class":119},[105,568,459],{"class":193},[105,570,197],{"class":115},[105,572,130],{"class":119},[105,574,93],{"class":133},[105,576,136],{"class":115},[105,578,139],{"class":119},[105,580,582],{"class":107,"line":581},4,[105,583,530],{"emptyLinePlaceholder":529},[105,585,587,589,591,593,595,597,599,601,603,605,607,609,611,613,616,618,620,622,624,626,628,630],{"class":107,"line":586},5,[105,588,112],{"class":111},[105,590,177],{"class":115},[105,592,120],{"class":119},[105,594,124],{"class":123},[105,596,127],{"class":115},[105,598,130],{"class":119},[105,600,322],{"class":133},[105,602,190],{"class":115},[105,604,327],{"class":119},[105,606,452],{"class":330},[105,608,327],{"class":119},[105,610,236],{"class":119},[105,612,506],{"class":119},[105,614,615],{"class":330},"\u003C>",[105,617,327],{"class":119},[105,619,236],{"class":119},[105,621,459],{"class":193},[105,623,197],{"class":115},[105,625,130],{"class":119},[105,627,93],{"class":133},[105,629,136],{"class":115},[105,631,139],{"class":119},[145,633,635],{"id":634},"where-in","Where In",[75,637,638,639,642],{},"You can use the ",[87,640,641],{},"whereIn"," method to verify that a given column's value is contained within the given array of values.",[96,644,646],{"className":98,"code":645,"language":100,"meta":101,"style":101},"const users = await User.whereIn(\"id\", [1, 2, 3]).get();\n",[87,647,648],{"__ignoreMap":101},[105,649,650,652,654,656,658,660,662,664,666,668,671,673,675,678,680,682,684,686,688,690,692,694,696],{"class":107,"line":108},[105,651,112],{"class":111},[105,653,116],{"class":115},[105,655,120],{"class":119},[105,657,124],{"class":123},[105,659,127],{"class":115},[105,661,130],{"class":119},[105,663,641],{"class":133},[105,665,190],{"class":115},[105,667,327],{"class":119},[105,669,670],{"class":330},"id",[105,672,327],{"class":119},[105,674,236],{"class":119},[105,676,677],{"class":115}," [",[105,679,194],{"class":193},[105,681,236],{"class":119},[105,683,239],{"class":193},[105,685,236],{"class":119},[105,687,244],{"class":193},[105,689,247],{"class":115},[105,691,130],{"class":119},[105,693,93],{"class":133},[105,695,136],{"class":115},[105,697,139],{"class":119},[145,699,701],{"id":700},"where-not-null","Where Not Null",[75,703,252,704,707,708,130],{},[87,705,706],{},"whereNotNull"," method verifies that the column's value is not ",[87,709,710],{},"NULL",[96,712,714],{"className":98,"code":713,"language":100,"meta":101,"style":101},"const users = await User.whereNotNull(\"updated_at\").get();\n",[87,715,716],{"__ignoreMap":101},[105,717,718,720,722,724,726,728,730,732,734,736,739,741,743,745,747,749],{"class":107,"line":108},[105,719,112],{"class":111},[105,721,116],{"class":115},[105,723,120],{"class":119},[105,725,124],{"class":123},[105,727,127],{"class":115},[105,729,130],{"class":119},[105,731,706],{"class":133},[105,733,190],{"class":115},[105,735,327],{"class":119},[105,737,738],{"class":330},"updated_at",[105,740,327],{"class":119},[105,742,197],{"class":115},[105,744,130],{"class":119},[105,746,93],{"class":133},[105,748,136],{"class":115},[105,750,139],{"class":119},[79,752,754],{"id":753},"ordering","Ordering",[75,756,757,758,761,762,90,765,130],{},"To sort the results of the query, you may use the ",[87,759,760],{},"orderBy"," method. The first argument should be the column you wish to sort by, while the second argument controls the direction of the sort and may be either ",[87,763,764],{},"asc",[87,766,767],{},"desc",[96,769,771],{"className":98,"code":770,"language":100,"meta":101,"style":101},"const user = await User.orderBy(\"name\", \"desc\").get();\n",[87,772,773],{"__ignoreMap":101},[105,774,775,777,779,781,783,785,787,789,791,793,796,798,800,802,804,806,808,810,812,814],{"class":107,"line":108},[105,776,112],{"class":111},[105,778,177],{"class":115},[105,780,120],{"class":119},[105,782,124],{"class":123},[105,784,127],{"class":115},[105,786,130],{"class":119},[105,788,760],{"class":133},[105,790,190],{"class":115},[105,792,327],{"class":119},[105,794,795],{"class":330},"name",[105,797,327],{"class":119},[105,799,236],{"class":119},[105,801,506],{"class":119},[105,803,767],{"class":330},[105,805,327],{"class":119},[105,807,197],{"class":115},[105,809,130],{"class":119},[105,811,93],{"class":133},[105,813,136],{"class":115},[105,815,139],{"class":119},[79,817,819],{"id":818},"pagination","Pagination",[75,821,822,823,826],{},"Vasta's paginator is integrated with the query builder and provides a convenient, easy-to-use way of paginating database results. The ",[87,824,825],{},"paginate"," method accepts the number of items per page as its first argument and the current page number as its second argument.",[96,828,830],{"className":98,"code":829,"language":100,"meta":101,"style":101},"const result = await User.paginate(15, 1);\n",[87,831,832],{"__ignoreMap":101},[105,833,834,836,839,841,843,845,847,849,851,854,856,859,861],{"class":107,"line":108},[105,835,112],{"class":111},[105,837,838],{"class":115}," result ",[105,840,120],{"class":119},[105,842,124],{"class":123},[105,844,127],{"class":115},[105,846,130],{"class":119},[105,848,825],{"class":133},[105,850,190],{"class":115},[105,852,853],{"class":193},"15",[105,855,236],{"class":119},[105,857,858],{"class":193}," 1",[105,860,197],{"class":115},[105,862,139],{"class":119},[75,864,252,865,867],{},[87,866,825],{}," method returns an object with the following properties:",[869,870,871,878,884,890,896],"ul",{},[872,873,874,877],"li",{},[87,875,876],{},"data",": An array of model instances for the current page.",[872,879,880,883],{},[87,881,882],{},"total",": The total number of records matching the query.",[872,885,886,889],{},[87,887,888],{},"perPage",": The number of items per page.",[872,891,892,895],{},[87,893,894],{},"currentPage",": The current page number.",[872,897,898,901],{},[87,899,900],{},"lastPage",": The last page number.",[79,903,905],{"id":904},"aggregates","Aggregates",[75,907,908,909,912,913,916,917,130],{},"The query builder also provides a variety of aggregate methods such as ",[87,910,911],{},"count",", ",[87,914,915],{},"max",", and ",[87,918,919],{},"sum",[96,921,923],{"className":98,"code":922,"language":100,"meta":101,"style":101},"const count = await User.count();\n\nconst max = await User.max(\"price\");\n",[87,924,925,946,950],{"__ignoreMap":101},[105,926,927,929,932,934,936,938,940,942,944],{"class":107,"line":108},[105,928,112],{"class":111},[105,930,931],{"class":115}," count ",[105,933,120],{"class":119},[105,935,124],{"class":123},[105,937,127],{"class":115},[105,939,130],{"class":119},[105,941,911],{"class":133},[105,943,136],{"class":115},[105,945,139],{"class":119},[105,947,948],{"class":107,"line":172},[105,949,530],{"emptyLinePlaceholder":529},[105,951,952,954,957,959,961,963,965,967,969,971,974,976,978],{"class":107,"line":533},[105,953,112],{"class":111},[105,955,956],{"class":115}," max ",[105,958,120],{"class":119},[105,960,124],{"class":123},[105,962,127],{"class":115},[105,964,130],{"class":119},[105,966,915],{"class":133},[105,968,190],{"class":115},[105,970,327],{"class":119},[105,972,973],{"class":330},"price",[105,975,327],{"class":119},[105,977,197],{"class":115},[105,979,139],{"class":119},[79,981,983],{"id":982},"selecting-columns","Selecting Columns",[75,985,986,987,990],{},"You may not always want to select all columns from a database table. Using the ",[87,988,989],{},"select"," method, you can specify a custom \"select\" clause for the query:",[96,992,994],{"className":98,"code":993,"language":100,"meta":101,"style":101},"const users = await User.select([\"name\", \"email\"]).get();\n",[87,995,996],{"__ignoreMap":101},[105,997,998,1000,1002,1004,1006,1008,1010,1012,1014,1016,1018,1020,1022,1024,1027,1029,1031,1033,1035,1037],{"class":107,"line":108},[105,999,112],{"class":111},[105,1001,116],{"class":115},[105,1003,120],{"class":119},[105,1005,124],{"class":123},[105,1007,127],{"class":115},[105,1009,130],{"class":119},[105,1011,989],{"class":133},[105,1013,231],{"class":115},[105,1015,327],{"class":119},[105,1017,795],{"class":330},[105,1019,327],{"class":119},[105,1021,236],{"class":119},[105,1023,506],{"class":119},[105,1025,1026],{"class":330},"email",[105,1028,327],{"class":119},[105,1030,247],{"class":115},[105,1032,130],{"class":119},[105,1034,93],{"class":133},[105,1036,136],{"class":115},[105,1038,139],{"class":119},[79,1040,1042],{"id":1041},"expressions-subqueries","Expressions & Subqueries",[75,1044,1045,1046,1049,1050,1053,1054,912,1056,912,1058,916,1060,1062],{},"Because Vasta is built on top of Kysely, it natively supports Kysely's expression and subquery system for advanced queries. You can pass an ",[87,1047,1048],{},"ExpressionBuilder"," callback—or standard Kysely ",[87,1051,1052],{},"Expression"," objects—directly into your ",[87,1055,989],{},[87,1057,322],{},[87,1059,641],{},[87,1061,760],{}," clauses.",[75,1064,1065,1066,130],{},"For detailed information on writing expressions, please refer to the ",[1067,1068,1072],"a",{"href":1069,"rel":1070},"https://kysely.dev/docs/recipes/expressions",[1071],"nofollow","official Kysely documentation about expressions",[145,1074,1076],{"id":1075},"select-expressions","Select Expressions",[75,1078,638,1079,1081,1082,1084],{},[87,1080,1048],{}," callback in the ",[87,1083,989],{}," method to utilize database functions, aliasing, and raw values. Vasta provides strict typings for aliased selections right out of the box:",[96,1086,1088],{"className":98,"code":1087,"language":100,"meta":101,"style":101},"const users = await User.select((eb) => [\n  \"id\",\n  \"email\",\n  eb.fn(\"upper\", [\"name\"]).as(\"upper_name\"), // SQL: upper(\"name\") as \"upper_name\"\n]).get();\n\n// Typed access is natively supported on the returned model instance!\nconsole.log(users[0].upper_name);\nconsole.log(users[0].attributes.upper_name);\n",[87,1089,1090,1122,1134,1144,1196,1208,1213,1219,1246],{"__ignoreMap":101},[105,1091,1092,1094,1096,1098,1100,1102,1104,1106,1108,1110,1114,1116,1119],{"class":107,"line":108},[105,1093,112],{"class":111},[105,1095,116],{"class":115},[105,1097,120],{"class":119},[105,1099,124],{"class":123},[105,1101,127],{"class":115},[105,1103,130],{"class":119},[105,1105,989],{"class":133},[105,1107,190],{"class":115},[105,1109,190],{"class":119},[105,1111,1113],{"class":1112},"sHdIc","eb",[105,1115,197],{"class":119},[105,1117,1118],{"class":111}," =>",[105,1120,1121],{"class":115}," [\n",[105,1123,1124,1127,1129,1131],{"class":107,"line":172},[105,1125,1126],{"class":119},"  \"",[105,1128,670],{"class":330},[105,1130,327],{"class":119},[105,1132,1133],{"class":119},",\n",[105,1135,1136,1138,1140,1142],{"class":107,"line":533},[105,1137,1126],{"class":119},[105,1139,1026],{"class":330},[105,1141,327],{"class":119},[105,1143,1133],{"class":119},[105,1145,1146,1149,1151,1154,1156,1158,1161,1163,1165,1167,1169,1171,1173,1175,1177,1180,1182,1184,1187,1189,1191,1193],{"class":107,"line":581},[105,1147,1148],{"class":115},"  eb",[105,1150,130],{"class":119},[105,1152,1153],{"class":133},"fn",[105,1155,190],{"class":115},[105,1157,327],{"class":119},[105,1159,1160],{"class":330},"upper",[105,1162,327],{"class":119},[105,1164,236],{"class":119},[105,1166,677],{"class":115},[105,1168,327],{"class":119},[105,1170,795],{"class":330},[105,1172,327],{"class":119},[105,1174,247],{"class":115},[105,1176,130],{"class":119},[105,1178,1179],{"class":133},"as",[105,1181,190],{"class":115},[105,1183,327],{"class":119},[105,1185,1186],{"class":330},"upper_name",[105,1188,327],{"class":119},[105,1190,197],{"class":115},[105,1192,236],{"class":119},[105,1194,1195],{"class":168}," // SQL: upper(\"name\") as \"upper_name\"\n",[105,1197,1198,1200,1202,1204,1206],{"class":107,"line":586},[105,1199,247],{"class":115},[105,1201,130],{"class":119},[105,1203,93],{"class":133},[105,1205,136],{"class":115},[105,1207,139],{"class":119},[105,1209,1211],{"class":107,"line":1210},6,[105,1212,530],{"emptyLinePlaceholder":529},[105,1214,1216],{"class":107,"line":1215},7,[105,1217,1218],{"class":168},"// Typed access is natively supported on the returned model instance!\n",[105,1220,1222,1225,1227,1230,1233,1236,1239,1241,1244],{"class":107,"line":1221},8,[105,1223,1224],{"class":115},"console",[105,1226,130],{"class":119},[105,1228,1229],{"class":133},"log",[105,1231,1232],{"class":115},"(users[",[105,1234,1235],{"class":193},"0",[105,1237,1238],{"class":115},"]",[105,1240,130],{"class":119},[105,1242,1243],{"class":115},"upper_name)",[105,1245,139],{"class":119},[105,1247,1249,1251,1253,1255,1257,1259,1261,1263,1266,1268,1270],{"class":107,"line":1248},9,[105,1250,1224],{"class":115},[105,1252,130],{"class":119},[105,1254,1229],{"class":133},[105,1256,1232],{"class":115},[105,1258,1235],{"class":193},[105,1260,1238],{"class":115},[105,1262,130],{"class":119},[105,1264,1265],{"class":115},"attributes",[105,1267,130],{"class":119},[105,1269,1243],{"class":115},[105,1271,139],{"class":119},[145,1273,1275],{"id":1274},"where-expressions","Where Expressions",[75,1277,1278,1279,1281,1282,1284],{},"You can use the same ",[87,1280,1048],{}," context in ",[87,1283,322],{}," clauses to filter against database functions or computed columns without needing to drop down into raw SQL strings:",[96,1286,1288],{"className":98,"code":1287,"language":100,"meta":101,"style":101},"// Using database functions in constraints\nconst users = await User.where((eb) => eb.fn(\"upper\", [\"name\"]), \"=\", \"DAVID\").get();\n",[87,1289,1290,1295],{"__ignoreMap":101},[105,1291,1292],{"class":107,"line":108},[105,1293,1294],{"class":168},"// Using database functions in constraints\n",[105,1296,1297,1299,1301,1303,1305,1307,1309,1311,1313,1315,1317,1319,1321,1324,1326,1328,1330,1332,1334,1336,1338,1340,1342,1344,1346,1348,1350,1352,1354,1356,1358,1360,1363,1365,1367,1369,1371,1373],{"class":107,"line":172},[105,1298,112],{"class":111},[105,1300,116],{"class":115},[105,1302,120],{"class":119},[105,1304,124],{"class":123},[105,1306,127],{"class":115},[105,1308,130],{"class":119},[105,1310,322],{"class":133},[105,1312,190],{"class":115},[105,1314,190],{"class":119},[105,1316,1113],{"class":1112},[105,1318,197],{"class":119},[105,1320,1118],{"class":111},[105,1322,1323],{"class":115}," eb",[105,1325,130],{"class":119},[105,1327,1153],{"class":133},[105,1329,190],{"class":115},[105,1331,327],{"class":119},[105,1333,1160],{"class":330},[105,1335,327],{"class":119},[105,1337,236],{"class":119},[105,1339,677],{"class":115},[105,1341,327],{"class":119},[105,1343,795],{"class":330},[105,1345,327],{"class":119},[105,1347,247],{"class":115},[105,1349,236],{"class":119},[105,1351,506],{"class":119},[105,1353,120],{"class":330},[105,1355,327],{"class":119},[105,1357,236],{"class":119},[105,1359,506],{"class":119},[105,1361,1362],{"class":330},"DAVID",[105,1364,327],{"class":119},[105,1366,197],{"class":115},[105,1368,130],{"class":119},[105,1370,93],{"class":133},[105,1372,136],{"class":115},[105,1374,139],{"class":119},[145,1376,1378],{"id":1377},"subqueries","Subqueries",[75,1380,1381],{},"You can also pass Kysely subquery expressions directly into your constraints. This is highly useful for matching values against a separate query result:",[96,1383,1385],{"className":98,"code":1384,"language":100,"meta":101,"style":101},"import { db } from \"./database\";\n\n// Create a subquery (resolves to a single value)\nconst latestPostSubquery = db.selectFrom(\"posts\").select(\"user_id\").orderBy(\"created_at\", \"desc\").limit(1);\n\n// Find the user who made the latest post matching the subquery\nconst user = await User.where(\"id\", \"=\", latestPostSubquery).first();\n",[87,1386,1387,1413,1417,1422,1500,1504,1509],{"__ignoreMap":101},[105,1388,1389,1392,1395,1398,1401,1404,1406,1409,1411],{"class":107,"line":108},[105,1390,1391],{"class":123},"import",[105,1393,1394],{"class":119}," {",[105,1396,1397],{"class":115}," db",[105,1399,1400],{"class":119}," }",[105,1402,1403],{"class":123}," from",[105,1405,506],{"class":119},[105,1407,1408],{"class":330},"./database",[105,1410,327],{"class":119},[105,1412,139],{"class":119},[105,1414,1415],{"class":107,"line":172},[105,1416,530],{"emptyLinePlaceholder":529},[105,1418,1419],{"class":107,"line":533},[105,1420,1421],{"class":168},"// Create a subquery (resolves to a single value)\n",[105,1423,1424,1426,1429,1431,1433,1435,1438,1440,1442,1445,1447,1449,1451,1453,1455,1457,1460,1462,1464,1466,1468,1470,1472,1475,1477,1479,1481,1483,1485,1487,1489,1492,1494,1496,1498],{"class":107,"line":581},[105,1425,112],{"class":111},[105,1427,1428],{"class":115}," latestPostSubquery ",[105,1430,120],{"class":119},[105,1432,1397],{"class":115},[105,1434,130],{"class":119},[105,1436,1437],{"class":133},"selectFrom",[105,1439,190],{"class":115},[105,1441,327],{"class":119},[105,1443,1444],{"class":330},"posts",[105,1446,327],{"class":119},[105,1448,197],{"class":115},[105,1450,130],{"class":119},[105,1452,989],{"class":133},[105,1454,190],{"class":115},[105,1456,327],{"class":119},[105,1458,1459],{"class":330},"user_id",[105,1461,327],{"class":119},[105,1463,197],{"class":115},[105,1465,130],{"class":119},[105,1467,760],{"class":133},[105,1469,190],{"class":115},[105,1471,327],{"class":119},[105,1473,1474],{"class":330},"created_at",[105,1476,327],{"class":119},[105,1478,236],{"class":119},[105,1480,506],{"class":119},[105,1482,767],{"class":330},[105,1484,327],{"class":119},[105,1486,197],{"class":115},[105,1488,130],{"class":119},[105,1490,1491],{"class":133},"limit",[105,1493,190],{"class":115},[105,1495,194],{"class":193},[105,1497,197],{"class":115},[105,1499,139],{"class":119},[105,1501,1502],{"class":107,"line":586},[105,1503,530],{"emptyLinePlaceholder":529},[105,1505,1506],{"class":107,"line":1210},[105,1507,1508],{"class":168},"// Find the user who made the latest post matching the subquery\n",[105,1510,1511,1513,1515,1517,1519,1521,1523,1525,1527,1529,1531,1533,1535,1537,1539,1541,1543,1546,1548,1550,1552],{"class":107,"line":1215},[105,1512,112],{"class":111},[105,1514,177],{"class":115},[105,1516,120],{"class":119},[105,1518,124],{"class":123},[105,1520,127],{"class":115},[105,1522,130],{"class":119},[105,1524,322],{"class":133},[105,1526,190],{"class":115},[105,1528,327],{"class":119},[105,1530,670],{"class":330},[105,1532,327],{"class":119},[105,1534,236],{"class":119},[105,1536,506],{"class":119},[105,1538,120],{"class":330},[105,1540,327],{"class":119},[105,1542,236],{"class":119},[105,1544,1545],{"class":115}," latestPostSubquery)",[105,1547,130],{"class":119},[105,1549,293],{"class":133},[105,1551,136],{"class":115},[105,1553,139],{"class":119},[75,1555,1556,1557,1560],{},"You can use arrays and ",[87,1558,1559],{},"in"," clauses in exactly the same way to match multiple results from a subquery:",[96,1562,1564],{"className":98,"code":1563,"language":100,"meta":101,"style":101},"// Query returning an array of IDs\nconst activeUsersSubquery = db.selectFrom(\"sessions\").select(\"user_id\").where(\"is_active\", \"=\", true);\n\n// Pass the subquery properly to the \"in\" operator\nconst activeUsers = await User.whereIn(\"id\", activeUsersSubquery).get();\n",[87,1565,1566,1571,1640,1644,1649],{"__ignoreMap":101},[105,1567,1568],{"class":107,"line":108},[105,1569,1570],{"class":168},"// Query returning an array of IDs\n",[105,1572,1573,1575,1578,1580,1582,1584,1586,1588,1590,1593,1595,1597,1599,1601,1603,1605,1607,1609,1611,1613,1615,1617,1619,1622,1624,1626,1628,1630,1632,1634,1636,1638],{"class":107,"line":172},[105,1574,112],{"class":111},[105,1576,1577],{"class":115}," activeUsersSubquery ",[105,1579,120],{"class":119},[105,1581,1397],{"class":115},[105,1583,130],{"class":119},[105,1585,1437],{"class":133},[105,1587,190],{"class":115},[105,1589,327],{"class":119},[105,1591,1592],{"class":330},"sessions",[105,1594,327],{"class":119},[105,1596,197],{"class":115},[105,1598,130],{"class":119},[105,1600,989],{"class":133},[105,1602,190],{"class":115},[105,1604,327],{"class":119},[105,1606,1459],{"class":330},[105,1608,327],{"class":119},[105,1610,197],{"class":115},[105,1612,130],{"class":119},[105,1614,322],{"class":133},[105,1616,190],{"class":115},[105,1618,327],{"class":119},[105,1620,1621],{"class":330},"is_active",[105,1623,327],{"class":119},[105,1625,236],{"class":119},[105,1627,506],{"class":119},[105,1629,120],{"class":330},[105,1631,327],{"class":119},[105,1633,236],{"class":119},[105,1635,339],{"class":338},[105,1637,197],{"class":115},[105,1639,139],{"class":119},[105,1641,1642],{"class":107,"line":533},[105,1643,530],{"emptyLinePlaceholder":529},[105,1645,1646],{"class":107,"line":581},[105,1647,1648],{"class":168},"// Pass the subquery properly to the \"in\" operator\n",[105,1650,1651,1653,1656,1658,1660,1662,1664,1666,1668,1670,1672,1674,1676,1679,1681,1683,1685],{"class":107,"line":586},[105,1652,112],{"class":111},[105,1654,1655],{"class":115}," activeUsers ",[105,1657,120],{"class":119},[105,1659,124],{"class":123},[105,1661,127],{"class":115},[105,1663,130],{"class":119},[105,1665,641],{"class":133},[105,1667,190],{"class":115},[105,1669,327],{"class":119},[105,1671,670],{"class":330},[105,1673,327],{"class":119},[105,1675,236],{"class":119},[105,1677,1678],{"class":115}," activeUsersSubquery)",[105,1680,130],{"class":119},[105,1682,93],{"class":133},[105,1684,136],{"class":115},[105,1686,139],{"class":119},[1688,1689,1690],"style",{},"html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}",{"title":101,"searchDepth":172,"depth":172,"links":1692},[1693,1694,1698,1703,1704,1705,1706,1707],{"id":81,"depth":172,"text":82},{"id":142,"depth":172,"text":143,"children":1695},[1696,1697],{"id":147,"depth":533,"text":148},{"id":293,"depth":533,"text":294},{"id":411,"depth":172,"text":412,"children":1699},[1700,1701,1702],{"id":415,"depth":533,"text":416},{"id":634,"depth":533,"text":635},{"id":700,"depth":533,"text":701},{"id":753,"depth":172,"text":754},{"id":818,"depth":172,"text":819},{"id":904,"depth":172,"text":905},{"id":982,"depth":172,"text":983},{"id":1041,"depth":172,"text":1042,"children":1708},[1709,1710,1711],{"id":1075,"depth":533,"text":1076},{"id":1274,"depth":533,"text":1275},{"id":1377,"depth":533,"text":1378},"Retrieving models with Vasta.","md",null,{},{"icon":34},{"description":1718,"title":31},"Learn how to retrieve models with Vasta.","5_qtKSUENWxIpxPsaF66FUWBM8RLckAX56lNPO2DM6w",[1721,1723],{"title":26,"path":27,"stem":28,"description":1722,"icon":29,"children":-1},"Building models with Vasta.",{"title":36,"path":37,"stem":38,"description":1724,"icon":39,"children":-1},"Inserting and updating models with Vasta.",1779373330912]