From fac1a1e446150ceaddd114df66b5438d6d05d9f7 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sun, 24 Sep 2023 17:03:15 +0300 Subject: [PATCH] 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); }