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
87 changes: 76 additions & 11 deletions src/sscce-sequelize-6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ 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 6

// Your SSCCE goes inside this function.
export async function run() {
// This function should be used instead of `new Sequelize()`.
Expand All @@ -18,24 +16,91 @@ export async function run() {
define: {
// For less clutter in the SSCCE
timestamps: false,
underscored: true
},
});

class Foo extends Model {}

Foo.init({
class Parents extends Model {};
Parents.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
name: DataTypes.TEXT,
}, {
sequelize,
modelName: 'Foo',
});
},
{sequelize},
);

class Children extends Model {};
Children.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
parentId: {
type: DataTypes.INTEGER,
references: {
model: Parents,
key: 'id'
}
}
},
{sequelize}

)

class GrandChildren extends Model {};
GrandChildren.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
parentId: {
type: DataTypes.INTEGER,
references: {
model: Children,
key: 'id'
}
}
},
{sequelize}
);

Parents.hasMany(Children)
Children.belongsTo(Parents)
Children.hasMany(GrandChildren)
GrandChildren.belongsTo(Children)

// 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);
const created = await Parents.create()
const {rows, count} = await Parents.findAndCountAll({
include: {
model: Children,
required: false,
include: [{
model: GrandChildren,
required: true,
}]
},
limit: 1
})

console.log(rows);
expect(created).to.not.be.undefined;
expect(created).to.not.be.null;
expect(count).to.equal(1);
expect(rows.length).to.equal(1);
}


95 changes: 80 additions & 15 deletions src/sscce-sequelize-7.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from '@sequelize/core';
import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model, DialectOptions } from '@sequelize/core';
import { Attribute, NotNull } from '@sequelize/core/decorators-legacy';
import { createSequelize7Instance } from '../dev/create-sequelize-instance';
import { expect } from 'chai';
Expand All @@ -13,31 +13,96 @@ export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb',
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,
underscored: true
},
});

class Foo extends Model<InferAttributes<Foo>, InferCreationAttributes<Foo>> {
declare id: CreationOptional<number>;
class Parents extends Model {};
Parents.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
name: DataTypes.TEXT,
},
{sequelize},
);

class Children extends Model {};
Children.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
parentId: {
type: DataTypes.INTEGER,
references: {
model: Parents,
key: 'id'
}
}
},
{sequelize}

)

class GrandChildren extends Model {};
GrandChildren.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
parentId: {
type: DataTypes.INTEGER,
references: {
model: Children,
key: 'id'
}
}
},
{sequelize}
);

@Attribute(DataTypes.TEXT)
@NotNull
declare name: string;
}
Parents.hasMany(Children)
Children.belongsTo(Parents)
Children.hasMany(GrandChildren)
GrandChildren.belongsTo(Children)

sequelize.addModels([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;

// 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;
const created = await Parents.create()
const {rows, count} = await Parents.findAndCountAll({
include: {
model: Children,
required: false,
include: [{
model: GrandChildren,
required: true,
}]
},
limit: 1
})

console.log(await Foo.create({ name: 'TS foo' }));
expect(await Foo.count()).to.equal(1);
console.log(rows);
expect(created).to.not.be.undefined;
expect(created).to.not.be.null;
expect(count).to.equal(1);
expect(rows.length).to.equal(1);
}
Loading