Skip to content

Commit

Permalink
init: setup basic SSCCE
Browse files Browse the repository at this point in the history
  • Loading branch information
Tchekda committed Nov 16, 2023
1 parent a8ce25f commit 4c64a35
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 49 deletions.
36 changes: 28 additions & 8 deletions src/sscce-sequelize-6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand All @@ -21,21 +31,31 @@ export async function run() {
},
});

class Foo extends Model {}
class Foo extends Model<FooAttributes, FooCreationAttributes> {
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 } });
}
41 changes: 0 additions & 41 deletions src/sscce-sequelize-7.ts

This file was deleted.

0 comments on commit 4c64a35

Please sign in to comment.