Skip to content

Commit

Permalink
Merge pull request #1610 from taozhi8833998/refactor-real-sqlite
Browse files Browse the repository at this point in the history
refactor: support real in sqlite
  • Loading branch information
taozhi8833998 authored Oct 4, 2023
2 parents 4102a06 + a52d0e0 commit 2068f92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,7 @@ KW_BIGINT = "BIGINT"i !ident_start { return 'BIGINT'; }
KW_ENUM = "ENUM"i !ident_start { return 'ENUM'; }
KW_FLOAT = "FLOAT"i !ident_start { return 'FLOAT'; }
KW_DOUBLE = "DOUBLE"i !ident_start { return 'DOUBLE'; }
KW_REAL = "REAL"i !ident_start { return 'REAL'; }
KW_DATE = "DATE"i !ident_start { return 'DATE'; }
KW_DATETIME = "DATETIME"i !ident_start { return 'DATETIME'; }
KW_TIME = "TIME"i !ident_start { return 'TIME'; }
Expand Down Expand Up @@ -2769,9 +2770,9 @@ numeric_type_suffix
return result
}
numeric_type
= t:(KW_NUMERIC / KW_DECIMAL / KW_INT / KW_INTEGER / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_DOUBLE / KW_BIT) __ LPAREN __ l:[0-9]+ __ r:(COMMA __ [0-9]+)? __ RPAREN __ s:numeric_type_suffix? { return { dataType: t, length: parseInt(l.join(''), 10), scale: r && parseInt(r[2].join(''), 10), parentheses: true, suffix: s }; }
/ t:(KW_NUMERIC / KW_DECIMAL / KW_INT / KW_INTEGER / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_DOUBLE)l:[0-9]+ __ s:numeric_type_suffix? { return { dataType: t, length: parseInt(l.join(''), 10), suffix: s }; }
/ t:(KW_NUMERIC / KW_DECIMAL / KW_INT / KW_INTEGER / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_DOUBLE) __ s:numeric_type_suffix? __{ return { dataType: t, suffix: s }; }
= t:(KW_NUMERIC / KW_DECIMAL / KW_INT / KW_INTEGER / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_DOUBLE / KW_BIT / KW_REAL) __ LPAREN __ l:[0-9]+ __ r:(COMMA __ [0-9]+)? __ RPAREN __ s:numeric_type_suffix? { return { dataType: t, length: parseInt(l.join(''), 10), scale: r && parseInt(r[2].join(''), 10), parentheses: true, suffix: s }; }
/ t:(KW_NUMERIC / KW_DECIMAL / KW_INT / KW_INTEGER / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_DOUBLE / KW_REAL)l:[0-9]+ __ s:numeric_type_suffix? { return { dataType: t, length: parseInt(l.join(''), 10), suffix: s }; }
/ t:(KW_NUMERIC / KW_DECIMAL / KW_INT / KW_INTEGER / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_DOUBLE / KW_REAL) __ s:numeric_type_suffix? __{ return { dataType: t, suffix: s }; }


datetime_type
Expand Down
4 changes: 2 additions & 2 deletions test/sqlite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ describe('sqlite', () => {
})

it('should support keyword as column name in create table sql', () => {
const sql = 'CREATE TABLE IF NOT EXISTS "Test" (Id INTEGER NOT NULL PRIMARY KEY UNIQUE, like TEXT NOT NULL, Difficulty TEXT, PRIMARY KEY(Id));'
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE IF NOT EXISTS `Test` (`Id` INTEGER NOT NULL PRIMARY KEY UNIQUE, `like` TEXT NOT NULL, `Difficulty` TEXT, PRIMARY KEY (`Id`))')
const sql = 'CREATE TABLE IF NOT EXISTS "Test" (Id INTEGER NOT NULL PRIMARY KEY UNIQUE, like TEXT NOT NULL, Difficulty TEXT, percent real, PRIMARY KEY(Id));'
expect(getParsedSql(sql)).to.be.equal('CREATE TABLE IF NOT EXISTS `Test` (`Id` INTEGER NOT NULL PRIMARY KEY UNIQUE, `like` TEXT NOT NULL, `Difficulty` TEXT, `percent` REAL, PRIMARY KEY (`Id`))')
})

it('should support sqlify autoincrement to other db', () => {
Expand Down

0 comments on commit 2068f92

Please sign in to comment.