Skip to content

Commit e72c338

Browse files
committed
feat: support contraint key in create table in sqlite
1 parent 3868cb9 commit e72c338

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pegjs/sqlite.pegjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ column_definition_opt
562562
/ co:keyword_comment {
563563
return { comment: co }
564564
}
565+
/ kc:KW_CONSTRAINT __ n:ident_without_kw_type {
566+
return { constraint: { keyword: kc.toLowerCase(), constraint: n } }
567+
}
565568
/ ca:collate_expr {
566569
return { collate: ca }
567570
}

test/sqlite.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,11 @@ describe('sqlite', () => {
206206
sql = 'CREATE INDEX if not exists schema_name.visits_url_index ON visits (url collate cn asc) where id > 10;'
207207
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')
208208
})
209+
it('should support constraint in create table', () => {
210+
const sql = `CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
211+
"MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY,
212+
"ProductVersion" TEXT NOT NULL
213+
);`
214+
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)`)
215+
})
209216
})

0 commit comments

Comments
 (0)