mirror of https://github.com/aldy505/sql-dsl.git
test: multiple values instead of single one
This commit is contained in:
parent
eab24c96ac
commit
e59a7e473c
|
@ -9,24 +9,27 @@ test('should be able to parse select query', () => {
|
|||
});
|
||||
|
||||
test('should be able to parse insert query', () => {
|
||||
const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'pengangguran'})`;
|
||||
const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'jobless'})`;
|
||||
assert.equal(query.sql, 'insert into users (name, age, profession) values ($1, $2, $3)');
|
||||
assert.equal(query.values, ['Jonas', 21, 'pengangguran']);
|
||||
assert.equal(query.values, ['Jonas', 21, 'jobless']);
|
||||
});
|
||||
|
||||
test('should be able to parse to question marks', () => {
|
||||
const query = sql`select * from 'users' where email = ${'example@mail.com'}`.formatQuestion();
|
||||
assert.equal(query, {sql: 'select * from \'users\' where email = ?', values: ['example@mail.com']});
|
||||
const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'jobless'})`.formatQuestion();
|
||||
assert.equal(query.sql, 'insert into users (name, age, profession) values (?, ?, ?)');
|
||||
assert.equal(query.values, ['Jonas', 21, 'jobless']);
|
||||
});
|
||||
|
||||
test('should be able to parse to colons', () => {
|
||||
const query = sql`select * from 'users' where email = ${'example@mail.com'}`.formatColon();
|
||||
assert.equal(query, {sql: 'select * from \'users\' where email = :1', values: ['example@mail.com']});
|
||||
const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'jobless'})`.formatColon();
|
||||
assert.equal(query.sql, 'insert into users (name, age, profession) values (:1, :2, :3)');
|
||||
assert.equal(query.values, ['Jonas', 21, 'jobless']);
|
||||
});
|
||||
|
||||
test('should be able to parse to @p', () => {
|
||||
const query = sql`select * from 'users' where email = ${'example@mail.com'}`.formatAtP();
|
||||
assert.equal(query, {sql: 'select * from \'users\' where email = @p1', values: ['example@mail.com']});
|
||||
const query = sql`insert into users (name, age, profession) values (${'Jonas'}, ${21}, ${'jobless'})`.formatAtP();
|
||||
assert.equal(query.sql, 'insert into users (name, age, profession) values (@p1, @p2, @p3)');
|
||||
assert.equal(query.values, ['Jonas', 21, 'jobless']);
|
||||
});
|
||||
|
||||
test.run();
|
||||
|
|
Loading…
Reference in New Issue