changes
This commit is contained in:
1 parent
a99af426db
commit
8886aa8640
91 files changed
+2823
-773
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import pg from "pg";
|
||||
import { readFileSync, existsSync } from "fs";
|
||||
|
||||
if (existsSync(".env.local")) {
|
||||
for (const line of readFileSync(".env.local", "utf8").split(/\r?\n/)) {
|
||||
const m = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/);
|
||||
if (m && !(m[1] in process.env)) process.env[m[1]] = m[2];
|
||||
}
|
||||
}
|
||||
|
||||
const c = new pg.Client({ connectionString: process.env.DATABASE_URL });
|
||||
await c.connect();
|
||||
const r = await c.query(`
|
||||
SELECT c.slug,
|
||||
(SELECT json_agg(json_build_object('id',cat.id,'slug',cat.slug,'label',cat.label)
|
||||
ORDER BY cat.sort_order)
|
||||
FROM course_category_links l
|
||||
JOIN course_categories cat ON cat.id=l.category_id
|
||||
WHERE l.course_id=c.id) AS categories,
|
||||
(SELECT json_agg(json_build_object('id',t.id,'slug',t.slug,'label',t.label)
|
||||
ORDER BY t.sort_order)
|
||||
FROM course_tag_links l
|
||||
JOIN course_tags t ON t.id=l.tag_id
|
||||
WHERE l.course_id=c.id) AS tags
|
||||
FROM courses c
|
||||
LIMIT 2
|
||||
`);
|
||||
console.log(JSON.stringify(r.rows, null, 2));
|
||||
await c.end();
|
||||
Reference in new issue
Block a user