knex 单表查询_knex.js

软件简介

knex.js 是一个查询构建器,用于 PostgreSQL, MySQL 和 SQLite3。它设计灵活,轻便和有趣。

特性:

例子:

var knex = require('knex')({

dialect: '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.insert({user_name: 'Tim'}).into('users');

})

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

.then(function(rows) {

return knex.table('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);

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值