knex 找不到mysql_knex-JavaScript中文网-JavaScript教程资源分享门户

A batteries-included SQL query & schema builder for Postgres, MySQL and SQLite3 and the Browser

knex.js

knex.svg

knex.svg

knex.svg?branch=master

badge.svg?branch=master

knex.svg

knex.svg

knex.svg?logo=lgtm&logoWidth=18

A SQL query builder that is flexible, portable, and fun to use!

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

Node.js, featuring:

Node.js versions 8+ are supported.

For support and questions, join the #bookshelf channel on freenode IRC

For an Object Relational Mapper, see:

To see the SQL that Knex will generate for a given query, see: Knex Query Lab

Examples

We have several examples on the website. Here is the first one to get you started:

const knex = require('knex')({

client: 'sqlite3',

connection: {

filename: './data.db',

},

});

// Create a table

knex.schema

.createTable('users', function(table) {

table.increments('id');

table.string('user_name');

})

// ...and another

.createTable('accounts', function(table) {

table.increments('id');

table.string('account_name');

table

.integer('user_id')

.unsigned()

.references('users.id');

})

// Then query the table...

.then(function() {

return knex('users').insert({ user_name: 'Tim' });

})

// ...and using the insert id, insert into the other table.

.then(function(rows) {

return knex('accounts').insert({ account_name: 'knex', user_id: rows[0] });

})

// Query both of the rows.

.then(function() {

return knex('users')

.join('accounts', 'users.id', 'accounts.user_id')

.select('users.user_name as user', 'accounts.account_name as account');

})

// .map over the results

.map(function(row) {

console.log(row);

})

// Finally, add a .catch handler for the promise chain

.catch(function(e) {

console.error(e);

});

HomePage

Repository

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值