/
config.ts
34 lines (30 loc) 路 866 Bytes
/
config.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
import knex from 'knex'
import { faker } from '@faker-js/faker'
import type { UsableLocale } from '@faker-js/faker'
import type { Knex } from 'knex'
import type { FactorioConfig } from './contracts'
/**
* Global configuration
*/
export const factorioConfig = {
knex: null as Knex | null,
casing: {
insert: 'snake',
return: 'camel',
} as NonNullable<FactorioConfig['casing']>,
}
/**
* Define the Factorio configuration.
*
* Returns a function that can be used to clean up the connection.
*/
export const defineFactorioConfig = (options: FactorioConfig & { locale?: UsableLocale }) => {
faker.locale = options.locale || faker.locale
factorioConfig.knex = knex(options.database)
factorioConfig.casing = options.casing || factorioConfig.casing
return () => {
if (factorioConfig.knex) {
factorioConfig.knex.destroy()
}
}
}