@contember/database
Advanced tools
Comparing version 2.0.0-alpha.10 to 2.0.0-alpha.12
import { Client } from "./src/client/Client.js"; | ||
import { ClientErrorCodes } from "./src/client/errorCodes.js"; | ||
import { ClientError, DatabaseError, ForeignKeyViolationError, InvalidDataError, NotNullViolationError, QueryError, SerializationFailureError, TransactionAbortedError, UniqueViolationError } from "./src/client/errors.js"; | ||
import { CannotCommitError, ClientError, DatabaseError, ForeignKeyViolationError, InvalidDataError, NotNullViolationError, QueryError, SerializationFailureError, TransactionAbortedError, UniqueViolationError } from "./src/client/errors.js"; | ||
import { Connection } from "./src/client/Connection.js"; | ||
@@ -39,2 +39,3 @@ import { EventManager } from "./src/client/EventManager.js"; | ||
AcquiringListener, | ||
CannotCommitError, | ||
CaseStatement, | ||
@@ -41,0 +42,0 @@ Client, |
@@ -54,3 +54,6 @@ var __defProp = Object.defineProperty; | ||
} | ||
class CannotCommitError extends DatabaseError { | ||
} | ||
export { | ||
CannotCommitError, | ||
ClientError, | ||
@@ -57,0 +60,0 @@ DatabaseError, |
@@ -9,2 +9,3 @@ import { wrapIdentifier } from "../utils/sql.js"; | ||
import "@contember/queryable"; | ||
import { CannotCommitError } from "./errors.js"; | ||
import "./Connection.js"; | ||
@@ -53,7 +54,11 @@ import "node:timers"; | ||
async commit() { | ||
await this.close("COMMIT"); | ||
const commitResult = await this.close("COMMIT"); | ||
if (commitResult.command !== "COMMIT") { | ||
throw new CannotCommitError("Unexpected commit result: " + commitResult.command); | ||
} | ||
} | ||
async close(command) { | ||
await this.query(command); | ||
const result = await this.query(command); | ||
this.state.close(); | ||
return result; | ||
} | ||
@@ -60,0 +65,0 @@ } |
import { Client } from "./src/client/Client.js"; | ||
import { ClientErrorCodes } from "./src/client/errorCodes.js"; | ||
import { ClientError, DatabaseError, ForeignKeyViolationError, InvalidDataError, NotNullViolationError, QueryError, SerializationFailureError, TransactionAbortedError, UniqueViolationError } from "./src/client/errors.js"; | ||
import { CannotCommitError, ClientError, DatabaseError, ForeignKeyViolationError, InvalidDataError, NotNullViolationError, QueryError, SerializationFailureError, TransactionAbortedError, UniqueViolationError } from "./src/client/errors.js"; | ||
import { Connection } from "./src/client/Connection.js"; | ||
@@ -39,2 +39,3 @@ import { EventManager } from "./src/client/EventManager.js"; | ||
AcquiringListener, | ||
CannotCommitError, | ||
CaseStatement, | ||
@@ -41,0 +42,0 @@ Client, |
@@ -54,3 +54,6 @@ var __defProp = Object.defineProperty; | ||
} | ||
class CannotCommitError extends DatabaseError { | ||
} | ||
export { | ||
CannotCommitError, | ||
ClientError, | ||
@@ -57,0 +60,0 @@ DatabaseError, |
@@ -9,2 +9,3 @@ import { wrapIdentifier } from "../utils/sql.js"; | ||
import "@contember/queryable"; | ||
import { CannotCommitError } from "./errors.js"; | ||
import "./Connection.js"; | ||
@@ -53,7 +54,11 @@ import "node:timers"; | ||
async commit() { | ||
await this.close("COMMIT"); | ||
const commitResult = await this.close("COMMIT"); | ||
if (commitResult.command !== "COMMIT") { | ||
throw new CannotCommitError("Unexpected commit result: " + commitResult.command); | ||
} | ||
} | ||
async close(command) { | ||
await this.query(command); | ||
const result = await this.query(command); | ||
this.state.close(); | ||
return result; | ||
} | ||
@@ -60,0 +65,0 @@ } |
@@ -5,3 +5,4 @@ import { Connection } from '../../../src'; | ||
timeout?: number; | ||
result?: any; | ||
}[][]) => [Connection, () => void]; | ||
//# sourceMappingURL=createConnectionMockAlt.d.ts.map |
@@ -64,2 +64,3 @@ import { EventManager } from './EventManager'; | ||
interface Result<Row extends Record<string, any> = Record<string, any>> { | ||
readonly command?: string; | ||
readonly rowCount: number; | ||
@@ -66,0 +67,0 @@ readonly rows: Row[]; |
@@ -32,2 +32,4 @@ export declare class DatabaseError extends Error { | ||
} | ||
export declare class CannotCommitError extends DatabaseError { | ||
} | ||
//# sourceMappingURL=errors.d.ts.map |
{ | ||
"name": "@contember/database", | ||
"version": "2.0.0-alpha.10", | ||
"version": "2.0.0-alpha.12", | ||
"license": "Apache-2.0", | ||
@@ -26,6 +26,6 @@ "main": "./dist/production/index.js", | ||
"dependencies": { | ||
"@contember/queryable": "2.0.0-alpha.10" | ||
"@contember/queryable": "2.0.0-alpha.12" | ||
}, | ||
"devDependencies": { | ||
"@contember/database-tester": "2.0.0-alpha.10", | ||
"@contember/database-tester": "2.0.0-alpha.12", | ||
"@types/node": "^20.9.0", | ||
@@ -32,0 +32,0 @@ "pg": "^8.11.3" |
@@ -143,2 +143,3 @@ import { EventManager } from './EventManager' | ||
export interface Result<Row extends Record<string, any> = Record<string, any>> { | ||
readonly command?: string | ||
readonly rowCount: number | ||
@@ -145,0 +146,0 @@ readonly rows: Row[] |
@@ -1,3 +0,1 @@ | ||
import { ClientErrorCodes } from './errorCodes' | ||
export class DatabaseError extends Error { | ||
@@ -60,2 +58,4 @@ public readonly code?: string | ||
export class CannotCommitError extends DatabaseError {} | ||
@@ -5,2 +5,3 @@ import { Connection } from './Connection' | ||
import { Notification } from 'pg' | ||
import { DatabaseError, CannotCommitError } from './errors' | ||
@@ -62,8 +63,12 @@ export class Transaction implements Connection.TransactionLike { | ||
async commit(): Promise<void> { | ||
await this.close('COMMIT') | ||
const commitResult = await this.close('COMMIT') | ||
if (commitResult.command !== 'COMMIT') { | ||
throw new CannotCommitError('Unexpected commit result: ' + commitResult.command) | ||
} | ||
} | ||
private async close(command: string) { | ||
await this.query(command) | ||
const result = await this.query(command) | ||
this.state.close() | ||
return result | ||
} | ||
@@ -70,0 +75,0 @@ } |
@@ -19,3 +19,3 @@ import { expect, it } from 'vitest' | ||
const [connection, end] = createConnectionMockAlt( | ||
[{ sql: 'SELECT 1', timeout: 5 }, { sql: 'SELECT 2', timeout: 5 }], | ||
[{ sql: 'SELECT 1', timeout: 5 }, { sql: 'SELECT 2', timeout: 5 }], | ||
[{ sql: 'SELECT 3', timeout: 5 }], | ||
@@ -59,3 +59,3 @@ ) | ||
{ sql: 'SELECT 3', timeout: 5 }, | ||
{ sql: 'COMMIT', timeout: 5 }, | ||
{ sql: 'COMMIT', timeout: 5, result: { command: 'COMMIT' } }, | ||
], | ||
@@ -116,3 +116,3 @@ ) | ||
{ sql: 'SELECT 9' }, | ||
{ sql: 'COMMIT' }, | ||
{ sql: 'COMMIT', result: { command: 'COMMIT' } }, | ||
], | ||
@@ -119,0 +119,0 @@ ) |
@@ -6,3 +6,3 @@ import { Connection, Pool } from '../../../src' | ||
export const createConnectionMockAlt = (...queries: { sql: string; timeout?: number }[][]): [Connection, () => void] => { | ||
export const createConnectionMockAlt = (...queries: { sql: string; timeout?: number; result?: any }[][]): [Connection, () => void] => { | ||
const connectionMocks: (PgClient & { assertEmpty: () => void })[] = [] | ||
@@ -25,3 +25,3 @@ for (const queriesSet of queries) { | ||
return sql as any | ||
return query?.result | ||
} | ||
@@ -28,0 +28,0 @@ |
@@ -30,3 +30,3 @@ import { EventManager } from '../../../src' | ||
{ sql: 'SELECT 1' }, | ||
{ sql: 'COMMIT' }, | ||
{ sql: 'COMMIT', result: { command: 'COMMIT' } }, | ||
{ sql: 'SELECT 2' }, | ||
@@ -100,3 +100,3 @@ { sql: 'SELECT 3' }, | ||
{ sql: 'RELEASE SAVEPOINT "savepoint_1"' }, | ||
{ sql: 'COMMIT' }, | ||
{ sql: 'COMMIT', result: { command: 'COMMIT' } }, | ||
{ sql: 'SELECT 3' }, | ||
@@ -103,0 +103,0 @@ { sql: 'SELECT 4' }, |
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
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1675421
18219
+ Added@contember/queryable@2.0.0-alpha.12(transitive)
- Removed@contember/queryable@2.0.0-alpha.10(transitive)