From 4c64a35a50287129262fcca685da29c324f0a6a2 Mon Sep 17 00:00:00 2001 From: David Tchekachev Date: Thu, 16 Nov 2023 02:22:06 +0100 Subject: [PATCH] init: setup basic SSCCE --- src/sscce-sequelize-6.ts | 36 +++++++++++++++++++++++++++-------- src/sscce-sequelize-7.ts | 41 ---------------------------------------- 2 files changed, 28 insertions(+), 49 deletions(-) delete mode 100644 src/sscce-sequelize-7.ts diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index c90761b96..adcf3ea56 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -7,7 +7,17 @@ import sinon from 'sinon'; 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 +interface FooAttributes { + createdAt: Date; + active: boolean; + completedAt: Date; + time: number; +} +interface FooCreationAttributes { + createdAt: Date; + active: boolean; +} // Your SSCCE goes inside this function. export async function run() { // This function should be used instead of `new Sequelize()`. @@ -21,21 +31,31 @@ export async function run() { }, }); - class Foo extends Model {} + class Foo extends Model { + createdAt!: Date; + active!: boolean; + completedAt: Date|null = null; + time?: number; + } Foo.init({ - name: DataTypes.TEXT, + createdAt: DataTypes.DATE, + active: DataTypes.BOOLEAN, + completedAt: DataTypes.DATE, + time: { + type: DataTypes.INTEGER, + get() { + return Math.trunc(((this.completedAt ?? new Date()).getTime() - this.createdAt.getTime()) / 1000); + } + } }, { 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); + await Foo.create({ createdAt: new Date(), active: true }); + + await Foo.update({ completedAt: sequelize.literal('createdAt') }, { where: { active: 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); -}