node-firebird-driver 3.2.0 → 3.3.0

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.
Files changed (42) hide show
  1. package/README.md +7 -4
  2. package/dist/lib/impl/attachment.d.ts +4 -4
  3. package/dist/lib/impl/attachment.js +8 -6
  4. package/dist/lib/impl/attachment.js.map +1 -1
  5. package/dist/lib/impl/blob.d.ts +0 -1
  6. package/dist/lib/impl/blob.js.map +1 -1
  7. package/dist/lib/impl/client.js +3 -2
  8. package/dist/lib/impl/client.js.map +1 -1
  9. package/dist/lib/impl/date-time.js +6 -6
  10. package/dist/lib/impl/date-time.js.map +1 -1
  11. package/dist/lib/impl/events.js +2 -1
  12. package/dist/lib/impl/events.js.map +1 -1
  13. package/dist/lib/impl/fb-util.d.ts +2 -2
  14. package/dist/lib/impl/fb-util.js +107 -88
  15. package/dist/lib/impl/fb-util.js.map +1 -1
  16. package/dist/lib/impl/resultset.js +11 -5
  17. package/dist/lib/impl/resultset.js.map +1 -1
  18. package/dist/lib/impl/statement.js +4 -2
  19. package/dist/lib/impl/statement.js.map +1 -1
  20. package/dist/lib/impl/time-zones.js +7 -6
  21. package/dist/lib/impl/time-zones.js.map +1 -1
  22. package/dist/lib/impl/transaction.js +2 -1
  23. package/dist/lib/impl/transaction.js.map +1 -1
  24. package/dist/lib/index.d.ts +8 -2
  25. package/dist/lib/index.js +7 -1
  26. package/dist/lib/index.js.map +1 -1
  27. package/dist/test/tests.js +177 -70
  28. package/dist/test/tests.js.map +1 -1
  29. package/package.json +6 -5
  30. package/src/lib/impl/attachment.ts +290 -253
  31. package/src/lib/impl/blob.ts +37 -35
  32. package/src/lib/impl/client.ts +60 -61
  33. package/src/lib/impl/date-time.ts +33 -33
  34. package/src/lib/impl/events.ts +17 -18
  35. package/src/lib/impl/fb-util.ts +552 -448
  36. package/src/lib/impl/resultset.ts +94 -86
  37. package/src/lib/impl/statement.ts +154 -127
  38. package/src/lib/impl/time-zones.ts +643 -641
  39. package/src/lib/impl/transaction.ts +37 -38
  40. package/src/lib/index.ts +325 -285
  41. package/src/test/tests.ts +996 -860
  42. package/tsconfig.json +7 -13
@@ -3,92 +3,100 @@ import { AbstractTransaction } from './transaction';
3
3
 
4
4
  import { FetchOptions, ResultSet } from '..';
5
5
 
6
-
7
6
  /** AbstractResultSet implementation. */
8
7
  export abstract class AbstractResultSet implements ResultSet {
9
- finished = false;
10
- diposeStatementOnClose = false;
11
-
12
- /** Default result set's fetch options. */
13
- defaultFetchOptions: FetchOptions;
14
-
15
- protected constructor(public statement?: AbstractStatement, public transaction?: AbstractTransaction) {
16
- }
17
-
18
- /** Closes this result set. */
19
- async close(): Promise<void> {
20
- this.check();
21
-
22
- if (this.diposeStatementOnClose) {
23
- this.diposeStatementOnClose = false;
24
- await this.statement!.dispose();
25
- return;
26
- }
27
-
28
- await this.internalClose();
29
-
30
- this.statement!.resultSet = undefined;
31
- this.statement = undefined;
32
- }
33
-
34
- /**
35
- * Fetchs data from this result set as [col1, col2, ..., colN][].
36
- *
37
- * If an exception is found after fetching a row but before reaching options.fetchSize, its throw is delayed for the next fetch call.
38
- *
39
- * If result set has no more rows, returns an empty array.
40
- */
41
- async fetch(options?: FetchOptions): Promise<any[][]> {
42
- this.check();
43
-
44
- if (this.finished)
45
- return [];
46
-
47
- const fetchRet = await this.internalFetch(
48
- options || this.defaultFetchOptions || this.statement!.defaultFetchOptions || this.statement!.attachment!.defaultFetchOptions ||
49
- this.statement!.attachment!.client!.defaultFetchOptions);
50
-
51
- if (fetchRet.finished)
52
- this.finished = true;
53
-
54
- return fetchRet.rows;
55
- }
56
-
57
- /**
58
- * Fetchs data from this result set as T[].
59
- * Where <T> represents your object interface.
60
- *
61
- * If an exception is found after fetching a row but before reaching options.fetchSize, its throw is delayed for the next fetch call.
62
- *
63
- * If result set has no more rows, returns an empty array.
64
- */
65
- async fetchAsObject<T extends object>(options?: FetchOptions): Promise<T[]> {
66
- const array = await this.fetch(options);
67
- const cols = (await this.statement?.columnLabels) || [];
68
-
69
- return array.map(row => {
70
- const obj = {} as T;
71
-
72
- // Loop on row column value.
73
- row.forEach((v: any, idx: number) => {
74
- const col = cols[idx];
75
- (obj as any)[col] = v;
76
- });
77
-
78
- return obj;
79
- });
80
- }
81
-
82
- get isValid(): boolean {
83
- return !!this.statement;
84
- }
85
-
86
- private check() {
87
- if (!this.isValid)
88
- throw new Error('ResultSet is already closed.');
89
- }
90
-
91
- protected abstract internalClose(): Promise<void>;
92
-
93
- protected abstract internalFetch(options?: FetchOptions): Promise<{ finished: boolean; rows: any[][] }>;
8
+ finished = false;
9
+ diposeStatementOnClose = false;
10
+
11
+ /** Default result set's fetch options. */
12
+ defaultFetchOptions: FetchOptions;
13
+
14
+ protected constructor(
15
+ public statement?: AbstractStatement,
16
+ public transaction?: AbstractTransaction,
17
+ ) {}
18
+
19
+ /** Closes this result set. */
20
+ async close(): Promise<void> {
21
+ this.check();
22
+
23
+ if (this.diposeStatementOnClose) {
24
+ this.diposeStatementOnClose = false;
25
+ await this.statement!.dispose();
26
+ return;
27
+ }
28
+
29
+ await this.internalClose();
30
+
31
+ this.statement!.resultSet = undefined;
32
+ this.statement = undefined;
33
+ }
34
+
35
+ /**
36
+ * Fetchs data from this result set as [col1, col2, ..., colN][].
37
+ *
38
+ * If an exception is found after fetching a row but before reaching options.fetchSize, its throw is delayed for the next fetch call.
39
+ *
40
+ * If result set has no more rows, returns an empty array.
41
+ */
42
+ async fetch(options?: FetchOptions): Promise<any[][]> {
43
+ this.check();
44
+
45
+ if (this.finished) {
46
+ return [];
47
+ }
48
+
49
+ const fetchRet = await this.internalFetch(
50
+ options ||
51
+ this.defaultFetchOptions ||
52
+ this.statement!.defaultFetchOptions ||
53
+ this.statement!.attachment!.defaultFetchOptions ||
54
+ this.statement!.attachment!.client!.defaultFetchOptions,
55
+ );
56
+
57
+ if (fetchRet.finished) {
58
+ this.finished = true;
59
+ }
60
+
61
+ return fetchRet.rows;
62
+ }
63
+
64
+ /**
65
+ * Fetchs data from this result set as T[].
66
+ * Where <T> represents your object interface.
67
+ *
68
+ * If an exception is found after fetching a row but before reaching options.fetchSize, its throw is delayed for the next fetch call.
69
+ *
70
+ * If result set has no more rows, returns an empty array.
71
+ */
72
+ async fetchAsObject<T extends object>(options?: FetchOptions): Promise<T[]> {
73
+ const array = await this.fetch(options);
74
+ const cols = (await this.statement?.columnLabels) || [];
75
+
76
+ return array.map((row) => {
77
+ const obj = {} as T;
78
+
79
+ // Loop on row column value.
80
+ row.forEach((v: any, idx: number) => {
81
+ const col = cols[idx];
82
+ (obj as any)[col] = v;
83
+ });
84
+
85
+ return obj;
86
+ });
87
+ }
88
+
89
+ get isValid(): boolean {
90
+ return !!this.statement;
91
+ }
92
+
93
+ private check() {
94
+ if (!this.isValid) {
95
+ throw new Error('ResultSet is already closed.');
96
+ }
97
+ }
98
+
99
+ protected abstract internalClose(): Promise<void>;
100
+
101
+ protected abstract internalFetch(options?: FetchOptions): Promise<{ finished: boolean; rows: any[][] }>;
94
102
  }
@@ -2,134 +2,161 @@ import { AbstractAttachment } from './attachment';
2
2
  import { AbstractResultSet } from './resultset';
3
3
  import { AbstractTransaction } from './transaction';
4
4
 
5
- import {
6
- ExecuteOptions,
7
- ExecuteQueryOptions,
8
- FetchOptions,
9
- Statement
10
- } from '..';
11
-
5
+ import { ExecuteOptions, ExecuteQueryOptions, FetchOptions, Statement } from '..';
12
6
 
13
7
  /** AbstractStatement implementation. */
14
8
  export abstract class AbstractStatement implements Statement {
15
- resultSet?: AbstractResultSet;
16
-
17
- abstract getExecPathText(): Promise<string | undefined>;
18
-
19
- /** Gets the query's result columns labels. Returns empty array for queries without result. */
20
- abstract get columnLabels(): Promise<string[]>
21
-
22
- /** When true, query result must be obtained with method executeQuery. */
23
- readonly hasResultSet: boolean;
24
-
25
- /** Default query's execute options. */
26
- defaultExecuteOptions: ExecuteOptions;
27
-
28
- /** Default query's executeQuery options. */
29
- defaultExecuteQueryOptions: ExecuteQueryOptions;
30
-
31
- /** Default result set's fetch options. */
32
- defaultFetchOptions: FetchOptions;
33
-
34
- protected constructor(public attachment?: AbstractAttachment) {
35
- }
36
-
37
- /** Disposes this statement's resources. */
38
- async dispose(): Promise<void> {
39
- this.check();
40
-
41
- if (this.resultSet)
42
- await this.resultSet.close();
43
-
44
- await this.internalDispose();
45
-
46
- this.attachment!.statements.delete(this);
47
- this.attachment = undefined;
48
- }
49
-
50
- /** Executes a prepared statement that uses the SET TRANSACTION command. Returns the new transaction. */
51
- async executeTransaction(transaction: AbstractTransaction): Promise<AbstractTransaction> {
52
- this.check();
53
-
54
- //// TODO: check opened resultSet.
55
- return await this.internalExecuteTransaction(transaction);
56
- }
57
-
58
- /** Executes a prepared statement that has no result set. */
59
- async execute(transaction: AbstractTransaction, parameters?: any[], options?: ExecuteOptions): Promise<void> {
60
- this.check();
61
-
62
- //// TODO: check opened resultSet.
63
- await this.internalExecute(transaction, parameters,
64
- options || this.attachment!.defaultExecuteOptions || this.attachment!.client!.defaultExecuteOptions);
65
- }
66
-
67
- /** Executes a statement that returns a single record as [col1, col2, ..., colN]. */
68
- async executeSingleton(transaction: AbstractTransaction, parameters?: any[], options?: ExecuteOptions): Promise<any[]> {
69
- this.check();
70
-
71
- //// TODO: check opened resultSet.
72
- return await this.internalExecute(transaction, parameters,
73
- options || this.attachment!.defaultExecuteOptions || this.attachment!.client!.defaultExecuteOptions);
74
- }
75
-
76
- /** Executes a statement that returns a single record as an object. */
77
- async executeSingletonAsObject<T extends object>(transaction: AbstractTransaction, parameters?: any[],
78
- options?: ExecuteOptions): Promise<T> {
79
- this.check();
80
-
81
- const row = await this.executeSingleton(transaction, parameters, options);
82
- const cols = (await this?.columnLabels) || [];
83
-
84
- const obj = {} as T;
85
-
86
- // Loop on row column value.
87
- row.forEach((v: any, idx: number) => {
88
- const col = cols[idx];
89
- (obj as any)[col] = v;
90
- });
91
-
92
- return obj;
93
- }
94
-
95
- /** Executes a statement that returns a single record as [col1, col2, ..., colN]. */
96
- async executeReturning(transaction: AbstractTransaction, parameters?: any[], options?: ExecuteOptions): Promise<any[]> {
97
- return await this.executeSingleton(transaction, parameters, options);
98
- }
99
-
100
- /** Executes a statement that returns a single record as an object. */
101
- async executeReturningAsObject<T extends object>(transaction: AbstractTransaction, parameters?: any[],
102
- options?: ExecuteOptions): Promise<T> {
103
- return await this.executeSingletonAsObject<T>(transaction, parameters, options);
104
- }
105
-
106
- /** Executes a prepared statement that has result set. */
107
- async executeQuery(transaction: AbstractTransaction, parameters?: any[], options?: ExecuteQueryOptions):
108
- Promise<AbstractResultSet> {
109
- this.check();
110
-
111
- //// TODO: check opened resultSet.
112
- const resultSet = await this.internalExecuteQuery(transaction, parameters,
113
- options || this.attachment!.defaultExecuteQueryOptions || this.attachment!.client!.defaultExecuteQueryOptions);
114
- this.resultSet = resultSet;
115
- return resultSet;
116
- }
117
-
118
- get isValid(): boolean {
119
- return !!this.attachment;
120
- }
121
-
122
- private check() {
123
- if (!this.isValid)
124
- throw new Error('Statement is already disposed.');
125
- }
126
-
127
- public abstract setCursorName(cursorName: string): Promise<void>;
128
-
129
- protected abstract internalDispose(): Promise<void>;
130
- protected abstract internalExecuteTransaction(transaction: AbstractTransaction): Promise<AbstractTransaction>;
131
- protected abstract internalExecute(transaction: AbstractTransaction, parameters?: any[], options?: ExecuteOptions):
132
- Promise<any[]>;
133
- protected abstract internalExecuteQuery(transaction: AbstractTransaction, parameters?: any[], options?: ExecuteQueryOptions):
134
- Promise<AbstractResultSet>;
9
+ resultSet?: AbstractResultSet;
10
+
11
+ abstract getExecPathText(): Promise<string | undefined>;
12
+
13
+ /** Gets the query's result columns labels. Returns empty array for queries without result. */
14
+ abstract get columnLabels(): Promise<string[]>;
15
+
16
+ /** When true, query result must be obtained with method executeQuery. */
17
+ readonly hasResultSet: boolean;
18
+
19
+ /** Default query's execute options. */
20
+ defaultExecuteOptions: ExecuteOptions;
21
+
22
+ /** Default query's executeQuery options. */
23
+ defaultExecuteQueryOptions: ExecuteQueryOptions;
24
+
25
+ /** Default result set's fetch options. */
26
+ defaultFetchOptions: FetchOptions;
27
+
28
+ protected constructor(public attachment?: AbstractAttachment) {}
29
+
30
+ /** Disposes this statement's resources. */
31
+ async dispose(): Promise<void> {
32
+ this.check();
33
+
34
+ if (this.resultSet) {
35
+ await this.resultSet.close();
36
+ }
37
+
38
+ await this.internalDispose();
39
+
40
+ this.attachment!.statements.delete(this);
41
+ this.attachment = undefined;
42
+ }
43
+
44
+ /** Executes a prepared statement that uses the SET TRANSACTION command. Returns the new transaction. */
45
+ async executeTransaction(transaction: AbstractTransaction): Promise<AbstractTransaction> {
46
+ this.check();
47
+
48
+ //// TODO: check opened resultSet.
49
+ return await this.internalExecuteTransaction(transaction);
50
+ }
51
+
52
+ /** Executes a prepared statement that has no result set. */
53
+ async execute(transaction: AbstractTransaction, parameters?: any[], options?: ExecuteOptions): Promise<void> {
54
+ this.check();
55
+
56
+ //// TODO: check opened resultSet.
57
+ await this.internalExecute(
58
+ transaction,
59
+ parameters,
60
+ options || this.attachment!.defaultExecuteOptions || this.attachment!.client!.defaultExecuteOptions,
61
+ );
62
+ }
63
+
64
+ /** Executes a statement that returns a single record as [col1, col2, ..., colN]. */
65
+ async executeSingleton(
66
+ transaction: AbstractTransaction,
67
+ parameters?: any[],
68
+ options?: ExecuteOptions,
69
+ ): Promise<any[]> {
70
+ this.check();
71
+
72
+ //// TODO: check opened resultSet.
73
+ return await this.internalExecute(
74
+ transaction,
75
+ parameters,
76
+ options || this.attachment!.defaultExecuteOptions || this.attachment!.client!.defaultExecuteOptions,
77
+ );
78
+ }
79
+
80
+ /** Executes a statement that returns a single record as an object. */
81
+ async executeSingletonAsObject<T extends object>(
82
+ transaction: AbstractTransaction,
83
+ parameters?: any[],
84
+ options?: ExecuteOptions,
85
+ ): Promise<T> {
86
+ this.check();
87
+
88
+ const row = await this.executeSingleton(transaction, parameters, options);
89
+ const cols = (await this?.columnLabels) || [];
90
+
91
+ const obj = {} as T;
92
+
93
+ // Loop on row column value.
94
+ row.forEach((v: any, idx: number) => {
95
+ const col = cols[idx];
96
+ (obj as any)[col] = v;
97
+ });
98
+
99
+ return obj;
100
+ }
101
+
102
+ /** Executes a statement that returns a single record as [col1, col2, ..., colN]. */
103
+ async executeReturning(
104
+ transaction: AbstractTransaction,
105
+ parameters?: any[],
106
+ options?: ExecuteOptions,
107
+ ): Promise<any[]> {
108
+ return await this.executeSingleton(transaction, parameters, options);
109
+ }
110
+
111
+ /** Executes a statement that returns a single record as an object. */
112
+ async executeReturningAsObject<T extends object>(
113
+ transaction: AbstractTransaction,
114
+ parameters?: any[],
115
+ options?: ExecuteOptions,
116
+ ): Promise<T> {
117
+ return await this.executeSingletonAsObject<T>(transaction, parameters, options);
118
+ }
119
+
120
+ /** Executes a prepared statement that has result set. */
121
+ async executeQuery(
122
+ transaction: AbstractTransaction,
123
+ parameters?: any[],
124
+ options?: ExecuteQueryOptions,
125
+ ): Promise<AbstractResultSet> {
126
+ this.check();
127
+
128
+ //// TODO: check opened resultSet.
129
+ const resultSet = await this.internalExecuteQuery(
130
+ transaction,
131
+ parameters,
132
+ options || this.attachment!.defaultExecuteQueryOptions || this.attachment!.client!.defaultExecuteQueryOptions,
133
+ );
134
+ this.resultSet = resultSet;
135
+ return resultSet;
136
+ }
137
+
138
+ get isValid(): boolean {
139
+ return !!this.attachment;
140
+ }
141
+
142
+ private check() {
143
+ if (!this.isValid) {
144
+ throw new Error('Statement is already disposed.');
145
+ }
146
+ }
147
+
148
+ public abstract setCursorName(cursorName: string): Promise<void>;
149
+
150
+ protected abstract internalDispose(): Promise<void>;
151
+ protected abstract internalExecuteTransaction(transaction: AbstractTransaction): Promise<AbstractTransaction>;
152
+ protected abstract internalExecute(
153
+ transaction: AbstractTransaction,
154
+ parameters?: any[],
155
+ options?: ExecuteOptions,
156
+ ): Promise<any[]>;
157
+ protected abstract internalExecuteQuery(
158
+ transaction: AbstractTransaction,
159
+ parameters?: any[],
160
+ options?: ExecuteQueryOptions,
161
+ ): Promise<AbstractResultSet>;
135
162
  }