Skip to content

Commit

Permalink
feat: generation gin and gist indexes for pg SQL DDL
Browse files Browse the repository at this point in the history
Closes: #5

PR-URL: #19
  • Loading branch information
tshemsedinov committed Sep 11, 2020
1 parent 13365e0 commit ad96ef2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/ddl.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ const createIndex = (entityName, { name, unique, index }) => {
const prefix = unique ? 'ak' : 'idx';
let fields = unique || index;
const type = typeof fields;
if (type === 'boolean') fields = [name];
else if (type === 'string') fields = [fields];
if (type === 'boolean') fields = `("${name}")`;
else if (type !== 'string') fields = `("${fields.join('", "')}")`;
else if (fields.includes('(')) fields = `USING ${fields}`;
else fields = `("${fields}")`;
const idxName = `"${prefix}${entityName}${toUpperCamel(name)}"`;
const idxOn = `"${entityName}" ("${fields.join('", "')}")`;
return `CREATE ${uni}INDEX ${idxName} ON ${idxOn};`;
return `CREATE ${uni}INDEX ${idxName} ON "${entityName}" ${fields};`;
};

const foreignKey = (entityName, { name, type }) => {
Expand Down

0 comments on commit ad96ef2

Please sign in to comment.