From f6ef01ec1ee8d9efda949aaae608729972aca9ad Mon Sep 17 00:00:00 2001 From: taozhi8833998 Date: Sun, 13 Apr 2025 22:29:49 +0800 Subject: [PATCH] feat: support contraint key in create table in sqlite --- pegjs/sqlite.pegjs | 3 +++ test/sqlite.spec.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/pegjs/sqlite.pegjs b/pegjs/sqlite.pegjs index 425d27f2..7206e789 100644 --- a/pegjs/sqlite.pegjs +++ b/pegjs/sqlite.pegjs @@ -562,6 +562,9 @@ column_definition_opt / co:keyword_comment { return { comment: co } } + / kc:KW_CONSTRAINT __ n:ident_without_kw_type { + return { constraint: { keyword: kc.toLowerCase(), constraint: n } } + } / ca:collate_expr { return { collate: ca } } diff --git a/test/sqlite.spec.js b/test/sqlite.spec.js index 22481774..0fe38ffc 100644 --- a/test/sqlite.spec.js +++ b/test/sqlite.spec.js @@ -206,4 +206,11 @@ describe('sqlite', () => { sql = 'CREATE INDEX if not exists schema_name.visits_url_index ON visits (url collate cn asc) where id > 10;' expect(getParsedSql(sql)).to.be.equal('CREATE INDEX IF NOT EXISTS "schema_name"."visits_url_index" ON "visits" ("url" COLLATE cn ASC) WHERE "id" > 10') }) + it('should support constraint in create table', () => { + const sql = `CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" ( + "MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY, + "ProductVersion" TEXT NOT NULL + );` + expect(getParsedSql(sql)).to.be.equal(`CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" ("MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY, "ProductVersion" TEXT NOT NULL)`) + }) })