Making sqlite design doc generation more accessible.
This commit is contained in:
parent
0efa1f06ab
commit
d7f3109a22
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -29,3 +29,5 @@ export interface SQLiteDefinition {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type PreSaveSQLiteDefinition = Omit<SQLiteDefinition, "_rev">
|
||||
|
|
Loading…
Reference in New Issue