不要怂,就是干,撸起袖子干!

Commit 1898679f by Daniel Durante

Moved all Postgres Jasmine tests to Buster, also fixed up a timezone issue within sql-string.

1 parent 21956102
...@@ -111,7 +111,7 @@ SqlString.dateToString = function(date, timeZone, dialect) { ...@@ -111,7 +111,7 @@ SqlString.dateToString = function(date, timeZone, dialect) {
// TODO: Ideally all dialects would work a bit more like this // TODO: Ideally all dialects would work a bit more like this
if (dialect === "postgres") { if (dialect === "postgres") {
return moment(dt).format("YYYY-MM-DD HH:mm:ss.SSS Z"); return moment(dt).zone('+00:00').format("YYYY-MM-DD HH:mm:ss.SSS Z");
} }
if (timeZone !== 'local') { if (timeZone !== 'local') {
......
var config = require("../config/config")
, Sequelize = require("../../index")
, sequelize = new Sequelize(config.postgres.database, config.postgres.username, config.postgres.password, {
logging: false,
port: config.postgres.port,
dialect: 'postgres'
})
, Helpers = new (require("../config/helpers"))(sequelize)
describe('HasMany', function() {
beforeEach(function() { Helpers.sync() })
afterEach(function() { Helpers.drop() })
//prevent periods from occurring in the table name since they are used to delimit (table.column)
var User = sequelize.define('User' + Math.ceil(Math.random()*10000000), { name: Sequelize.STRING })
, Task = sequelize.define('Task' + Math.ceil(Math.random()*10000000), { name: Sequelize.STRING })
, users = null
, tasks = null
User.hasMany(Task, {as:'Tasks'})
Task.hasMany(User, {as:'Users'})
beforeEach(function() {
Helpers.async(function(_done) {
Helpers.Factories.DAO(User.name, {name: 'User' + Math.random()}, function(_users) {
users = _users; _done()
}, 5)
})
Helpers.async(function(_done) {
Helpers.Factories.DAO(Task.name, {name: 'Task' + Math.random()}, function(_tasks) {
tasks = _tasks; _done()
}, 2)
})
})
describe('addDAO / getDAO', function() {
var user = null
, task = null
beforeEach(function() {
Helpers.async(function(done) {
User.all().on('success', function(_users) {
Task.all().on('success', function(_tasks) {
user = _users[0]
task = _tasks[0]
done()
})
})
})
})
it('should correctly add an association to the dao', function() {
Helpers.async(function(done) {
user.getTasks().on('success', function(_tasks) {
expect(_tasks.length).toEqual(0)
user.addTask(task).on('success', function() {
user.getTasks().on('success', function(_tasks) {
expect(_tasks.length).toEqual(1)
done()
})
})
})
})
})
})
describe('removeDAO', function() {
var user = null
, tasks = null
beforeEach(function() {
Helpers.async(function(done) {
User.all().on('success', function(users) {
Task.all().on('success', function(_tasks) {
user = users[0]
tasks = _tasks
done()
})
})
})
})
it("should correctly remove associated objects", function() {
Helpers.async(function(done) {
user.getTasks().on('success', function(__tasks) {
expect(__tasks.length).toEqual(0)
user.setTasks(tasks).on('success', function() {
user.getTasks().on('success', function(_tasks) {
expect(_tasks.length).toEqual(tasks.length)
user.removeTask(tasks[0]).on('success', function() {
user.getTasks().on('success', function(_tasks) {
expect(_tasks.length).toEqual(tasks.length - 1)
done()
})
})
})
})
})
})
})
})
})
var config = require("../config/config")
, Sequelize = require("../../index")
, sequelize = new Sequelize(config.postgres.database, config.postgres.username, config.postgres.password, {
logging: false,
port: config.postgres.port,
dialect: 'postgres'
})
, Helpers = new (require("../config/helpers"))(sequelize)
describe('Associations', function() {
beforeEach(function() { Helpers.sync() })
afterEach(function() { Helpers.drop() })
/////////// many-to-many with same prefix ////////////
describe('many-to-many', function() {
describe('where tables have the same prefix', function() {
var Table2 = sequelize.define('wp_table2', {foo: Sequelize.STRING})
, Table1 = sequelize.define('wp_table1', {foo: Sequelize.STRING})
Table1.hasMany(Table2)
Table2.hasMany(Table1)
it("should create a table wp_table1wp_table2s", function() {
Helpers.async(function(done) {
expect(sequelize.daoFactoryManager.getDAO('wp_table1swp_table2s')).toBeDefined()
done()
})
})
})
describe('when join table name is specified', function() {
var Table2 = sequelize.define('ms_table1', {foo: Sequelize.STRING})
, Table1 = sequelize.define('ms_table2', {foo: Sequelize.STRING})
Table1.hasMany(Table2, {joinTableName: 'table1_to_table2'})
Table2.hasMany(Table1, {joinTableName: 'table1_to_table2'})
it("should not use a combined name", function() {
expect(sequelize.daoFactoryManager.getDAO('ms_table1sms_table2s')).toBeUndefined()
})
it("should use the specified name", function() {
expect(sequelize.daoFactoryManager.getDAO('table1_to_table2')).toBeDefined()
})
})
})
})
if(typeof require === 'function') {
const buster = require("buster")
, Helpers = require('../buster-helpers')
, dialect = Helpers.getTestDialect()
}
buster.spec.expose()
buster.testRunner.timeout = 1000
if (dialect.match(/^postgres/)) {
describe('[POSTGRES] associations', function() {
before(function(done) {
var self = this
Helpers.initTests({
dialect: dialect,
beforeComplete: function(sequelize, DataTypes) {
self.sequelize = sequelize
},
onComplete: function() {
self.sequelize.sync({ force: true }).success(done)
}
})
})
describe('many-to-many', function() {
describe('where tables have the same prefix', function() {
it("should create a table wp_table1wp_table2s", function(done) {
var Table2 = this.sequelize.define('wp_table2', {foo: Helpers.Sequelize.STRING})
, Table1 = this.sequelize.define('wp_table1', {foo: Helpers.Sequelize.STRING})
Table1.hasMany(Table2)
Table2.hasMany(Table1)
expect(this.sequelize.daoFactoryManager.getDAO('wp_table1swp_table2s')).toBeDefined()
done()
})
})
describe('when join table name is specified', function() {
before(function(done){
var Table2 = this.sequelize.define('ms_table1', {foo: Helpers.Sequelize.STRING})
, Table1 = this.sequelize.define('ms_table2', {foo: Helpers.Sequelize.STRING})
Table1.hasMany(Table2, {joinTableName: 'table1_to_table2'})
Table2.hasMany(Table1, {joinTableName: 'table1_to_table2'})
done()
})
it("should not use a combined name", function(done) {
expect(this.sequelize.daoFactoryManager.getDAO('ms_table1sms_table2s')).not.toBeDefined()
done()
})
it("should use the specified name", function(done) {
expect(this.sequelize.daoFactoryManager.getDAO('table1_to_table2')).toBeDefined()
done()
})
})
})
describe('HasMany', function() {
before(function(done) {
//prevent periods from occurring in the table name since they are used to delimit (table.column)
this.User = this.sequelize.define('User' + Math.ceil(Math.random()*10000000), { name: Helpers.Sequelize.STRING })
this.Task = this.sequelize.define('Task' + Math.ceil(Math.random()*10000000), { name: Helpers.Sequelize.STRING })
this.users = null
this.tasks = null
this.User.hasMany(this.Task, {as:'Tasks'})
this.Task.hasMany(this.User, {as:'Users'})
var self = this
, users = []
, tasks = []
for (var i = 0; i < 5; ++i) {
users[users.length] = {name: 'User' + Math.random()}
}
for (var x = 0; x < 5; ++x) {
tasks[tasks.length] = {name: 'Task' + Math.random()}
}
this.sequelize.sync({ force: true }).success(function() {
self.User.bulkCreate(users).success(function() {
self.Task.bulkCreate(tasks).success(done)
})
})
})
describe('addDAO / getDAO', function() {
before(function(done) {
var self = this
self.user = null
self.task = null
self.User.all().success(function(_users) {
self.Task.all().success(function(_tasks) {
self.user = _users[0]
self.task = _tasks[0]
done()
})
})
})
it('should correctly add an association to the dao', function(done) {
var self = this
self.user.getTasks().on('success', function(_tasks) {
expect(_tasks.length).toEqual(0)
self.user.addTask(self.task).on('success', function() {
self.user.getTasks().on('success', function(_tasks) {
expect(_tasks.length).toEqual(1)
done()
})
})
})
})
})
describe('removeDAO', function() {
before(function(done) {
var self = this
self.user = null
self.tasks = null
self.User.all().success(function(_users) {
self.Task.all().success(function(_tasks) {
self.user = _users[0]
self.tasks = _tasks
done()
})
})
})
it("should correctly remove associated objects", function(done) {
var self = this
self.user.getTasks().on('success', function(__tasks) {
expect(__tasks.length).toEqual(0)
self.user.setTasks(self.tasks).on('success', function() {
self.user.getTasks().on('success', function(_tasks) {
expect(_tasks.length).toEqual(self.tasks.length)
self.user.removeTask(self.tasks[0]).on('success', function() {
self.user.getTasks().on('success', function(_tasks) {
expect(_tasks.length).toEqual(self.tasks.length - 1)
done()
})
})
})
})
})
})
})
})
})
}
var config = require("../config/config") if(typeof require === 'function') {
, Sequelize = require("../../index") const buster = require("buster")
, sequelize = new Sequelize(config.postgres.database, config.postgres.username, config.postgres.password, { , Helpers = require('../buster-helpers')
logging: false, , dialect = Helpers.getTestDialect()
dialect: 'postgres', , QueryGenerator = require("../../lib/dialects/postgres/query-generator")
port: config.postgres.port , util = require("util")
}) , moment = require('moment')
, Helpers = new (require("../config/helpers"))(sequelize) }
, QueryGenerator = require("../../lib/dialects/postgres/query-generator")
, util = require("util") buster.spec.expose()
buster.testRunner.timeout = 1000
describe('QueryGenerator', function() { if (dialect.match(/^postgres/)) {
beforeEach(function() { Helpers.sync() }) describe('[POSTGRES] QueryGenerator', function() {
afterEach(function() { Helpers.drop() }) before(function(done) {
var self = this
var suites = { Helpers.initTests({
dialect: dialect,
beforeComplete: function(sequelize, DataTypes) {
self.sequelize = sequelize
attributesToSQL: [ self.User = sequelize.define('User', {
{ username: DataTypes.STRING,
arguments: [{id: 'INTEGER'}], email: {type: DataTypes.ARRAY(DataTypes.TEXT)},
expectation: {id: 'INTEGER'} document: {type: DataTypes.HSTORE, defaultValue: '"default"=>"value"'}
}, })
{ },
arguments: [{id: 'INTEGER', foo: 'VARCHAR(255)'}], onComplete: function() {
expectation: {id: 'INTEGER', foo: 'VARCHAR(255)'} self.User.sync({ force: true }).success(done)
}, }
{ })
arguments: [{id: {type: 'INTEGER'}}], })
expectation: {id: 'INTEGER'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false}}],
expectation: {id: 'INTEGER NOT NULL'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: true}}],
expectation: {id: 'INTEGER'}
},
{
arguments: [{id: {type: 'INTEGER', primaryKey: true, autoIncrement: true}}],
expectation: {id: 'INTEGER SERIAL PRIMARY KEY'}
},
{
arguments: [{id: {type: 'INTEGER', defaultValue: 0}}],
expectation: {id: 'INTEGER DEFAULT 0'}
},
{
arguments: [{id: {type: 'INTEGER', unique: true}}],
expectation: {id: 'INTEGER UNIQUE'}
},
{
arguments: [{id: {type: 'INTEGER', comment: "I'm a comment!" }}],
expectation: {id: "INTEGER COMMENT ON COLUMN <%= table %>.\"id\" IS 'I''m a comment!'" }
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id")'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("pk")'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON DELETE CASCADE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON UPDATE RESTRICT'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES "Bar" ("id") ON DELETE CASCADE ON UPDATE RESTRICT'}
},
// Variants when quoteIdentifiers is false var suites = {
{ attributesToSQL: [
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}], {
expectation: {id: 'INTEGER REFERENCES Bar (id)'}, arguments: [{id: 'INTEGER'}],
context: {options: {quoteIdentifiers: false}} expectation: {id: 'INTEGER'}
}, },
{ {
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}], arguments: [{id: 'INTEGER', foo: 'VARCHAR(255)'}],
expectation: {id: 'INTEGER REFERENCES Bar (pk)'}, expectation: {id: 'INTEGER', foo: 'VARCHAR(255)'}
context: {options: {quoteIdentifiers: false}} },
}, {
{ arguments: [{id: {type: 'INTEGER'}}],
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}], expectation: {id: 'INTEGER'}
expectation: {id: 'INTEGER REFERENCES Bar (id) ON DELETE CASCADE'}, },
context: {options: {quoteIdentifiers: false}} {
}, arguments: [{id: {type: 'INTEGER', allowNull: false}}],
{ expectation: {id: 'INTEGER NOT NULL'}
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}], },
expectation: {id: 'INTEGER REFERENCES Bar (id) ON UPDATE RESTRICT'}, {
context: {options: {quoteIdentifiers: false}} arguments: [{id: {type: 'INTEGER', allowNull: true}}],
}, expectation: {id: 'INTEGER'}
{ },
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}], {
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES Bar (id) ON DELETE CASCADE ON UPDATE RESTRICT'}, arguments: [{id: {type: 'INTEGER', primaryKey: true, autoIncrement: true}}],
context: {options: {quoteIdentifiers: false}} expectation: {id: 'INTEGER SERIAL PRIMARY KEY'}
}, },
{
arguments: [{id: {type: 'INTEGER', defaultValue: 0}}],
expectation: {id: 'INTEGER DEFAULT 0'}
},
{
arguments: [{id: {type: 'INTEGER', unique: true}}],
expectation: {id: 'INTEGER UNIQUE'}
},
{
arguments: [{id: {type: 'INTEGER', comment: "I'm a comment!" }}],
expectation: {id: "INTEGER COMMENT ON COLUMN <%= table %>.\"id\" IS 'I''m a comment!'" }
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id")'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("pk")'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON DELETE CASCADE'}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON UPDATE RESTRICT'}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES "Bar" ("id") ON DELETE CASCADE ON UPDATE RESTRICT'}
},
], // Variants when quoteIdentifiers is false
{
arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],
expectation: {id: 'INTEGER REFERENCES Bar (id)'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],
expectation: {id: 'INTEGER REFERENCES Bar (pk)'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],
expectation: {id: 'INTEGER REFERENCES Bar (id) ON DELETE CASCADE'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER REFERENCES Bar (id) ON UPDATE RESTRICT'},
context: {options: {quoteIdentifiers: false}}
},
{
arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],
expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES Bar (id) ON DELETE CASCADE ON UPDATE RESTRICT'},
context: {options: {quoteIdentifiers: false}}
},
createTableQuery: [ ],
{
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],
expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));",
},
{
arguments: ['myTable', {title: "INTEGER COMMENT ON COLUMN <%= table %>.\"title\" IS 'I''m a comment!'"}],
expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" INTEGER ); COMMENT ON COLUMN \"myTable\".\"title\" IS 'I''m a comment!';",
},
{
arguments: ['myTable', {title: "INTEGER"}, {comment: "I'm a comment!"}],
expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" INTEGER); COMMENT ON TABLE \"myTable\" IS 'I''m a comment!';",
},
{
arguments: ['mySchema.myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],
expectation: "CREATE TABLE IF NOT EXISTS \"mySchema\".\"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));"
},
{
arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}],
expectation: "DROP TYPE IF EXISTS \"enum_myTable_title\"; CREATE TYPE \"enum_myTable_title\" AS ENUM(\"A\", \"B\", \"C\"); CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" \"enum_myTable_title\", \"name\" VARCHAR(255));"
},
{
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY'}],
expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255), \"id\" INTEGER , PRIMARY KEY (\"id\"));"
},
{
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES "otherTable" ("id") ON DELETE CASCADE ON UPDATE NO ACTION'}],
expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255), \"otherId\" INTEGER REFERENCES \"otherTable\" (\"id\") ON DELETE CASCADE ON UPDATE NO ACTION);"
},
// Variants when quoteIdentifiers is false createTableQuery: [
{ {
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}], arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],
expectation: "CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255));", expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));",
context: {options: {quoteIdentifiers: false}} },
}, {
{ arguments: ['myTable', {title: "INTEGER COMMENT ON COLUMN <%= table %>.\"title\" IS 'I''m a comment!'"}],
arguments: ['mySchema.myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}], expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" INTEGER ); COMMENT ON COLUMN \"myTable\".\"title\" IS 'I''m a comment!';",
expectation: "CREATE TABLE IF NOT EXISTS mySchema.myTable (title VARCHAR(255), name VARCHAR(255));", },
context: {options: {quoteIdentifiers: false}} {
}, arguments: ['myTable', {title: "INTEGER"}, {comment: "I'm a comment!"}],
{ expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" INTEGER); COMMENT ON TABLE \"myTable\" IS 'I''m a comment!';",
arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}], },
expectation: "DROP TYPE IF EXISTS enum_myTable_title; CREATE TYPE enum_myTable_title AS ENUM(\"A\", \"B\", \"C\"); CREATE TABLE IF NOT EXISTS myTable (title enum_myTable_title, name VARCHAR(255));", {
context: {options: {quoteIdentifiers: false}} arguments: ['mySchema.myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],
}, expectation: "CREATE TABLE IF NOT EXISTS \"mySchema\".\"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));"
{ },
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY'}], {
expectation: "CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255), id INTEGER , PRIMARY KEY (id));", arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}],
context: {options: {quoteIdentifiers: false}} expectation: "DROP TYPE IF EXISTS \"enum_myTable_title\"; CREATE TYPE \"enum_myTable_title\" AS ENUM(\"A\", \"B\", \"C\"); CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" \"enum_myTable_title\", \"name\" VARCHAR(255));"
}, },
{ {
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES otherTable (id) ON DELETE CASCADE ON UPDATE NO ACTION'}], arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY'}],
expectation: "CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255), otherId INTEGER REFERENCES otherTable (id) ON DELETE CASCADE ON UPDATE NO ACTION);", expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255), \"id\" INTEGER , PRIMARY KEY (\"id\"));"
context: {options: {quoteIdentifiers: false}} },
} {
], arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES "otherTable" ("id") ON DELETE CASCADE ON UPDATE NO ACTION'}],
expectation: "CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255), \"otherId\" INTEGER REFERENCES \"otherTable\" (\"id\") ON DELETE CASCADE ON UPDATE NO ACTION);"
},
dropTableQuery: [ // Variants when quoteIdentifiers is false
{ {
arguments: ['myTable'], arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],
expectation: "DROP TABLE IF EXISTS \"myTable\";" expectation: "CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255));",
}, context: {options: {quoteIdentifiers: false}}
{ },
arguments: ['mySchema.myTable'], {
expectation: "DROP TABLE IF EXISTS \"mySchema\".\"myTable\";" arguments: ['mySchema.myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],
}, expectation: "CREATE TABLE IF NOT EXISTS mySchema.myTable (title VARCHAR(255), name VARCHAR(255));",
{ context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {cascade: true}], },
expectation: "DROP TABLE IF EXISTS \"myTable\" CASCADE;" {
}, arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}],
{ expectation: "DROP TYPE IF EXISTS enum_myTable_title; CREATE TYPE enum_myTable_title AS ENUM(\"A\", \"B\", \"C\"); CREATE TABLE IF NOT EXISTS myTable (title enum_myTable_title, name VARCHAR(255));",
arguments: ['mySchema.myTable', {cascade: true}], context: {options: {quoteIdentifiers: false}}
expectation: "DROP TABLE IF EXISTS \"mySchema\".\"myTable\" CASCADE;" },
}, {
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY'}],
expectation: "CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255), id INTEGER , PRIMARY KEY (id));",
context: {options: {quoteIdentifiers: false}}
},
{
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES otherTable (id) ON DELETE CASCADE ON UPDATE NO ACTION'}],
expectation: "CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255), otherId INTEGER REFERENCES otherTable (id) ON DELETE CASCADE ON UPDATE NO ACTION);",
context: {options: {quoteIdentifiers: false}}
}
],
// Variants when quoteIdentifiers is false dropTableQuery: [
{ {
arguments: ['myTable'], arguments: ['myTable'],
expectation: "DROP TABLE IF EXISTS myTable;", expectation: "DROP TABLE IF EXISTS \"myTable\";"
context: {options: {quoteIdentifiers: false}} },
}, {
{ arguments: ['mySchema.myTable'],
arguments: ['mySchema.myTable'], expectation: "DROP TABLE IF EXISTS \"mySchema\".\"myTable\";"
expectation: "DROP TABLE IF EXISTS mySchema.myTable;", },
context: {options: {quoteIdentifiers: false}} {
}, arguments: ['myTable', {cascade: true}],
{ expectation: "DROP TABLE IF EXISTS \"myTable\" CASCADE;"
arguments: ['myTable', {cascade: true}], },
expectation: "DROP TABLE IF EXISTS myTable CASCADE;", {
context: {options: {quoteIdentifiers: false}} arguments: ['mySchema.myTable', {cascade: true}],
}, expectation: "DROP TABLE IF EXISTS \"mySchema\".\"myTable\" CASCADE;"
{ },
arguments: ['mySchema.myTable', {cascade: true}],
expectation: "DROP TABLE IF EXISTS mySchema.myTable CASCADE;",
context: {options: {quoteIdentifiers: false}}
}
],
selectQuery: [ // Variants when quoteIdentifiers is false
{ {
arguments: ['myTable'], arguments: ['myTable'],
expectation: "SELECT * FROM \"myTable\";" expectation: "DROP TABLE IF EXISTS myTable;",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {attributes: ['id', 'name']}], },
expectation: "SELECT \"id\", \"name\" FROM \"myTable\";" {
}, { arguments: ['mySchema.myTable'],
arguments: ['myTable', {where: {id: 2}}], expectation: "DROP TABLE IF EXISTS mySchema.myTable;",
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"id\"=2;" context: {options: {quoteIdentifiers: false}}
}, { },
arguments: ['myTable', {where: {name: 'foo'}}], {
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"name\"='foo';" arguments: ['myTable', {cascade: true}],
}, { expectation: "DROP TABLE IF EXISTS myTable CASCADE;",
arguments: ['myTable', {where: {name: "foo';DROP TABLE myTable;"}}], context: {options: {quoteIdentifiers: false}}
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"name\"='foo'';DROP TABLE myTable;';" },
}, { {
arguments: ['myTable', {where: 2}], arguments: ['mySchema.myTable', {cascade: true}],
expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"id\"=2;" expectation: "DROP TABLE IF EXISTS mySchema.myTable CASCADE;",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['foo', { attributes: [['count(*)', 'count']] }], }
expectation: 'SELECT count(*) as \"count\" FROM \"foo\";' ],
}, {
arguments: ['myTable', {where: "foo='bar'"}],
expectation: "SELECT * FROM \"myTable\" WHERE foo='bar';"
}, {
arguments: ['myTable', {order: "id DESC"}],
expectation: "SELECT * FROM \"myTable\" ORDER BY \"id\" DESC;"
}, {
arguments: ['myTable', {group: "name"}],
expectation: "SELECT * FROM \"myTable\" GROUP BY \"name\";"
}, {
arguments: ['myTable', {group: ["name"]}],
expectation: "SELECT * FROM \"myTable\" GROUP BY \"name\";"
}, {
arguments: ['myTable', {group: ["name","title"]}],
expectation: "SELECT * FROM \"myTable\" GROUP BY \"name\", \"title\";"
}, {
arguments: ['myTable', {limit: 10}],
expectation: "SELECT * FROM \"myTable\" LIMIT 10;"
}, {
arguments: ['myTable', {limit: 10, offset: 2}],
expectation: "SELECT * FROM \"myTable\" LIMIT 10 OFFSET 2;"
}, {
title: 'uses offset even if no limit was passed',
arguments: ['myTable', {offset: 2}],
expectation: "SELECT * FROM \"myTable\" OFFSET 2;"
}, {
arguments: ['mySchema.myTable'],
expectation: "SELECT * FROM \"mySchema\".\"myTable\";"
}, {
arguments: ['mySchema.myTable', {where: {name: "foo';DROP TABLE mySchema.myTable;"}}],
expectation: "SELECT * FROM \"mySchema\".\"myTable\" WHERE \"mySchema\".\"myTable\".\"name\"='foo'';DROP TABLE mySchema.myTable;';"
},
// Variants when quoteIdentifiers is false selectQuery: [
{ {
arguments: ['myTable'], arguments: ['myTable'],
expectation: "SELECT * FROM myTable;", expectation: "SELECT * FROM \"myTable\";"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {attributes: ['id', 'name']}],
arguments: ['myTable', {attributes: ['id', 'name']}], expectation: "SELECT \"id\", \"name\" FROM \"myTable\";"
expectation: "SELECT id, name FROM myTable;", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['myTable', {where: {id: 2}}],
}, { expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"id\"=2;"
arguments: ['myTable', {where: {id: 2}}], }, {
expectation: "SELECT * FROM myTable WHERE myTable.id=2;", arguments: ['myTable', {where: {name: 'foo'}}],
context: {options: {quoteIdentifiers: false}} expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"name\"='foo';"
}, { }, {
arguments: ['myTable', {where: {name: 'foo'}}], arguments: ['myTable', {where: {name: "foo';DROP TABLE myTable;"}}],
expectation: "SELECT * FROM myTable WHERE myTable.name='foo';", expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"name\"='foo'';DROP TABLE myTable;';"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {where: 2}],
arguments: ['myTable', {where: {name: "foo';DROP TABLE myTable;"}}], expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"id\"=2;"
expectation: "SELECT * FROM myTable WHERE myTable.name='foo'';DROP TABLE myTable;';", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['foo', { attributes: [['count(*)', 'count']] }],
}, { expectation: 'SELECT count(*) as \"count\" FROM \"foo\";'
arguments: ['myTable', {where: 2}], }, {
expectation: "SELECT * FROM myTable WHERE myTable.id=2;", arguments: ['myTable', {where: "foo='bar'"}],
context: {options: {quoteIdentifiers: false}} expectation: "SELECT * FROM \"myTable\" WHERE foo='bar';"
}, { }, {
arguments: ['foo', { attributes: [['count(*)', 'count']] }], arguments: ['myTable', {order: "id DESC"}],
expectation: 'SELECT count(*) as count FROM foo;', expectation: "SELECT * FROM \"myTable\" ORDER BY \"id\" DESC;"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {group: "name"}],
arguments: ['myTable', {where: "foo='bar'"}], expectation: "SELECT * FROM \"myTable\" GROUP BY \"name\";"
expectation: "SELECT * FROM myTable WHERE foo='bar';", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['myTable', {group: ["name"]}],
}, { expectation: "SELECT * FROM \"myTable\" GROUP BY \"name\";"
arguments: ['myTable', {order: "id DESC"}], }, {
expectation: "SELECT * FROM myTable ORDER BY id DESC;", arguments: ['myTable', {group: ["name","title"]}],
context: {options: {quoteIdentifiers: false}} expectation: "SELECT * FROM \"myTable\" GROUP BY \"name\", \"title\";"
}, { }, {
arguments: ['myTable', {group: "name"}], arguments: ['myTable', {limit: 10}],
expectation: "SELECT * FROM myTable GROUP BY name;", expectation: "SELECT * FROM \"myTable\" LIMIT 10;"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {limit: 10, offset: 2}],
arguments: ['myTable', {group: ["name"]}], expectation: "SELECT * FROM \"myTable\" LIMIT 10 OFFSET 2;"
expectation: "SELECT * FROM myTable GROUP BY name;", }, {
context: {options: {quoteIdentifiers: false}} title: 'uses offset even if no limit was passed',
}, { arguments: ['myTable', {offset: 2}],
arguments: ['myTable', {group: ["name","title"]}], expectation: "SELECT * FROM \"myTable\" OFFSET 2;"
expectation: "SELECT * FROM myTable GROUP BY name, title;", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['mySchema.myTable'],
}, { expectation: "SELECT * FROM \"mySchema\".\"myTable\";"
arguments: ['myTable', {limit: 10}], }, {
expectation: "SELECT * FROM myTable LIMIT 10;", arguments: ['mySchema.myTable', {where: {name: "foo';DROP TABLE mySchema.myTable;"}}],
context: {options: {quoteIdentifiers: false}} expectation: "SELECT * FROM \"mySchema\".\"myTable\" WHERE \"mySchema\".\"myTable\".\"name\"='foo'';DROP TABLE mySchema.myTable;';"
}, { },
arguments: ['myTable', {limit: 10, offset: 2}],
expectation: "SELECT * FROM myTable LIMIT 10 OFFSET 2;",
context: {options: {quoteIdentifiers: false}}
}, {
title: 'uses offset even if no limit was passed',
arguments: ['myTable', {offset: 2}],
expectation: "SELECT * FROM myTable OFFSET 2;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable'],
expectation: "SELECT * FROM mySchema.myTable;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', {where: {name: "foo';DROP TABLE mySchema.myTable;"}}],
expectation: "SELECT * FROM mySchema.myTable WHERE mySchema.myTable.name='foo'';DROP TABLE mySchema.myTable;';",
context: {options: {quoteIdentifiers: false}}
}
],
insertQuery: [ // Variants when quoteIdentifiers is false
{ {
arguments: ['myTable', {name: 'foo'}], arguments: ['myTable'],
expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo') RETURNING *;" expectation: "SELECT * FROM myTable;",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}], }, {
expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'';DROP TABLE myTable;') RETURNING *;" arguments: ['myTable', {attributes: ['id', 'name']}],
}, { expectation: "SELECT id, name FROM myTable;",
arguments: ['myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}], context: {options: {quoteIdentifiers: false}}
expectation: "INSERT INTO \"myTable\" (\"name\",\"birthday\") VALUES ('foo','2011-03-27 10:01:55.000 +00:00') RETURNING *;" }, {
}, { arguments: ['myTable', {where: {id: 2}}],
arguments: ['myTable', {name: 'foo', foo: 1}], expectation: "SELECT * FROM myTable WHERE myTable.id=2;",
expectation: "INSERT INTO \"myTable\" (\"name\",\"foo\") VALUES ('foo',1) RETURNING *;" context: {options: {quoteIdentifiers: false}}
}, { }, {
arguments: ['myTable', {name: 'foo', nullValue: null}], arguments: ['myTable', {where: {name: 'foo'}}],
expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL) RETURNING *;" expectation: "SELECT * FROM myTable WHERE myTable.name='foo';",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {name: 'foo', nullValue: null}], }, {
expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL) RETURNING *;", arguments: ['myTable', {where: {name: "foo';DROP TABLE myTable;"}}],
context: {options: {omitNull: false}} expectation: "SELECT * FROM myTable WHERE myTable.name='foo'';DROP TABLE myTable;';",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {name: 'foo', nullValue: null}], }, {
expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo') RETURNING *;", arguments: ['myTable', {where: 2}],
context: {options: {omitNull: true}} expectation: "SELECT * FROM myTable WHERE myTable.id=2;",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {name: 'foo', nullValue: undefined}], }, {
expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo') RETURNING *;", arguments: ['foo', { attributes: [['count(*)', 'count']] }],
context: {options: {omitNull: true}} expectation: 'SELECT count(*) as count FROM foo;',
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['mySchema.myTable', {name: 'foo'}], }, {
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo') RETURNING *;" arguments: ['myTable', {where: "foo='bar'"}],
}, { expectation: "SELECT * FROM myTable WHERE foo='bar';",
arguments: ['mySchema.myTable', {name: JSON.stringify({info: 'Look ma a " quote'})}], context: {options: {quoteIdentifiers: false}}
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('{\"info\":\"Look ma a \\\" quote\"}') RETURNING *;" }, {
}, { arguments: ['myTable', {order: "id DESC"}],
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}], expectation: "SELECT * FROM myTable ORDER BY id DESC;",
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'';DROP TABLE mySchema.myTable;') RETURNING *;" context: {options: {quoteIdentifiers: false}}
}, }, {
arguments: ['myTable', {group: "name"}],
expectation: "SELECT * FROM myTable GROUP BY name;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {group: ["name"]}],
expectation: "SELECT * FROM myTable GROUP BY name;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {group: ["name","title"]}],
expectation: "SELECT * FROM myTable GROUP BY name, title;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {limit: 10}],
expectation: "SELECT * FROM myTable LIMIT 10;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {limit: 10, offset: 2}],
expectation: "SELECT * FROM myTable LIMIT 10 OFFSET 2;",
context: {options: {quoteIdentifiers: false}}
}, {
title: 'uses offset even if no limit was passed',
arguments: ['myTable', {offset: 2}],
expectation: "SELECT * FROM myTable OFFSET 2;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable'],
expectation: "SELECT * FROM mySchema.myTable;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', {where: {name: "foo';DROP TABLE mySchema.myTable;"}}],
expectation: "SELECT * FROM mySchema.myTable WHERE mySchema.myTable.name='foo'';DROP TABLE mySchema.myTable;';",
context: {options: {quoteIdentifiers: false}}
}
],
// Variants when quoteIdentifiers is false insertQuery: [
{ {
arguments: ['myTable', {name: 'foo'}], arguments: ['myTable', {name: 'foo'}],
expectation: "INSERT INTO myTable (name) VALUES ('foo') RETURNING *;", expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo') RETURNING *;"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}],
arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}], expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'';DROP TABLE myTable;') RETURNING *;"
expectation: "INSERT INTO myTable (name) VALUES ('foo'';DROP TABLE myTable;') RETURNING *;", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}],
}, { expectation: "INSERT INTO \"myTable\" (\"name\",\"birthday\") VALUES ('foo','2011-03-27 10:01:55.000 +00:00') RETURNING *;"
arguments: ['myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}], }, {
expectation: "INSERT INTO myTable (name,birthday) VALUES ('foo','2011-03-27 10:01:55.000 +00:00') RETURNING *;", arguments: ['myTable', {name: 'foo', foo: 1}],
context: {options: {quoteIdentifiers: false}} expectation: "INSERT INTO \"myTable\" (\"name\",\"foo\") VALUES ('foo',1) RETURNING *;"
}, { }, {
arguments: ['myTable', {name: 'foo', foo: 1}], arguments: ['myTable', {name: 'foo', nullValue: null}],
expectation: "INSERT INTO myTable (name,foo) VALUES ('foo',1) RETURNING *;", expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL) RETURNING *;"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {name: 'foo', nullValue: null}],
arguments: ['myTable', {name: 'foo', nullValue: null}], expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL) RETURNING *;",
expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL) RETURNING *;", context: {options: {omitNull: false}}
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {name: 'foo', nullValue: null}],
arguments: ['myTable', {name: 'foo', nullValue: null}], expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo') RETURNING *;",
expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL) RETURNING *;", context: {options: {omitNull: true}}
context: {options: {omitNull: false, quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {name: 'foo', nullValue: undefined}],
arguments: ['myTable', {name: 'foo', nullValue: null}], expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo') RETURNING *;",
expectation: "INSERT INTO myTable (name) VALUES ('foo') RETURNING *;", context: {options: {omitNull: true}}
context: {options: {omitNull: true, quoteIdentifiers: false}} }, {
}, { arguments: ['mySchema.myTable', {name: 'foo'}],
arguments: ['myTable', {name: 'foo', nullValue: undefined}], expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo') RETURNING *;"
expectation: "INSERT INTO myTable (name) VALUES ('foo') RETURNING *;", }, {
context: {options: {omitNull: true, quoteIdentifiers: false}} arguments: ['mySchema.myTable', {name: JSON.stringify({info: 'Look ma a " quote'})}],
}, { expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('{\"info\":\"Look ma a \\\" quote\"}') RETURNING *;"
arguments: ['mySchema.myTable', {name: 'foo'}], }, {
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo') RETURNING *;", arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}],
context: {options: {quoteIdentifiers: false}} expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'';DROP TABLE mySchema.myTable;') RETURNING *;"
}, { },
arguments: ['mySchema.myTable', {name: JSON.stringify({info: 'Look ma a " quote'})}],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('{\"info\":\"Look ma a \\\" quote\"}') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'';DROP TABLE mySchema.myTable;') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}
], // Variants when quoteIdentifiers is false
{
arguments: ['myTable', {name: 'foo'}],
expectation: "INSERT INTO myTable (name) VALUES ('foo') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}],
expectation: "INSERT INTO myTable (name) VALUES ('foo'';DROP TABLE myTable;') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}],
expectation: "INSERT INTO myTable (name,birthday) VALUES ('foo','2011-03-27 10:01:55.000 +00:00') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {name: 'foo', foo: 1}],
expectation: "INSERT INTO myTable (name,foo) VALUES ('foo',1) RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {name: 'foo', nullValue: null}],
expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL) RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {name: 'foo', nullValue: null}],
expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL) RETURNING *;",
context: {options: {omitNull: false, quoteIdentifiers: false}}
}, {
arguments: ['myTable', {name: 'foo', nullValue: null}],
expectation: "INSERT INTO myTable (name) VALUES ('foo') RETURNING *;",
context: {options: {omitNull: true, quoteIdentifiers: false}}
}, {
arguments: ['myTable', {name: 'foo', nullValue: undefined}],
expectation: "INSERT INTO myTable (name) VALUES ('foo') RETURNING *;",
context: {options: {omitNull: true, quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', {name: 'foo'}],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', {name: JSON.stringify({info: 'Look ma a " quote'})}],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('{\"info\":\"Look ma a \\\" quote\"}') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'';DROP TABLE mySchema.myTable;') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}
bulkInsertQuery: [ ],
{
arguments: ['myTable', [{name: 'foo'}, {name: 'bar'}]],
expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'),('bar') RETURNING *;"
}, {
arguments: ['myTable', [{name: "foo';DROP TABLE myTable;"}, {name: 'bar'}]],
expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'';DROP TABLE myTable;'),('bar') RETURNING *;"
}, {
arguments: ['myTable', [{name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, {name: 'bar', birthday: new Date(Date.UTC(2012, 2, 27, 10, 1, 55))}]],
expectation: "INSERT INTO \"myTable\" (\"name\",\"birthday\") VALUES ('foo','2011-03-27 10:01:55.000 +00:00'),('bar','2012-03-27 10:01:55.000 +00:00') RETURNING *;"
}, {
arguments: ['myTable', [{name: 'foo', foo: 1}, {name: 'bar', foo: 2}]],
expectation: "INSERT INTO \"myTable\" (\"name\",\"foo\") VALUES ('foo',1),('bar',2) RETURNING *;"
}, {
arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],
expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;"
}, {
arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],
expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
context: {options: {omitNull: false}}
}, {
arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],
expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
context: {options: {omitNull: true}} // Note: We don't honour this because it makes little sense when some rows may have nulls and others not
}, {
arguments: ['myTable', [{name: 'foo', nullValue: undefined}, {name: 'bar', nullValue: undefined}]],
expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
context: {options: {omitNull: true}} // Note: As above
}, {
arguments: ['mySchema.myTable', [{name: 'foo'}, {name: 'bar'}]],
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'),('bar') RETURNING *;"
}, {
arguments: ['mySchema.myTable', [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]],
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}') RETURNING *;"
}, {
arguments: ['mySchema.myTable', [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]],
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar') RETURNING *;"
},
// Variants when quoteIdentifiers is false bulkInsertQuery: [
{ {
arguments: ['myTable', [{name: 'foo'}, {name: 'bar'}]], arguments: ['myTable', [{name: 'foo'}, {name: 'bar'}]],
expectation: "INSERT INTO myTable (name) VALUES ('foo'),('bar') RETURNING *;", expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'),('bar') RETURNING *;"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', [{name: "foo';DROP TABLE myTable;"}, {name: 'bar'}]],
arguments: ['myTable', [{name: "foo';DROP TABLE myTable;"}, {name: 'bar'}]], expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'';DROP TABLE myTable;'),('bar') RETURNING *;"
expectation: "INSERT INTO myTable (name) VALUES ('foo'';DROP TABLE myTable;'),('bar') RETURNING *;", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['myTable', [{name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {name: 'bar', birthday: moment("2012-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}]],
}, { expectation: "INSERT INTO \"myTable\" (\"name\",\"birthday\") VALUES ('foo','2011-03-27 10:01:55.000 +00:00'),('bar','2012-03-27 10:01:55.000 +00:00') RETURNING *;"
arguments: ['myTable', [{name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, {name: 'bar', birthday: new Date(Date.UTC(2012, 2, 27, 10, 1, 55))}]], }, {
expectation: "INSERT INTO myTable (name,birthday) VALUES ('foo','2011-03-27 10:01:55.000 +00:00'),('bar','2012-03-27 10:01:55.000 +00:00') RETURNING *;", arguments: ['myTable', [{name: 'foo', foo: 1}, {name: 'bar', foo: 2}]],
context: {options: {quoteIdentifiers: false}} expectation: "INSERT INTO \"myTable\" (\"name\",\"foo\") VALUES ('foo',1),('bar',2) RETURNING *;"
}, { }, {
arguments: ['myTable', [{name: 'foo', foo: 1}, {name: 'bar', foo: 2}]], arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],
expectation: "INSERT INTO myTable (name,foo) VALUES ('foo',1),('bar',2) RETURNING *;", expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],
arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]], expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;", context: {options: {omitNull: false}}
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],
arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]], expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;", context: {options: {omitNull: true}} // Note: We don't honour this because it makes little sense when some rows may have nulls and others not
context: {options: {quoteIdentifiers: false, omitNull: false}}, }, {
}, { arguments: ['myTable', [{name: 'foo', nullValue: undefined}, {name: 'bar', nullValue: undefined}]],
arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]], expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;", context: {options: {omitNull: true}} // Note: As above
context: {options: {omitNull: true, quoteIdentifiers: false}} // Note: We don't honour this because it makes little sense when some rows may have nulls and others not }, {
}, { arguments: ['mySchema.myTable', [{name: 'foo'}, {name: 'bar'}]],
arguments: ['myTable', [{name: 'foo', nullValue: undefined}, {name: 'bar', nullValue: undefined}]], expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'),('bar') RETURNING *;"
expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;", }, {
context: {options: {omitNull: true, quoteIdentifiers: false}} // Note: As above arguments: ['mySchema.myTable', [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]],
}, { expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}') RETURNING *;"
arguments: ['mySchema.myTable', [{name: 'foo'}, {name: 'bar'}]], }, {
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'),('bar') RETURNING *;", arguments: ['mySchema.myTable', [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]],
context: {options: {quoteIdentifiers: false}} expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar') RETURNING *;"
}, { },
arguments: ['mySchema.myTable', [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}
],
updateQuery: [ // Variants when quoteIdentifiers is false
{ {
arguments: ['myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, {id: 2}], arguments: ['myTable', [{name: 'foo'}, {name: 'bar'}]],
expectation: "UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\"=2 RETURNING *" expectation: "INSERT INTO myTable (name) VALUES ('foo'),('bar') RETURNING *;",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, 2], }, {
expectation: "UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\"=2 RETURNING *" arguments: ['myTable', [{name: "foo';DROP TABLE myTable;"}, {name: 'bar'}]],
}, { expectation: "INSERT INTO myTable (name) VALUES ('foo'';DROP TABLE myTable;'),('bar') RETURNING *;",
arguments: ['myTable', {bar: 2}, {name: 'foo'}], context: {options: {quoteIdentifiers: false}}
expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo' RETURNING *" }, {
}, { arguments: ['myTable', [{name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {name: 'bar', birthday: moment("2012-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}]],
arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {name: 'foo'}], expectation: "INSERT INTO myTable (name,birthday) VALUES ('foo','2011-03-27 10:01:55.000 +00:00'),('bar','2012-03-27 10:01:55.000 +00:00') RETURNING *;",
expectation: "UPDATE \"myTable\" SET \"name\"='foo'';DROP TABLE myTable;' WHERE \"name\"='foo' RETURNING *" context: {options: {quoteIdentifiers: false}}
}, { }, {
arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}], arguments: ['myTable', [{name: 'foo', foo: 1}, {name: 'bar', foo: 2}]],
expectation: "UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\"='foo' RETURNING *" expectation: "INSERT INTO myTable (name,foo) VALUES ('foo',1),('bar',2) RETURNING *;",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}], }, {
expectation: "UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\"='foo' RETURNING *", arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],
context: {options: {omitNull: false}} expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}], }, {
expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo' RETURNING *", arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],
context: {options: {omitNull: true}} expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
}, { context: {options: {quoteIdentifiers: false, omitNull: false}},
arguments: ['myTable', {bar: 2, nullValue: undefined}, {name: 'foo'}], }, {
expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo' RETURNING *", arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],
context: {options: {omitNull: true}} expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
}, { context: {options: {omitNull: true, quoteIdentifiers: false}} // Note: We don't honour this because it makes little sense when some rows may have nulls and others not
arguments: ['mySchema.myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, {id: 2}], }, {
expectation: "UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\"=2 RETURNING *" arguments: ['myTable', [{name: 'foo', nullValue: undefined}, {name: 'bar', nullValue: undefined}]],
}, { expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'foo'}], context: {options: {omitNull: true, quoteIdentifiers: false}} // Note: As above
expectation: "UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo'';DROP TABLE mySchema.myTable;' WHERE \"name\"='foo' RETURNING *" }, {
}, arguments: ['mySchema.myTable', [{name: 'foo'}, {name: 'bar'}]],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'),('bar') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar') RETURNING *;",
context: {options: {quoteIdentifiers: false}}
}
],
// Variants when quoteIdentifiers is false updateQuery: [
{ {
arguments: ['myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, {id: 2}], arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {id: 2}],
expectation: "UPDATE myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id=2 RETURNING *", expectation: "UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\"=2 RETURNING *"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, 2],
arguments: ['myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, 2], expectation: "UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\"=2 RETURNING *"
expectation: "UPDATE myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id=2 RETURNING *", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['myTable', {bar: 2}, {name: 'foo'}],
}, { expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo' RETURNING *"
arguments: ['myTable', {bar: 2}, {name: 'foo'}], }, {
expectation: "UPDATE myTable SET bar=2 WHERE name='foo' RETURNING *", arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {name: 'foo'}],
context: {options: {quoteIdentifiers: false}} expectation: "UPDATE \"myTable\" SET \"name\"='foo'';DROP TABLE myTable;' WHERE \"name\"='foo' RETURNING *"
}, { }, {
arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {name: 'foo'}], arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],
expectation: "UPDATE myTable SET name='foo'';DROP TABLE myTable;' WHERE name='foo' RETURNING *", expectation: "UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\"='foo' RETURNING *"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],
arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}], expectation: "UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\"='foo' RETURNING *",
expectation: "UPDATE myTable SET bar=2,nullValue=NULL WHERE name='foo' RETURNING *", context: {options: {omitNull: false}}
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],
arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}], expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo' RETURNING *",
expectation: "UPDATE myTable SET bar=2,nullValue=NULL WHERE name='foo' RETURNING *", context: {options: {omitNull: true}}
context: {options: {omitNull: false, quoteIdentifiers: false}}, }, {
}, { arguments: ['myTable', {bar: 2, nullValue: undefined}, {name: 'foo'}],
arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}], expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo' RETURNING *",
expectation: "UPDATE myTable SET bar=2 WHERE name='foo' RETURNING *", context: {options: {omitNull: true}}
context: {options: {omitNull: true, quoteIdentifiers: false}}, }, {
}, { arguments: ['mySchema.myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {id: 2}],
arguments: ['myTable', {bar: 2, nullValue: undefined}, {name: 'foo'}], expectation: "UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\"=2 RETURNING *"
expectation: "UPDATE myTable SET bar=2 WHERE name='foo' RETURNING *", }, {
context: {options: {omitNull: true, quoteIdentifiers: false}}, arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'foo'}],
}, { expectation: "UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo'';DROP TABLE mySchema.myTable;' WHERE \"name\"='foo' RETURNING *"
arguments: ['mySchema.myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, {id: 2}], },
expectation: "UPDATE mySchema.myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id=2 RETURNING *",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'foo'}],
expectation: "UPDATE mySchema.myTable SET name='foo'';DROP TABLE mySchema.myTable;' WHERE name='foo' RETURNING *",
context: {options: {quoteIdentifiers: false}}
}
],
deleteQuery: [ // Variants when quoteIdentifiers is false
{ {
arguments: ['myTable', {name: 'foo'}], arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {id: 2}],
expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"name\"='foo' LIMIT 1)" expectation: "UPDATE myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id=2 RETURNING *",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', 1], }, {
expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"id\"=1 LIMIT 1)" arguments: ['myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, 2],
}, { expectation: "UPDATE myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id=2 RETURNING *",
arguments: ['myTable', undefined, {truncate: true}], context: {options: {quoteIdentifiers: false}}
expectation: "TRUNCATE \"myTable\"" }, {
}, { arguments: ['myTable', {bar: 2}, {name: 'foo'}],
arguments: ['myTable', 1, {limit: 10, truncate: true}], expectation: "UPDATE myTable SET bar=2 WHERE name='foo' RETURNING *",
expectation: "TRUNCATE \"myTable\"" context: {options: {quoteIdentifiers: false}}
}, { }, {
arguments: ['myTable', 1, {limit: 10}], arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {name: 'foo'}],
expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"id\"=1 LIMIT 10)" expectation: "UPDATE myTable SET name='foo'';DROP TABLE myTable;' WHERE name='foo' RETURNING *",
}, { context: {options: {quoteIdentifiers: false}}
arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {limit: 10}], }, {
expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"name\"='foo'';DROP TABLE myTable;' LIMIT 10)" arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],
}, { expectation: "UPDATE myTable SET bar=2,nullValue=NULL WHERE name='foo' RETURNING *",
arguments: ['mySchema.myTable', {name: 'foo'}], context: {options: {quoteIdentifiers: false}}
expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo' LIMIT 1)" }, {
}, { arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {limit: 10}], expectation: "UPDATE myTable SET bar=2,nullValue=NULL WHERE name='foo' RETURNING *",
expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo'';DROP TABLE mySchema.myTable;' LIMIT 10)" context: {options: {omitNull: false, quoteIdentifiers: false}},
}, { }, {
arguments: ['myTable', {name: 'foo'}, {limit: null}], arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],
expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"name\"='foo')" expectation: "UPDATE myTable SET bar=2 WHERE name='foo' RETURNING *",
}, context: {options: {omitNull: true, quoteIdentifiers: false}},
}, {
arguments: ['myTable', {bar: 2, nullValue: undefined}, {name: 'foo'}],
expectation: "UPDATE myTable SET bar=2 WHERE name='foo' RETURNING *",
context: {options: {omitNull: true, quoteIdentifiers: false}},
}, {
arguments: ['mySchema.myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {id: 2}],
expectation: "UPDATE mySchema.myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id=2 RETURNING *",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'foo'}],
expectation: "UPDATE mySchema.myTable SET name='foo'';DROP TABLE mySchema.myTable;' WHERE name='foo' RETURNING *",
context: {options: {quoteIdentifiers: false}}
}
],
// Variants when quoteIdentifiers is false deleteQuery: [
{ {
arguments: ['myTable', {name: 'foo'}], arguments: ['myTable', {name: 'foo'}],
expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE name='foo' LIMIT 1)", expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"name\"='foo' LIMIT 1)"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', 1],
arguments: ['myTable', 1], expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"id\"=1 LIMIT 1)"
expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE id=1 LIMIT 1)", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['myTable', undefined, {truncate: true}],
}, { expectation: "TRUNCATE \"myTable\""
arguments: ['myTable', 1, {limit: 10}], }, {
expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE id=1 LIMIT 10)", arguments: ['myTable', 1, {limit: 10, truncate: true}],
context: {options: {quoteIdentifiers: false}} expectation: "TRUNCATE \"myTable\""
}, { }, {
arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {limit: 10}], arguments: ['myTable', 1, {limit: 10}],
expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE name='foo'';DROP TABLE myTable;' LIMIT 10)", expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"id\"=1 LIMIT 10)"
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {limit: 10}],
arguments: ['mySchema.myTable', {name: 'foo'}], expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"name\"='foo'';DROP TABLE myTable;' LIMIT 10)"
expectation: "DELETE FROM mySchema.myTable WHERE id IN (SELECT id FROM mySchema.myTable WHERE name='foo' LIMIT 1)", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['mySchema.myTable', {name: 'foo'}],
}, { expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo' LIMIT 1)"
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {limit: 10}], }, {
expectation: "DELETE FROM mySchema.myTable WHERE id IN (SELECT id FROM mySchema.myTable WHERE name='foo'';DROP TABLE mySchema.myTable;' LIMIT 10)", arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {limit: 10}],
context: {options: {quoteIdentifiers: false}} expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo'';DROP TABLE mySchema.myTable;' LIMIT 10)"
}, { }, {
arguments: ['myTable', {name: 'foo'}, {limit: null}], arguments: ['myTable', {name: 'foo'}, {limit: null}],
expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE name='foo')", expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"name\"='foo')"
context: {options: {quoteIdentifiers: false}} },
}
],
addIndexQuery: [ // Variants when quoteIdentifiers is false
{ {
arguments: ['User', ['username', 'isAdmin']], arguments: ['myTable', {name: 'foo'}],
expectation: 'CREATE INDEX \"user_username_is_admin\" ON \"User\" (\"username\", \"isAdmin\")' expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE name='foo' LIMIT 1)",
}, { context: {options: {quoteIdentifiers: false}}
arguments: [ }, {
'User', [ arguments: ['myTable', 1],
{ attribute: 'username', length: 10, order: 'ASC'}, expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE id=1 LIMIT 1)",
'isAdmin' context: {options: {quoteIdentifiers: false}}
] }, {
], arguments: ['myTable', 1, {limit: 10}],
expectation: "CREATE INDEX \"user_username_is_admin\" ON \"User\" (\"username\"(10) ASC, \"isAdmin\")" expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE id=1 LIMIT 10)",
}, { context: {options: {quoteIdentifiers: false}}
arguments: [ }, {
'User', ['username', 'isAdmin'], { indicesType: 'FULLTEXT', indexName: 'bar'} arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {limit: 10}],
], expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE name='foo'';DROP TABLE myTable;' LIMIT 10)",
expectation: "CREATE FULLTEXT INDEX \"bar\" ON \"User\" (\"username\", \"isAdmin\")" context: {options: {quoteIdentifiers: false}}
}, { }, {
arguments: ['mySchema.User', ['username', 'isAdmin']], arguments: ['mySchema.myTable', {name: 'foo'}],
expectation: 'CREATE INDEX \"user_username_is_admin\" ON \"mySchema\".\"User\" (\"username\", \"isAdmin\")' expectation: "DELETE FROM mySchema.myTable WHERE id IN (SELECT id FROM mySchema.myTable WHERE name='foo' LIMIT 1)",
}, context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {limit: 10}],
expectation: "DELETE FROM mySchema.myTable WHERE id IN (SELECT id FROM mySchema.myTable WHERE name='foo'';DROP TABLE mySchema.myTable;' LIMIT 10)",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {name: 'foo'}, {limit: null}],
expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE name='foo')",
context: {options: {quoteIdentifiers: false}}
}
],
// Variants when quoteIdentifiers is false addIndexQuery: [
{ {
arguments: ['User', ['username', 'isAdmin']], arguments: ['User', ['username', 'isAdmin']],
expectation: 'CREATE INDEX user_username_is_admin ON User (username, isAdmin)', expectation: 'CREATE INDEX \"user_username_is_admin\" ON \"User\" (\"username\", \"isAdmin\")'
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: [
arguments: [ 'User', [
'User', [ { attribute: 'username', length: 10, order: 'ASC'},
{ attribute: 'username', length: 10, order: 'ASC'}, 'isAdmin'
'isAdmin' ]
] ],
], expectation: "CREATE INDEX \"user_username_is_admin\" ON \"User\" (\"username\"(10) ASC, \"isAdmin\")"
expectation: "CREATE INDEX user_username_is_admin ON User (username(10) ASC, isAdmin)", }, {
context: {options: {quoteIdentifiers: false}} arguments: [
}, { 'User', ['username', 'isAdmin'], { indicesType: 'FULLTEXT', indexName: 'bar'}
arguments: [ ],
'User', ['username', 'isAdmin'], { indicesType: 'FULLTEXT', indexName: 'bar'} expectation: "CREATE FULLTEXT INDEX \"bar\" ON \"User\" (\"username\", \"isAdmin\")"
], }, {
expectation: "CREATE FULLTEXT INDEX bar ON User (username, isAdmin)", arguments: ['mySchema.User', ['username', 'isAdmin']],
context: {options: {quoteIdentifiers: false}} expectation: 'CREATE INDEX \"user_username_is_admin\" ON \"mySchema\".\"User\" (\"username\", \"isAdmin\")'
}, { },
arguments: ['mySchema.User', ['username', 'isAdmin']],
expectation: 'CREATE INDEX user_username_is_admin ON mySchema.User (username, isAdmin)',
context: {options: {quoteIdentifiers: false}}
}
],
// FIXME: not implemented // Variants when quoteIdentifiers is false
//showIndexQuery: [ {
// { arguments: ['User', ['username', 'isAdmin']],
// arguments: ['User'], expectation: 'CREATE INDEX user_username_is_admin ON User (username, isAdmin)',
// expectation: 'SHOW INDEX FROM \"User\"' context: {options: {quoteIdentifiers: false}}
// }, { }, {
// arguments: ['User', { database: 'sequelize' }], arguments: [
// expectation: "SHOW INDEX FROM \"User\" FROM \"sequelize\"" 'User', [
// } { attribute: 'username', length: 10, order: 'ASC'},
//], 'isAdmin'
]
],
expectation: "CREATE INDEX user_username_is_admin ON User (username(10) ASC, isAdmin)",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: [
'User', ['username', 'isAdmin'], { indicesType: 'FULLTEXT', indexName: 'bar'}
],
expectation: "CREATE FULLTEXT INDEX bar ON User (username, isAdmin)",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['mySchema.User', ['username', 'isAdmin']],
expectation: 'CREATE INDEX user_username_is_admin ON mySchema.User (username, isAdmin)',
context: {options: {quoteIdentifiers: false}}
}
],
removeIndexQuery: [ // FIXME: not implemented
{ //showIndexQuery: [
arguments: ['User', 'user_foo_bar'], // {
expectation: "DROP INDEX IF EXISTS \"user_foo_bar\"" // arguments: ['User'],
}, { // expectation: 'SHOW INDEX FROM \"User\"'
arguments: ['User', ['foo', 'bar']], // }, {
expectation: "DROP INDEX IF EXISTS \"user_foo_bar\"" // arguments: ['User', { database: 'sequelize' }],
}, { // expectation: "SHOW INDEX FROM \"User\" FROM \"sequelize\""
arguments: ['User', 'mySchema.user_foo_bar'], // }
expectation: "DROP INDEX IF EXISTS \"mySchema\".\"user_foo_bar\"" //],
},
// Variants when quoteIdentifiers is false removeIndexQuery: [
{ {
arguments: ['User', 'user_foo_bar'], arguments: ['User', 'user_foo_bar'],
expectation: "DROP INDEX IF EXISTS user_foo_bar", expectation: "DROP INDEX IF EXISTS \"user_foo_bar\""
context: {options: {quoteIdentifiers: false}} }, {
}, { arguments: ['User', ['foo', 'bar']],
arguments: ['User', ['foo', 'bar']], expectation: "DROP INDEX IF EXISTS \"user_foo_bar\""
expectation: "DROP INDEX IF EXISTS user_foo_bar", }, {
context: {options: {quoteIdentifiers: false}} arguments: ['User', 'mySchema.user_foo_bar'],
}, { expectation: "DROP INDEX IF EXISTS \"mySchema\".\"user_foo_bar\""
arguments: ['User', 'mySchema.user_foo_bar'], },
expectation: "DROP INDEX IF EXISTS mySchema.user_foo_bar",
context: {options: {quoteIdentifiers: false}}
}
],
hashToWhereConditions: [ // Variants when quoteIdentifiers is false
{ {
arguments: [{ id: [1,2,3] }], arguments: ['User', 'user_foo_bar'],
expectation: "\"id\" IN (1,2,3)" expectation: "DROP INDEX IF EXISTS user_foo_bar",
}, context: {options: {quoteIdentifiers: false}}
{ }, {
arguments: [{ id: [] }], arguments: ['User', ['foo', 'bar']],
expectation: "\"id\" IN (NULL)" expectation: "DROP INDEX IF EXISTS user_foo_bar",
}, context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['User', 'mySchema.user_foo_bar'],
expectation: "DROP INDEX IF EXISTS mySchema.user_foo_bar",
context: {options: {quoteIdentifiers: false}}
}
],
// Variants when quoteIdentifiers is false hashToWhereConditions: [
{ {
arguments: [{ id: [1,2,3] }], arguments: [{ id: [1,2,3] }],
expectation: "id IN (1,2,3)", expectation: "\"id\" IN (1,2,3)"
context: {options: {quoteIdentifiers: false}} },
}, {
{ arguments: [{ id: [] }],
arguments: [{ id: [] }], expectation: "\"id\" IN (NULL)"
expectation: "id IN (NULL)", },
context: {options: {quoteIdentifiers: false}}
},
]
}
Sequelize.Utils._.each(suites, function(tests, suiteTitle) { // Variants when quoteIdentifiers is false
describe(suiteTitle, function() { {
tests.forEach(function(test) { arguments: [{ id: [1,2,3] }],
var title = test.title || 'Postgres correctly returns ' + test.expectation + ' for ' + util.inspect(test.arguments) expectation: "id IN (1,2,3)",
it(title, function() { context: {options: {quoteIdentifiers: false}}
// Options would normally be set by the query interface that instantiates the query-generator, but here we specify it explicitly },
var context = test.context || {options: {}}; {
QueryGenerator.options = context.options arguments: [{ id: [] }],
var conditions = QueryGenerator[suiteTitle].apply(QueryGenerator, test.arguments) expectation: "id IN (NULL)",
context: {options: {quoteIdentifiers: false}}
},
]
}
expect(conditions).toEqual(test.expectation) Helpers.Sequelize.Utils._.each(suites, function(tests, suiteTitle) {
describe(suiteTitle, function() {
tests.forEach(function(test) {
var title = test.title || 'Postgres correctly returns ' + test.expectation + ' for ' + util.inspect(test.arguments)
it(title, function(done) {
// Options would normally be set by the query interface that instantiates the query-generator, but here we specify it explicitly
var context = test.context || {options: {}};
QueryGenerator.options = context.options
var conditions = QueryGenerator[suiteTitle].apply(QueryGenerator, test.arguments)
expect(conditions).toEqual(test.expectation)
done()
})
}) })
}) })
}) })
}) })
}) }
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!