unoffical wafrn mirror
wafrn.net
atproto
social-network
activitypub
1import { logger } from '../utils/logger.js'
2import { Sequelize } from 'sequelize-typescript'
3import { beforeFindAfterExpandIncludeAll, afterFind } from './hierarchy/hierarchy.js'
4import { completeEnvironment } from '../utils/backendOptions.js'
5
6const sequelize = new Sequelize(completeEnvironment.databaseConnectionString, {
7 benchmark: true,
8 logging: (sql: any, time?: number) => {
9 if (completeEnvironment.logSQLQueries) {
10 logger.trace({ duration: time, query: sql })
11 } else if (time && time > 2500) {
12 logger.warn({ duration: time, query: sql })
13 }
14 },
15 dialectOptions: {
16 connectTimeout: 10000
17 },
18 pool: {
19 max: 40,
20 min: 2,
21 acquire: 30000,
22 idle: 5000
23 },
24 retry: {
25 max: completeEnvironment.prod ? 3 : 0,
26 backoffBase: 100, // Initial backoff duration in ms. Default: 100,
27 backoffExponent: 1.1 // Exponent to increase backoff each try. Default: 1.1
28 }
29})
30
31sequelize.addHook('beforeFindAfterExpandIncludeAll', 'hierarchyPreCheck', beforeFindAfterExpandIncludeAll)
32sequelize.addHook('afterFind', 'hierarchyPostProcess', afterFind)
33
34export { sequelize, Sequelize }