1.65.7 • Published 2 months ago
@biorate/sequelize v1.65.7
Sequelize
Sequelize ORM connector
Examples:
import { join } from 'path';
import { tmpdir } from 'os';
import { container, Core, inject, Types } from '@biorate/inversion';
import { Config, IConfig } from '@biorate/config';
import {
ISequelizeConnector,
SequelizeConnector as BaseSequelizeConnector,
} from '@biorate/sequelize';
import { Table, Column, Model, DataType } from '@biorate/sequelize';
const connectionName = 'db';
// Create model
@Table({
tableName: 'test',
timestamps: false,
})
export class TestModel extends Model {
@Column({ type: DataType.CHAR, primaryKey: true })
key: string;
@Column(DataType.INTEGER)
value: number;
}
// Assign models with sequelize connector
class SequelizeConnector extends BaseSequelizeConnector {
protected readonly models = { [connectionName]: [TestModel] };
}
// Create Root class
export class Root extends Core() {
@inject(SequelizeConnector) public connector: ISequelizeConnector;
}
// Bind dependencies
container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container.bind<ISequelizeConnector>(SequelizeConnector).toSelf().inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();
// Merge config
container.get<IConfig>(Types.Config).merge({
Sequelize: [
{
name: connectionName,
options: {
logging: false,
dialect: 'sqlite',
storage: join(tmpdir(), 'sqlite-test.db'),
},
},
],
});
// Example
(async () => {
await container.get<Root>(Root).$run();
// Drop table if exists
await TestModel.drop();
// Create table
await TestModel.sync();
// Create model item
await TestModel.create({ key: 'test', value: 1 });
// Create find model item by key
const data = await TestModel.findOne({ where: { key: 'test' } });
console.log(data.toJSON()); // { key: 'test', value: 1 }
})();
Learn
- Documentation can be found here - docs.
Release History
See the CHANGELOG
License
Copyright (c) 2021-present Leonid Levkin (llevkin)
1.65.7
2 months ago
1.65.5
2 months ago
1.65.6
2 months ago
1.65.4
2 months ago
1.64.0
2 months ago
1.54.0
4 months ago
1.38.2
9 months ago
1.38.3
9 months ago
1.38.1
9 months ago
1.38.4
9 months ago
1.42.2
8 months ago
1.42.1
9 months ago
1.30.12
10 months ago
1.29.0
1 year ago
1.28.1
1 year ago
1.28.0
1 year ago
1.26.0
1 year ago
1.27.2
1 year ago
1.27.0
1 year ago
1.27.1
1 year ago
1.24.0
1 year ago
1.20.1
2 years ago
1.11.2
2 years ago
1.7.1
2 years ago
1.7.0
2 years ago
1.6.0
2 years ago
1.0.0
2 years ago
0.30.11
2 years ago
0.30.14
2 years ago
0.30.2
2 years ago
0.30.17
2 years ago
0.30.18
2 years ago
0.30.0
2 years ago
0.30.19
2 years ago
1.4.0
2 years ago
1.2.2
2 years ago
0.30.9
2 years ago
0.30.7
2 years ago
0.30.6
2 years ago
0.30.5
2 years ago
0.29.1
2 years ago
0.28.3
2 years ago
0.28.0
2 years ago
0.27.3
2 years ago
0.27.0
2 years ago