@sqb/connect 4.0.7 → 4.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -7
- package/dist/client/Adapter.d.ts +0 -57
- package/dist/client/Adapter.js +0 -2
- package/dist/client/Cursor.d.ts +0 -116
- package/dist/client/Cursor.js +0 -250
- package/dist/client/CursorStream.d.ts +0 -29
- package/dist/client/CursorStream.js +0 -98
- package/dist/client/FieldInfoMap.d.ts +0 -10
- package/dist/client/FieldInfoMap.js +0 -33
- package/dist/client/SqbClient.d.ts +0 -70
- package/dist/client/SqbClient.js +0 -165
- package/dist/client/SqbConnection.d.ts +0 -74
- package/dist/client/SqbConnection.js +0 -272
- package/dist/client/extensions.d.ts +0 -4
- package/dist/client/extensions.js +0 -14
- package/dist/client/helpers.d.ts +0 -9
- package/dist/client/helpers.js +0 -133
- package/dist/client/types.d.ts +0 -189
- package/dist/client/types.js +0 -5
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -37
- package/dist/orm/base-entity.class.d.ts +0 -16
- package/dist/orm/base-entity.class.js +0 -56
- package/dist/orm/commands/command.helper.d.ts +0 -14
- package/dist/orm/commands/command.helper.js +0 -140
- package/dist/orm/commands/count.command.d.ts +0 -11
- package/dist/orm/commands/count.command.js +0 -30
- package/dist/orm/commands/create.command.d.ts +0 -20
- package/dist/orm/commands/create.command.js +0 -83
- package/dist/orm/commands/destroy.command.d.ts +0 -11
- package/dist/orm/commands/destroy.command.js +0 -30
- package/dist/orm/commands/find.command.d.ts +0 -44
- package/dist/orm/commands/find.command.js +0 -308
- package/dist/orm/commands/row-converter.d.ts +0 -55
- package/dist/orm/commands/row-converter.js +0 -187
- package/dist/orm/commands/update.command.d.ts +0 -22
- package/dist/orm/commands/update.command.js +0 -82
- package/dist/orm/decorators/column.decorator.d.ts +0 -4
- package/dist/orm/decorators/column.decorator.js +0 -14
- package/dist/orm/decorators/embedded.decorator.d.ts +0 -2
- package/dist/orm/decorators/embedded.decorator.js +0 -17
- package/dist/orm/decorators/entity.decorator.d.ts +0 -6
- package/dist/orm/decorators/entity.decorator.js +0 -23
- package/dist/orm/decorators/events.decorator.d.ts +0 -6
- package/dist/orm/decorators/events.decorator.js +0 -76
- package/dist/orm/decorators/foreignkey.decorator.d.ts +0 -2
- package/dist/orm/decorators/foreignkey.decorator.js +0 -13
- package/dist/orm/decorators/index.decorator.d.ts +0 -3
- package/dist/orm/decorators/index.decorator.js +0 -22
- package/dist/orm/decorators/link.decorator.d.ts +0 -23
- package/dist/orm/decorators/link.decorator.js +0 -88
- package/dist/orm/decorators/primarykey.decorator.d.ts +0 -3
- package/dist/orm/decorators/primarykey.decorator.js +0 -23
- package/dist/orm/decorators/transform.decorator.d.ts +0 -3
- package/dist/orm/decorators/transform.decorator.js +0 -24
- package/dist/orm/model/abstract-entityelement.d.ts +0 -8
- package/dist/orm/model/abstract-entityelement.js +0 -10
- package/dist/orm/model/association-node.d.ts +0 -9
- package/dist/orm/model/association-node.js +0 -25
- package/dist/orm/model/association.d.ts +0 -28
- package/dist/orm/model/association.js +0 -129
- package/dist/orm/model/entity-association-element.d.ts +0 -9
- package/dist/orm/model/entity-association-element.js +0 -13
- package/dist/orm/model/entity-column-element.d.ts +0 -68
- package/dist/orm/model/entity-column-element.js +0 -27
- package/dist/orm/model/entity-model.d.ts +0 -59
- package/dist/orm/model/entity-model.js +0 -295
- package/dist/orm/model/entity-object-element.d.ts +0 -12
- package/dist/orm/model/entity-object-element.js +0 -24
- package/dist/orm/model/index-meta.d.ts +0 -9
- package/dist/orm/model/index-meta.js +0 -16
- package/dist/orm/model/link-chain.d.ts +0 -15
- package/dist/orm/model/link-chain.js +0 -50
- package/dist/orm/orm.const.d.ts +0 -2
- package/dist/orm/orm.const.js +0 -5
- package/dist/orm/orm.type.d.ts +0 -112
- package/dist/orm/orm.type.js +0 -2
- package/dist/orm/repository.class.d.ts +0 -125
- package/dist/orm/repository.class.js +0 -217
- package/dist/orm/util/entity-mapping.d.ts +0 -12
- package/dist/orm/util/entity-mapping.js +0 -154
- package/dist/orm/util/extract-keyvalues.d.ts +0 -2
- package/dist/orm/util/extract-keyvalues.js +0 -60
- package/dist/orm/util/orm.helper.d.ts +0 -14
- package/dist/orm/util/orm.helper.js +0 -39
- package/dist/orm/util/serialize-element.d.ts +0 -2
- package/dist/orm/util/serialize-element.js +0 -43
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -2
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/connect",
|
|
3
3
|
"description": "Multi-dialect database connection framework written with TypeScript",
|
|
4
|
-
"version": "4.0.
|
|
5
|
-
"author": "Panates
|
|
4
|
+
"version": "4.0.10",
|
|
5
|
+
"author": "Panates",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
8
8
|
],
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"putil-taskqueue": "^2.5.3",
|
|
39
39
|
"putil-varhelpers": "^1.6.1",
|
|
40
40
|
"reflect-metadata": "^0.1.13",
|
|
41
|
-
"strict-typed-events": "^1.0
|
|
42
|
-
"ts-gems": "^
|
|
41
|
+
"strict-typed-events": "^2.1.0",
|
|
42
|
+
"ts-gems": "^1.1.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/debug": "^4.1.6",
|
|
46
46
|
"@types/lodash": "^4.14.171"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@sqb/builder": "^4.
|
|
49
|
+
"@sqb/builder": "^4.x.x"
|
|
50
50
|
},
|
|
51
51
|
"main": "dist/index.js",
|
|
52
52
|
"types": "dist/index.d.ts",
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
"clean:dist": "rimraf ../../build/connect",
|
|
71
71
|
"compile": "tsc",
|
|
72
72
|
"lint": "eslint src/** --no-error-on-unmatched-pattern",
|
|
73
|
-
"test": "TS_NODE_PROJECT='./test/tsconfig.json' mocha -r ts-node/register -r tsconfig-paths/register --reporter spec test/**/*.spec.ts"
|
|
74
|
-
"version": "#version"
|
|
73
|
+
"test": "TS_NODE_PROJECT='./test/tsconfig.json' mocha -r ts-node/register -r tsconfig-paths/register --reporter spec test/**/*.spec.ts"
|
|
75
74
|
}
|
|
76
75
|
}
|
package/dist/client/Adapter.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Maybe } from 'ts-gems';
|
|
2
|
-
import { classes } from '@sqb/builder';
|
|
3
|
-
import { ClientConfiguration, QueryRequest, RowType, DataType } from './types';
|
|
4
|
-
export interface Adapter {
|
|
5
|
-
driver: string;
|
|
6
|
-
dialect: string;
|
|
7
|
-
features?: {
|
|
8
|
-
cursor?: boolean;
|
|
9
|
-
schema?: boolean;
|
|
10
|
-
fetchAsString?: DataType[];
|
|
11
|
-
};
|
|
12
|
-
connect: (config: ClientConfiguration) => Promise<Adapter.Connection>;
|
|
13
|
-
}
|
|
14
|
-
export declare namespace Adapter {
|
|
15
|
-
interface Connection {
|
|
16
|
-
sessionId: any;
|
|
17
|
-
execute: (request: QueryRequest) => Promise<Response>;
|
|
18
|
-
close: () => Promise<void>;
|
|
19
|
-
reset: () => Promise<void>;
|
|
20
|
-
test: () => Promise<void>;
|
|
21
|
-
startTransaction: () => Promise<void>;
|
|
22
|
-
setSavepoint?: (savepoint: string) => Promise<void>;
|
|
23
|
-
releaseSavepoint?: (savepoint: string) => Promise<void>;
|
|
24
|
-
rollbackSavepoint?: (savepoint: string) => Promise<void>;
|
|
25
|
-
commit: () => Promise<void>;
|
|
26
|
-
rollback: () => Promise<void>;
|
|
27
|
-
setSchema?: (schema: string) => Promise<void>;
|
|
28
|
-
getSchema?: () => Promise<string>;
|
|
29
|
-
onGenerateQuery?: (request: QueryRequest, query: classes.Query) => void;
|
|
30
|
-
getInTransaction?: () => boolean;
|
|
31
|
-
}
|
|
32
|
-
interface Cursor {
|
|
33
|
-
readonly isClosed: boolean;
|
|
34
|
-
readonly rowType: RowType;
|
|
35
|
-
close: () => Promise<void>;
|
|
36
|
-
fetch: (rows: number) => Promise<Maybe<any[]>>;
|
|
37
|
-
}
|
|
38
|
-
interface Response {
|
|
39
|
-
fields?: Field[];
|
|
40
|
-
rows?: Record<string, any>[] | any[][];
|
|
41
|
-
rowType?: RowType;
|
|
42
|
-
cursor?: Adapter.Cursor;
|
|
43
|
-
rowsAffected?: number;
|
|
44
|
-
}
|
|
45
|
-
interface Field {
|
|
46
|
-
fieldName: string;
|
|
47
|
-
dataType: string;
|
|
48
|
-
jsType: string;
|
|
49
|
-
isArray?: boolean;
|
|
50
|
-
elementDataType?: string;
|
|
51
|
-
nullable?: boolean;
|
|
52
|
-
fixedLength?: boolean;
|
|
53
|
-
size?: number;
|
|
54
|
-
precision?: number;
|
|
55
|
-
_inf: any;
|
|
56
|
-
}
|
|
57
|
-
}
|
package/dist/client/Adapter.js
DELETED
package/dist/client/Cursor.d.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
|
-
import { Adapter } from './Adapter';
|
|
3
|
-
import { SqbConnection } from './SqbConnection';
|
|
4
|
-
import { FieldInfoMap } from './FieldInfoMap';
|
|
5
|
-
import { ObjectRow, QueryRequest } from './types';
|
|
6
|
-
import { CursorStream, CursorStreamOptions } from './CursorStream';
|
|
7
|
-
interface CursorEvents {
|
|
8
|
-
close: () => void;
|
|
9
|
-
error: (error: unknown) => void;
|
|
10
|
-
eof: () => void;
|
|
11
|
-
reset: () => void;
|
|
12
|
-
move: (row: any, rowNum: number) => void;
|
|
13
|
-
fetch: (row: any, rowNum: number) => void;
|
|
14
|
-
}
|
|
15
|
-
export declare class Cursor extends AsyncEventEmitter<CursorEvents> {
|
|
16
|
-
private readonly _connection;
|
|
17
|
-
private readonly _fields;
|
|
18
|
-
private readonly _prefetchRows;
|
|
19
|
-
private readonly _request;
|
|
20
|
-
private _intlcur?;
|
|
21
|
-
private _taskQueue;
|
|
22
|
-
private _fetchCache;
|
|
23
|
-
private _rowNum;
|
|
24
|
-
private _fetchedAll;
|
|
25
|
-
private _fetchedRows;
|
|
26
|
-
private _row;
|
|
27
|
-
private _cache?;
|
|
28
|
-
constructor(connection: SqbConnection, fields: FieldInfoMap, adapterCursor: Adapter.Cursor, request: QueryRequest);
|
|
29
|
-
/**
|
|
30
|
-
* Returns the Connection instance
|
|
31
|
-
*/
|
|
32
|
-
get connection(): SqbConnection;
|
|
33
|
-
/**
|
|
34
|
-
* Returns if cursor is before first record.
|
|
35
|
-
*/
|
|
36
|
-
get isBof(): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Returns if cursor is closed.
|
|
39
|
-
*/
|
|
40
|
-
get isClosed(): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Returns if cursor is after last record.
|
|
43
|
-
*/
|
|
44
|
-
get isEof(): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Returns number of fetched record count from database.
|
|
47
|
-
*/
|
|
48
|
-
get fetchedRows(): number;
|
|
49
|
-
/**
|
|
50
|
-
* Returns object instance which contains information about fields.
|
|
51
|
-
*/
|
|
52
|
-
get fields(): FieldInfoMap;
|
|
53
|
-
/**
|
|
54
|
-
* Returns current row
|
|
55
|
-
*/
|
|
56
|
-
get row(): any;
|
|
57
|
-
/**
|
|
58
|
-
* Returns current row number.
|
|
59
|
-
*/
|
|
60
|
-
get rowNum(): number;
|
|
61
|
-
/**
|
|
62
|
-
* Enables cache
|
|
63
|
-
*/
|
|
64
|
-
cached(): void;
|
|
65
|
-
/**
|
|
66
|
-
* Closes cursor
|
|
67
|
-
*/
|
|
68
|
-
close(): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* If cache is enabled, this call fetches and keeps all records in the internal cache.
|
|
71
|
-
* Otherwise it throws error. Once all all records fetched,
|
|
72
|
-
* you can close Cursor safely and can continue to use it in memory.
|
|
73
|
-
* Returns number of fetched rows
|
|
74
|
-
*/
|
|
75
|
-
fetchAll(): Promise<number>;
|
|
76
|
-
/**
|
|
77
|
-
* Moves cursor to given row number.
|
|
78
|
-
* cursor can move both forward and backward if cache enabled.
|
|
79
|
-
* Otherwise it throws error.
|
|
80
|
-
*/
|
|
81
|
-
moveTo(rowNum: number): Promise<ObjectRow>;
|
|
82
|
-
/**
|
|
83
|
-
* Moves cursor forward by one row and returns that row.
|
|
84
|
-
* And also it allows iterating over rows easily.
|
|
85
|
-
*/
|
|
86
|
-
next(): Promise<ObjectRow>;
|
|
87
|
-
/**
|
|
88
|
-
* Moves cursor back by one row and returns that row.
|
|
89
|
-
* And also it allows iterating over rows easily.
|
|
90
|
-
*/
|
|
91
|
-
prev(): Promise<ObjectRow>;
|
|
92
|
-
/**
|
|
93
|
-
* Moves cursor before first row. (Required cache enabled)
|
|
94
|
-
*/
|
|
95
|
-
reset(): void;
|
|
96
|
-
/**
|
|
97
|
-
* Moves cursor by given step. If caching is enabled,
|
|
98
|
-
* cursor can move both forward and backward. Otherwise it throws error.
|
|
99
|
-
*/
|
|
100
|
-
seek(step: number): Promise<ObjectRow>;
|
|
101
|
-
/**
|
|
102
|
-
* Creates and returns a readable stream.
|
|
103
|
-
*/
|
|
104
|
-
toStream(options?: CursorStreamOptions): CursorStream;
|
|
105
|
-
toString(): string;
|
|
106
|
-
inspect(): string;
|
|
107
|
-
/**
|
|
108
|
-
*
|
|
109
|
-
*/
|
|
110
|
-
_seek(step: number, silent?: boolean): Promise<number>;
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
113
|
-
*/
|
|
114
|
-
_fetchRows(): Promise<void>;
|
|
115
|
-
}
|
|
116
|
-
export {};
|
package/dist/client/Cursor.js
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Cursor = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const strict_typed_events_1 = require("strict-typed-events");
|
|
6
|
-
const doublylinked_1 = (0, tslib_1.__importDefault)(require("doublylinked"));
|
|
7
|
-
const putil_taskqueue_1 = (0, tslib_1.__importDefault)(require("putil-taskqueue"));
|
|
8
|
-
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
9
|
-
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
10
|
-
const helpers_1 = require("./helpers");
|
|
11
|
-
const CursorStream_1 = require("./CursorStream");
|
|
12
|
-
const debug = (0, debug_1.default)('sqb:cursor');
|
|
13
|
-
class Cursor extends strict_typed_events_1.AsyncEventEmitter {
|
|
14
|
-
constructor(connection, fields, adapterCursor, request) {
|
|
15
|
-
super();
|
|
16
|
-
this._taskQueue = new putil_taskqueue_1.default();
|
|
17
|
-
this._fetchCache = new doublylinked_1.default();
|
|
18
|
-
this._rowNum = 0;
|
|
19
|
-
this._fetchedAll = false;
|
|
20
|
-
this._fetchedRows = 0;
|
|
21
|
-
this._connection = connection;
|
|
22
|
-
this._intlcur = adapterCursor;
|
|
23
|
-
this._fields = fields;
|
|
24
|
-
this._request = request;
|
|
25
|
-
this._prefetchRows = request?.fetchRows || 100;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Returns the Connection instance
|
|
29
|
-
*/
|
|
30
|
-
get connection() {
|
|
31
|
-
return this._connection;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Returns if cursor is before first record.
|
|
35
|
-
*/
|
|
36
|
-
get isBof() {
|
|
37
|
-
return !this._rowNum;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns if cursor is closed.
|
|
41
|
-
*/
|
|
42
|
-
get isClosed() {
|
|
43
|
-
return !this._intlcur;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Returns if cursor is after last record.
|
|
47
|
-
*/
|
|
48
|
-
get isEof() {
|
|
49
|
-
return this._fetchedAll && this.rowNum > this._fetchedRows;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns number of fetched record count from database.
|
|
53
|
-
*/
|
|
54
|
-
get fetchedRows() {
|
|
55
|
-
return this._fetchedRows;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Returns object instance which contains information about fields.
|
|
59
|
-
*/
|
|
60
|
-
get fields() {
|
|
61
|
-
return this._fields;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Returns current row
|
|
65
|
-
*/
|
|
66
|
-
get row() {
|
|
67
|
-
return this._row;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Returns current row number.
|
|
71
|
-
*/
|
|
72
|
-
get rowNum() {
|
|
73
|
-
return this._rowNum;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Enables cache
|
|
77
|
-
*/
|
|
78
|
-
cached() {
|
|
79
|
-
if (this.fetchedRows)
|
|
80
|
-
throw new Error('Cache can be enabled before fetching rows');
|
|
81
|
-
if (!this._cache)
|
|
82
|
-
this._cache = new doublylinked_1.default();
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Closes cursor
|
|
86
|
-
*/
|
|
87
|
-
async close() {
|
|
88
|
-
if (!this._intlcur)
|
|
89
|
-
return;
|
|
90
|
-
try {
|
|
91
|
-
await this._intlcur.close();
|
|
92
|
-
this._intlcur = undefined;
|
|
93
|
-
debug('close');
|
|
94
|
-
this.emit('close');
|
|
95
|
-
}
|
|
96
|
-
catch (err) {
|
|
97
|
-
debug('close-error:', err);
|
|
98
|
-
this.emit('error', err);
|
|
99
|
-
throw err;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* If cache is enabled, this call fetches and keeps all records in the internal cache.
|
|
104
|
-
* Otherwise it throws error. Once all all records fetched,
|
|
105
|
-
* you can close Cursor safely and can continue to use it in memory.
|
|
106
|
-
* Returns number of fetched rows
|
|
107
|
-
*/
|
|
108
|
-
async fetchAll() {
|
|
109
|
-
if (!this._cache)
|
|
110
|
-
throw new Error('fetchAll() method needs cache to be enabled');
|
|
111
|
-
const n = this.rowNum;
|
|
112
|
-
const v = await this._seek(Number.MAX_SAFE_INTEGER, true);
|
|
113
|
-
await this._seek(n - this.rowNum, true);
|
|
114
|
-
return v;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Moves cursor to given row number.
|
|
118
|
-
* cursor can move both forward and backward if cache enabled.
|
|
119
|
-
* Otherwise it throws error.
|
|
120
|
-
*/
|
|
121
|
-
async moveTo(rowNum) {
|
|
122
|
-
await this._seek(rowNum - this.rowNum);
|
|
123
|
-
return this.row;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Moves cursor forward by one row and returns that row.
|
|
127
|
-
* And also it allows iterating over rows easily.
|
|
128
|
-
*/
|
|
129
|
-
async next() {
|
|
130
|
-
debug('next');
|
|
131
|
-
await this._seek(1);
|
|
132
|
-
return this.row;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Moves cursor back by one row and returns that row.
|
|
136
|
-
* And also it allows iterating over rows easily.
|
|
137
|
-
*/
|
|
138
|
-
async prev() {
|
|
139
|
-
await this._seek(-1);
|
|
140
|
-
return this.row;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Moves cursor before first row. (Required cache enabled)
|
|
144
|
-
*/
|
|
145
|
-
reset() {
|
|
146
|
-
if (!this._cache)
|
|
147
|
-
throw new Error('reset() method needs cache to be enabled');
|
|
148
|
-
this._cache.reset();
|
|
149
|
-
this._rowNum = 0;
|
|
150
|
-
this.emit('reset');
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Moves cursor by given step. If caching is enabled,
|
|
154
|
-
* cursor can move both forward and backward. Otherwise it throws error.
|
|
155
|
-
*/
|
|
156
|
-
async seek(step) {
|
|
157
|
-
await this._seek(step);
|
|
158
|
-
return this.row;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Creates and returns a readable stream.
|
|
162
|
-
*/
|
|
163
|
-
toStream(options) {
|
|
164
|
-
return new CursorStream_1.CursorStream(this, options);
|
|
165
|
-
}
|
|
166
|
-
toString() {
|
|
167
|
-
return '[object ' + Object.getPrototypeOf(this).constructor.name + ']';
|
|
168
|
-
}
|
|
169
|
-
inspect() {
|
|
170
|
-
return this.toString();
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
*
|
|
174
|
-
*/
|
|
175
|
-
async _seek(step, silent) {
|
|
176
|
-
step = (0, putil_varhelpers_1.coerceToInt)(step, 0);
|
|
177
|
-
if (!step || (step > 0 && this.isClosed))
|
|
178
|
-
return this.rowNum;
|
|
179
|
-
if (step < 0 && !this._cache)
|
|
180
|
-
throw new Error('To move cursor back, it needs cache to be enabled');
|
|
181
|
-
const _this = this;
|
|
182
|
-
await this._taskQueue.enqueue(async function () {
|
|
183
|
-
/* If moving backward */
|
|
184
|
-
if (step < 0) {
|
|
185
|
-
/* Seek cache */
|
|
186
|
-
while (step < 0 && _this._cache?.cursor) {
|
|
187
|
-
_this._row = _this._cache.prev();
|
|
188
|
-
_this._rowNum--;
|
|
189
|
-
step++;
|
|
190
|
-
}
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
while (step > 0) {
|
|
194
|
-
if (_this.isEof)
|
|
195
|
-
return;
|
|
196
|
-
/* Seek cache */
|
|
197
|
-
while (step > 0 && _this._cache && (_this._row = _this._cache.next())) {
|
|
198
|
-
_this._rowNum++;
|
|
199
|
-
step--;
|
|
200
|
-
}
|
|
201
|
-
/* Fetch from prefetch cache */
|
|
202
|
-
while (step > 0 && (_this._row = _this._fetchCache.shift())) {
|
|
203
|
-
_this._rowNum++;
|
|
204
|
-
step--;
|
|
205
|
-
}
|
|
206
|
-
if (_this._fetchedAll) {
|
|
207
|
-
_this._rowNum++;
|
|
208
|
-
_this.emit('eof');
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
if (!step || _this._fetchedAll)
|
|
212
|
-
return;
|
|
213
|
-
await _this._fetchRows();
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
if (!silent)
|
|
217
|
-
this.emit('move', this.row, this._rowNum);
|
|
218
|
-
return this._rowNum;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
*
|
|
222
|
-
*/
|
|
223
|
-
async _fetchRows() {
|
|
224
|
-
if (!this._intlcur)
|
|
225
|
-
throw new Error('Cursor is closed');
|
|
226
|
-
let rows = await this._intlcur.fetch(this._prefetchRows);
|
|
227
|
-
if (rows && rows.length) {
|
|
228
|
-
debug('Fetched %d rows from database', rows.length);
|
|
229
|
-
// Normalize rows
|
|
230
|
-
rows = this._request.objectRows ?
|
|
231
|
-
(0, helpers_1.normalizeRowsToObjectRows)(this._fields, this._intlcur.rowType, rows, this._request) :
|
|
232
|
-
(0, helpers_1.normalizeRowsToArrayRows)(this._fields, this._intlcur.rowType, rows, this._request);
|
|
233
|
-
(0, helpers_1.callFetchHooks)(rows, this._request);
|
|
234
|
-
for (const [idx, row] of rows.entries()) {
|
|
235
|
-
this.emit('fetch', row, (this._rowNum + idx + 1));
|
|
236
|
-
}
|
|
237
|
-
/* Add rows to cache */
|
|
238
|
-
if (this._cache) {
|
|
239
|
-
this._cache.push(...rows);
|
|
240
|
-
}
|
|
241
|
-
else
|
|
242
|
-
this._fetchCache.push(...rows);
|
|
243
|
-
this._fetchedRows += rows.length;
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
this._fetchedAll = true;
|
|
247
|
-
return this.close();
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
exports.Cursor = Cursor;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Readable } from 'stream';
|
|
3
|
-
import { Cursor } from './Cursor';
|
|
4
|
-
export interface CursorStreamOptions {
|
|
5
|
-
objectMode?: boolean;
|
|
6
|
-
limit?: number;
|
|
7
|
-
}
|
|
8
|
-
declare const inspect: unique symbol;
|
|
9
|
-
export declare class CursorStream extends Readable {
|
|
10
|
-
private readonly _cursor;
|
|
11
|
-
private readonly _objectMode?;
|
|
12
|
-
private readonly _limit;
|
|
13
|
-
private _rowNum;
|
|
14
|
-
private _eof;
|
|
15
|
-
constructor(cursor: Cursor, options?: CursorStreamOptions);
|
|
16
|
-
/**
|
|
17
|
-
* Returns if stream is closed.
|
|
18
|
-
*/
|
|
19
|
-
get isClosed(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Closes stream and releases the cursor
|
|
22
|
-
*/
|
|
23
|
-
close(): Promise<void>;
|
|
24
|
-
toString(): string;
|
|
25
|
-
[inspect](): string;
|
|
26
|
-
_read(): void;
|
|
27
|
-
emit(event: string | symbol, ...args: any[]): boolean;
|
|
28
|
-
}
|
|
29
|
-
export {};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CursorStream = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
7
|
-
const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
8
|
-
const debug = (0, debug_1.default)('sqb:cursorstream');
|
|
9
|
-
class CursorStream extends stream_1.Readable {
|
|
10
|
-
constructor(cursor, options) {
|
|
11
|
-
super(options);
|
|
12
|
-
this._rowNum = -1;
|
|
13
|
-
this._eof = false;
|
|
14
|
-
this._cursor = cursor;
|
|
15
|
-
this._objectMode = options?.objectMode;
|
|
16
|
-
this._limit = options?.limit || Number.MAX_SAFE_INTEGER;
|
|
17
|
-
this.on('end', () => {
|
|
18
|
-
this.close().catch(() => false);
|
|
19
|
-
});
|
|
20
|
-
cursor.once('close', () => this.emit('close'));
|
|
21
|
-
cursor.on('error', (err) => this.emit('error', err));
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Returns if stream is closed.
|
|
25
|
-
*/
|
|
26
|
-
get isClosed() {
|
|
27
|
-
return this._cursor.isClosed;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Closes stream and releases the cursor
|
|
31
|
-
*/
|
|
32
|
-
close() {
|
|
33
|
-
this.pause();
|
|
34
|
-
this.unpipe();
|
|
35
|
-
return this._cursor.close();
|
|
36
|
-
}
|
|
37
|
-
toString() {
|
|
38
|
-
return '[object ' + Object.getPrototypeOf(this).constructor.name + ']';
|
|
39
|
-
}
|
|
40
|
-
[inspect]() {
|
|
41
|
-
return this.toString();
|
|
42
|
-
}
|
|
43
|
-
_read() {
|
|
44
|
-
if (this._rowNum >= this._limit) {
|
|
45
|
-
this.pause();
|
|
46
|
-
this.unpipe();
|
|
47
|
-
this.emit('end');
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
this._cursor.next().then(row => {
|
|
51
|
-
if (this._eof)
|
|
52
|
-
return this.push(null);
|
|
53
|
-
let buf = '';
|
|
54
|
-
if (this._rowNum < 0) {
|
|
55
|
-
this._rowNum = 0;
|
|
56
|
-
if (!this._objectMode)
|
|
57
|
-
buf += '[';
|
|
58
|
-
}
|
|
59
|
-
if (!row) {
|
|
60
|
-
this._eof = true;
|
|
61
|
-
if (!this._objectMode) {
|
|
62
|
-
buf += ']';
|
|
63
|
-
this.push(buf);
|
|
64
|
-
}
|
|
65
|
-
else
|
|
66
|
-
this.push(null);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
this._rowNum++;
|
|
70
|
-
if (this._objectMode)
|
|
71
|
-
this.push(row);
|
|
72
|
-
else {
|
|
73
|
-
if (this._rowNum > 1)
|
|
74
|
-
buf += ',';
|
|
75
|
-
this.push(buf + JSON.stringify(row));
|
|
76
|
-
}
|
|
77
|
-
}).catch(err => {
|
|
78
|
-
/* istanbul ignore next */
|
|
79
|
-
if (typeof this.destroy == 'function')
|
|
80
|
-
this.destroy(err);
|
|
81
|
-
else
|
|
82
|
-
this.emit('error', err);
|
|
83
|
-
this.close().catch(() => 0);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
emit(event, ...args) {
|
|
87
|
-
try {
|
|
88
|
-
if (event === 'error' && !this.listenerCount('error'))
|
|
89
|
-
return false;
|
|
90
|
-
return super.emit(event, ...args);
|
|
91
|
-
}
|
|
92
|
-
catch (ignored) {
|
|
93
|
-
debug('emit-error', ignored);
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.CursorStream = CursorStream;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { FieldInfo } from './types';
|
|
2
|
-
export declare class FieldInfoMap {
|
|
3
|
-
private _obj;
|
|
4
|
-
private _arr;
|
|
5
|
-
add(field: FieldInfo): void;
|
|
6
|
-
get(k: string | number): FieldInfo;
|
|
7
|
-
entries(): [string, FieldInfo][];
|
|
8
|
-
keys(): string[];
|
|
9
|
-
values(): FieldInfo[];
|
|
10
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FieldInfoMap = void 0;
|
|
4
|
-
class FieldInfoMap {
|
|
5
|
-
constructor() {
|
|
6
|
-
this._obj = {};
|
|
7
|
-
this._arr = [];
|
|
8
|
-
}
|
|
9
|
-
add(field) {
|
|
10
|
-
const idx = field.index != null ? field.index : this._arr.length;
|
|
11
|
-
this._arr[idx] = field;
|
|
12
|
-
field.index = idx;
|
|
13
|
-
this._obj = this._arr.reduce((a, f) => {
|
|
14
|
-
a[f.name.toUpperCase()] = f;
|
|
15
|
-
return a;
|
|
16
|
-
}, {});
|
|
17
|
-
}
|
|
18
|
-
get(k) {
|
|
19
|
-
if (typeof k === 'number')
|
|
20
|
-
return this._arr[k];
|
|
21
|
-
return this._obj[k.toUpperCase()];
|
|
22
|
-
}
|
|
23
|
-
entries() {
|
|
24
|
-
return Object.entries(this._obj);
|
|
25
|
-
}
|
|
26
|
-
keys() {
|
|
27
|
-
return Object.keys(this._obj);
|
|
28
|
-
}
|
|
29
|
-
values() {
|
|
30
|
-
return [...this._arr];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.FieldInfoMap = FieldInfoMap;
|