Skip to content

Commit 65d1bfd

Browse files
committed
fix: reference table bug in sqlite
1 parent 953a69b commit 65d1bfd

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

pegjs/sqlite.pegjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,14 +898,14 @@ create_constraint_foreign
898898

899899
reference_definition
900900
= kc:KW_REFERENCES __
901-
t:table_ref_list __
901+
t:table_name __
902902
de:cte_column_definition __
903903
m:('MATCH FULL'i / 'MATCH PARTIAL'i / 'MATCH SIMPLE'i)? __
904904
od:on_reference? __
905905
ou:on_reference? {
906906
return {
907907
definition: de,
908-
table: t,
908+
table: [t],
909909
keyword: kc.toLowerCase(),
910910
match: m && m.toLowerCase(),
911911
on_action: [od, ou].filter(v => v)

test/sqlite.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,13 @@ describe('sqlite', () => {
163163
sql = 'DROP VIEW IF EXISTS view_name;',
164164
expect(getParsedSql(sql)).to.be.equal('DROP VIEW IF EXISTS `view_name`')
165165
})
166+
167+
it('should create table', () => {
168+
const sql = `CREATE TABLE IF NOT EXISTS posts (
169+
user_id INTEGER NOT NULL,
170+
FOREIGN KEY (user_id) REFERENCES users(user_id)
171+
);
172+
`
173+
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE IF NOT EXISTS `posts` (`user_id` INTEGER NOT NULL, FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`))')
174+
})
166175
})

0 commit comments

Comments
 (0)