⌨️
Web Design
  • Index
  • Front End
    • Front End Index
  • HTML/CSS/JS
    • HTML Index
      • Page layout
      • Form
      • Image Optimization
    • CSS Index
      • CSS Selectors
        • Selectors
        • Combinators
        • Attribute Selectors
        • Pseudo classes
      • CSS Cascade and Inheritance
        • Cascade
        • Inheritance
      • Specificity
      • Box Model
      • CSS Clearfix
      • Responsive Meta Tag
      • Flexbox Layout
      • Grid Layout
      • CSS Naming Rules
        • Golden Guidelines for Writing Clean CSS
        • BEM
        • Rules
      • Frameworks & Libraries
    • JS Index
      • JS loading
      • Modules
      • Js Array Common Method 1
      • Js Array Common Method 2
      • Custom attributes on the element
      • Operator
      • Parse a JSON Date in JavaScript
      • Importmap
  • Git
    • Git Index
    • Initialize a Repository
    • Top 20 Git Commands With Examples
  • UML
    • UML Class
  • React
    • Index
      • setState async issue
      • Redux
      • Axios
      • useState update in A Timeout
  • WebGL
    • WebGL Index
  • Back End
    • Back-End Index
      • Knex
      • Bookshelf
        • bookshelf install
        • Bookshelf only returns one row
      • Server side init flow
      • Install Wordpress on Ubuntu 22.04 with a LAMP Stack
  • React Native
    • React Native Index
      • Dynamically changing Image URLs in React Native
  • Expo
    • EAS build config
Powered by GitBook
On this page
  • install
  • Usage

Was this helpful?

  1. Back End
  2. Back-End Index

Knex

install

A batteries-included, multi-dialect (PostgreSQL, MySQL, CockroachDB, MSSQL, SQLite3, Oracle (including Oracle Wallet Authentication)) query builder for Node.js.

npm install knex --save

npm install -g knex

if npm install -g knex fails, use sudo npm install -g knex instead.

Usage

Knex init // create a config file named knexfile.js
Knex migrate:make users // creat a migration file with timestamp
Knex migrate:latest // run the latest migration file
knexfile.js
/**
@type { Object.<string, import("knex").Knex.Config> } 
*/ 

module.exports = {
    development: { 
        client: 'mysql', 
        connection: { 
            database: 'myDataBase', 
            user: 'root', 
            password: '' 
        }, 
        pool: { 
            min: 2, 
            max: 10 
        }, 
        migrations: { tableName: 'knex_migrations' } },
    staging: { 
        client: 'mysql', 
        connection: { 
            database: 'myDataBase', 
            user: 'root', 
            password: '' 
        }, 
        pool: { 
            min: 2, 
            max: 10 
        }, 
        migrations: { tableName: 'knex_migrations' } },
    production: { 
        client: 'mysql', 
        connection: { 
            database: 'myDataBase', 
            user: 'root', 
            password: '' 
        }, 
        pool: { 
            min: 2, 
            max: 10 
        }, 
        migrations: { tableName: 'knex_migrations' } },
};
PreviousBack-End IndexNextBookshelf

Last updated 2 years ago

Was this helpful?

More:

http://knexjs.org/guide