From 501131c97412a6facdf43faf727bb1cb97bc8dbf Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Tue, 6 Sep 2022 23:17:40 +0300 Subject: [PATCH 01/22] Update sscce-sequelize-6.ts --- src/sscce-sequelize-6.ts | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index c90761b96..60e22a352 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -1,10 +1,10 @@ -import { DataTypes, Model } from 'sequelize'; +import { DataTypes, Model, QueryTypes } from 'sequelize'; import { createSequelize6Instance } from '../setup/create-sequelize-instance'; import { expect } from 'chai'; import sinon from 'sinon'; // if your issue is dialect specific, remove the dialects you don't need to test on. -export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', 'postgres', 'postgres-native']); +export const testingOnDialects = new Set(['postgres', 'postgres-native']); // You can delete this file if you don't want your SSCCE to be tested against Sequelize 6 @@ -24,6 +24,11 @@ export async function run() { class Foo extends Model {} Foo.init({ + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true + }, name: DataTypes.TEXT, }, { sequelize, @@ -35,7 +40,34 @@ export async function run() { sequelize.afterBulkSync(() => spy()); await sequelize.sync({ force: true }); expect(spy).to.have.been.called; + + const result1 = await sequelize.query( + ` + INSERT INTO foo (id, name) + VALUES (1, 'steve') + ON CONFLICT DO UPDATE + SET name='pekka' + RETURNING id, name + `, + { + type: QueryTypes.RAW, + } + ); + + const result2 = await sequelize.query( + ` + -- HAX + INSERT INTO foo (id, name) + VALUES (1, 'steve') + ON CONFLICT DO UPDATE + SET name='pekka' + RETURNING id, name + `, + { + type: QueryTypes.RAW, + } + ); - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); + console.log(result1, result2); + expect(result1).to.deep.equal(result2); } From 33a1ed0c1cf7558b88a78b806e5722736c20f4f3 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Tue, 6 Sep 2022 23:23:15 +0300 Subject: [PATCH 02/22] Update sscce-sequelize-6.ts --- src/sscce-sequelize-6.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 60e22a352..463006c5d 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -43,7 +43,7 @@ export async function run() { const result1 = await sequelize.query( ` - INSERT INTO foo (id, name) + INSERT INTO foos (id, name) VALUES (1, 'steve') ON CONFLICT DO UPDATE SET name='pekka' @@ -57,7 +57,7 @@ export async function run() { const result2 = await sequelize.query( ` -- HAX - INSERT INTO foo (id, name) + INSERT INTO foos (id, name) VALUES (1, 'steve') ON CONFLICT DO UPDATE SET name='pekka' From 58bbd42447d628c4a9ad0a0b73ba72b02330eeff Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Tue, 6 Sep 2022 23:26:30 +0300 Subject: [PATCH 03/22] Update sscce-sequelize-6.ts --- src/sscce-sequelize-6.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 463006c5d..1fcf28991 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -43,7 +43,7 @@ export async function run() { const result1 = await sequelize.query( ` - INSERT INTO foos (id, name) + INSERT INTO Foos (id, name) VALUES (1, 'steve') ON CONFLICT DO UPDATE SET name='pekka' @@ -57,7 +57,7 @@ export async function run() { const result2 = await sequelize.query( ` -- HAX - INSERT INTO foos (id, name) + INSERT INTO Foos (id, name) VALUES (1, 'steve') ON CONFLICT DO UPDATE SET name='pekka' From cbf9a3778f9afa6229e3fd7f3191c5d64a37dc58 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Tue, 6 Sep 2022 23:36:58 +0300 Subject: [PATCH 04/22] Update sscce-sequelize-6.ts --- src/sscce-sequelize-6.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 1fcf28991..1d2456ee5 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -43,7 +43,7 @@ export async function run() { const result1 = await sequelize.query( ` - INSERT INTO Foos (id, name) + INSERT INTO "Foos" (id, name) VALUES (1, 'steve') ON CONFLICT DO UPDATE SET name='pekka' @@ -57,7 +57,7 @@ export async function run() { const result2 = await sequelize.query( ` -- HAX - INSERT INTO Foos (id, name) + INSERT INTO "Foos" (id, name) VALUES (1, 'steve') ON CONFLICT DO UPDATE SET name='pekka' From fac312960434b0c9c9ff97577fa0febad61ec420 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Tue, 6 Sep 2022 23:42:46 +0300 Subject: [PATCH 05/22] Update sscce-sequelize-6.ts --- src/sscce-sequelize-6.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 1d2456ee5..134b5cbc8 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -43,9 +43,9 @@ export async function run() { const result1 = await sequelize.query( ` - INSERT INTO "Foos" (id, name) - VALUES (1, 'steve') - ON CONFLICT DO UPDATE + INSERT INTO "Foos" (id, name) + VALUES (1, 'steve') + ON CONFLICT (id) DO UPDATE SET name='pekka' RETURNING id, name `, @@ -57,9 +57,9 @@ export async function run() { const result2 = await sequelize.query( ` -- HAX - INSERT INTO "Foos" (id, name) - VALUES (1, 'steve') - ON CONFLICT DO UPDATE + INSERT INTO "Foos" (id, name) + VALUES (1, 'steve') + ON CONFLICT (id) DO UPDATE SET name='pekka' RETURNING id, name `, From e3c97d3ea9d48207ec1486b3fd4a1619318fad6b Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Thu, 8 Sep 2022 12:13:39 +0300 Subject: [PATCH 06/22] Update sscce-sequelize-6.ts --- src/sscce-sequelize-6.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 134b5cbc8..36724cb9d 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -46,7 +46,7 @@ export async function run() { INSERT INTO "Foos" (id, name) VALUES (1, 'steve') ON CONFLICT (id) DO UPDATE - SET name='pekka' + SET name='steve' RETURNING id, name `, { @@ -60,7 +60,7 @@ export async function run() { INSERT INTO "Foos" (id, name) VALUES (1, 'steve') ON CONFLICT (id) DO UPDATE - SET name='pekka' + SET name='steve' RETURNING id, name `, { From fdbbd9c60ba6d199d77dd9c302f54aabf46e83e2 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Tue, 4 Oct 2022 23:15:08 +0300 Subject: [PATCH 07/22] Update sscce-sequelize-6.ts --- src/sscce-sequelize-6.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 36724cb9d..cf1be194d 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -4,7 +4,7 @@ import { expect } from 'chai'; import sinon from 'sinon'; // if your issue is dialect specific, remove the dialects you don't need to test on. -export const testingOnDialects = new Set(['postgres', 'postgres-native']); +export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', 'postgres', 'postgres-native']); // You can delete this file if you don't want your SSCCE to be tested against Sequelize 6 From fac1a1e446150ceaddd114df66b5438d6d05d9f7 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 17:03:15 +0300 Subject: [PATCH 08/22] Initial test --- src/sscce-sequelize-6.ts | 85 ++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index cf1be194d..f1639390e 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -1,4 +1,4 @@ -import { DataTypes, Model, QueryTypes } from 'sequelize'; +import { DataTypes, Model, QueryTypes, Op } from 'sequelize'; import { createSequelize6Instance } from '../setup/create-sequelize-instance'; import { expect } from 'chai'; import sinon from 'sinon'; @@ -35,39 +35,66 @@ export async function run() { modelName: 'Foo', }); + Bar.init({ + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true + }, + fooId: { + type: DataTypes.INTEGER, + }, + data: DataTypes.TEXT, + }, { + sequelize, + modelName: 'Bar', + }); + + Foo.hasMany(Bar); + Bar.belongsTo(Foo); + // You can use sinon and chai assertions directly in your SSCCE. const spy = sinon.spy(); sequelize.afterBulkSync(() => spy()); await sequelize.sync({ force: true }); expect(spy).to.have.been.called; + + await Promise.all([ + sequelize.query(` + insert into Foo ( + id, name + ) + select + i::integer, + md5(random()::text) + from generate_series(1, 1000000) s(i) + `), + sequelize.query(` + insert into Bar ( + id, fooId, data + ) + select + i::integer, + i::integer, + md5(random()::text) + from generate_series(1, 1000000) s(i) + `), + ]); - const result1 = await sequelize.query( - ` - INSERT INTO "Foos" (id, name) - VALUES (1, 'steve') - ON CONFLICT (id) DO UPDATE - SET name='steve' - RETURNING id, name - `, - { - type: QueryTypes.RAW, - } - ); - - const result2 = await sequelize.query( - ` - -- HAX - INSERT INTO "Foos" (id, name) - VALUES (1, 'steve') - ON CONFLICT (id) DO UPDATE - SET name='steve' - RETURNING id, name - `, - { - type: QueryTypes.RAW, - } - ); + const offset = 0; + const limit = 10; + const result = await Foo.FindAll({ + logging: console.log, + benchmark: true, + distinct: true, + limit, + offset, + include: { + model: Bar, + required: true, + where: { id: { [Op.gt]: 1 } } + }, + }); - console.log(result1, result2); - expect(result1).to.deep.equal(result2); + console.log(result); } From 0eaa2ed2ce866ff497a01b8aabc9cc4381b9fbc8 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 17:05:42 +0300 Subject: [PATCH 09/22] Fix stuff --- src/sscce-sequelize-6.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index f1639390e..ff0d9e495 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -22,7 +22,6 @@ export async function run() { }); class Foo extends Model {} - Foo.init({ id: { type: DataTypes.INTEGER, @@ -35,6 +34,7 @@ export async function run() { modelName: 'Foo', }); + class Bar extends Model {} Bar.init({ id: { type: DataTypes.INTEGER, From 0a686f5f7bac35e24367508be9367ef51586720d Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 17:14:13 +0300 Subject: [PATCH 10/22] Fix stuff --- src/sscce-sequelize-6.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index ff0d9e495..e9dff1236 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -83,7 +83,7 @@ export async function run() { const offset = 0; const limit = 10; - const result = await Foo.FindAll({ + const result = await Foo.findAll({ logging: console.log, benchmark: true, distinct: true, From 8680014a23cf2b21283bacc64b9bbbc264ac497b Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 17:31:23 +0300 Subject: [PATCH 11/22] Distinct not a part of findAll, but is findAndCountAll --- src/sscce-sequelize-6.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index e9dff1236..0d90a3908 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -86,7 +86,7 @@ export async function run() { const result = await Foo.findAll({ logging: console.log, benchmark: true, - distinct: true, + // distinct: true, limit, offset, include: { From efcaf39781ddfecb6d97ae2df35c3dfd8e907a49 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 17:35:36 +0300 Subject: [PATCH 12/22] lowercased --- src/sscce-sequelize-6.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 0d90a3908..6c4f0498d 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -31,7 +31,7 @@ export async function run() { name: DataTypes.TEXT, }, { sequelize, - modelName: 'Foo', + modelName: 'foo', }); class Bar extends Model {} @@ -47,7 +47,7 @@ export async function run() { data: DataTypes.TEXT, }, { sequelize, - modelName: 'Bar', + modelName: 'bar', }); Foo.hasMany(Bar); @@ -61,7 +61,7 @@ export async function run() { await Promise.all([ sequelize.query(` - insert into Foo ( + insert into foo ( id, name ) select @@ -70,7 +70,7 @@ export async function run() { from generate_series(1, 1000000) s(i) `), sequelize.query(` - insert into Bar ( + insert into bar ( id, fooId, data ) select From 364f4e5ced4915e5a5e3da44c024efc7dd640a00 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 17:38:25 +0300 Subject: [PATCH 13/22] plural, I hate this convention --- src/sscce-sequelize-6.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 6c4f0498d..f80cefc05 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -61,7 +61,7 @@ export async function run() { await Promise.all([ sequelize.query(` - insert into foo ( + insert into foos ( id, name ) select @@ -70,7 +70,7 @@ export async function run() { from generate_series(1, 1000000) s(i) `), sequelize.query(` - insert into bar ( + insert into bars ( id, fooId, data ) select From 89a253604cd52e04856938aba3399f8277da5307 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 17:41:23 +0300 Subject: [PATCH 14/22] Lets just get this show on the road already --- src/sscce-sequelize-6.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index f80cefc05..213506515 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -32,6 +32,7 @@ export async function run() { }, { sequelize, modelName: 'foo', + underscored: true, }); class Bar extends Model {} @@ -48,6 +49,7 @@ export async function run() { }, { sequelize, modelName: 'bar', + underscored: true, }); Foo.hasMany(Bar); @@ -71,7 +73,7 @@ export async function run() { `), sequelize.query(` insert into bars ( - id, fooId, data + id, foo_id, data ) select i::integer, From b405e960ffd15c6804766488870dbad19e7e055d Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 17:53:08 +0300 Subject: [PATCH 15/22] Full on --- src/sscce-sequelize-6.ts | 73 ++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 213506515..1ccebdb18 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -69,7 +69,7 @@ export async function run() { select i::integer, md5(random()::text) - from generate_series(1, 1000000) s(i) + from generate_series(1, 10000000) s(i) `), sequelize.query(` insert into bars ( @@ -79,24 +79,63 @@ export async function run() { i::integer, i::integer, md5(random()::text) - from generate_series(1, 1000000) s(i) + from generate_series(1, 10000000) s(i) `), ]); - const offset = 0; - const limit = 10; - const result = await Foo.findAll({ - logging: console.log, - benchmark: true, - // distinct: true, - limit, - offset, - include: { - model: Bar, - required: true, - where: { id: { [Op.gt]: 1 } } - }, - }); + { + console.log("TEST 1") + const offset = 0; + const limit = 10; + const result = await Foo.findAll({ + logging: console.log, + benchmark: true, + // distinct: true, + limit, + offset, + include: { + model: Bar, + required: true, + where: { id: { [Op.gt]: 1 } } + }, + }); + + console.log(result); + } + + { + console.log("TEST 2") + const result = await sequelize.query( + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" + FROM (SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE ( SELECT "foo_id" FROM "bars" AS "bars" WHERE ("bars"."id" > 1 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) IS NOT NULL + LIMIT 10 OFFSET 0) + AS "foo" + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 1;`, + { + logging: console.log, + benchmark: true, + } + ); + + console.log(result); + } + + { + console.log("TEST 3") + const result = await sequelize.query( + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" + FROM (SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE EXISTS ( SELECT "foo_id" FROM "bars" AS "bars" WHERE ("bars"."id" > 1 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) + LIMIT 10 OFFSET 0) + AS "foo" + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 1;`, + { + logging: console.log, + benchmark: true, + } + ); - console.log(result); + console.log(result); + } } From 51c3243942c57b990b386b92614e417647ea4138 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 18:22:21 +0300 Subject: [PATCH 16/22] Foobar --- src/sscce-sequelize-6.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 1ccebdb18..d75ef2823 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -44,6 +44,7 @@ export async function run() { }, fooId: { type: DataTypes.INTEGER, + references: { model: 'foos' }, }, data: DataTypes.TEXT, }, { @@ -90,17 +91,15 @@ export async function run() { const result = await Foo.findAll({ logging: console.log, benchmark: true, - // distinct: true, limit, offset, + where: { id: { [Op.between]: [345, 5678] } }, include: { model: Bar, required: true, - where: { id: { [Op.gt]: 1 } } + where: { id: { [Op.gt]: 123 } } }, }); - - console.log(result); } { @@ -108,17 +107,15 @@ export async function run() { const result = await sequelize.query( `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM (SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" - WHERE ( SELECT "foo_id" FROM "bars" AS "bars" WHERE ("bars"."id" > 1 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) IS NOT NULL + WHERE ( SELECT "foo_id" FROM "bars" AS "bars" WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) IS NOT NULL LIMIT 10 OFFSET 0) AS "foo" - INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 1;`, + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, { logging: console.log, benchmark: true, } ); - - console.log(result); } { @@ -126,16 +123,14 @@ export async function run() { const result = await sequelize.query( `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM (SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" - WHERE EXISTS ( SELECT "foo_id" FROM "bars" AS "bars" WHERE ("bars"."id" > 1 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) + WHERE EXISTS ( SELECT "foo_id" FROM "bars" AS "bars" WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) LIMIT 10 OFFSET 0) AS "foo" - INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 1;`, + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, { logging: console.log, benchmark: true, } ); - - console.log(result); } } From d160d7499952259215a370965c3053a738c38332 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 18:33:49 +0300 Subject: [PATCH 17/22] Craete more clear case --- src/sscce-sequelize-6.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index d75ef2823..b39dab29c 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -105,11 +105,15 @@ export async function run() { { console.log("TEST 2") const result = await sequelize.query( - `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" - FROM (SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" - WHERE ( SELECT "foo_id" FROM "bars" AS "bars" WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) IS NOT NULL - LIMIT 10 OFFSET 0) - AS "foo" + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( + SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE "foo"."id" BETWEEN 345 AND 5678 AND + ( + SELECT "foo_id" FROM "bars" AS "bars" + WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + ) IS NOT NULL + LIMIT 10 OFFSET 0 + ) AS "foo" INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, { logging: console.log, @@ -121,11 +125,15 @@ export async function run() { { console.log("TEST 3") const result = await sequelize.query( - `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" - FROM (SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" - WHERE EXISTS ( SELECT "foo_id" FROM "bars" AS "bars" WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) - LIMIT 10 OFFSET 0) - AS "foo" + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( + SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE "foo"."id" BETWEEN 345 AND 5678 AND + EXISTS ( + SELECT "foo_id" FROM "bars" AS "bars" + WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + ) + LIMIT 10 OFFSET 0 + ) AS "foo" INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, { logging: console.log, From b2cb97ca7c1f8d97043ab2241e1708391ea12f95 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 18:50:30 +0300 Subject: [PATCH 18/22] Maybe we have special case? --- src/sscce-sequelize-6.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index b39dab29c..d6f2f1d4f 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -97,7 +97,7 @@ export async function run() { include: { model: Bar, required: true, - where: { id: { [Op.gt]: 123 } } + where: { id: { [Op.between]: [2345, 8678] } } }, }); } @@ -110,11 +110,11 @@ export async function run() { WHERE "foo"."id" BETWEEN 345 AND 5678 AND ( SELECT "foo_id" FROM "bars" AS "bars" - WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + WHERE ("bars"."id" BETWEEN 2345 AND 8678 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) IS NOT NULL LIMIT 10 OFFSET 0 ) AS "foo" - INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" BETWEEN 2345 AND 8678;`, { logging: console.log, benchmark: true, @@ -130,11 +130,11 @@ export async function run() { WHERE "foo"."id" BETWEEN 345 AND 5678 AND EXISTS ( SELECT "foo_id" FROM "bars" AS "bars" - WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + WHERE ("bars"."id" BETWEEN 2345 AND 8678 AND "bars"."foo_id" = "foo"."id") LIMIT 1 ) LIMIT 10 OFFSET 0 ) AS "foo" - INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" BETWEEN 2345 AND 8678;`, { logging: console.log, benchmark: true, From d754b42eb18d22acb21a35137947fb1707b8703a Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 19:00:54 +0300 Subject: [PATCH 19/22] Maybe its our postgres version? --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c45963caf..c6b7b5e07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,14 +31,14 @@ jobs: strategy: fail-fast: false matrix: - postgres-version: [9.5, 10] # Does not work with 12 + postgres-version: [9.5, 10, 11, 12, 16] native: [true, false] node: [10, 14, 16] name: Postgres ${{ matrix.postgres-version }}${{ matrix.native && ' (native)' || '' }} (sequelize 6 & 7, node ${{ matrix.node }}) runs-on: ubuntu-latest services: postgres: - image: sushantdhiman/postgres:${{ matrix.postgres-version }} + image: postgres:${{ matrix.postgres-version }} env: POSTGRES_USER: sequelize_test POSTGRES_DB: sequelize_test From 96ea2429938944efbf30c0be75650996314aff0d Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 20:46:55 +0300 Subject: [PATCH 20/22] Improvements, show both test cases --- .github/workflows/ci.yml | 8 ++--- src/sscce-sequelize-6.ts | 64 ++++++++++++++++++++++++++++++++++++++-- src/sscce-sequelize-7.ts | 41 ------------------------- 3 files changed, 65 insertions(+), 48 deletions(-) delete mode 100644 src/sscce-sequelize-7.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6b7b5e07..e3969a809 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: # node 10 is the minimum supported version for Sequelize 6 # node 14 is the minimum supported version for Sequelize 7 # node 16 is latest LTS (to keep updated) - node: [10, 14, 16] + node: [10] name: SQLite (sequelize 6 & 7, node ${{ matrix.node }}) runs-on: ubuntu-latest env: @@ -33,7 +33,7 @@ jobs: matrix: postgres-version: [9.5, 10, 11, 12, 16] native: [true, false] - node: [10, 14, 16] + node: [10] name: Postgres ${{ matrix.postgres-version }}${{ matrix.native && ' (native)' || '' }} (sequelize 6 & 7, node ${{ matrix.node }}) runs-on: ubuntu-latest services: @@ -61,7 +61,7 @@ jobs: strategy: fail-fast: false matrix: - node: [10, 14, 16] + node: [10] db: - '{ name: "MySQL 5.7", image: "mysql:5.7", dialect: "mysql" }' - '{ name: "MariaDB 10.3", image: "mariadb:10.3", dialect: "mariadb" }' @@ -93,7 +93,7 @@ jobs: strategy: fail-fast: false matrix: - node: [10, 14, 16] + node: [10] mssql-version: [2017, 2019] name: MSSQL ${{ matrix.mssql-version }} (sequelize 6 & 7, node ${{ matrix.node }}) runs-on: ubuntu-latest diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index d6f2f1d4f..07a0ab65e 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -85,7 +85,7 @@ export async function run() { ]); { - console.log("TEST 1") + console.log("TEST 1.1") const offset = 0; const limit = 10; const result = await Foo.findAll({ @@ -103,7 +103,7 @@ export async function run() { } { - console.log("TEST 2") + console.log("TEST 1.2") const result = await sequelize.query( `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" @@ -123,7 +123,7 @@ export async function run() { } { - console.log("TEST 3") + console.log("TEST 1.3") const result = await sequelize.query( `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" @@ -141,4 +141,62 @@ export async function run() { } ); } + + { + console.log("TEST 1.1") + const offset = 0; + const limit = 10; + const result = await Foo.findAll({ + logging: console.log, + benchmark: true, + limit, + offset, + where: { id: { [Op.between]: [345, 5678] } }, + include: { + model: Bar, + required: true, + where: { id: { [Op.gt]: 123 } } + }, + }); + } + + { + console.log("TEST 2.2") + const result = await sequelize.query( + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( + SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE "foo"."id" BETWEEN 345 AND 5678 AND + ( + SELECT "foo_id" FROM "bars" AS "bars" + WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + ) IS NOT NULL + LIMIT 10 OFFSET 0 + ) AS "foo" + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, + { + logging: console.log, + benchmark: true, + } + ); + } + + { + console.log("TEST 2.3") + const result = await sequelize.query( + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( + SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE "foo"."id" BETWEEN 345 AND 5678 AND + EXISTS ( + SELECT "foo_id" FROM "bars" AS "bars" + WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + ) + LIMIT 10 OFFSET 0 + ) AS "foo" + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, + { + logging: console.log, + benchmark: true, + } + ); + } } diff --git a/src/sscce-sequelize-7.ts b/src/sscce-sequelize-7.ts deleted file mode 100644 index 861b9fdea..000000000 --- a/src/sscce-sequelize-7.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { DataTypes, Model } from '@sequelize/core'; -import { createSequelize7Instance } from '../setup/create-sequelize-instance'; -import { expect } from 'chai'; -import sinon from 'sinon'; - -// if your issue is dialect specific, remove the dialects you don't need to test on. -export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', 'postgres', 'postgres-native']); - -// You can delete this file if you don't want your SSCCE to be tested against Sequelize 7 - -// Your SSCCE goes inside this function. -export async function run() { - // This function should be used instead of `new Sequelize()`. - // It applies the config for your SSCCE to work on CI. - const sequelize = createSequelize7Instance({ - logQueryParameters: true, - benchmark: true, - define: { - // For less clutter in the SSCCE - timestamps: false, - }, - }); - - class Foo extends Model {} - - Foo.init({ - name: DataTypes.TEXT, - }, { - sequelize, - modelName: 'Foo', - }); - - // You can use sinon and chai assertions directly in your SSCCE. - const spy = sinon.spy(); - sequelize.afterBulkSync(() => spy()); - await sequelize.sync({ force: true }); - expect(spy).to.have.been.called; - - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); -} From e8d1b586632d61ceda4bb16b66941cb5aca096bf Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 21:18:11 +0300 Subject: [PATCH 21/22] add one more test case --- src/sscce-sequelize-6.ts | 116 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 07a0ab65e..0a2b7c228 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -199,4 +199,120 @@ export async function run() { } ); } + + { + console.log("TEST 3.1") + const offset = 0; + const limit = 10; + const result = await Foo.findAll({ + logging: console.log, + benchmark: true, + limit, + offset, + where: { id: { [Op.gt]: 123 } }, + include: { + model: Bar, + required: true, + where: { id: { [Op.gt]: 123 } } + }, + }); + } + + { + console.log("TEST 3.2") + const result = await sequelize.query( + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( + SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE "foo"."id" > 123 AND + ( + SELECT "foo_id" FROM "bars" AS "bars" + WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + ) IS NOT NULL + LIMIT 10 OFFSET 0 + ) AS "foo" + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, + { + logging: console.log, + benchmark: true, + } + ); + } + + { + console.log("TEST 3.3") + const result = await sequelize.query( + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( + SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE "foo"."id" > 123 AND + EXISTS ( + SELECT "foo_id" FROM "bars" AS "bars" + WHERE ("bars"."id" > 123 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + ) + LIMIT 10 OFFSET 0 + ) AS "foo" + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" > 123;`, + { + logging: console.log, + benchmark: true, + } + ); + } + + { + console.log("TEST 4.1") + const offset = 0; + const limit = 10; + const result = await Foo.findAll({ + logging: console.log, + benchmark: true, + limit, + offset, + where: { id: { [Op.gt]: 123 } }, + include: { + model: Bar, + required: true, + where: { id: { [Op.between]: [345, 5678] } } + }, + }); + } + + { + console.log("TEST 4.2") + const result = await sequelize.query( + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( + SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE "foo"."id" > 123 AND + ( + SELECT "foo_id" FROM "bars" AS "bars" + WHERE ("bars"."id" BETWEEN 345 AND 5678 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + ) IS NOT NULL + LIMIT 10 OFFSET 0 + ) AS "foo" + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" BETWEEN 345 AND 5678;`, + { + logging: console.log, + benchmark: true, + } + ); + } + + { + console.log("TEST 4.3") + const result = await sequelize.query( + `SELECT "foo".*, "bars"."id" AS "bars.id", "bars"."foo_id" AS "bars.fooId", "bars"."data" AS "bars.data" FROM ( + SELECT "foo"."id", "foo"."name" FROM "foos" AS "foo" + WHERE "foo"."id" > 123 AND + EXISTS ( + SELECT "foo_id" FROM "bars" AS "bars" + WHERE ("bars"."id" BETWEEN 345 AND 5678 AND "bars"."foo_id" = "foo"."id") LIMIT 1 + ) + LIMIT 10 OFFSET 0 + ) AS "foo" + INNER JOIN "bars" AS "bars" ON "foo"."id" = "bars"."foo_id" AND "bars"."id" BETWEEN 345 AND 5678;`, + { + logging: console.log, + benchmark: true, + } + ); + } } From 10015bb84d45be55c740162428cb2f697470fdd5 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 21:32:52 +0300 Subject: [PATCH 22/22] Fix typo --- src/sscce-sequelize-6.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 0a2b7c228..3e0993557 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -143,7 +143,7 @@ export async function run() { } { - console.log("TEST 1.1") + console.log("TEST 2.1") const offset = 0; const limit = 10; const result = await Foo.findAll({