Skip to content

Commit

Permalink
Merge pull request #1954 from taozhi8833998/fix-reference-table-sqlite
Browse files Browse the repository at this point in the history
fix: reference table bug in sqlite
  • Loading branch information
taozhi8833998 authored Jun 13, 2024
2 parents 307bbda + 65d1bfd commit d86d055
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -898,14 +898,14 @@ create_constraint_foreign

reference_definition
= kc:KW_REFERENCES __
t:table_ref_list __
t:table_name __
de:cte_column_definition __
m:('MATCH FULL'i / 'MATCH PARTIAL'i / 'MATCH SIMPLE'i)? __
od:on_reference? __
ou:on_reference? {
return {
definition: de,
table: t,
table: [t],
keyword: kc.toLowerCase(),
match: m && m.toLowerCase(),
on_action: [od, ou].filter(v => v)
Expand Down
9 changes: 9 additions & 0 deletions test/sqlite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,13 @@ describe('sqlite', () => {
sql = 'DROP VIEW IF EXISTS view_name;',
expect(getParsedSql(sql)).to.be.equal('DROP VIEW IF EXISTS `view_name`')
})

it('should create table', () => {
const sql = `CREATE TABLE IF NOT EXISTS posts (
user_id INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
`
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`))')
})
})

0 comments on commit d86d055

Please sign in to comment.