@scaleleap/typeorm v1.1.15

š¦ @scaleleap/typeorm
Enhanced and pre-configured TypeORM version with helpers included.
Download & Installation
$ npm i -s typeorm @scaleleap/typeormCreate a config file in src/ormconfig.ts:
import { createConnectionOptions } from '@scaleleap/typeorm'
export = createConnectionOptions({
// ... your config
})Add the following to package.json:
{
"scripts": {
"typeorm": "typeorm-cli -f src/ormconfig.ts"
}
}Add the following to tsconfig.json:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
},
}Usage
Our package is a superset of typeorm, and thus you can use it exactly the same way as you would
use typeorm directly.
import { createConnection } from '@scaleleap/typeorm'Enhancements
typeorm-cli CLI replacement that supports TypeScript config files
typeorm-cli migration:generate ...Here is a list of features and enhancements over stock typeorm:
createConnectionOptions factory function
Factory function for creating TypeORM configuration object. Suitable to be passed to createConnection
function or inside ormconfig.ts.
Logger
You can pass an instance of @scaleleap/logger to createConnectionOptions factory to be used
as a custom logger for TypeORM.
Naming Strategy
This package is pre-configured to use a custom naming strategy that is more descriptive and sane
than TypeORM default. It uses meaningful identity naming. E.g. instead of
PK_adc83b19e793491b1c6ea0fd8b46cd9f32e592fc it will use pk_user_id_a4378d.
createConnection factory function
The stock createConnection is amended to return a connection with enhanced type that exposes
PostgreSQL connection Pool via connection.driver.master. The prop was already there, we are just
casting the connection and driver to the right type to expose it correctly.
createEncryptionTransformer factory function
Creates a column transformer which can then be used to encrypt data.
export class Encrypted {
// ...
@Column({ transformer: createEncryptionTransformer(encryptionKey) })
public secret!: string
}migration:generate
The migration:generate command has been enhanced to create prettified SQL.
TestDatabaseConnection class for tests
// pass the same params as `createConnectionOptions`
const tdc = new TestDatabaseConnection({
connectionOptions: {
entities: [User],
},
})
// 1. Creates a test database
// 2. Returns TypeORM connection
const connection = await tdc.setup()
//
// run the tests here...
//
// 1. Destroys the test database
// 2. Disconnects
await tdc.teardown()upsert function - WIP
Technically the code is ready. But an issue with TypeORM is preventing us from using it.
New features
QidTransformer
A transformer to convert UUID strings to Qid and back.
See test/entities/qid.ts for usage example.
Contributing
This repository uses Conventional Commit style commit messages.
Authors or Acknowledgments
- Roman Filippov (Scale Leap)
License
This project is licensed under the MIT License.
Badges
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago