How to use mytable method in wpt

Best JavaScript code snippet using wpt

query-generator.test.js

Source:query-generator.test.js Github

copy

Full Screen

1'use strict';2/* jshint -W110 */3var chai = require('chai')4 , expect = chai.expect5 , QueryGenerator = require('../../../../lib/dialects/postgres/query-generator')6 , Support = require(__dirname + '/../../support')7 , dialect = Support.getTestDialect()8 , DataTypes = require(__dirname + '/../../../../lib/data-types')9 , moment = require('moment')10 , current = Support.sequelize11 , _ = require('lodash');12if (dialect.match(/^postgres/)) {13 describe('[POSTGRES Specific] QueryGenerator', function() {14 var suites = {15 attributesToSQL: [16 {17 arguments: [{id: 'INTEGER'}],18 expectation: {id: 'INTEGER'}19 },20 {21 arguments: [{id: 'INTEGER', foo: 'VARCHAR(255)'}],22 expectation: {id: 'INTEGER', foo: 'VARCHAR(255)'}23 },24 {25 arguments: [{id: {type: 'INTEGER'}}],26 expectation: {id: 'INTEGER'}27 },28 {29 arguments: [{id: {type: 'INTEGER', allowNull: false}}],30 expectation: {id: 'INTEGER NOT NULL'}31 },32 {33 arguments: [{id: {type: 'INTEGER', allowNull: true}}],34 expectation: {id: 'INTEGER'}35 },36 {37 arguments: [{id: {type: 'INTEGER', primaryKey: true, autoIncrement: true}}],38 expectation: {id: 'INTEGER SERIAL PRIMARY KEY'}39 },40 {41 arguments: [{id: {type: 'INTEGER', defaultValue: 0}}],42 expectation: {id: 'INTEGER DEFAULT 0'}43 },44 {45 arguments: [{id: {type: 'INTEGER', unique: true}}],46 expectation: {id: 'INTEGER UNIQUE'}47 },48 // Old references style49 {50 arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],51 expectation: {id: 'INTEGER REFERENCES "Bar" ("id")'}52 },53 {54 arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],55 expectation: {id: 'INTEGER REFERENCES "Bar" ("pk")'}56 },57 {58 arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],59 expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON DELETE CASCADE'}60 },61 {62 arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],63 expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON UPDATE RESTRICT'}64 },65 {66 arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],67 expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES "Bar" ("id") ON DELETE CASCADE ON UPDATE RESTRICT'}68 },69 // Variants when quoteIdentifiers is false70 {71 arguments: [{id: {type: 'INTEGER', references: 'Bar'}}],72 expectation: {id: 'INTEGER REFERENCES Bar (id)'},73 context: {options: {quoteIdentifiers: false}}74 },75 {76 arguments: [{id: {type: 'INTEGER', references: 'Bar', referencesKey: 'pk'}}],77 expectation: {id: 'INTEGER REFERENCES Bar (pk)'},78 context: {options: {quoteIdentifiers: false}}79 },80 {81 arguments: [{id: {type: 'INTEGER', references: 'Bar', onDelete: 'CASCADE'}}],82 expectation: {id: 'INTEGER REFERENCES Bar (id) ON DELETE CASCADE'},83 context: {options: {quoteIdentifiers: false}}84 },85 {86 arguments: [{id: {type: 'INTEGER', references: 'Bar', onUpdate: 'RESTRICT'}}],87 expectation: {id: 'INTEGER REFERENCES Bar (id) ON UPDATE RESTRICT'},88 context: {options: {quoteIdentifiers: false}}89 },90 {91 arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: 'Bar', onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],92 expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES Bar (id) ON DELETE CASCADE ON UPDATE RESTRICT'},93 context: {options: {quoteIdentifiers: false}}94 },95 // New references style96 {97 arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],98 expectation: {id: 'INTEGER REFERENCES "Bar" ("id")'}99 },100 {101 arguments: [{id: {type: 'INTEGER', references: { model: 'Bar', key: 'pk' }}}],102 expectation: {id: 'INTEGER REFERENCES "Bar" ("pk")'}103 },104 {105 arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onDelete: 'CASCADE'}}],106 expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON DELETE CASCADE'}107 },108 {109 arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onUpdate: 'RESTRICT'}}],110 expectation: {id: 'INTEGER REFERENCES "Bar" ("id") ON UPDATE RESTRICT'}111 },112 {113 arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: { model: 'Bar' }, onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],114 expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES "Bar" ("id") ON DELETE CASCADE ON UPDATE RESTRICT'}115 },116 // Variants when quoteIdentifiers is false117 {118 arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],119 expectation: {id: 'INTEGER REFERENCES Bar (id)'},120 context: {options: {quoteIdentifiers: false}}121 },122 {123 arguments: [{id: {type: 'INTEGER', references: { model: 'Bar', key: 'pk' }}}],124 expectation: {id: 'INTEGER REFERENCES Bar (pk)'},125 context: {options: {quoteIdentifiers: false}}126 },127 {128 arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onDelete: 'CASCADE'}}],129 expectation: {id: 'INTEGER REFERENCES Bar (id) ON DELETE CASCADE'},130 context: {options: {quoteIdentifiers: false}}131 },132 {133 arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }, onUpdate: 'RESTRICT'}}],134 expectation: {id: 'INTEGER REFERENCES Bar (id) ON UPDATE RESTRICT'},135 context: {options: {quoteIdentifiers: false}}136 },137 {138 arguments: [{id: {type: 'INTEGER', allowNull: false, defaultValue: 1, references: { model: 'Bar' }, onDelete: 'CASCADE', onUpdate: 'RESTRICT'}}],139 expectation: {id: 'INTEGER NOT NULL DEFAULT 1 REFERENCES Bar (id) ON DELETE CASCADE ON UPDATE RESTRICT'},140 context: {options: {quoteIdentifiers: false}}141 }142 ],143 createTableQuery: [144 {145 arguments: ['myTable', {int: 'INTEGER', bigint: 'BIGINT'}],146 expectation: 'CREATE TABLE IF NOT EXISTS \"myTable\" (\"int\" INTEGER, \"bigint\" BIGINT);'147 },148 {149 arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],150 expectation: 'CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));'151 },152 {153 arguments: ['myTable', {data: current.normalizeDataType(DataTypes.BLOB).toSql()}],154 expectation: 'CREATE TABLE IF NOT EXISTS \"myTable\" (\"data\" BYTEA);'155 },156 {157 arguments: ['myTable', {data: current.normalizeDataType(DataTypes.BLOB('long')).toSql()}],158 expectation: 'CREATE TABLE IF NOT EXISTS \"myTable\" (\"data\" BYTEA);'159 },160 {161 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],162 expectation: 'CREATE TABLE IF NOT EXISTS \"mySchema\".\"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255));'163 },164 {165 arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}],166 expectation: 'CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" \"public\".\"enum_myTable_title\", \"name\" VARCHAR(255));'167 },168 {169 arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY'}],170 expectation: 'CREATE TABLE IF NOT EXISTS \"myTable\" (\"title\" VARCHAR(255), \"name\" VARCHAR(255), \"id\" INTEGER , PRIMARY KEY (\"id\"));'171 },172 {173 arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES "otherTable" ("id") ON DELETE CASCADE ON UPDATE NO ACTION'}],174 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);'175 },176 // Variants when quoteIdentifiers is false177 {178 arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],179 expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255));',180 context: {options: {quoteIdentifiers: false}}181 },182 {183 arguments: [{schema: 'mySchema', tableName: 'myTable'}, {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],184 expectation: 'CREATE TABLE IF NOT EXISTS mySchema.myTable (title VARCHAR(255), name VARCHAR(255));',185 context: {options: {quoteIdentifiers: false}}186 },187 {188 arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}],189 expectation: 'CREATE TABLE IF NOT EXISTS myTable (title public."enum_myTable_title", name VARCHAR(255));',190 context: {options: {quoteIdentifiers: false}}191 },192 {193 arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY'}],194 expectation: 'CREATE TABLE IF NOT EXISTS myTable (title VARCHAR(255), name VARCHAR(255), id INTEGER , PRIMARY KEY (id));',195 context: {options: {quoteIdentifiers: false}}196 },197 {198 arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', otherId: 'INTEGER REFERENCES otherTable (id) ON DELETE CASCADE ON UPDATE NO ACTION'}],199 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);',200 context: {options: {quoteIdentifiers: false}}201 }202 ],203 dropTableQuery: [204 {205 arguments: ['myTable'],206 expectation: 'DROP TABLE IF EXISTS \"myTable\";'207 },208 {209 arguments: [{tableName: 'myTable', schema: 'mySchema'}],210 expectation: 'DROP TABLE IF EXISTS \"mySchema\".\"myTable\";'211 },212 {213 arguments: ['myTable', {cascade: true}],214 expectation: 'DROP TABLE IF EXISTS \"myTable\" CASCADE;'215 },216 {217 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {cascade: true}],218 expectation: 'DROP TABLE IF EXISTS \"mySchema\".\"myTable\" CASCADE;'219 },220 // Variants when quoteIdentifiers is false221 {222 arguments: ['myTable'],223 expectation: 'DROP TABLE IF EXISTS myTable;',224 context: {options: {quoteIdentifiers: false}}225 },226 {227 arguments: [{tableName: 'myTable', schema: 'mySchema'}],228 expectation: 'DROP TABLE IF EXISTS mySchema.myTable;',229 context: {options: {quoteIdentifiers: false}}230 },231 {232 arguments: ['myTable', {cascade: true}],233 expectation: 'DROP TABLE IF EXISTS myTable CASCADE;',234 context: {options: {quoteIdentifiers: false}}235 },236 {237 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {cascade: true}],238 expectation: 'DROP TABLE IF EXISTS mySchema.myTable CASCADE;',239 context: {options: {quoteIdentifiers: false}}240 }241 ],242 selectQuery: [243 {244 arguments: ['myTable'],245 expectation: 'SELECT * FROM \"myTable\";'246 }, {247 arguments: ['myTable', {attributes: ['id', 'name']}],248 expectation: 'SELECT \"id\", \"name\" FROM \"myTable\";'249 }, {250 arguments: ['myTable', {where: {id: 2}}],251 expectation: 'SELECT * FROM \"myTable\" WHERE \"myTable\".\"id\" = 2;'252 }, {253 arguments: ['myTable', {where: {name: 'foo'}}],254 expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"name\" = 'foo';"255 }, {256 arguments: ['myTable', {where: {name: "foo';DROP TABLE myTable;"}}],257 expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"name\" = 'foo'';DROP TABLE myTable;';"258 }, {259 arguments: ['myTable', {where: 2}],260 expectation: 'SELECT * FROM \"myTable\" WHERE \"myTable\".\"id\" = 2;'261 }, {262 arguments: ['foo', { attributes: [['count(*)', 'count']] }],263 expectation: 'SELECT count(*) AS \"count\" FROM \"foo\";'264 }, {265 arguments: ['myTable', {where: ["foo='bar'"]}],266 expectation: "SELECT * FROM \"myTable\" WHERE foo='bar';"267 }, {268 arguments: ['myTable', {order: 'id DESC'}],269 expectation: 'SELECT * FROM \"myTable\" ORDER BY id DESC;'270 }, {271 arguments: ['myTable', {order: ['id']}],272 expectation: 'SELECT * FROM "myTable" ORDER BY "id";',273 context: QueryGenerator274 }, {275 arguments: ['myTable', {order: ['myTable.id']}],276 expectation: 'SELECT * FROM "myTable" ORDER BY "myTable"."id";',277 context: QueryGenerator278 }, {279 arguments: ['myTable', {order: [['id', 'DESC']]}, function(sequelize) {return sequelize.define('myTable', {});}],280 expectation: 'SELECT * FROM "myTable" AS "myTable" ORDER BY "myTable"."id" DESC;',281 context: QueryGenerator,282 needsSequelize: true283 },{284 title: 'uses limit 0',285 arguments: ['myTable', {limit: 0}],286 expectation: 'SELECT * FROM "myTable" LIMIT 0;',287 context: QueryGenerator288 }, {289 title: 'uses offset 0',290 arguments: ['myTable', {offset: 0}],291 expectation: 'SELECT * FROM "myTable" OFFSET 0;',292 context: QueryGenerator293 }, {294 title: 'raw arguments are neither quoted nor escaped',295 arguments: ['myTable', {order: [[{raw: 'f1(f2(id))'},'DESC']]}],296 expectation: 'SELECT * FROM "myTable" ORDER BY f1(f2(id)) DESC;',297 context: QueryGenerator298 }, {299 title: 'sequelize.where with .fn as attribute and default comparator',300 arguments: ['myTable', function(sequelize) {301 return {302 where: sequelize.and(303 sequelize.where(sequelize.fn('LOWER', sequelize.col('user.name')), 'jan'),304 { type: 1 }305 )306 };307 }],308 expectation: 'SELECT * FROM "myTable" WHERE (LOWER("user"."name") = \'jan\' AND "myTable"."type" = 1);',309 context: QueryGenerator,310 needsSequelize: true311 }, {312 title: 'sequelize.where with .fn as attribute and LIKE comparator',313 arguments: ['myTable', function(sequelize) {314 return {315 where: sequelize.and(316 sequelize.where(sequelize.fn('LOWER', sequelize.col('user.name')), 'LIKE', '%t%'),317 { type: 1 }318 )319 };320 }],321 expectation: 'SELECT * FROM "myTable" WHERE (LOWER("user"."name") LIKE \'%t%\' AND "myTable"."type" = 1);',322 context: QueryGenerator,323 needsSequelize: true324 },{325 title: 'functions can take functions as arguments',326 arguments: ['myTable', function(sequelize) {327 return {328 order: [[sequelize.fn('f1', sequelize.fn('f2', sequelize.col('id'))), 'DESC']]329 };330 }],331 expectation: 'SELECT * FROM "myTable" ORDER BY f1(f2("id")) DESC;',332 context: QueryGenerator,333 needsSequelize: true334 }, {335 title: 'functions can take all types as arguments',336 arguments: ['myTable', function(sequelize) {337 return {338 order: [339 [sequelize.fn('f1', sequelize.col('myTable.id')), 'DESC'],340 [sequelize.fn('f2', 12, 'lalala', new Date(Date.UTC(2011, 2, 27, 10, 1, 55))), 'ASC']341 ]342 };343 }],344 expectation: 'SELECT * FROM "myTable" ORDER BY f1("myTable"."id") DESC, f2(12, \'lalala\', \'2011-03-27 10:01:55.000 +00:00\') ASC;',345 context: QueryGenerator,346 needsSequelize: true347 }, {348 title: 'Combination of sequelize.fn, sequelize.col and { in: ... }',349 arguments: ['myTable', function(sequelize) {350 return {351 where: sequelize.and(352 { archived: null},353 sequelize.where(sequelize.fn('COALESCE', sequelize.col('place_type_codename'), sequelize.col('announcement_type_codename')), { in : ['Lost', 'Found'] })354 )355 };356 }],357 expectation: 'SELECT * FROM "myTable" WHERE ("myTable"."archived" IS NULL AND COALESCE("place_type_codename", "announcement_type_codename") IN (\'Lost\', \'Found\'));',358 context: QueryGenerator,359 needsSequelize: true360 }, {361 title: 'single string argument is not quoted',362 arguments: ['myTable', {group: 'name'}],363 expectation: 'SELECT * FROM \"myTable\" GROUP BY name;'364 }, {365 arguments: ['myTable', {group: ['name']}],366 expectation: 'SELECT * FROM \"myTable\" GROUP BY \"name\";'367 }, {368 title: 'functions work for group by',369 arguments: ['myTable', function(sequelize) {370 return {371 group: [sequelize.fn('YEAR', sequelize.col('createdAt'))]372 };373 }],374 expectation: 'SELECT * FROM \"myTable\" GROUP BY YEAR(\"createdAt\");',375 needsSequelize: true376 },{377 title: 'It is possible to mix sequelize.fn and string arguments to group by',378 arguments: ['myTable', function(sequelize) {379 return {380 group: [sequelize.fn('YEAR', sequelize.col('createdAt')), 'title']381 };382 }],383 expectation: 'SELECT * FROM \"myTable\" GROUP BY YEAR(\"createdAt\"), \"title\";',384 context: QueryGenerator,385 needsSequelize: true386 }, {387 arguments: ['myTable', {group: ['name', 'title']}],388 expectation: 'SELECT * FROM \"myTable\" GROUP BY \"name\", \"title\";'389 }, {390 title: 'HAVING clause works with string replacements',391 arguments: ['myTable', function(sequelize) {392 return {393 attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],394 group: ['creationYear', 'title'],395 having: ['creationYear > ?', 2002]396 };397 }],398 expectation: 'SELECT *, YEAR(\"createdAt\") AS \"creationYear\" FROM \"myTable\" GROUP BY \"creationYear\", \"title\" HAVING creationYear > 2002;',399 context: QueryGenerator,400 needsSequelize: true401 }, {402 title: 'HAVING clause works with where-like hash',403 arguments: ['myTable', function(sequelize) {404 return {405 attributes: ['*', [sequelize.fn('YEAR', sequelize.col('createdAt')), 'creationYear']],406 group: ['creationYear', 'title'],407 having: { creationYear: { gt: 2002 } }408 };409 }],410 expectation: 'SELECT *, YEAR(\"createdAt\") AS \"creationYear\" FROM \"myTable\" GROUP BY \"creationYear\", \"title\" HAVING \"creationYear\" > 2002;',411 context: QueryGenerator,412 needsSequelize: true413 }, {414 arguments: ['myTable', {limit: 10}],415 expectation: 'SELECT * FROM \"myTable\" LIMIT 10;'416 }, {417 arguments: ['myTable', {limit: 10, offset: 2}],418 expectation: 'SELECT * FROM \"myTable\" LIMIT 10 OFFSET 2;'419 }, {420 title: 'uses offset even if no limit was passed',421 arguments: ['myTable', {offset: 2}],422 expectation: 'SELECT * FROM \"myTable\" OFFSET 2;'423 }, {424 arguments: [{tableName: 'myTable', schema: 'mySchema'}],425 expectation: 'SELECT * FROM \"mySchema\".\"myTable\";'426 }, {427 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {where: {name: "foo';DROP TABLE mySchema.myTable;"}}],428 expectation: "SELECT * FROM \"mySchema\".\"myTable\" WHERE \"mySchema\".\"myTable\".\"name\" = 'foo'';DROP TABLE mySchema.myTable;';"429 }, {430 title: 'buffer as where argument',431 arguments: ['myTable', {where: { field: new Buffer('Sequelize')}}],432 expectation: "SELECT * FROM \"myTable\" WHERE \"myTable\".\"field\" = E'\\\\x53657175656c697a65';",433 context: QueryGenerator434 },435 // Variants when quoteIdentifiers is false436 {437 arguments: ['myTable'],438 expectation: 'SELECT * FROM myTable;',439 context: {options: {quoteIdentifiers: false}}440 }, {441 arguments: ['myTable', {attributes: ['id', 'name']}],442 expectation: 'SELECT id, name FROM myTable;',443 context: {options: {quoteIdentifiers: false}}444 }, {445 arguments: ['myTable', {where: {id: 2}}],446 expectation: 'SELECT * FROM myTable WHERE myTable.id = 2;',447 context: {options: {quoteIdentifiers: false}}448 }, {449 arguments: ['myTable', {where: {name: 'foo'}}],450 expectation: "SELECT * FROM myTable WHERE myTable.name = 'foo';",451 context: {options: {quoteIdentifiers: false}}452 }, {453 arguments: ['myTable', {where: {name: "foo';DROP TABLE myTable;"}}],454 expectation: "SELECT * FROM myTable WHERE myTable.name = 'foo'';DROP TABLE myTable;';",455 context: {options: {quoteIdentifiers: false}}456 }, {457 arguments: ['myTable', {where: 2}],458 expectation: 'SELECT * FROM myTable WHERE myTable.id = 2;',459 context: {options: {quoteIdentifiers: false}}460 }, {461 arguments: ['foo', { attributes: [['count(*)', 'count']] }],462 expectation: 'SELECT count(*) AS count FROM foo;',463 context: {options: {quoteIdentifiers: false}}464 }, {465 arguments: ['myTable', {where: ["foo='bar'"]}],466 expectation: "SELECT * FROM myTable WHERE foo='bar';",467 context: {options: {quoteIdentifiers: false}}468 }, {469 arguments: ['myTable', {order: 'id DESC'}],470 expectation: 'SELECT * FROM myTable ORDER BY id DESC;',471 context: {options: {quoteIdentifiers: false}}472 }, {473 arguments: ['myTable', {group: 'name'}],474 expectation: 'SELECT * FROM myTable GROUP BY name;',475 context: {options: {quoteIdentifiers: false}}476 }, {477 arguments: ['myTable', {group: ['name']}],478 expectation: 'SELECT * FROM myTable GROUP BY name;',479 context: {options: {quoteIdentifiers: false}}480 }, {481 arguments: ['myTable', {group: ['name', 'title']}],482 expectation: 'SELECT * FROM myTable GROUP BY name, title;',483 context: {options: {quoteIdentifiers: false}}484 }, {485 arguments: ['myTable', {limit: 10}],486 expectation: 'SELECT * FROM myTable LIMIT 10;',487 context: {options: {quoteIdentifiers: false}}488 }, {489 arguments: ['myTable', {limit: 10, offset: 2}],490 expectation: 'SELECT * FROM myTable LIMIT 10 OFFSET 2;',491 context: {options: {quoteIdentifiers: false}}492 }, {493 title: 'uses offset even if no limit was passed',494 arguments: ['myTable', {offset: 2}],495 expectation: 'SELECT * FROM myTable OFFSET 2;',496 context: {options: {quoteIdentifiers: false}}497 }, {498 arguments: [{tableName: 'myTable', schema: 'mySchema'}],499 expectation: 'SELECT * FROM mySchema.myTable;',500 context: {options: {quoteIdentifiers: false}}501 }, {502 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {where: {name: "foo';DROP TABLE mySchema.myTable;"}}],503 expectation: "SELECT * FROM mySchema.myTable WHERE mySchema.myTable.name = 'foo'';DROP TABLE mySchema.myTable;';",504 context: {options: {quoteIdentifiers: false}}505 }, {506 title: 'use != if ne !== null',507 arguments: ['myTable', {where: {field: {ne: 0}}}],508 expectation: 'SELECT * FROM myTable WHERE myTable.field != 0;',509 context: {options: {quoteIdentifiers: false}}510 }, {511 title: 'use IS NOT if ne === null',512 arguments: ['myTable', {where: {field: {ne: null}}}],513 expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT NULL;',514 context: {options: {quoteIdentifiers: false}}515 }, {516 title: 'use IS NOT if not === BOOLEAN',517 arguments: ['myTable', {where: {field: {not: true}}}],518 expectation: 'SELECT * FROM myTable WHERE myTable.field IS NOT true;',519 context: {options: {quoteIdentifiers: false}}520 }, {521 title: 'use != if not !== BOOLEAN',522 arguments: ['myTable', {where: {field: {not: 3}}}],523 expectation: 'SELECT * FROM myTable WHERE myTable.field != 3;',524 context: {options: {quoteIdentifiers: false}}525 }526 ],527 insertQuery: [528 {529 arguments: ['myTable', {}],530 expectation: 'INSERT INTO \"myTable\" DEFAULT VALUES;'531 },532 {533 arguments: ['myTable', {name: 'foo'}],534 expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo');"535 }, {536 arguments: ['myTable', {name: 'foo'}, {}, { returning: true }],537 expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo') RETURNING *;"538 }, {539 arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}],540 expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'';DROP TABLE myTable;');"541 }, {542 arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}],543 expectation: "INSERT INTO \"myTable\" (\"name\",\"birthday\") VALUES ('foo','2011-03-27 10:01:55.000 +00:00');"544 }, {545 arguments: ['myTable', {data: new Buffer('Sequelize') }],546 expectation: "INSERT INTO \"myTable\" (\"data\") VALUES (E'\\\\x53657175656c697a65');"547 }, {548 arguments: ['myTable', {name: 'foo', numbers: [1, 2, 3]}],549 expectation: "INSERT INTO \"myTable\" (\"name\",\"numbers\") VALUES ('foo',ARRAY[1,2,3]);"550 }, {551 arguments: ['myTable', {name: 'foo', foo: 1}],552 expectation: "INSERT INTO \"myTable\" (\"name\",\"foo\") VALUES ('foo',1);"553 }, {554 arguments: ['myTable', {name: 'foo', nullValue: null}],555 expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL);"556 }, {557 arguments: ['myTable', {name: 'foo', nullValue: null}],558 expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL);",559 context: {options: {omitNull: false}}560 }, {561 arguments: ['myTable', {name: 'foo', nullValue: null}],562 expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo');",563 context: {options: {omitNull: true}}564 }, {565 arguments: ['myTable', {name: 'foo', nullValue: undefined}],566 expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo');",567 context: {options: {omitNull: true}}568 }, {569 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {name: 'foo'}],570 expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo');"571 }, {572 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {name: JSON.stringify({info: 'Look ma a " quote'})}],573 expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('{\"info\":\"Look ma a \\\" quote\"}');"574 }, {575 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {name: "foo';DROP TABLE mySchema.myTable;"}],576 expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'';DROP TABLE mySchema.myTable;');"577 }, {578 arguments: ['myTable', function(sequelize) {579 return {580 foo: sequelize.fn('NOW')581 };582 }],583 expectation: 'INSERT INTO \"myTable\" (\"foo\") VALUES (NOW());',584 needsSequelize: true585 },586 // Variants when quoteIdentifiers is false587 {588 arguments: ['myTable', {name: 'foo'}],589 expectation: "INSERT INTO myTable (name) VALUES ('foo');",590 context: {options: {quoteIdentifiers: false}}591 }, {592 arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}],593 expectation: "INSERT INTO myTable (name) VALUES ('foo'';DROP TABLE myTable;');",594 context: {options: {quoteIdentifiers: false}}595 }, {596 arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}],597 expectation: "INSERT INTO myTable (name,birthday) VALUES ('foo','2011-03-27 10:01:55.000 +00:00');",598 context: {options: {quoteIdentifiers: false}}599 }, {600 arguments: ['myTable', {name: 'foo', numbers: [1, 2, 3]}],601 expectation: "INSERT INTO myTable (name,numbers) VALUES ('foo',ARRAY[1,2,3]);",602 context: {options: {quoteIdentifiers: false}}603 }, {604 arguments: ['myTable', {name: 'foo', foo: 1}],605 expectation: "INSERT INTO myTable (name,foo) VALUES ('foo',1);",606 context: {options: {quoteIdentifiers: false}}607 }, {608 arguments: ['myTable', {name: 'foo', nullValue: null}],609 expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL);",610 context: {options: {quoteIdentifiers: false}}611 }, {612 arguments: ['myTable', {name: 'foo', nullValue: null}],613 expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL);",614 context: {options: {omitNull: false, quoteIdentifiers: false}}615 }, {616 arguments: ['myTable', {name: 'foo', nullValue: null}],617 expectation: "INSERT INTO myTable (name) VALUES ('foo');",618 context: {options: {omitNull: true, quoteIdentifiers: false}}619 }, {620 arguments: ['myTable', {name: 'foo', nullValue: undefined}],621 expectation: "INSERT INTO myTable (name) VALUES ('foo');",622 context: {options: {omitNull: true, quoteIdentifiers: false}}623 }, {624 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {name: 'foo'}],625 expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo');",626 context: {options: {quoteIdentifiers: false}}627 }, {628 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {name: JSON.stringify({info: 'Look ma a " quote'})}],629 expectation: "INSERT INTO mySchema.myTable (name) VALUES ('{\"info\":\"Look ma a \\\" quote\"}');",630 context: {options: {quoteIdentifiers: false}}631 }, {632 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {name: "foo';DROP TABLE mySchema.myTable;"}],633 expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'';DROP TABLE mySchema.myTable;');",634 context: {options: {quoteIdentifiers: false}}635 }636 ],637 bulkInsertQuery: [638 {639 arguments: ['myTable', [{name: 'foo'}, {name: 'bar'}]],640 expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'),('bar');"641 }, {642 arguments: ['myTable', [{name: 'foo'}, {name: 'bar'}], { returning: true }],643 expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'),('bar') RETURNING *;"644 }, {645 arguments: ['myTable', [{name: "foo';DROP TABLE myTable;"}, {name: 'bar'}]],646 expectation: "INSERT INTO \"myTable\" (\"name\") VALUES ('foo'';DROP TABLE myTable;'),('bar');"647 }, {648 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()}]],649 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');"650 }, {651 arguments: ['myTable', [{name: 'foo', foo: 1}, {name: 'bar', foo: 2}]],652 expectation: "INSERT INTO \"myTable\" (\"name\",\"foo\") VALUES ('foo',1),('bar',2);"653 }, {654 arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],655 expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL);"656 }, {657 arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],658 expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL);",659 context: {options: {omitNull: false}}660 }, {661 arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],662 expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL);",663 context: {options: {omitNull: true}} // Note: We don't honour this because it makes little sense when some rows may have nulls and others not664 }, {665 arguments: ['myTable', [{name: 'foo', nullValue: undefined}, {name: 'bar', nullValue: undefined}]],666 expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL);",667 context: {options: {omitNull: true}} // Note: As above668 }, {669 arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: 'foo'}, {name: 'bar'}]],670 expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'),('bar');"671 }, {672 arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]],673 expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}');"674 }, {675 arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]],676 expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar');"677 },678 // Variants when quoteIdentifiers is false679 {680 arguments: ['myTable', [{name: 'foo'}, {name: 'bar'}]],681 expectation: "INSERT INTO myTable (name) VALUES ('foo'),('bar');",682 context: {options: {quoteIdentifiers: false}}683 }, {684 arguments: ['myTable', [{name: "foo';DROP TABLE myTable;"}, {name: 'bar'}]],685 expectation: "INSERT INTO myTable (name) VALUES ('foo'';DROP TABLE myTable;'),('bar');",686 context: {options: {quoteIdentifiers: false}}687 }, {688 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()}]],689 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');",690 context: {options: {quoteIdentifiers: false}}691 }, {692 arguments: ['myTable', [{name: 'foo', foo: 1}, {name: 'bar', foo: 2}]],693 expectation: "INSERT INTO myTable (name,foo) VALUES ('foo',1),('bar',2);",694 context: {options: {quoteIdentifiers: false}}695 }, {696 arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],697 expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL);",698 context: {options: {quoteIdentifiers: false}}699 }, {700 arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],701 expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL);",702 context: {options: {quoteIdentifiers: false, omitNull: false}}703 }, {704 arguments: ['myTable', [{name: 'foo', nullValue: null}, {name: 'bar', nullValue: null}]],705 expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL);",706 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 not707 }, {708 arguments: ['myTable', [{name: 'foo', nullValue: undefined}, {name: 'bar', nullValue: undefined}]],709 expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL);",710 context: {options: {omitNull: true, quoteIdentifiers: false}} // Note: As above711 }, {712 arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: 'foo'}, {name: 'bar'}]],713 expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'),('bar');",714 context: {options: {quoteIdentifiers: false}}715 }, {716 arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]],717 expectation: "INSERT INTO mySchema.myTable (name) VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}');",718 context: {options: {quoteIdentifiers: false}}719 }, {720 arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]],721 expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar');",722 context: {options: {quoteIdentifiers: false}}723 }724 ],725 updateQuery: [726 {727 arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],728 expectation: "UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\" = 2"729 }, {730 arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],731 expectation: "UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\" = 2"732 }, {733 arguments: ['myTable', {bar: 2}, {name: 'foo'}],734 expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\" = 'foo'"735 }, {736 arguments: ['myTable', {bar: 2}, {name: 'foo'}, { returning: true }],737 expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\" = 'foo' RETURNING *"738 }, {739 arguments: ['myTable', {numbers: [1, 2, 3]}, {name: 'foo'}],740 expectation: "UPDATE \"myTable\" SET \"numbers\"=ARRAY[1,2,3] WHERE \"name\" = 'foo'"741 }, {742 arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {name: 'foo'}],743 expectation: "UPDATE \"myTable\" SET \"name\"='foo'';DROP TABLE myTable;' WHERE \"name\" = 'foo'"744 }, {745 arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],746 expectation: "UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\" = 'foo'"747 }, {748 arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],749 expectation: "UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\" = 'foo'",750 context: {options: {omitNull: false}}751 }, {752 arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],753 expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\" = 'foo'",754 context: {options: {omitNull: true}}755 }, {756 arguments: ['myTable', {bar: 2, nullValue: undefined}, {name: 'foo'}],757 expectation: "UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\" = 'foo'",758 context: {options: {omitNull: true}}759 }, {760 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],761 expectation: "UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\" = 2"762 }, {763 arguments: [{tableName: 'myTable', schema: 'mySchema'}, {name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'foo'}],764 expectation: "UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo'';DROP TABLE mySchema.myTable;' WHERE \"name\" = 'foo'"765 }, {766 arguments: ['myTable', function(sequelize) {767 return {768 bar: sequelize.fn('NOW')769 };770 }, {name: 'foo'}],771 expectation: "UPDATE \"myTable\" SET \"bar\"=NOW() WHERE \"name\" = 'foo'",772 needsSequelize: true773 }, {774 arguments: ['myTable', function(sequelize) {775 return {776 bar: sequelize.col('foo')777 };778 }, {name: 'foo'}],779 expectation: "UPDATE \"myTable\" SET \"bar\"=\"foo\" WHERE \"name\" = 'foo'",780 needsSequelize: true781 },782 // Variants when quoteIdentifiers is false783 {784 arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],785 expectation: "UPDATE myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id = 2",786 context: {options: {quoteIdentifiers: false}}787 }, {788 arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],789 expectation: "UPDATE myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id = 2",790 context: {options: {quoteIdentifiers: false}}791 }, {792 arguments: ['myTable', {bar: 2}, {name: 'foo'}],793 expectation: "UPDATE myTable SET bar=2 WHERE name = 'foo'",794 context: {options: {quoteIdentifiers: false}}795 }, {796 arguments: ['myTable', {numbers: [1, 2, 3]}, {name: 'foo'}],797 expectation: "UPDATE myTable SET numbers=ARRAY[1,2,3] WHERE name = 'foo'",798 context: {options: {quoteIdentifiers: false}}799 }, {800 arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {name: 'foo'}],801 expectation: "UPDATE myTable SET name='foo'';DROP TABLE myTable;' WHERE name = 'foo'",802 context: {options: {quoteIdentifiers: false}}803 }, {804 arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],805 expectation: "UPDATE myTable SET bar=2,nullValue=NULL WHERE name = 'foo'",806 context: {options: {quoteIdentifiers: false}}807 }, {808 arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],809 expectation: "UPDATE myTable SET bar=2,nullValue=NULL WHERE name = 'foo'",810 context: {options: {omitNull: false, quoteIdentifiers: false}}811 }, {812 arguments: ['myTable', {bar: 2, nullValue: null}, {name: 'foo'}],813 expectation: "UPDATE myTable SET bar=2 WHERE name = 'foo'",814 context: {options: {omitNull: true, quoteIdentifiers: false}}815 }, {816 arguments: ['myTable', {bar: 2, nullValue: undefined}, {name: 'foo'}],817 expectation: "UPDATE myTable SET bar=2 WHERE name = 'foo'",818 context: {options: {omitNull: true, quoteIdentifiers: false}}819 }, {820 arguments: [{schema: 'mySchema', tableName: 'myTable'}, {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],821 expectation: "UPDATE mySchema.myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id = 2",822 context: {options: {quoteIdentifiers: false}}823 }, {824 arguments: [{schema: 'mySchema', tableName: 'myTable'}, {name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'foo'}],825 expectation: "UPDATE mySchema.myTable SET name='foo'';DROP TABLE mySchema.myTable;' WHERE name = 'foo'",826 context: {options: {quoteIdentifiers: false}}827 }828 ],829 removeIndexQuery: [830 {831 arguments: ['User', 'user_foo_bar'],832 expectation: 'DROP INDEX IF EXISTS \"user_foo_bar\"'833 }, {834 arguments: ['User', ['foo', 'bar']],835 expectation: 'DROP INDEX IF EXISTS \"user_foo_bar\"'836 }, {837 arguments: ['User', 'mySchema.user_foo_bar'],838 expectation: 'DROP INDEX IF EXISTS \"mySchema\".\"user_foo_bar\"'839 },840 // Variants when quoteIdentifiers is false841 {842 arguments: ['User', 'user_foo_bar'],843 expectation: 'DROP INDEX IF EXISTS user_foo_bar',844 context: {options: {quoteIdentifiers: false}}845 }, {846 arguments: ['User', ['foo', 'bar']],847 expectation: 'DROP INDEX IF EXISTS user_foo_bar',848 context: {options: {quoteIdentifiers: false}}849 }, {850 arguments: ['User', 'mySchema.user_foo_bar'],851 expectation: 'DROP INDEX IF EXISTS mySchema.user_foo_bar',852 context: {options: {quoteIdentifiers: false}}853 }854 ],855 startTransactionQuery: [856 {857 arguments: [{}],858 expectation: 'START TRANSACTION;',859 context: {options: {quoteIdentifiers: false}}860 },861 {862 arguments: [{parent: 'MockTransaction', name: 'transaction-uid'}],863 expectation: 'SAVEPOINT \"transaction-uid\";',864 context: {options: {quoteIdentifiers: false}}865 },866 {867 arguments: [{parent: 'MockTransaction', name: 'transaction-uid'}],868 expectation: 'SAVEPOINT \"transaction-uid\";',869 context: {options: {quoteIdentifiers: true}}870 }871 ],872 rollbackTransactionQuery: [873 {874 arguments: [{}],875 expectation: 'ROLLBACK;',876 context: {options: {quoteIdentifiers: false}}877 },878 {879 arguments: [{parent: 'MockTransaction', name: 'transaction-uid'}],880 expectation: 'ROLLBACK TO SAVEPOINT \"transaction-uid\";',881 context: {options: {quoteIdentifiers: false}}882 },883 {884 arguments: [{parent: 'MockTransaction', name: 'transaction-uid'}],885 expectation: 'ROLLBACK TO SAVEPOINT \"transaction-uid\";',886 context: {options: {quoteIdentifiers: true}}887 }888 ]889 };890 _.each(suites, function(tests, suiteTitle) {891 describe(suiteTitle, function() {892 afterEach(function() {893 this.sequelize.options.quoteIdentifiers = true;894 QueryGenerator.options.quoteIdentifiers = true;895 });896 tests.forEach(function(test) {897 var title = test.title || 'Postgres correctly returns ' + test.expectation + ' for ' + JSON.stringify(test.arguments);898 it(title, function() {899 // Options would normally be set by the query interface that instantiates the query-generator, but here we specify it explicitly900 var context = test.context || {options: {}};901 if (test.needsSequelize) {902 if (_.isFunction(test.arguments[1])) test.arguments[1] = test.arguments[1](this.sequelize);903 if (_.isFunction(test.arguments[2])) test.arguments[2] = test.arguments[2](this.sequelize);904 }905 QueryGenerator.options = _.assign(context.options, { timezone: '+00:00' });906 QueryGenerator._dialect = this.sequelize.dialect;907 var conditions = QueryGenerator[suiteTitle].apply(QueryGenerator, test.arguments);908 expect(conditions).to.deep.equal(test.expectation);909 });910 });911 });912 });913 });...

Full Screen

Full Screen

misFunciones.js

Source:misFunciones.js Github

copy

Full Screen

1function traerInformacionCategorias(){2 $.ajax({3 url:"http://129.151.105.241:8080/api/Category/all",4 type:"GET",5 datatype:"JSON",6 success:function(respuesta){7 console.log(respuesta);8 pintarRespuesta(respuesta);9 }10 });11}1213function pintarRespuesta(respuesta){1415 let myTable="<table>";16 myTable+="<tr bgcolor='#186EE6'>";17 myTable+="<td>"+"Id"+"</td>";18 myTable+="<td>"+"Name"+"</td>";19 myTable+="<td>"+"Descripcion"+"</td>";20 myTable+="<td>"+"Actualizar"+"</td>";21 myTable+="<td>"+"Eliminar"+"</td>";22 myTable+="</tr>";23 for(i=0;i<respuesta.length;i++){24 posicion = i + 1;25 myTable+="<tr>";26 myTable+="<td>"+posicion+"</td>";27 myTable+="<td>"+respuesta[i].name+"</td>";28 myTable+="<td>"+respuesta[i].description+"</td>";29 myTable+="<td> <button onclick='actualizarInformacionCategorias("+respuesta[i].id+")' class='Actualizar'>Actualizar</button>";30 myTable+="</tr>";31 }32 myTable+="</table>";33 $("#resultado1").html(myTable);34}3536function guardarInformacionCategorias(){37 let var2 = {38 name:$("#Cname").val(),39 description:$("#Cdescription").val()40 };41 42 $.ajax({43 type:'POST',44 contentType: "application/json; charset=utf-8",45 dataType: 'JSON',46 data: JSON.stringify(var2),47 48 url:"http://129.151.105.241:8080/api/Category/save",49 50 51 success:function(response) {52 console.log(response);53 console.log("Se guardo correctamente");54 alert("Se guardo correctamente");55 window.location.reload()56 57 },58 59 error: function(jqXHR, textStatus, errorThrown) {60 window.location.reload()61 alert("No se guardo correctamente");62 63 64 }65 });6667}6869function actualizarInformacionCategorias(idElemento){70 71 if ($("#Cname").val().length==0 || $("#Cdescription").val().length==0){7273 alert("Todos los campos son obligatorios");74 }else{75 76 77 let myData={78 id:idElemento,79 name:$("#Cname").val(),80 description:$("#Cdescription").val()8182 };83 console.log(myData);84 let dataToSend=JSON.stringify(myData);85 $.ajax({86 url:"http://129.151.105.241:8080/api/Category/update",87 type:"PUT",88 data:dataToSend,89 contentType:"application/JSON",90 datatype:"JSON",91 success:function(respuesta){92 $("#resultado").empty();93 $("#id").val("");94 $("#Cname").val("");95 $("#Cdescription").val("");96 traerInformacionCategorias();97 alert("se ha Actualizado correctamente la categoria")98 }99 });}100101}102103///////////////////Bikes//////////////////////////////////////104function traerInformacionBikes(){105 $.ajax({106 url:"http://129.151.105.241:8080/api/Bike/all",107 type:"GET",108 datatype:"JSON",109 success:function(respuesta){110 console.log(respuesta);111 pintarRespuestaBikes(respuesta);112 }113 });114}115116function pintarRespuestaBikes(respuesta){117118 let myTable="<table>";119 myTable+="<tr bgcolor='#186EE6'>";120 myTable+="<td>"+"Id"+"</td>";121 myTable+="<td>"+"Name"+"</td>";122 myTable+="<td>"+"Brand"+"</td>";123 myTable+="<td>"+"Year"+"</td>";124 myTable+="<td>"+"Description"+"</td>";125 myTable+="</tr>";126 for(i=0;i<respuesta.length;i++){127 posicion = i + 1;128 myTable+="<tr>";129 myTable+="<td>"+posicion+"</td>";130 myTable+="<td>"+respuesta[i].name+"</td>";131 myTable+="<td>"+respuesta[i].brand+"</td>";132 myTable+="<td>"+respuesta[i].year+"</td>";133 myTable+="<td>"+respuesta[i].description+"</td>";134 myTable+="</tr>";135 }136 myTable+="</table>";137 $("#resultado2").html(myTable);138}139140function guardarInformacionBikes(){141 let var3 = {142 name:$("#Bname").val(),143 brand:$("#Bbrand").val(),144 year:$("#Byear").val(),145 description:$("#Bdescription").val(),146 };147 148 $.ajax({149 type:'POST',150 contentType: "application/json; charset=utf-8",151 dataType: 'JSON',152 data: JSON.stringify(var3),153 154 url:"http://129.151.105.241:8080/api/Bike/save",155 156 157 success:function(response) {158 console.log(response);159 console.log("Se guardo correctamente");160 alert("Se guardo correctamente");161 window.location.reload()162 163 },164 165 error: function(jqXHR, textStatus, errorThrown) {166 window.location.reload()167 alert("No se guardo correctamente");168 169 170 }171 });172173}174//////////////////////Clientes//////////////////////////////////175function traerInformacionClientes(){176 $.ajax({177 url:"http://129.151.105.241:8080/api/Client/all",178 type:"GET",179 datatype:"JSON",180 success:function(respuesta){181 console.log(respuesta);182 pintarRespuestaClientes(respuesta);183 }184 });185}186187function pintarRespuestaClientes(respuesta){188189 let myTable="<table>";190 myTable+="<tr bgcolor='#186EE6'>";191 myTable+="<td>"+"Id"+"</td>";192 myTable+="<td>"+"Name"+"</td>";193 myTable+="<td>"+"Age"+"</td>";194 myTable+="<td>"+"Email"+"</td>";195 myTable+="<td>"+"Password"+"</td>";196 myTable+="</tr>";197 for(i=0;i<respuesta.length;i++){198 posicion = i + 1;199 myTable+="<tr>";200 myTable+="<td>"+posicion+"</td>";201 myTable+="<td>"+respuesta[i].name+"</td>";202 myTable+="<td>"+respuesta[i].age+"</td>";203 myTable+="<td>"+respuesta[i].email+"</td>";204 myTable+="<td>"+respuesta[i].password+"</td>";205 myTable+="</tr>";206 }207 myTable+="</table>";208 $("#resultado3").html(myTable);209}210211function guardarInformacionClientes(){212 let var4 = {213 email:$("#CLemail").val(),214 password:$("#CLpassword").val(),215 name:$("#CLname").val(),216 age:$("#CLage").val(),217 };218 219 $.ajax({220 type:'POST',221 contentType: "application/json; charset=utf-8",222 dataType: 'JSON',223 data: JSON.stringify(var4),224 225 url:"http://129.151.105.241:8080/api/Client/save",226 227 228 success:function(response) {229 console.log(response);230 console.log("Se guardo correctamente");231 alert("Se guardo correctamente");232 window.location.reload()233 234 },235 236 error: function(jqXHR, textStatus, errorThrown) {237 window.location.reload()238 alert("No se guardo correctamente");239 240 241 }242 });243244}245246247////////////////////////////////////MENSAJE/////////////////////////////////////////248249function traerInformacionMensaje(){250 $.ajax({251 url:"http://129.151.105.241:8080/api/Message/all",252 type:"GET",253 datatype:"JSON",254 success:function(respuesta){255 console.log(respuesta);256 pintarRespuestaMensaje(respuesta);257 }258 });259}260261function pintarRespuestaMensaje(respuesta){262263 let myTable="<table>";264 myTable+="<tr bgcolor='#186EE6'>";265 myTable+="<td>"+"Id"+"</td>";266 myTable+="<td>"+"Mensaje"+"</td>";267 myTable+="<td>"+"Nombre de bicicleta"+"</td>";268 myTable+="</tr>";269 for(i=0;i<respuesta.length;i++){270 posicion = i + 1;271 myTable+="<tr>";272 myTable+="<td>"+posicion+"</td>";273 myTable+="<td>"+respuesta[i].messageText+"</td>";274 myTable+="<td>"+respuesta[i].name+"</td>";275 myTable+="</tr>";276 }277 myTable+="</table>";278 $("#resultado4").html(myTable);279}280281function guardarInformacionMensaje(){282 let var5 = {283 messageText:$("#MmessageText").val(),284 name:$("#Mname").val(),285 };286 287 $.ajax({288 type:'POST',289 contentType: "application/json; charset=utf-8",290 dataType: 'JSON',291 data: JSON.stringify(var5),292 293 url:"http://129.151.105.241:8080/api/Message/save",294295 success:function(response) {296 console.log(response);297 console.log("Se guardo correctamente");298 alert("Se guardo correctamente");299 window.location.reload()300301 },302 303 error: function(jqXHR, textStatus, errorThrown) {304 window.location.reload()305 alert("No se guardo correctamente");306307308 }309 });310311}312313314///////////////////////////////////reservacion/////////////////////////////////////////315316function traerInformacionReservacion(){317 $.ajax({318 url:"http://129.151.105.241:8080/api/Reservation/all",319 type:"GET",320 datatype:"JSON",321 success:function(respuesta){322 console.log(respuesta);323 pintarRespuestaReservaciones(respuesta);324 }325 });326}327328function pintarRespuestaReservaciones(respuesta){329330 let myTable="<table>";331 myTable+="<tr bgcolor='#186EE6'>";332 myTable+="<td>"+"Id"+"</td>";333 myTable+="<td>"+"Fecha de prestamo"+"</td>";334 myTable+="<td>"+"Fecha de devolución"+"</td>";335 myTable+="<td>"+"Estado"+"</td>";336 myTable+="</tr>";337 for(i=0;i<respuesta.length;i++){338 posicion = i + 1;339 myTable+="<tr>";340 myTable+="<td>"+posicion+"</td>";341 myTable+="<td>"+respuesta[i].startDate+"</td>";342 myTable+="<td>"+respuesta[i].devolutionDate+"</td>";343 myTable+="<td>"+respuesta[i].status+"</td>";344 myTable+="</tr>";345 }346 myTable+="</table>";347 $("#resultado5").html(myTable);348}349350function guardarInformacionReservacion(){351 let var6 = {352 startDate:$("#RstartDate").val(),353 bdevolutionDate:$("#RdevolutionDate").val(),354 status:$("#Rstatus").val(),355 356 };357 358 $.ajax({359 type:'POST',360 contentType: "application/json; charset=utf-8",361 dataType: 'JSON',362 data: JSON.stringify(var6),363 364 url:"http://129.151.105.241:8080/api/Reservation/save",365366 success:function(response) {367 console.log(response);368 console.log("Se guardo correctamente");369 alert("Se guardo correctamente");370 window.location.reload()371372 },373 374 error: function(jqXHR, textStatus, errorThrown) {375 window.location.reload()376 alert("No se guardo correctamente");377378379 }380 });381 ...

Full Screen

Full Screen

reportes.js

Source:reportes.js Github

copy

Full Screen

1function traerReporteStatus(){2 console.log("test");3 $.ajax({4 url:"http://168.138.149.45:8080/api/Reservation/report-status",5 type:"GET",6 datatype:"JSON",7 success:function(respuesta){8 console.log(respuesta);9 pintarRespuesta(respuesta);10 }11 });12}13function pintarRespuesta(respuesta){14 let myTable="<table>";15 myTable+="<tr>";16 myTable+="<th>completadas</th>";17 myTable+="<td>"+respuesta.completed+"</td>";18 myTable+="<th>canceladas</th>";19 myTable+="<td>"+respuesta.cancelled+"</td>";20 myTable+="</tr>";21 myTable+="</table>";22 $("#resultadoStatus").html(myTable);23}24function traerReporteDate(){25 var fechaInicio = document.getElementById("RstarDate").value;26 var fechaCierre = document.getElementById("RdevolutionDate").value;27 console.log(fechaInicio);28 console.log(fechaCierre);29 30 $.ajax({31 url:"http://168.138.149.45:8080/api/Reservation/report-dates/"+fechaInicio+"/"+fechaCierre,32 type:"GET",33 datatype:"JSON",34 success:function(respuesta){35 console.log(respuesta);36 pintarRespuestaDate(respuesta);37 }38 });39 }40 function pintarRespuestaDate(respuesta){41 let myTable="<table>";42 myTable+="<tr>";43 44 for(i=0;i<respuesta.length;i++){45 myTable+="<th>total</th>";46 myTable+="<td>"+respuesta[i].devolutionDate+"</td>";47 myTable+="<td>"+respuesta[i].startDate+"</td>";48 myTable+="<td>"+respuesta[i].status+"</td>";49 50 51 myTable+="</tr>";52 }53 myTable+="</table>";54 $("#resultadoDate").html(myTable);55 }56 function traerReporteClientes(){57 $.ajax({58 url:"http://168.138.149.45:8080/api/Reservation/report-clients",59 type:"GET",60 datatype:"JSON",61 success:function(respuesta){62 63 pintarRespuestaClientes(respuesta);64 }65 });66 }67 function pintarRespuestaClientes(respuesta){68 let myTable="<table>";69 myTable+="<tr>";70 71 for(i=0;i<respuesta.length;i++){72 myTable+="<th>total</th>";73 myTable+="<td>"+respuesta[i].total+"</td>";74 myTable+="<td>"+respuesta[i].client.name+"</td>";75 myTable+="<td>"+respuesta[i].client.email+"</td>";76 myTable+="<td>"+respuesta[i].client.age+"</td>";77 78 myTable+="</tr>";79 }80 myTable+="</table>";81 $("#resultadoClientes").html(myTable);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptable = require('wptable');2wptable.mytable();3var wptable = require('wptable');4wptable.mytable1();5var {mytable} = require('wptable');6mytable();7var {mytable1} = require('wptable');8mytable1();9var {mytable} = require('wptable');10mytable();11var {mytable1} = require('wptable');12mytable1();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptable = require('wptable');2wptable.mytable();3var wptable = function() {4 this.mytable = function() {5 console.log('mytable');6 }7}8module.exports = new wptable();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptable = require('wptable');2wptable.mytable();3exports.mytable = function() {4 console.log('mytable');5};6exports.mytable = function() {7 console.log('mytable');8}

Full Screen

Using AI Code Generation

copy

Full Screen

1var mytable = require('wptable');2mytable.mytable();3exports.mytable = function() {4 console.log("mytable method");5};6var mytable = require('wptable');7mytable.mytable();

Full Screen

Using AI Code Generation

copy

Full Screen

1 if (err) {2 console.log(err);3 }4 else {5 console.log(data);6 }7});8 if (err) {9 console.log(err);10 }11 else {12 console.log(data);13 }14});15 if (err) {16 console.log(err);17 }18 else {19 console.log(data);20 }21});22 if (err) {23 console.log(err);24 }25 else {26 console.log(data);27 }28});29 if (err) {30 console.log(err);31 }32 else {33 console.log(data);34 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var table = new wptable('mytable');2table.mytable();3var wptable = function(tableId){4 this.tableId = tableId;5 this.table = document.getElementById(tableId);6 this.mytable = function(){7 }8}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptable = require('wptable');2var mytable = wptable.mytable;3var table = mytable();4var data = [1,2,3];5table.fromArray(data);6console.log(table.toString());7var wptable = (function () {8 var mytable = function () {9 var table = {};10 table.fromArray = function (data) {11 };12 table.toString = function () {13 };14 return table;15 };16 return {17 };18})();19module.exports = wptable;20var wptable = (function () {21 var mytable = function () {22 var table = {};23 table.fromArray = function (data) {24 };25 table.toString = function () {26 };27 return table;28 };29 return {30 };31})();32module.exports = wptable.mytable;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful