Index: database/drizzle/queries/builds.ts
===================================================================
--- database/drizzle/queries/builds.ts	(revision e729b8837b00e5c0fbe29b756ff8d07dcd34047d)
+++ database/drizzle/queries/builds.ts	(revision 59f8f5a16f9f7d37cd99c84e17950de4121a83e9)
@@ -8,5 +8,5 @@
     reviewsTable, usersTable
 } from "../schema";
-import {eq, desc, and, sql, ilike} from "drizzle-orm";
+import {eq, desc, and, sql, ilike, asc} from "drizzle-orm";
 import {inArray} from "drizzle-orm/sql/expressions/conditions";
 
@@ -85,6 +85,7 @@
 }
 
-export async function getApprovedBuilds(db: Database, limit?: number, q?: string) {
+export async function getApprovedBuilds(db: Database, limit?: number, sort?: string, q?: string) {
     let queryConditions = [eq(buildsTable.isApproved, true)];
+    let sortConditions = [];
 
     if (q) {
@@ -93,4 +94,37 @@
         );
     }
+
+    switch(sort) {
+        case 'price_asc':
+            sortConditions.push(
+                asc(buildsTable.totalPrice)
+            );
+            break;
+        case 'price_desc':
+            sortConditions.push(
+                desc(buildsTable.totalPrice)
+            );
+            break;
+        case 'rating_desc':
+            sortConditions.push(
+                desc(sql<number>`COALESCE(AVG(${ratingBuildsTable.value}::float),0)`)
+            );
+            break;
+        case 'oldest':
+            sortConditions.push(
+                asc(buildsTable.createdAt)
+            );
+            break;
+        case 'newest':
+            sortConditions.push(
+                desc(buildsTable.createdAt)
+            );
+            break;
+        default:
+            sortConditions.push(
+                desc(buildsTable.createdAt)
+            );
+            break;
+        }
 
     const approvedBuildsList = await db
@@ -104,4 +138,14 @@
         })
         .from(buildsTable)
+        .leftJoin(
+            ratingBuildsTable,
+            eq(buildsTable.id, ratingBuildsTable.buildId)
+        )
+        .groupBy(
+            buildsTable.userId,
+            buildsTable.name,
+            buildsTable.createdAt,
+            buildsTable.totalPrice
+        )
         .where(
             and (
@@ -110,5 +154,5 @@
         )
         .orderBy(
-            desc(buildsTable.totalPrice)
+            ...sortConditions
         )
         .limit(limit || 100); // 100 placeholder
