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