import { MysqlConnectionOptions } from 'typeorm/driver/mysql/MysqlConnectionOptions'; import { SqliteConnectionOptions } from 'typeorm/driver/sqlite/SqliteConnectionOptions'; /** * Config of database connection, which is an alias to MySql connection or Sqlite connection. * Sqlite connection is only supported in unit test environment. * * Please do not use the following parameter in the configuration: * - synchronize (Unsafe) * - dropSchema (Unsafe) * - entities (already defined in entity package) */ export type ModelConfig = MysqlConnectionOptions | SqliteConnectionOptions; export type ModelConfigProvider = (() => Promise) | ModelConfig; /** * Checks if the current environment is a unit test environment. * Sqlite entity type will be different in these environments. * * @return {boolean} Returns `true` if the current environment is a unit test environment, otherwise `false`. */ export function isUnitTestEnv(): boolean { return typeof window === 'undefined' && process.env.NODE_ENV === 'test'; } /** * Returns the type argument for a long text based on the environment. * * @return {'text' | 'longtext'} - The type argument for a long text. */ export function getLongTextEntityType(): 'text' | 'longtext' { return isUnitTestEnv() ? 'text' : 'longtext'; }