@contember/database
Advanced tools
Comparing version 1.1.0-alpha.2 to 1.1.0-alpha.3
import { PoolConfig } from 'pg'; | ||
import { EventManager } from './EventManager'; | ||
import { Client } from './Client'; | ||
import { DatabaseCredentials } from '../types'; | ||
declare class Connection implements Connection.ConnectionLike, Connection.ClientFactory, Connection.PoolStatusProvider { | ||
readonly config: PoolConfig; | ||
readonly config: PoolConfig & DatabaseCredentials; | ||
private readonly queryConfig; | ||
readonly eventManager: EventManager; | ||
private readonly pool; | ||
constructor(config: PoolConfig, queryConfig: Connection.QueryConfig, eventManager?: EventManager); | ||
constructor(config: PoolConfig & DatabaseCredentials, queryConfig: Connection.QueryConfig, eventManager?: EventManager); | ||
createClient(schema: string, queryMeta: Record<string, any>): Client; | ||
@@ -32,2 +33,5 @@ transaction<Result>(callback: (connection: Connection.TransactionLike) => Promise<Result> | Result, options?: { | ||
} | ||
type ConnectionType = Connection.ConnectionLike & Connection.ClientFactory & Connection.PoolStatusProvider & { | ||
config: DatabaseCredentials; | ||
}; | ||
interface ConnectionLike extends Transactional, Queryable { | ||
@@ -34,0 +38,0 @@ } |
@@ -1,11 +0,13 @@ | ||
import { Client as PgClient } from 'pg'; | ||
import { ClientConfig } from 'pg'; | ||
import { EventManager } from './EventManager'; | ||
import { Client } from './Client'; | ||
import { Connection } from './Connection'; | ||
declare class SingleConnection implements Connection.ConnectionLike, Connection.ClientFactory { | ||
private readonly pgClient; | ||
import { DatabaseCredentials } from '../types'; | ||
export declare class SingleConnection implements Connection.ConnectionLike, Connection.ClientFactory { | ||
private readonly config; | ||
private readonly queryConfig; | ||
readonly eventManager: EventManager; | ||
private readonly pgClient; | ||
private isConnected; | ||
constructor(pgClient: PgClient, queryConfig: Connection.QueryConfig, eventManager?: EventManager, isConnected?: boolean); | ||
constructor(config: ClientConfig & DatabaseCredentials, queryConfig: Connection.QueryConfig, eventManager?: EventManager); | ||
createClient(schema: string, queryMeta: Record<string, any>): Client; | ||
@@ -18,3 +20,2 @@ transaction<Result>(callback: (connection: Connection.TransactionLike) => Promise<Result> | Result, options?: { | ||
} | ||
export { SingleConnection }; | ||
//# sourceMappingURL=SingleConnection.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SingleConnection = void 0; | ||
const pg_1 = require("pg"); | ||
const EventManager_1 = require("./EventManager"); | ||
@@ -9,7 +10,13 @@ const Client_1 = require("./Client"); | ||
class SingleConnection { | ||
constructor(pgClient, queryConfig, eventManager = new EventManager_1.EventManager(null), isConnected = false) { | ||
this.pgClient = pgClient; | ||
constructor(config, queryConfig, eventManager = new EventManager_1.EventManager(null)) { | ||
this.config = config; | ||
this.queryConfig = queryConfig; | ||
this.eventManager = eventManager; | ||
this.isConnected = isConnected; | ||
this.isConnected = false; | ||
this.pgClient = new pg_1.Client(config); | ||
this.pgClient.on('error', err => { | ||
// eslint-disable-next-line no-console | ||
console.error(err); | ||
this.eventManager.fire(EventManager_1.EventManager.Event.clientError, err); | ||
}); | ||
} | ||
@@ -16,0 +23,0 @@ createClient(schema, queryMeta) { |
@@ -12,3 +12,3 @@ import { With } from './builders/internal/With'; | ||
export * from './types'; | ||
export { wrapIdentifier, retryTransaction, ConstraintHelper } from './utils'; | ||
export { wrapIdentifier, retryTransaction, ConstraintHelper, withDatabaseAdvisoryLock, createDatabaseIfNotExists, } from './utils'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -13,3 +13,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ConstraintHelper = exports.retryTransaction = exports.wrapIdentifier = void 0; | ||
exports.createDatabaseIfNotExists = exports.withDatabaseAdvisoryLock = exports.ConstraintHelper = exports.retryTransaction = exports.wrapIdentifier = void 0; | ||
__exportStar(require("./client"), exports); | ||
@@ -24,2 +24,4 @@ __exportStar(require("./builders"), exports); | ||
Object.defineProperty(exports, "ConstraintHelper", { enumerable: true, get: function () { return utils_1.ConstraintHelper; } }); | ||
Object.defineProperty(exports, "withDatabaseAdvisoryLock", { enumerable: true, get: function () { return utils_1.withDatabaseAdvisoryLock; } }); | ||
Object.defineProperty(exports, "createDatabaseIfNotExists", { enumerable: true, get: function () { return utils_1.createDatabaseIfNotExists; } }); | ||
//# sourceMappingURL=index.js.map |
export * from './assertNever'; | ||
export * from './ConstraintHelper'; | ||
export * from './createDatabaseIfNotExists'; | ||
export * from './sql'; | ||
export * from './retryTransaction'; | ||
export * from './withDatabaseAdvisoryLock'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -15,4 +15,6 @@ "use strict"; | ||
__exportStar(require("./ConstraintHelper"), exports); | ||
__exportStar(require("./createDatabaseIfNotExists"), exports); | ||
__exportStar(require("./sql"), exports); | ||
__exportStar(require("./retryTransaction"), exports); | ||
__exportStar(require("./withDatabaseAdvisoryLock"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@contember/database", | ||
"version": "1.1.0-alpha.2", | ||
"version": "1.1.0-alpha.3", | ||
"license": "Apache-2.0", | ||
@@ -11,9 +11,9 @@ "main": "dist/src/index.js", | ||
"dependencies": { | ||
"@contember/queryable": "^1.1.0-alpha.2" | ||
"@contember/queryable": "^1.1.0-alpha.3" | ||
}, | ||
"devDependencies": { | ||
"@contember/database-tester": "^1.1.0-alpha.2", | ||
"@contember/database-tester": "^1.1.0-alpha.3", | ||
"@types/node": "^17.0.5", | ||
"pg": "^8.5.0", | ||
"uvu": "^0.5.1" | ||
"uvu": "^0.5.3" | ||
}, | ||
@@ -20,0 +20,0 @@ "peerDependencies": { |
@@ -6,2 +6,3 @@ import { Pool, PoolConfig } from 'pg' | ||
import { executeClientOperation, executeQuery } from './execution' | ||
import { DatabaseCredentials } from '../types' | ||
@@ -12,3 +13,3 @@ class Connection implements Connection.ConnectionLike, Connection.ClientFactory, Connection.PoolStatusProvider { | ||
constructor( | ||
public readonly config: PoolConfig, | ||
public readonly config: PoolConfig & DatabaseCredentials, | ||
private readonly queryConfig: Connection.QueryConfig, | ||
@@ -110,2 +111,10 @@ public readonly eventManager: EventManager = new EventManager(null), | ||
export type ConnectionType = | ||
& Connection.ConnectionLike | ||
& Connection.ClientFactory | ||
& Connection.PoolStatusProvider | ||
& { | ||
config: DatabaseCredentials | ||
} | ||
export interface ConnectionLike extends Transactional, Queryable {} | ||
@@ -112,0 +121,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Client as PgClient } from 'pg' | ||
import { Client as PgClient, ClientConfig } from 'pg' | ||
import { EventManager } from './EventManager' | ||
@@ -7,10 +7,20 @@ import { Client } from './Client' | ||
import { Connection } from './Connection' | ||
import { DatabaseCredentials } from '../types' | ||
class SingleConnection implements Connection.ConnectionLike, Connection.ClientFactory { | ||
export class SingleConnection implements Connection.ConnectionLike, Connection.ClientFactory { | ||
private readonly pgClient: PgClient | ||
private isConnected = false | ||
constructor( | ||
private readonly pgClient: PgClient, | ||
private readonly config: ClientConfig & DatabaseCredentials, | ||
private readonly queryConfig: Connection.QueryConfig, | ||
public readonly eventManager: EventManager = new EventManager(null), | ||
private isConnected = false, | ||
) {} | ||
) { | ||
this.pgClient = new PgClient(config) | ||
this.pgClient.on('error', err => { | ||
// eslint-disable-next-line no-console | ||
console.error(err) | ||
this.eventManager.fire(EventManager.Event.clientError, err) | ||
}) | ||
} | ||
@@ -74,2 +84,1 @@ public createClient(schema: string, queryMeta: Record<string, any>): Client { | ||
} | ||
export { SingleConnection } |
@@ -14,2 +14,8 @@ import { With } from './builders/internal/With' | ||
export * from './types' | ||
export { wrapIdentifier, retryTransaction, ConstraintHelper } from './utils' | ||
export { | ||
wrapIdentifier, | ||
retryTransaction, | ||
ConstraintHelper, | ||
withDatabaseAdvisoryLock, | ||
createDatabaseIfNotExists, | ||
} from './utils' |
export * from './assertNever' | ||
export * from './ConstraintHelper' | ||
export * from './createDatabaseIfNotExists' | ||
export * from './sql' | ||
export * from './retryTransaction' | ||
export * from './withDatabaseAdvisoryLock' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
465029
238
6543