21 lines
726 B
TypeScript
21 lines
726 B
TypeScript
import type { TableName } from './table-order'
|
|
import * as postgresSchema from '../../../backend/src/db/schema-postgres'
|
|
import * as sqliteSchema from '../../../backend/src/db/schema-sqlite'
|
|
import { tableOrder } from './table-order'
|
|
|
|
export type TableMap = Record<TableName, any>
|
|
|
|
const buildMap = (schema: Record<string, unknown>): TableMap => {
|
|
const map = {} as TableMap
|
|
tableOrder.forEach((name) => {
|
|
const table = schema[name]
|
|
if (!table) {
|
|
throw new Error(`Missing table export for ${name}`)
|
|
}
|
|
map[name] = table
|
|
})
|
|
return map
|
|
}
|
|
|
|
export const postgresTables = buildMap(postgresSchema as Record<string, unknown>)
|
|
export const sqliteTables = buildMap(sqliteSchema as Record<string, unknown>)
|