Skip to content

Commit 3364822

Browse files
committed
feat: add primary keys and indexes
1 parent 3fa8b99 commit 3364822

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

server/api/_hub/database/tables.get.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@ export default eventHandler(async () => {
2020
return !isInternal
2121
})
2222

23-
const [columns, count] = await Promise.all([
23+
const [columns, count, primaryKeys, indexes] = await Promise.all([
2424
db.batch(tables.map(({ name }) => db.prepare(`PRAGMA table_info("${name}")`)))
25-
.then(res => res.map(({ results }) => results as { name: string; type: string }[])),
25+
.then(res => res.map(({ results }) => results as { name: string; type: string, notnull: number, dflt_value: null | string, pk: number }[])),
2626
db.batch<{ c: number }>(tables.map(({ name }) => db.prepare(`SELECT COUNT(*) AS c FROM "${name}"`)))
27-
.then(res => res.map(({ results }) => results[0].c))
27+
.then(res => res.map(({ results }) => results[0].c)),
28+
db.batch(tables.map(({ name }) => db.prepare(`PRAGMA foreign_key_list("${name}")`)))
29+
.then(res => res.map(({ results }) => results as { name: string; type: string }[])),
30+
db.batch(tables.map(({ name }) => db.prepare(`PRAGMA index_list("${name}")`)))
31+
.then(res => res.map(({ results }) => results as { name: string; type: string }[])),
2832
])
2933

30-
3134
return tables.map(({ name }, i) => ({
3235
name,
3336
columns: columns[i],
37+
primaryKeys: primaryKeys[i],
38+
indexes: indexes[i],
3439
count: count[i]
3540
}))
3641
})

0 commit comments

Comments
 (0)