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)`) + }) })