feat: SQL 语法支持 CREATE TABLE IF NOT EXISTS
- Parser 支持 CREATE TABLE IF NOT EXISTS 语法 - AST CreateTableStatement 新增 ifNotExists 字段 - Executor 表已存在时静默跳过 - 修复 demo.html Aria 预设报错
This commit is contained in:
@@ -94,6 +94,8 @@ export interface CreateTableStatement {
|
||||
type: 'CREATE_TABLE';
|
||||
name: string;
|
||||
columns: ASTColumnDef[];
|
||||
/** IF NOT EXISTS — 表已存在时不报错 */
|
||||
ifNotExists?: boolean;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -228,6 +228,11 @@ export class QueryExecutor {
|
||||
}
|
||||
|
||||
private async executeCreateTable(stmt: CreateTableStatement): Promise<void> {
|
||||
// IF NOT EXISTS: 表已存在时静默返回
|
||||
if (stmt.ifNotExists) {
|
||||
const exists = await this.engine.hasTable(stmt.name);
|
||||
if (exists) return;
|
||||
}
|
||||
const columns: Record<string, any> = {};
|
||||
for (const col of stmt.columns) columns[col.name] = astColumnToColumnDef(col);
|
||||
return this.engine.createTable(createSchema(stmt.name, columns));
|
||||
|
||||
Reference in New Issue
Block a user