353253
This commit is contained in:
@@ -80,13 +80,16 @@ export class MetadataService {
|
||||
};
|
||||
}
|
||||
|
||||
async createTable(userId: string, payload: { tableName: string; columns: { name: string; type: string; nullable?: boolean }[] }) {
|
||||
async createTable(
|
||||
userId: string,
|
||||
payload: { tableName: string; columns: { name: string; type: string; nullable?: boolean; primaryKey?: boolean }[] }
|
||||
) {
|
||||
await this.assertSchemaPermission(userId, payload.tableName);
|
||||
|
||||
const columnSql = payload.columns
|
||||
.map(
|
||||
(column: { name: string; type: string; nullable?: boolean }) =>
|
||||
`${quoteIdentifier(column.name)} ${column.type}${column.nullable ? "" : " NOT NULL"}`
|
||||
(column: { name: string; type: string; nullable?: boolean; primaryKey?: boolean }) =>
|
||||
`${quoteIdentifier(column.name)} ${column.type}${column.primaryKey ? " PRIMARY KEY" : column.nullable ? "" : " NOT NULL"}`
|
||||
)
|
||||
.join(", ");
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ export const createTableSchema = z.object({
|
||||
z.object({
|
||||
name: z.string().min(1),
|
||||
type: z.string().min(1),
|
||||
nullable: z.boolean().optional()
|
||||
nullable: z.boolean().optional(),
|
||||
primaryKey: z.boolean().optional()
|
||||
})
|
||||
).min(1)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user