1
0
Fork 0
mirror of synced 2024-08-08 14:48:13 +12:00

Making sqlite design doc generation more accessible.

This commit is contained in:
mike12345567 2024-05-17 12:35:31 +01:00
parent 0efa1f06ab
commit d7f3109a22
4 changed files with 23 additions and 16 deletions

View file

@ -0,0 +1,17 @@
import { PreSaveSQLiteDefinition } from "@budibase/types"
import { SQLITE_DESIGN_DOC_ID } from "../constants"
// the table id property defines which property in the document
// to use when splitting the documents into different sqlite tables
export function base(tableIdProp: string): PreSaveSQLiteDefinition {
return {
_id: SQLITE_DESIGN_DOC_ID,
language: "sqlite",
sql: {
tables: {},
options: {
table_name: tableIdProp,
},
},
}
}

View file

@ -2,3 +2,4 @@ export * as utils from "./utils"
export { default as Sql } from "./sql"
export { default as SqlTable } from "./sqlTable"
export * as designDoc from "./designDoc"

View file

@ -1,33 +1,20 @@
import { context, SQLITE_DESIGN_DOC_ID } from "@budibase/backend-core"
import { context, sql, SQLITE_DESIGN_DOC_ID } from "@budibase/backend-core"
import {
FieldType,
RelationshipFieldMetadata,
SQLiteDefinition,
PreSaveSQLiteDefinition,
SQLiteTable,
SQLiteTables,
SQLiteType,
Table,
} from "@budibase/types"
import { cloneDeep } from "lodash"
import tablesSdk from "../"
import {
CONSTANT_INTERNAL_ROW_COLS,
generateJunctionTableID,
} from "../../../../db/utils"
type PreSaveSQLiteDefinition = Omit<SQLiteDefinition, "_rev">
const BASIC_SQLITE_DOC: PreSaveSQLiteDefinition = {
_id: SQLITE_DESIGN_DOC_ID,
language: "sqlite",
sql: {
tables: {},
options: {
table_name: "tableId",
},
},
}
const FieldTypeMap: Record<FieldType, SQLiteType> = {
[FieldType.BOOLEAN]: SQLiteType.NUMERIC,
[FieldType.DATETIME]: SQLiteType.TEXT,
@ -107,7 +94,7 @@ function mapTable(table: Table): SQLiteTables {
// nothing exists, need to iterate though existing tables
async function buildBaseDefinition(): Promise<PreSaveSQLiteDefinition> {
const tables = await tablesSdk.getAllInternalTables()
const definition = cloneDeep(BASIC_SQLITE_DOC)
const definition = sql.designDoc.base("tableId")
for (let table of tables) {
definition.sql.tables = {
...definition.sql.tables,

View file

@ -29,3 +29,5 @@ export interface SQLiteDefinition {
}
}
}
export type PreSaveSQLiteDefinition = Omit<SQLiteDefinition, "_rev">