model.ts
776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Association, HasOne, Model, Sequelize } from 'sequelize';
class MyModel extends Model {
public num: number;
public static associations: {
other: HasOne;
};
public static async customStuff() {
return this.sequelize!.query('select 1');
}
}
class OtherModel extends Model {}
const assoc: Association = MyModel.associations.other;
const Instance: MyModel = new MyModel({ int: 10 });
const num: number = Instance.get('num');
MyModel.findOne({
include: [
{ model: OtherModel, paranoid: true }
]
});
const sequelize = new Sequelize('mysql://user:user@localhost:3306/mydb');
MyModel.init({}, {
indexes: [
{
fields: ['foo'],
using: 'gin',
operator: 'jsonb_path_ops',
}
],
sequelize,
tableName: 'my_model'
});