|
|
@ -2,6 +2,8 @@ import type { TableType } from 'nocodb-sdk' |
|
|
|
import { UITypes } from 'nocodb-sdk' |
|
|
|
import { UITypes } from 'nocodb-sdk' |
|
|
|
import { useNuxtApp } from '#app' |
|
|
|
import { useNuxtApp } from '#app' |
|
|
|
import { useProject } from '#imports' |
|
|
|
import { useProject } from '#imports' |
|
|
|
|
|
|
|
import { useToast } from 'vue-toastification' |
|
|
|
|
|
|
|
import { extractSdkResponseErrorMsg } from '~/utils/errorUtils' |
|
|
|
|
|
|
|
|
|
|
|
export default (onTableCreate?: (tableMeta: TableType) => void) => { |
|
|
|
export default (onTableCreate?: (tableMeta: TableType) => void) => { |
|
|
|
const table = reactive<{ title: string; table_name: string; columns: Record<string, boolean> }>({ |
|
|
|
const table = reactive<{ title: string; table_name: string; columns: Record<string, boolean> }>({ |
|
|
@ -16,26 +18,33 @@ export default (onTableCreate?: (tableMeta: TableType) => void) => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const { sqlUi, project, tables } = useProject() |
|
|
|
const { sqlUi, project, tables } = useProject() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const toast = useToast() |
|
|
|
|
|
|
|
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const { $api } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
const createTable = async () => { |
|
|
|
const createTable = async () => { |
|
|
|
if (!sqlUi?.value) return |
|
|
|
try { |
|
|
|
const columns = sqlUi?.value?.getNewTableColumns().filter((col) => { |
|
|
|
if (!sqlUi?.value) return |
|
|
|
if (col.column_name === 'id' && table.columns.id_ag) { |
|
|
|
const columns = sqlUi?.value?.getNewTableColumns().filter((col) => { |
|
|
|
Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG')) |
|
|
|
if (col.column_name === 'id' && table.columns.id_ag) { |
|
|
|
col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt) |
|
|
|
Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG')) |
|
|
|
col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt) |
|
|
|
col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt) |
|
|
|
return true |
|
|
|
col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt) |
|
|
|
} |
|
|
|
return true |
|
|
|
return !!table.columns[col.column_name] |
|
|
|
} |
|
|
|
}) |
|
|
|
return !!table.columns[col.column_name] |
|
|
|
|
|
|
|
}) |
|
|
|
const tableMeta = await $api.dbTable.create(project?.value?.id as string, { |
|
|
|
|
|
|
|
...table, |
|
|
|
const tableMeta = await $api.dbTable.create(project?.value?.id as string, { |
|
|
|
columns, |
|
|
|
...table, |
|
|
|
}) |
|
|
|
columns, |
|
|
|
|
|
|
|
}) |
|
|
|
onTableCreate?.(tableMeta) |
|
|
|
|
|
|
|
|
|
|
|
onTableCreate?.(tableMeta) |
|
|
|
|
|
|
|
} catch (e: any) { |
|
|
|
|
|
|
|
toast.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
watch( |
|
|
|