Skip to content

Instantly share code, notes, and snippets.

@shernshiou
Created May 15, 2018 06:19
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shernshiou/d56832fad59a46fba04e08d3145d1479 to your computer and use it in GitHub Desktop.
Save shernshiou/d56832fad59a46fba04e08d3145d1479 to your computer and use it in GitHub Desktop.
Knex createtable sqlite uuid
let uuidGenerationRaw = connection.client.config.client === 'sqlite3' ?
`(lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6))))` :
`uuid_generate_v4()`;
connection.schema.createTableIfNotExists('notification', (table) => {
table.uuid('id').primary().defaultTo(connection.raw(uuidGenerationRaw));
// ... rest of the columns
}),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment