Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sqb/connect

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sqb/connect - npm Package Compare versions

Comparing version 4.0.1-alpha.2 to 4.0.1-alpha.3

9

dist/Adapter.d.ts

@@ -0,3 +1,3 @@

import { classes } from '@sqb/builder';
import { ClientConfiguration, Maybe, QueryRequest, RowType } from './types';
import { classes } from '@sqb/builder';
export interface Adapter {

@@ -27,3 +27,3 @@ driver: string;

interface Response {
fields?: Record<string, FieldInfo> | FieldInfo[];
fields?: Field[];
rows?: Record<string, any>[] | any[][];

@@ -34,9 +34,8 @@ rowType?: RowType;

}
interface FieldInfo {
index: number;
interface Field {
fieldName: string;
dataType: string;
elementDataType?: string;
jsType: string;
isArray?: boolean;
elementDataType?: string;
nullable?: boolean;

@@ -43,0 +42,0 @@ fixedLength?: boolean;

@@ -121,3 +121,3 @@ "use strict";

throw new Error('Adapter did not returned rowType');
result.fields = helpers_1.normalizeFieldMap(response.fields, request.fieldNaming);
result.fields = helpers_1.wrapAdapterFields(response.fields, request.fieldNaming);
result.rowType = response.rowType;

@@ -200,2 +200,4 @@ if (response.rows) {

request.values = q.params;
if (q.returningFields)
request.returningFields = q.returningFields;
if (query.listenerCount('execute'))

@@ -209,3 +211,3 @@ request.executeHooks = query.listeners('execute');

request.values = options.values;
// request.returningParams = options.returningParams;
request.returningFields = options.returningFields;
}

@@ -212,0 +214,0 @@ // @ts-ignore

@@ -227,7 +227,7 @@ "use strict";

throw new Error('Cursor is closed');
const rows = await this._intlcur.fetch(this._prefetchRows);
let rows = await this._intlcur.fetch(this._prefetchRows);
if (rows && rows.length) {
debug('Fetched %d rows from database', rows.length);
// Normalize rows
helpers_1.normalizeRows(this._fields, this._intlcur.rowType, rows, {
rows = helpers_1.normalizeRows(this._fields, this._intlcur.rowType, rows, {
objectRows: this._request.objectRows,

@@ -234,0 +234,0 @@ ignoreNulls: this._request.ignoreNulls,

@@ -7,4 +7,5 @@ import { FieldInfo } from './types';

get(k: string | number): FieldInfo;
entries(): [string, FieldInfo][];
keys(): string[];
values(): FieldInfo[];
}

@@ -23,2 +23,5 @@ "use strict";

}
entries() {
return Object.entries(this._obj);
}
keys() {

@@ -25,0 +28,0 @@ return Object.keys(this._obj);

import { ArrayRowset, FieldNaming, ObjectRowset, QueryRequest } from './types';
import { FieldInfoMap } from './FieldInfoMap';
import { Adapter } from './Adapter';
import { FieldInfoMap } from './FieldInfoMap';
export declare function applyNamingStrategy(fieldName: string, namingStrategy?: FieldNaming): string;
export declare function normalizeFieldMap(oldFields: Record<string, Adapter.FieldInfo> | Adapter.FieldInfo[], fieldNaming?: FieldNaming): FieldInfoMap;
export declare function applyNamingStrategy(value: string, namingStrategy?: FieldNaming): string;
export declare function wrapAdapterFields(oldFields: Adapter.Field[], fieldNaming?: FieldNaming): FieldInfoMap;
export declare function normalizeRows(fields: FieldInfoMap, rowType: 'array' | 'object', oldRows: ObjectRowset | ArrayRowset, options: Pick<QueryRequest, 'objectRows' | 'ignoreNulls' | 'coercion'>): Record<string, any>[] | any[][];
export declare function callFetchHooks(rows: ObjectRowset | ArrayRowset, request: QueryRequest): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.callFetchHooks = exports.normalizeRows = exports.normalizeFieldMap = exports.applyNamingStrategy = void 0;
exports.callFetchHooks = exports.normalizeRows = exports.wrapAdapterFields = exports.applyNamingStrategy = void 0;
const putil_varhelpers_1 = require("putil-varhelpers");
const FieldInfoMap_1 = require("./FieldInfoMap");
function applyNamingStrategy(fieldName, namingStrategy) {
function applyNamingStrategy(value, namingStrategy) {
if (typeof namingStrategy === 'string') {
switch (namingStrategy.toLowerCase()) {
case 'lowercase':
return fieldName.toLowerCase();
return value.toLowerCase();
case 'uppercase':
return fieldName.toUpperCase();
return value.toUpperCase();
case 'camelcase':
if (!fieldName.match(/[a-z]/))
return putil_varhelpers_1.camelCase(fieldName.toLowerCase());
fieldName = putil_varhelpers_1.camelCase(fieldName);
return fieldName[0].toLowerCase() + fieldName.substring(1);
if (!value.match(/[a-z]/))
return putil_varhelpers_1.camelCase(value.toLowerCase());
value = putil_varhelpers_1.camelCase(value);
return value[0].toLowerCase() + value.substring(1);
case 'pascalcase':
if (!fieldName.match(/[a-z]/))
return putil_varhelpers_1.pascalCase(fieldName.toLowerCase());
return putil_varhelpers_1.pascalCase(fieldName);
if (!value.match(/[a-z]/))
return putil_varhelpers_1.pascalCase(value.toLowerCase());
return putil_varhelpers_1.pascalCase(value);
}
}
else if (typeof namingStrategy === 'function')
return namingStrategy(fieldName);
return fieldName;
return namingStrategy(value);
return value;
}
exports.applyNamingStrategy = applyNamingStrategy;
function normalizeFieldMap(oldFields, fieldNaming) {
function wrapAdapterFields(oldFields, fieldNaming) {
const mapFieldInfo = (f, index) => {
const n = applyNamingStrategy(f.fieldName, fieldNaming);
const x = Object.assign(Object.assign({}, f), { name: f.fieldName, index });
if (n !== x.name)
x.name = n;
return x;
const name = applyNamingStrategy(f.fieldName, fieldNaming);
return Object.assign(Object.assign({}, f), { name, index });
};
const result = new FieldInfoMap_1.FieldInfoMap();
if (Array.isArray(oldFields)) {
oldFields.forEach((f, index) => {
const x = mapFieldInfo(f, index);
result.add(x);
});
}
else {
let i = 0;
for (const [k, f] of Object.entries(oldFields)) {
f.fieldName = k;
const x = mapFieldInfo(f, i++);
result.add(x);
}
}
oldFields.forEach((f, index) => {
const x = mapFieldInfo(f, index);
result.add(x);
});
return result;
}
exports.normalizeFieldMap = normalizeFieldMap;
exports.wrapAdapterFields = wrapAdapterFields;
function normalizeRows(fields, rowType, oldRows, options) {

@@ -56,0 +43,0 @@ const ignoreNulls = options.ignoreNulls && options.objectRows;

@@ -1,10 +0,11 @@

import { Connection } from './Connection';
import { FieldInfoMap } from './FieldInfoMap';
import { Cursor } from './Cursor';
import { PoolConfiguration } from 'lightning-pool';
import type { Connection } from './Connection';
import type { FieldInfoMap } from './FieldInfoMap';
import type { Cursor } from './Cursor';
import type { PoolConfiguration } from 'lightning-pool';
import { Adapter } from './Adapter';
export declare type Maybe<T> = T | void | null;
export declare type ExecuteHookFunction = (connection: Connection, request: QueryRequest) => Promise<void>;
export declare type FetchFunction = (row: any, request: QueryRequest) => void;
export declare type CoercionFunction = (value: any, fieldInfo?: FieldInfo) => any;
export declare type TransactionFunction = (session: Connection) => Promise<any>;
export declare type ExecuteHookFunction = (session: Connection, request: QueryRequest) => Promise<void>;
export declare type FetchFunction = (row: any, request: QueryRequest) => void;
export declare type RowType = 'array' | 'object';

@@ -30,8 +31,4 @@ export declare type FieldNaming = 'lowercase' | 'uppercase' | 'camelcase' | 'pascalcase' | ((fieldName: string) => string);

/**
* Connection string
* Database server address or url
*/
connectString?: string;
/**
* Database host address
*/
host?: string;

@@ -142,3 +139,18 @@ /**

action?: string;
returningFields?: Record<string, string>;
}
export interface QueryResult {
executeTime: number;
fields?: FieldInfoMap;
rows?: Record<string, any>[] | any[][];
rowType?: RowType;
query?: QueryRequest;
returns?: any;
rowsAffected?: number;
cursor?: Cursor;
}
export declare type FieldInfo = {
index: number;
name: string;
} & Adapter.Field;
export interface QueryRequest {

@@ -149,2 +161,3 @@ dialect?: string;

values?: any;
returningFields?: Record<string, string>;
autoCommit?: boolean;

@@ -162,16 +175,1 @@ cursor?: boolean;

}
export interface QueryResult {
executeTime: number;
fields?: FieldInfoMap;
rows?: Record<string, any>[] | any[][];
rowType?: RowType;
query?: QueryRequest;
returns?: any;
rowsAffected?: number;
cursor?: Cursor;
}
export interface FieldInfo {
name: string;
fieldName: string;
index: number;
}
{
"name": "@sqb/connect",
"description": "Multi-dialect database connection framework written with TypeScript",
"version": "4.0.1-alpha.2",
"version": "4.0.1-alpha.3",
"author": "Panates Ltd.",

@@ -44,3 +44,3 @@ "contributors": [

"peerDependencies": {
"@sqb/builder": "^4.0.1-alpha.2"
"@sqb/builder": "^4.0.1-alpha.3"
},

@@ -47,0 +47,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc