summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKojin Nakana <kohanajs@outlook.com>2022-04-28 12:43:31 +0800
committerKojin Nakana <kohanajs@outlook.com>2022-04-28 12:43:31 +0800
commita1654984eae1b0bac5cf1e4af5712d8ac9a95661 (patch)
tree3e6baf1cd0b8bfba6d96b48795a37d43252c6be0
parentd489fec242ab9a0329dce5641b7863fddce0ca1d (diff)
fix: auto increment SQLite
-rw-r--r--index.js4
-rw-r--r--tests/parseDDL.test.js8
2 files changed, 6 insertions, 6 deletions
diff --git a/index.js b/index.js
index 85e2bdb..87493db 100644
--- a/index.js
+++ b/index.js
@@ -185,11 +185,11 @@ END;`;
const isNonNull = (field.type.kind === 'NonNullType');
lines.push(
- `${name} ${SCALAR[fieldType]}${(opts.length > 0) ? ' ' : ''}${opts.join(' ')}${isNonNull ? ' NOT NULL' : ''}${isAutoIncrement ? ' AUTO_INCREMENT' : ''}`,
+ `${name} ${SCALAR[fieldType]}${(opts.length > 0) ? ' ' : ''}${opts.join(' ')}${isNonNull ? ' NOT NULL' : ''}`,
);
if (isPrimary) {
- lines.push(`PRIMARY KEY (${name})`);
+ lines.push(`PRIMARY KEY (${name}${isAutoIncrement ? ' AUTOINCREMENT' : ''})`);
}
});
diff --git a/tests/parseDDL.test.js b/tests/parseDDL.test.js
index 4b44f4c..73763ae 100644
--- a/tests/parseDDL.test.js
+++ b/tests/parseDDL.test.js
@@ -376,8 +376,8 @@ type Persons {
const sql = parse(schema, false);
const target = `
CREATE TABLE persons(
- id INTEGER NOT NULL AUTO_INCREMENT ,
- PRIMARY KEY (id) ,
+ id INTEGER NOT NULL ,
+ PRIMARY KEY (id AUTOINCREMENT) ,
name TEXT
);
`;
@@ -395,8 +395,8 @@ type Person {
const sql = parse(schema, false);
const target = `
CREATE TABLE persons(
- id INTEGER NOT NULL AUTO_INCREMENT ,
- PRIMARY KEY (id) ,
+ id INTEGER NOT NULL ,
+ PRIMARY KEY (id AUTOINCREMENT) ,
name TEXT
);
`;