2014-09-01 17:18:45 +02:00
|
|
|
'use strict';
|
|
|
|
|
2020-04-07 21:27:40 +02:00
|
|
|
const { TEST_TIMESTAMP } = require('../../util/constants');
|
2020-03-24 02:54:01 +05:45
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
module.exports = function (knex) {
|
|
|
|
describe('Deletes', function () {
|
|
|
|
it('should handle deletes', function () {
|
2013-09-11 23:36:55 -04:00
|
|
|
return knex('accounts')
|
2014-04-13 17:51:57 +10:00
|
|
|
.where('id', 1)
|
2014-04-16 02:50:19 -04:00
|
|
|
.del()
|
2020-04-19 00:40:23 +02:00
|
|
|
.testSql(function (tester) {
|
2018-07-09 08:10:34 -04:00
|
|
|
tester('mysql', 'delete from `accounts` where `id` = ?', [1], 1);
|
|
|
|
tester('pg', 'delete from "accounts" where "id" = ?', [1], 1);
|
2018-02-03 08:33:02 -05:00
|
|
|
tester(
|
|
|
|
'pg-redshift',
|
|
|
|
'delete from "accounts" where "id" = ?',
|
|
|
|
[1],
|
|
|
|
1
|
|
|
|
);
|
2018-07-09 08:10:34 -04:00
|
|
|
tester('sqlite3', 'delete from `accounts` where `id` = ?', [1], 1);
|
|
|
|
tester('oracledb', 'delete from "accounts" where "id" = ?', [1], 1);
|
2015-12-09 17:53:53 -06:00
|
|
|
tester(
|
|
|
|
'mssql',
|
|
|
|
'delete from [accounts] where [id] = ?;select @@rowcount',
|
|
|
|
[1],
|
|
|
|
1
|
|
|
|
);
|
2014-04-16 02:50:19 -04:00
|
|
|
});
|
2014-04-13 17:51:57 +10:00
|
|
|
});
|
2013-09-11 23:36:55 -04:00
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('should allow returning for deletes in postgresql and mssql', function () {
|
2014-04-13 17:51:57 +10:00
|
|
|
return knex('accounts')
|
|
|
|
.where('id', 2)
|
2014-04-16 02:50:19 -04:00
|
|
|
.del('*')
|
2020-04-19 00:40:23 +02:00
|
|
|
.testSql(function (tester) {
|
2018-07-09 08:10:34 -04:00
|
|
|
tester('mysql', 'delete from `accounts` where `id` = ?', [2], 1);
|
2014-04-16 02:59:27 -04:00
|
|
|
tester(
|
2018-06-29 10:47:06 +03:00
|
|
|
'pg',
|
2014-04-16 02:59:27 -04:00
|
|
|
'delete from "accounts" where "id" = ? returning *',
|
|
|
|
[2],
|
2018-07-09 08:10:34 -04:00
|
|
|
[
|
|
|
|
{
|
|
|
|
id: '2',
|
|
|
|
first_name: 'Test',
|
|
|
|
last_name: 'User',
|
|
|
|
email: 'test2@example.com',
|
|
|
|
logins: 1,
|
|
|
|
balance: 0,
|
|
|
|
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
2020-03-24 02:54:01 +05:45
|
|
|
created_at: TEST_TIMESTAMP,
|
|
|
|
updated_at: TEST_TIMESTAMP,
|
2018-07-09 08:10:34 -04:00
|
|
|
phone: null,
|
|
|
|
},
|
|
|
|
]
|
2014-04-16 02:59:27 -04:00
|
|
|
);
|
2018-02-03 08:33:02 -05:00
|
|
|
tester(
|
|
|
|
'pg-redshift',
|
|
|
|
'delete from "accounts" where "id" = ?',
|
|
|
|
[2],
|
|
|
|
1
|
|
|
|
);
|
2018-07-09 08:10:34 -04:00
|
|
|
tester('sqlite3', 'delete from `accounts` where `id` = ?', [2], 1);
|
|
|
|
tester('oracledb', 'delete from "accounts" where "id" = ?', [2], 1);
|
2015-12-09 17:53:53 -06:00
|
|
|
tester(
|
|
|
|
'mssql',
|
|
|
|
'delete from [accounts] output deleted.* where [id] = ?',
|
|
|
|
[2],
|
2018-07-09 08:10:34 -04:00
|
|
|
[
|
|
|
|
{
|
|
|
|
id: '2',
|
|
|
|
first_name: 'Test',
|
|
|
|
last_name: 'User',
|
|
|
|
email: 'test2@example.com',
|
|
|
|
logins: 1,
|
|
|
|
balance: 0,
|
|
|
|
about: 'Lorem ipsum Dolore labore incididunt enim.',
|
2020-03-24 02:54:01 +05:45
|
|
|
created_at: TEST_TIMESTAMP,
|
|
|
|
updated_at: TEST_TIMESTAMP,
|
2018-07-09 08:10:34 -04:00
|
|
|
phone: null,
|
|
|
|
},
|
|
|
|
]
|
2015-12-09 17:53:53 -06:00
|
|
|
);
|
2014-04-16 02:50:19 -04:00
|
|
|
});
|
2013-09-11 23:36:55 -04:00
|
|
|
});
|
|
|
|
});
|
2014-04-13 17:51:57 +10:00
|
|
|
};
|