more sequelize as usual

This commit is contained in:
Ciro Santilli
2021-09-03 13:49:06 +01:00
parent 1a1237218e
commit 0acd34a1d4
7 changed files with 285 additions and 36 deletions

View File

@@ -0,0 +1,33 @@
#!/usr/bin/env node
const assert = require('assert');
const path = require('path');
const { Sequelize, DataTypes } = require('sequelize');
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: 'tmp.' + path.basename(__filename) + '.sqlite',
});
(async () => {
await sequelize.authenticate();
const IntegerNames = sequelize.define('IntegerNames', {
value: {
type: DataTypes.INTEGER,
},
name: {
type: DataTypes.STRING,
},
});
await IntegerNames.sync({force: true})
await IntegerNames.create({value: 2, name: 'two'});
await IntegerNames.create({value: 3, name: 'three'});
await IntegerNames.create({value: 5, name: 'five'});
const integerName5 = await IntegerNames.findOne({ where: { value: 5 } });
integerName5.increment('value')
// Sequelize updates, but others don't...
console.error(integerName5.value);
const integerName6 = await IntegerNames.findOne({ where: { value: 6 } });
assert.strictEqual(integerName6.name, 'five')
await sequelize.close();
})();