Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sscce-sequelize-6.ts #241

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
45 changes: 42 additions & 3 deletions src/sscce-sequelize-6.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataTypes, Model } from 'sequelize';
import { DataTypes, Model, Op } from 'sequelize';
import { createSequelize6Instance } from '../setup/create-sequelize-instance';
import { expect } from 'chai';
import sinon from 'sinon';
Expand All @@ -25,6 +25,7 @@ export async function run() {

Foo.init({
name: DataTypes.TEXT,
schoolInfo: DataTypes.JSON
}, {
sequelize,
modelName: 'Foo',
Expand All @@ -36,6 +37,44 @@ export async function run() {
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);
console.log(await Foo.bulkCreate([{
name: 'Emma', schoolInfo: {
numCode: 'No.1', isRegister: false
}
}, {
name: 'Lily', schoolInfo: {
numCode: 'No.2', isRegister: true
}
}, {
name: 'Jennifer', schoolInfo: {
numCode: 'No.3'
}
}]));
expect(await Foo.count()).to.equal(3);

// error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''null'' at line 1
let foos = await Foo.findAll({
where: {
schoolInfo: {
isRegister: {
[Op.is]: null
}
}
}
});
expect(foos.length).to.equal(1)

foos = await Foo.findAll({
where: {
schoolInfo: {
isRegister: {
[Op.not]: true
}
}
}
});
// fail Expected: 2 Received: 1
expect(foos.length).to.equal(2);


}