1.120.0 • Published 7 months ago

@biorate/sequelize v1.120.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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

MIT

Copyright (c) 2021-present Leonid Levkin (llevkin)

1.96.0

11 months ago

1.90.0

12 months ago

1.120.0

7 months ago

1.105.2

9 months ago

1.95.1

11 months ago

1.91.5

12 months ago

1.95.0

11 months ago

1.91.4

12 months ago

1.93.1

11 months ago

1.91.3

12 months ago

1.93.0

11 months ago

1.91.2

12 months ago

1.91.1

12 months ago

1.91.0

12 months ago

1.100.0

9 months ago

1.104.0

9 months ago

1.102.0

9 months ago

1.102.1

9 months ago

1.87.4

1 year ago

1.79.0

1 year ago

1.74.1

1 year ago

1.76.3

1 year ago

1.65.7

2 years ago

1.65.5

2 years ago

1.65.6

2 years ago

1.65.4

2 years ago

1.64.0

2 years ago

1.54.0

2 years ago

1.38.2

2 years ago

1.38.3

2 years ago

1.38.1

2 years ago

1.38.4

2 years ago

1.42.2

2 years ago

1.42.1

2 years ago

1.30.12

2 years ago

1.29.0

3 years ago

1.28.1

3 years ago

1.28.0

3 years ago

1.26.0

3 years ago

1.27.2

3 years ago

1.27.0

3 years ago

1.27.1

3 years ago

1.24.0

3 years ago

1.20.1

3 years ago

1.11.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.0.0

3 years ago

0.30.11

3 years ago

0.30.14

3 years ago

0.30.2

3 years ago

0.30.17

3 years ago

0.30.18

3 years ago

0.30.0

3 years ago

0.30.19

3 years ago

1.4.0

3 years ago

1.2.2

3 years ago

0.30.9

3 years ago

0.30.7

3 years ago

0.30.6

3 years ago

0.30.5

3 years ago

0.29.1

3 years ago

0.28.3

4 years ago

0.28.0

4 years ago

0.27.3

4 years ago

0.27.0

4 years ago