mirror of
https://github.com/knex/knex.git
synced 2025-07-19 23:11:09 +00:00
35 lines
973 B
JavaScript
35 lines
973 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
var Raw = require('../../lib/raw');
|
||
|
var Client = require('../../lib/client')
|
||
|
var test = require('tape')
|
||
|
|
||
|
var client = new Client()
|
||
|
function raw(sql, bindings) {
|
||
|
return new Raw(client).set(sql, bindings)
|
||
|
}
|
||
|
|
||
|
test('allows for ?? to interpolate identifiers', function(t) {
|
||
|
t.plan(1)
|
||
|
t.equal(
|
||
|
raw('select * from ?? where id = ?', ['table', 1]).toString(),
|
||
|
'select * from "table" where id = 1'
|
||
|
)
|
||
|
})
|
||
|
|
||
|
test('allows for object bindings', function(t) {
|
||
|
t.plan(1)
|
||
|
t.equal(
|
||
|
raw('select * from users where user_id = :userId and name = :name', {userId: 1, name: 'tim'}).toString(),
|
||
|
"select * from users where user_id = 1 and name = 'tim'"
|
||
|
)
|
||
|
})
|
||
|
|
||
|
test('allows for :val: for interpolated identifiers', function(t) {
|
||
|
t.plan(1)
|
||
|
t.equal(
|
||
|
raw('select * from :table: where user_id = :userId and name = :name', {table: 'users', userId: 1, name: 'tim'}).toString(),
|
||
|
"select * from \"users\" where user_id = 1 and name = 'tim'"
|
||
|
)
|
||
|
})
|