knex node js code example

Example 1: knex migration

// best tutorial knex migration
https://www.youtube.com/watch?v=ipAH7lMfq7k
https://www.youtube.com/watch?v=U7GjS3FuSkA

Example 2: is knex built into node js

$ npm install knex --save

# Then add one of the following (adding a --save) flag:
$ npm install pg
$ npm install sqlite3
$ npm install mysql
$ npm install mysql2
$ npm install oracledb
$ npm install mssql

Example 3: knex datatypes

table.increments('id')
  table.string('account_name')
  table.integer('age')
  table.float('age')
  table.decimal('balance', 8, 2)
  table.boolean('is_admin')
  table.date('birthday')
  table.time('created_at')
  table.timestamp('created_at').defaultTo(knex.fn.now())
  table.json('profile')
  table.jsonb('profile')
  table.uuid('id').primary()

Tags:

Sql Example