Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions src/sscce-sequelize-6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,40 @@ export async function run() {
},
});

class Foo extends Model {}
class FooModel extends Model {}

Foo.init({
name: DataTypes.TEXT,
}, {
sequelize,
modelName: 'Foo',
});
FooModel.init(
{
id: {type: DataTypes.STRING, primaryKey: true}
},
{sequelize, modelName: 'FooModel'}
);

await FooModel.sync();

// 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;
class OtherModel extends Model {}

OtherModel.init(
{
id: {type: DataTypes.STRING, primaryKey: true},
modelId: {type: DataTypes.STRING, field: 'model_id'},
modelType: {type: DataTypes.ENUM('foo', 'bar'), field: 'model_type'}
},
{sequelize, modelName: 'OtherModel'}
);

console.log(await Foo.create({ name: 'TS foo' }));
expect(await Foo.count()).to.equal(1);
await OtherModel.sync();

FooModel.hasMany(OtherModel, {
foreignKey: 'modelId',
scope: {
modelType: 'foo'
}
});

await FooModel.findAndCountAll({
include: {
model: OtherModel
}
});
}
47 changes: 33 additions & 14 deletions src/sscce-sequelize-7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,40 @@ export async function run() {
},
});

class Foo extends Model {}
class FooModel extends Model {}

Foo.init({
name: DataTypes.TEXT,
}, {
sequelize,
modelName: 'Foo',
});
FooModel.init(
{
id: {type: DataTypes.STRING, primaryKey: true}
},
{sequelize, modelName: 'FooModel'}
);

await FooModel.sync();

// 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;
class OtherModel extends Model {}

OtherModel.init(
{
id: {type: DataTypes.STRING, primaryKey: true},
modelId: {type: DataTypes.STRING, field: 'model_id'},
modelType: {type: DataTypes.ENUM('foo', 'bar'), field: 'model_type'}
},
{sequelize, modelName: 'OtherModel'}
);

console.log(await Foo.create({ name: 'TS foo' }));
expect(await Foo.count()).to.equal(1);
await OtherModel.sync();

FooModel.hasMany(OtherModel, {
foreignKey: 'modelId',
scope: {
modelType: 'foo'
}
});

await FooModel.findAndCountAll({
include: {
model: OtherModel
}
});
}