@nodeboot/starter-persistence
Version:
Nodeboot starter package for persistence. Supports data access layer auto-configuration providing features like database initialization, consistency check, entity mapping, repository pattern, transactions, paging, migrations, persistence listeners, persis
425 lines (363 loc) • 19 kB
TypeScript
import {LogLevel} from "typeorm";
import {MysqlConnectionCredentialsOptions} from "typeorm/driver/mysql/MysqlConnectionCredentialsOptions";
export interface Config {
app: {
persistence?: {
/**
* Database type. This value is required.
*/
type:
| "mysql"
| "postgres"
| "cockroachdb"
| "sap"
| "mariadb"
| "sqlite"
| "oracle"
| "mssql"
| "mongodb"
| "aurora-mysql"
| "aurora-postgres"
| "better-sqlite3"
| "spanner";
/**
* Migrations table name, in case of different name from "migrations".
* Accepts single string name.
*/
migrationsTableName?: string;
/**
* Transaction mode for migrations to run in
*/
migrationsTransactionMode?: "all" | "none" | "each";
/**
* Typeorm metadata table name, in case of different name from "typeorm_metadata".
* Accepts single string name.
*/
metadataTableName?: string;
/**
* Logging options.
*/
logging?: boolean | "all" | LogLevel[];
/**
* FIXME move the logger to use the application logger through a proxy
* Logger instance used to log queries and events in the ORM.
*/
logger?: "advanced-console" | "simple-console" | "file" | "debug";
/**
* Maximum number of milliseconds query should be executed before logger log a warning.
*/
maxQueryExecutionTime?: number;
/**
* Maximum number of clients the pool should contain.
*/
poolSize?: number;
/**
* Indicates if database schema should be auto created on every application launch.
* Be careful with this option and don't use this in production - otherwise you can lose production data.
* This option is useful during debug and development.
* Alternative to it, you can use CLI and run schema:sync command.
*
* Note that for MongoDB database it does not create schema, because MongoDB is schemaless.
* Instead, it syncs just by creating indices.
*/
synchronize?: boolean;
/**
* Indicates if migrations should be auto run on every application launch.
* Alternative to it, you can use CLI and run migrations:run command.
*/
migrationsRun?: boolean;
/**
* Drops the schema each time connection is being established.
* Be careful with this option and don't use this in production - otherwise you'll lose all production data.
* This option is useful during debug and development.
*/
dropSchema?: boolean;
/**
* Prefix to use on all tables (collections) of this connection in the database.
*/
entityPrefix?: string;
/**
* When creating new Entity instances, skip all constructors when true.
*/
entitySkipConstructor?: boolean;
/**
* Specifies how relations must be loaded - using "joins" or separate queries.
* If you are loading too much data with nested joins it's better to load relations
* using separate queries.
*
* Default strategy is "join", but this default can be changed here.
* Also, strategy can be set per-query in FindOptions and QueryBuilder.
*/
relationLoadStrategy?: "join" | "query";
/**
* Optionally applied "typename" to the model.
* If set, then each hydrated model will have this property with the target model / entity name inside.
*
* (works like a discriminator property).
*/
typename?: string;
/**
* Holds reference to the baseDirectory where configuration file are expected.
*
* @internal
*/
baseDirectory?: string;
/**
* Allows to setup cache options.
*/
cache?:
| boolean
| {
/**
* Type of caching.
*
* - "database" means cached values will be stored in the separate table in database. This is default value.
* - "redis" means cached values will be stored inside redis. You must provide redis connection options.
*/
type?: "database" | "redis" | "ioredis" | "ioredis/cluster"; // todo: add mongodb and other cache providers as well in the future
/**
* Configurable table name for "database" type cache.
* Default value is "query-result-cache"
*/
tableName?: string;
/**
* Used to provide redis connection options.
*/
options?: any;
/**
* If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.
*/
alwaysEnabled?: boolean;
/**
* Time in milliseconds in which cache will expire.
* This can be setup per-query.
* Default value is 1000 which is equivalent to 1 second.
*/
duration?: number;
/**
* Used to specify if cache errors should be ignored, and pass through the call to the Database.
*/
ignoreErrors?: boolean;
};
mysql: {
/**
* The charset for the connection. This is called "collation" in the SQL-level of MySQL (like utf8_general_ci).
* If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used.
* Default: 'UTF8_GENERAL_CI'
*/
readonly charset?: string;
/**
* The timezone configured on the MySQL server.
* This is used to type cast server date/time values to JavaScript Date object and vice versa.
* This can be 'local', 'Z', or an offset in the form +HH:MM or -HH:MM. (Default: 'local')
*/
readonly timezone?: string;
/**
* The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10000)
*/
readonly connectTimeout?: number;
/**
* The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10000)
* This difference between connectTimeout and acquireTimeout is subtle and is described in the mysqljs/mysql docs
* https://github.com/mysqljs/mysql/tree/master#pool-options
*/
readonly acquireTimeout?: number;
/**
* Allow connecting to MySQL instances that ask for the old (insecure) authentication method. (Default: false)
*/
readonly insecureAuth?: boolean;
/**
* When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option (Default: false)
*/
readonly supportBigNumbers?: boolean;
/**
* Enabling both supportBigNumbers and bigNumberStrings forces big numbers (BIGINT and DECIMAL columns) to be always
* returned as JavaScript String objects (Default: false). Enabling supportBigNumbers but leaving bigNumberStrings
* disabled will return big numbers as String objects only when they cannot be accurately represented with
* [JavaScript Number objects](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5) (which happens when they exceed the [-2^53, +2^53] range),
* otherwise they will be returned as Number objects. This option is ignored if supportBigNumbers is disabled.
*/
readonly bigNumberStrings?: boolean;
/**
* Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then inflated into JavaScript Date objects.
* Can be true/false or an array of type names to keep as strings.
*/
readonly dateStrings?: boolean | string[];
/**
* Prints protocol details to stdout. Can be true/false or an array of packet type names that should be printed.
* (Default: false)
*/
readonly debug?: boolean | string[];
/**
* Generates stack traces on Error to include call site of library entrance ("long stack traces").
* Slight performance penalty for most calls. (Default: true)
*/
readonly trace?: boolean;
/**
* Allow multiple mysql statements per query. Be careful with this, it could increase the scope of SQL injection attacks.
* (Default: false)
*/
readonly multipleStatements?: boolean;
/**
* Use spatial functions like GeomFromText and AsText which are removed in MySQL 8.
* (Default: true)
*/
readonly legacySpatialSupport?: boolean;
/**
* List of connection flags to use other than the default ones. It is also possible to blacklist default ones.
* For more information, check https://github.com/mysqljs/mysql#connection-flags.
*/
readonly flags?: string[];
/**
* TypeORM will automatically use package found in your node_modules, prioritizing mysql over mysql2,
* but you can specify it manually
*/
readonly connectorPackage?: "mysql" | "mysql2";
/**
* Replication setup.
*/
readonly replication?: {
/**
* Master server used by orm to perform writes.
*/
readonly master: MysqlConnectionCredentialsOptions;
/**
* List of read-from severs (slaves).
*/
readonly slaves: MysqlConnectionCredentialsOptions[];
/**
* If true, PoolCluster will attempt to reconnect when connection fails. (Default: true)
*/
readonly canRetry?: boolean;
/**
* If connection fails, node's errorCount increases.
* When errorCount is greater than removeNodeErrorCount, remove a node in the PoolCluster. (Default: 5)
*/
readonly removeNodeErrorCount?: number;
/**
* If connection fails, specifies the number of milliseconds before another connection attempt will be made.
* If set to 0, then node will be removed instead and never re-used. (Default: 0)
*/
readonly restoreNodeTimeout?: number;
/**
* Determines how slaves are selected:
* RR: Select one alternately (Round-Robin).
* RANDOM: Select the node by random function.
* ORDER: Select the first node available unconditionally.
*/
readonly selector?: "RR" | "RANDOM" | "ORDER";
};
};
mariadb: {
/**
* The charset for the connection. This is called "collation" in the SQL-level of MySQL (like utf8_general_ci).
* If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used.
* Default: 'UTF8_GENERAL_CI'
*/
readonly charset?: string;
/**
* The timezone configured on the MySQL server.
* This is used to type cast server date/time values to JavaScript Date object and vice versa.
* This can be 'local', 'Z', or an offset in the form +HH:MM or -HH:MM. (Default: 'local')
*/
readonly timezone?: string;
/**
* The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10000)
*/
readonly connectTimeout?: number;
/**
* The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10000)
* This difference between connectTimeout and acquireTimeout is subtle and is described in the mysqljs/mysql docs
* https://github.com/mysqljs/mysql/tree/master#pool-options
*/
readonly acquireTimeout?: number;
/**
* Allow connecting to MySQL instances that ask for the old (insecure) authentication method. (Default: false)
*/
readonly insecureAuth?: boolean;
/**
* When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option (Default: false)
*/
readonly supportBigNumbers?: boolean;
/**
* Enabling both supportBigNumbers and bigNumberStrings forces big numbers (BIGINT and DECIMAL columns) to be always
* returned as JavaScript String objects (Default: false). Enabling supportBigNumbers but leaving bigNumberStrings
* disabled will return big numbers as String objects only when they cannot be accurately represented with
* [JavaScript Number objects](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5) (which happens when they exceed the [-2^53, +2^53] range),
* otherwise they will be returned as Number objects. This option is ignored if supportBigNumbers is disabled.
*/
readonly bigNumberStrings?: boolean;
/**
* Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then inflated into JavaScript Date objects.
* Can be true/false or an array of type names to keep as strings.
*/
readonly dateStrings?: boolean | string[];
/**
* Prints protocol details to stdout. Can be true/false or an array of packet type names that should be printed.
* (Default: false)
*/
readonly debug?: boolean | string[];
/**
* Generates stack traces on Error to include call site of library entrance ("long stack traces").
* Slight performance penalty for most calls. (Default: true)
*/
readonly trace?: boolean;
/**
* Allow multiple mysql statements per query. Be careful with this, it could increase the scope of SQL injection attacks.
* (Default: false)
*/
readonly multipleStatements?: boolean;
/**
* Use spatial functions like GeomFromText and AsText which are removed in MySQL 8.
* (Default: true)
*/
readonly legacySpatialSupport?: boolean;
/**
* List of connection flags to use other than the default ones. It is also possible to blacklist default ones.
* For more information, check https://github.com/mysqljs/mysql#connection-flags.
*/
readonly flags?: string[];
/**
* TypeORM will automatically use package found in your node_modules, prioritizing mysql over mysql2,
* but you can specify it manually
*/
readonly connectorPackage?: "mysql" | "mysql2";
/**
* Replication setup.
*/
readonly replication?: {
/**
* Master server used by orm to perform writes.
*/
readonly master: MysqlConnectionCredentialsOptions;
/**
* List of read-from severs (slaves).
*/
readonly slaves: MysqlConnectionCredentialsOptions[];
/**
* If true, PoolCluster will attempt to reconnect when connection fails. (Default: true)
*/
readonly canRetry?: boolean;
/**
* If connection fails, node's errorCount increases.
* When errorCount is greater than removeNodeErrorCount, remove a node in the PoolCluster. (Default: 5)
*/
readonly removeNodeErrorCount?: number;
/**
* If connection fails, specifies the number of milliseconds before another connection attempt will be made.
* If set to 0, then node will be removed instead and never re-used. (Default: 0)
*/
readonly restoreNodeTimeout?: number;
/**
* Determines how slaves are selected:
* RR: Select one alternately (Round-Robin).
* RANDOM: Select the node by random function.
* ORDER: Select the first node available unconditionally.
*/
readonly selector?: "RR" | "RANDOM" | "ORDER";
};
};
postgres: {};
};
};
}