knex/test/tape/query-builder.js

23 lines
734 B
JavaScript
Raw Normal View History

'use strict';
2015-04-29 15:13:15 -04:00
var tape = require('tape')
var QueryBuilder = require('../../lib/query/builder')
2015-04-29 15:13:15 -04:00
var Client = require('../../lib/client')
tape('accumulates multiple update calls #647', function(t) {
t.plan(1)
var qb = new QueryBuilder({})
qb.update('a', 1).update('b', 2)
t.deepEqual(qb._single.update, {a: 1, b: 2})
2015-04-28 09:14:13 -04:00
})
2015-04-29 15:13:15 -04:00
tape('allows for object syntax in join', function(t) {
t.plan(1)
var qb = new QueryBuilder(new Client())
var sql = qb.table('users').innerJoin('accounts', {
'accounts.id': 'users.account_id',
'accounts.owner_id': 'users.id'
}).toSQL('join')
t.equal(sql.sql,
'inner join "accounts" on "accounts"."id" = "users"."account_id" and "accounts"."owner_id" = "users"."id"')
})