-
Notifications
You must be signed in to change notification settings - Fork 1
/
sequelize.ts
68 lines (60 loc) · 1.2 KB
/
sequelize.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Options, Sequelize, DataTypes, Model } from 'sequelize';
import { postgresConfig } from '../config';
const { max, ...config } = postgresConfig;
const options: Options = {
dialect: 'postgres',
host: config.host,
username: config.user,
password: config.password,
port: config.port,
database: config.database,
pool: {
min: 0,
max,
},
logging: false,
};
if (!max) {
delete options.pool;
}
const sequelize = new Sequelize(options);
class User extends Model {}
User.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
username: {
type: DataTypes.STRING,
},
email: {
type: DataTypes.STRING,
},
password: {
type: DataTypes.STRING,
},
name: {
type: DataTypes.STRING,
},
createdAt: {
type: DataTypes.DATE,
},
updatedAt: {
type: DataTypes.DATE,
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true,
},
},
{ sequelize, underscored: true, tableName: 'users' }
);
export const sequelizePostgresGetUser = (id: number) =>
User.findOne({
where: {
id,
},
});
export const sequelizeClose = () => sequelize.close();