@contember/database
Advanced tools
Comparing version 1.0.0-alpha.3 to 1.0.0-alpha.4
@@ -6,2 +6,3 @@ "use strict"; | ||
const errors_1 = require("./errors"); | ||
const errorCodes_1 = require("./errorCodes"); | ||
function prepareSql(sql) { | ||
@@ -46,14 +47,14 @@ let parameterIndex = 0; | ||
switch (error.code) { | ||
case '23502': | ||
case errorCodes_1.ClientErrorCodes.NOT_NULL_VIOLATION: | ||
throw new errors_1.NotNullViolationError(sql, parameters, error); | ||
case '23503': | ||
case errorCodes_1.ClientErrorCodes.FOREIGN_KEY_VIOLATION: | ||
throw new errors_1.ForeignKeyViolationError(sql, parameters, error); | ||
case '23505': | ||
case errorCodes_1.ClientErrorCodes.UNIQUE_VIOLATION: | ||
throw new errors_1.UniqueViolationError(sql, parameters, error); | ||
case '40001': | ||
case errorCodes_1.ClientErrorCodes.T_R_SERIALIZATION_FAILURE: | ||
throw new errors_1.SerializationFailureError(sql, parameters, error); | ||
case '22P02': | ||
case '22008': | ||
case errorCodes_1.ClientErrorCodes.INVALID_TEXT_REPRESENTATION: | ||
case errorCodes_1.ClientErrorCodes.DATETIME_FIELD_OVERFLOW: | ||
throw new errors_1.InvalidDataError(sql, parameters, error); | ||
case '25P02': | ||
case errorCodes_1.ClientErrorCodes.IN_FAILED_SQL_TRANSACTION: | ||
throw new errors_1.TransactionAbortedError(sql, parameters, error); | ||
@@ -60,0 +61,0 @@ default: |
export * from './Client'; | ||
export * from './errorCodes'; | ||
export * from './errors'; | ||
@@ -3,0 +4,0 @@ export * from './Connection'; |
@@ -14,2 +14,3 @@ "use strict"; | ||
__exportStar(require("./Client"), exports); | ||
__exportStar(require("./errorCodes"), exports); | ||
__exportStar(require("./errors"), exports); | ||
@@ -16,0 +17,0 @@ __exportStar(require("./Connection"), exports); |
@@ -40,3 +40,3 @@ "use strict"; | ||
async end() { | ||
this.isConnected = true; | ||
this.isConnected = false; | ||
await this.pgClient.end(); | ||
@@ -43,0 +43,0 @@ } |
{ | ||
"name": "@contember/database", | ||
"version": "1.0.0-alpha.3", | ||
"version": "1.0.0-alpha.4", | ||
"license": "Apache-2.0", | ||
@@ -11,6 +11,6 @@ "main": "dist/src/index.js", | ||
"dependencies": { | ||
"@contember/queryable": "^1.0.0-alpha.3" | ||
"@contember/queryable": "^1.0.0-alpha.4" | ||
}, | ||
"devDependencies": { | ||
"@contember/database-tester": "^1.0.0-alpha.3", | ||
"@contember/database-tester": "^1.0.0-alpha.4", | ||
"@types/node": "^17.0.5", | ||
@@ -17,0 +17,0 @@ "pg": "^8.5.0", |
@@ -14,2 +14,3 @@ import { ClientBase } from 'pg' | ||
} from './errors' | ||
import { ClientErrorCodes } from './errorCodes' | ||
@@ -68,14 +69,14 @@ function prepareSql(sql: string) { | ||
switch ((error as any).code) { | ||
case '23502': | ||
case ClientErrorCodes.NOT_NULL_VIOLATION: | ||
throw new NotNullViolationError(sql, parameters, error) | ||
case '23503': | ||
case ClientErrorCodes.FOREIGN_KEY_VIOLATION: | ||
throw new ForeignKeyViolationError(sql, parameters, error) | ||
case '23505': | ||
case ClientErrorCodes.UNIQUE_VIOLATION: | ||
throw new UniqueViolationError(sql, parameters, error) | ||
case '40001': | ||
case ClientErrorCodes.T_R_SERIALIZATION_FAILURE: | ||
throw new SerializationFailureError(sql, parameters, error) | ||
case '22P02': | ||
case '22008': | ||
case ClientErrorCodes.INVALID_TEXT_REPRESENTATION: | ||
case ClientErrorCodes.DATETIME_FIELD_OVERFLOW: | ||
throw new InvalidDataError(sql, parameters, error) | ||
case '25P02': | ||
case ClientErrorCodes.IN_FAILED_SQL_TRANSACTION: | ||
throw new TransactionAbortedError(sql, parameters, error) | ||
@@ -82,0 +83,0 @@ default: |
export * from './Client' | ||
export * from './errorCodes' | ||
export * from './errors' | ||
@@ -3,0 +4,0 @@ export * from './Connection' |
@@ -46,3 +46,3 @@ import { Client as PgClient } from 'pg' | ||
async end(): Promise<void> { | ||
this.isConnected = true | ||
this.isConnected = false | ||
await this.pgClient.end() | ||
@@ -49,0 +49,0 @@ } |
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
444211
223
6242