@sqb/postgres
Advanced tools
Comparing version 4.0.1-alpha.11 to 4.0.1-alpha.12
@@ -1,2 +0,2 @@ | ||
import { Adapter, ClientConfiguration } from '@sqb/connect'; | ||
import { Adapter, ClientConfiguration, DataType } from '@sqb/connect'; | ||
import '@sqb/postgres-dialect'; | ||
@@ -6,3 +6,7 @@ export declare class PgAdapter implements Adapter { | ||
dialect: string; | ||
features: { | ||
cursor: boolean; | ||
fetchAsString: DataType[]; | ||
}; | ||
connect(config: ClientConfiguration): Promise<Adapter.Connection>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PgAdapter = void 0; | ||
const connect_1 = require("@sqb/connect"); | ||
require("@sqb/postgres-dialect"); | ||
@@ -11,2 +12,6 @@ const postgresql_client_1 = require("postgresql-client"); | ||
this.dialect = 'postgres'; | ||
this.features = { | ||
cursor: true, | ||
fetchAsString: [connect_1.DataType.DATE, connect_1.DataType.TIMESTAMP, connect_1.DataType.TIMESTAMPTZ] | ||
}; | ||
} | ||
@@ -13,0 +18,0 @@ async connect(config) { |
import { Adapter, QueryRequest } from '@sqb/connect'; | ||
import { Connection } from 'postgresql-client'; | ||
import { FieldInfo } from 'postgresql-client/dist/definitions'; | ||
import { Connection, FieldInfo } from 'postgresql-client'; | ||
export declare class PgConnection implements Adapter.Connection { | ||
@@ -5,0 +4,0 @@ private readonly intlcon; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PgConnection = void 0; | ||
const connect_1 = require("@sqb/connect"); | ||
const postgresql_client_1 = require("postgresql-client"); | ||
const SqbDataTypToOIDMap = { | ||
[connect_1.DataType.BOOL]: postgresql_client_1.DataTypeOIDs.bool, | ||
[connect_1.DataType.CHAR]: postgresql_client_1.DataTypeOIDs.char, | ||
[connect_1.DataType.VARCHAR]: postgresql_client_1.DataTypeOIDs.varchar, | ||
[connect_1.DataType.SMALLINT]: postgresql_client_1.DataTypeOIDs.int2, | ||
[connect_1.DataType.INTEGER]: postgresql_client_1.DataTypeOIDs.int4, | ||
[connect_1.DataType.BIGINT]: postgresql_client_1.DataTypeOIDs.int8, | ||
[connect_1.DataType.FLOAT]: postgresql_client_1.DataTypeOIDs.float4, | ||
[connect_1.DataType.DOUBLE]: postgresql_client_1.DataTypeOIDs.float8, | ||
[connect_1.DataType.NUMBER]: postgresql_client_1.DataTypeOIDs.float8, | ||
[connect_1.DataType.DATE]: postgresql_client_1.DataTypeOIDs.date, | ||
[connect_1.DataType.TIMESTAMP]: postgresql_client_1.DataTypeOIDs.timestamp, | ||
[connect_1.DataType.TIMESTAMPTZ]: postgresql_client_1.DataTypeOIDs.timestamptz, | ||
[connect_1.DataType.TIME]: postgresql_client_1.DataTypeOIDs.time, | ||
[connect_1.DataType.BINARY]: postgresql_client_1.DataTypeOIDs.bytea, | ||
[connect_1.DataType.TEXT]: postgresql_client_1.DataTypeOIDs.text, | ||
[connect_1.DataType.GUID]: postgresql_client_1.DataTypeOIDs.uuid, | ||
}; | ||
class PgConnection { | ||
@@ -34,3 +54,3 @@ constructor(conn) { | ||
async execute(query) { | ||
const resp = await this.intlcon.query(query.sql, { | ||
const opts = { | ||
autoCommit: query.autoCommit, | ||
@@ -41,3 +61,14 @@ params: query.params, | ||
objectRows: query.objectRows | ||
}); | ||
}; | ||
if (query.fetchAsString) { | ||
const items = query.fetchAsString.reduce((a, v) => { | ||
const oid = SqbDataTypToOIDMap[v]; | ||
if (oid) | ||
a.push(oid); | ||
return a; | ||
}, []); | ||
if (items.length) | ||
opts.fetchAsString = items; | ||
} | ||
const resp = await this.intlcon.query(query.sql, opts); | ||
const out = {}; | ||
@@ -44,0 +75,0 @@ if (resp.fields) |
{ | ||
"name": "@sqb/postgres", | ||
"description": "SQB serialization extension for PostgreSQL database", | ||
"version": "4.0.1-alpha.11", | ||
"version": "4.0.1-alpha.12", | ||
"author": "Panates Ltd.", | ||
@@ -30,7 +30,7 @@ "contributors": [ | ||
"devDependencies": { | ||
"postgresql-client": "^1.11.4" | ||
"postgresql-client": "^1.13.1" | ||
}, | ||
"peerDependencies": { | ||
"postgresql-client": "^1.11.4", | ||
"@sqb/postgres-dialect": "^4.0.1-alpha.11" | ||
"postgresql-client": "^1.13.0", | ||
"@sqb/postgres-dialect": "^4.0.1-alpha.12" | ||
}, | ||
@@ -37,0 +37,0 @@ "main": "dist/index.js", |
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
8777
178