Spaces:
Build error
Build error
File size: 524 Bytes
7e5cb25 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import postgres from "postgres"
import { cache } from "react"
const sql = postgres(process.env.POSTGRES_URL) // will use psql environment variables
export const getModels = cache(async () => {
const models = await sql`
SELECT models.*, SUM(results.score) as total_score
FROM models
LEFT JOIN results ON models.id = results.model
GROUP BY models.id
ORDER BY total_score DESC;
`
return models.map((m) => ({
...m,
slug: m.api_id.split("/").pop().toLowerCase(),
}))
})
export default sql
|