什么是Knex
A SQL query builder that is flexible, portable, and fun to use!
Knex 是一个开源的轻量级的数据库连接工具. 可以用来数据查询/数据维护/数据迁移等工作.
官网地址: SQL Query Builder for Javascript | Knex.js
支持多种数据库:
- PostgreSQL,
- MySQL,
- CockroachDB,
- MSSQL,
- SQLite3,
- Oracle (including Oracle Wallet Authentication)
安装Kenx
npm install knex --save
针对不同数据库还需要安装对应的model:
# Then add one of the following (adding a --save) flag:
$ npm install pg
$ npm install pg-native
$ npm install sqlite3
$ npm install better-sqlite3
$ npm install mysql
$ npm install mysql2
$ npm install oracledb
$ npm install tedious
使用Kenx
Mysql: