Add support for jobs & queueables, migrations
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is failing

- Create migration directives & migrators
- Modify Cache classes to support array manipulation
- Create Redis unit and RedisCache implementation
- Create Queueable base class and Queue class that uses Cache backend
This commit is contained in:
2021-08-23 23:51:53 -05:00
parent 26e0444e40
commit 074a3187eb
28 changed files with 962 additions and 56 deletions

View File

@@ -1,4 +1,4 @@
import {ErrorWithContext} from '../../util'
import {Awaitable, ErrorWithContext} from '../../util'
import {QueryResult} from '../types'
import {SQLDialect} from '../dialect/SQLDialect'
import {AppClass} from '../../lifecycle/AppClass'
@@ -68,6 +68,13 @@ export abstract class Connection extends AppClass {
*/
public abstract schema(name?: string): Schema
/**
* Execute all queries logged to this connection during the closure
* as a transaction in the database.
* @param closure
*/
public abstract asTransaction<T>(closure: () => Awaitable<T>): Awaitable<T>
/**
* Fire a QueryExecutedEvent for the given query string.
* @param query

View File

@@ -2,7 +2,7 @@ import {Connection, ConnectionNotReadyError} from './Connection'
import {Client} from 'pg'
import {Inject} from '../../di'
import {QueryResult} from '../types'
import {collect} from '../../util'
import {Awaitable, collect} from '../../util'
import {SQLDialect} from '../dialect/SQLDialect'
import {PostgreSQLDialect} from '../dialect/PostgreSQLDialect'
import {Logging} from '../../service/Logging'
@@ -70,6 +70,17 @@ export class PostgresConnection extends Connection {
}
}
public async asTransaction<T>(closure: () => Awaitable<T>): Promise<T> {
if ( !this.client ) {
throw new ConnectionNotReadyError(this.name, { config: JSON.stringify(this.config) })
}
await this.client.query('BEGIN')
const result = await closure()
await this.client.query('COMMIT')
return result
}
public schema(name?: string): Schema {
return new PostgresSchema(this, name)
}