node-firebird 0.9.9 → 1.1.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.
@@ -0,0 +1,78 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ${{ matrix.os }}
8
+
9
+ strategy:
10
+ matrix:
11
+ os: [ubuntu-16.04, ubuntu-18.04, windows-2019, macos-10.15]
12
+ node-version: [10.x, 12.x, 14.x, 15.x]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v1
16
+ with:
17
+ fetch-depth: 10
18
+
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v1
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+
24
+ - name: Firebird install (Linux)
25
+ if: matrix.os == 'ubuntu-16.04' || matrix.os == 'ubuntu-18.04'
26
+ run: |
27
+ if [ `lsb_release -rs` = '16.04' ]
28
+ then
29
+ sudo apt-get install libtommath0
30
+ else
31
+ sudo apt-get install libtommath1
32
+ sudo ln -s /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0
33
+ fi
34
+ wget -nv -O Firebird-3.0.7.33374-0.amd64.tar.gz "https://github.com/FirebirdSQL/firebird/releases/download/R3_0_7/Firebird-3.0.7.33374-0.amd64.tar.gz"
35
+ tar xzvf Firebird-3.0.7.33374-0.amd64.tar.gz
36
+ (cd Firebird-3.0.7.33374-0.amd64; sudo ./install.sh -silent)
37
+ sudo usermod -a -G firebird `whoami`
38
+
39
+ - name: Firebird install (MacOS)
40
+ if: matrix.os == 'macos-10.15'
41
+ run: |
42
+ wget -nv -O Firebird-3.0.7-33374-x86_64.pkg "https://github.com/FirebirdSQL/firebird/releases/download/R3_0_7/Firebird-3.0.7-33374-x86_64.pkg"
43
+ sudo installer -verbose -pkg "Firebird-3.0.7-33374-x86_64.pkg" -target /
44
+
45
+ - name: Firebird install (Windows)
46
+ if: matrix.os == 'windows-2019'
47
+ shell: cmd
48
+ run: |
49
+ set FB_ZIP=Firebird-3.0.7.33374-1_x64.zip
50
+ powershell Invoke-WebRequest "https://github.com/FirebirdSQL/firebird/releases/download/R3_0_7/$env:FB_ZIP" -OutFile "$env:FB_ZIP"
51
+ 7z x -oC:\Firebird %FB_ZIP%
52
+
53
+ - name: Build
54
+ shell: bash
55
+ run: |
56
+ npm ci
57
+
58
+ - name: Test (Linux)
59
+ if: matrix.os == 'ubuntu-16.04' || matrix.os == 'ubuntu-18.04'
60
+ run: |
61
+ sg firebird -c "npx nyc npm test"
62
+
63
+ - name: Test (MacOS)
64
+ if: matrix.os == 'macos-10.15'
65
+ run: |
66
+ sudo mkdir `pwd`/tmp-node-fb
67
+ sudo chmod 777 `pwd`/tmp-node-fb
68
+ export ISC_USER=sysdba
69
+ export ISC_PASSWORD=masterkey
70
+ export NODE_FB_TEST_TMP_DIR=`pwd`/tmp-node-fb
71
+ npx nyc npm test
72
+
73
+ - name: Test (Windows)
74
+ if: matrix.os == 'windows-2019'
75
+ shell: cmd
76
+ run: |
77
+ set PATH=C:\Firebird;%PATH%
78
+ call npx nyc npm test
package/README.md CHANGED
@@ -66,7 +66,9 @@ options.password = 'masterkey';
66
66
  options.lowercase_keys = false; // set to true to lowercase keys
67
67
  options.role = null; // default
68
68
  options.pageSize = 4096; // default when creating database
69
-
69
+ options.pageSize = 4096; // default when creating database
70
+ options.retryConnectionInterval = 1000; // reconnect interval in case of connection drop
71
+ options.blobAsText = false; // set to true to get blob as text, only affects blob subtype 1
70
72
  ```
71
73
 
72
74
  ### Classic
@@ -183,7 +185,7 @@ Firebird.attach(options, function(err, db) {
183
185
  });
184
186
  ```
185
187
 
186
- ### Reading Blobs (Aasynchronous)
188
+ ### Reading Blobs (Asynchronous)
187
189
 
188
190
  ```js
189
191
  Firebird.attach(options, function(err, db) {
@@ -222,6 +224,73 @@ Firebird.attach(options, function(err, db) {
222
224
  });
223
225
  ```
224
226
 
227
+ ### Reading Multiples Blobs (Asynchronous)
228
+ ```js
229
+ Firebird.attach(options, (err, db) => {
230
+ if (err)
231
+ throw err;
232
+
233
+ db.transaction(Firebird.ISOLATION_READ_COMMITED, (err, transaction) => {
234
+ if (err) {
235
+ throw err;
236
+ }
237
+
238
+ transaction.query('SELECT FIRST 10 * FROM JOB', (err, result) => {
239
+ if (err) {
240
+ transaction.rollback();
241
+ return;
242
+ }
243
+
244
+ const arrBlob = [];
245
+ for (const item of result) {
246
+ const fields = Object.keys(item);
247
+ for (const key of fields) {
248
+ if (typeof item[key] === 'function') {
249
+ item[key] = new Promise((resolve, reject) => {
250
+ // the same transaction is used (better performance)
251
+ // this is optional
252
+ item[key](transaction, (error, name, event, row) => {
253
+ if (error) {
254
+ return reject(error);
255
+ }
256
+
257
+ // reading data
258
+ let value = '';
259
+ event.on('data', (chunk) => {
260
+ value += chunk.toString('binary');
261
+ });
262
+ event.on('end', () => {
263
+ resolve({ value, column: name, row });
264
+ });
265
+ });
266
+ });
267
+ arrBlob.push(item[key]);
268
+ }
269
+ }
270
+ }
271
+
272
+ Promise.all(arrBlob).then((blobs) => {
273
+ for (const blob of blobs) {
274
+ result[blob.row][blob.column] = blob.value;
275
+ }
276
+
277
+ transaction.commit((err) => {
278
+ if (err) {
279
+ transaction.rollback();
280
+ return;
281
+ }
282
+
283
+ db.detach();
284
+ console.log(result);
285
+ });
286
+ }).catch((err) => {
287
+ transaction.rollback();
288
+ });
289
+ });
290
+ });
291
+ });
292
+ ```
293
+
225
294
  ### Streaming a big data
226
295
 
227
296
  ```js
@@ -513,7 +582,7 @@ This is why you should use **Firebird 2.5** server at least.
513
582
  ### Firebird 3.0 Support
514
583
 
515
584
  Firebird new wire protocol is not supported yet so
516
- for Firebird 3.0 you need to add the following in firebird.conf according to Firebird documentation
585
+ for Firebird 3.0 you need to add the following in firebird.conf according to Firebird 3 release notes
517
586
  <https://firebirdsql.org/file/documentation/release_notes/html/en/3_0/rnfb30-security-new-authentication.html>
518
587
 
519
588
  ```bash
@@ -522,6 +591,21 @@ WireCrypt = Disabled
522
591
  UserManager = Legacy_UserManager
523
592
  ```
524
593
 
594
+ Firebird 4 wire protocol is not supported yet so
595
+ for Firebird 4.0 you need to add the following in firebird.conf according to Firebird release notes
596
+ <https://firebirdsql.org/file/documentation/release_notes/html/en/4_0/rlsnotes40.html#rnfb40-config-srp256>
597
+
598
+ ```bash
599
+ AuthServer = Srp256, Srp, Legacy_Auth
600
+ WireCrypt = Disabled
601
+ UserManager = Legacy_UserManager
602
+ ```
603
+
604
+ Please read also Authorization with Firebird 2.5 client library from Firebird 4 migration guide
605
+ <https://ib-aid.com/download/docs/fb4migrationguide.html#_authorization_with_firebird_2_5_client_library_fbclient_dll>
606
+
607
+
608
+
525
609
  ## Contributors
526
610
 
527
611
  - Henri Gourvest, <https://github.com/hgourvest>
package/lib/index.d.ts CHANGED
@@ -9,9 +9,23 @@ declare module 'node-firebird' {
9
9
  type SimpleCallback = (err: any) => void;
10
10
  type SequentialCallback = (row: any, index: number) => void;
11
11
 
12
+ export const AUTH_PLUGIN_LEGACY: string;
13
+ export const AUTH_PLUGIN_SRP: string;
14
+ export const AUTH_PLUGIN_SRP256: string;
15
+
16
+ export const WIRE_CRYPT_ENABLE: number;
17
+ export const WIRE_CRYPT_DISABLE: number;
18
+
19
+ /** A transaction sees changes done by uncommitted transactions. */
12
20
  export const ISOLATION_READ_UNCOMMITTED: number[];
21
+ /** A transaction sees only data committed before the statement has been executed. */
13
22
  export const ISOLATION_READ_COMMITED: number[];
23
+ /** A transaction sees during its lifetime only data committed before the transaction has been started. */
14
24
  export const ISOLATION_REPEATABLE_READ: number[];
25
+ /**
26
+ * This is the strictest isolation level, which enforces transaction serialization.
27
+ * Data accessed in the context of a serializable transaction cannot be accessed by any other transaction.
28
+ */
15
29
  export const ISOLATION_SERIALIZABLE: number[];
16
30
  export const ISOLATION_READ_COMMITED_READ_ONLY: number[];
17
31
 
@@ -37,6 +51,37 @@ declare module 'node-firebird' {
37
51
  rollbackRetaining(callback?: SimpleCallback): void;
38
52
  }
39
53
 
54
+ export type SupportedCharacterSet = |
55
+ 'NONE' |
56
+ 'CP943C' |
57
+ 'DOS737' |
58
+ 'DOS775' |
59
+ 'DOS858' |
60
+ 'DOS862' |
61
+ 'DOS864' |
62
+ 'DOS866' |
63
+ 'DOS869' |
64
+ 'GB18030' |
65
+ 'GBK' |
66
+ 'ISO8859_2' |
67
+ 'ISO8859_3' |
68
+ 'ISO8859_4' |
69
+ 'ISO8859_5' |
70
+ 'ISO8859_6' |
71
+ 'ISO8859_7' |
72
+ 'ISO8859_8' |
73
+ 'ISO8859_9' |
74
+ 'ISO8859_13' |
75
+ 'KOI8R' |
76
+ 'KOI8U' |
77
+ 'TIS620' |
78
+ 'UTF8' |
79
+ 'WIN1255' |
80
+ 'WIN1256' |
81
+ 'WIN1257' |
82
+ 'WIN1258' |
83
+ 'WIN_1258';
84
+
40
85
  export interface Options {
41
86
  host?: string;
42
87
  port?: number;
@@ -46,6 +91,9 @@ declare module 'node-firebird' {
46
91
  lowercase_keys?: boolean;
47
92
  role?: string;
48
93
  pageSize?: number;
94
+ retryConnectionInterval?: number;
95
+ encoding?: SupportedCharacterSet;
96
+ blobAsText?: boolean; // only affects for blob subtype 1
49
97
  }
50
98
 
51
99
  export interface SvcMgrOptions extends Options {
@@ -54,12 +102,12 @@ declare module 'node-firebird' {
54
102
 
55
103
  export interface ConnectionPool {
56
104
  get(callback: DatabaseCallback): void;
57
- destroy(): void;
105
+ destroy(callback?: SimpleCallback): void;
58
106
  }
59
107
 
60
108
  export function attach(options: Options, callback: DatabaseCallback): void;
61
109
  export function attach(options: SvcMgrOptions, callback: ServiceManagerCallback): void;
62
- export function escape(value: any, protocolVersion: number /*PROTOCOL_VERSION13*/): string;
110
+ export function escape(value: any, protocolVersion?: number /*PROTOCOL_VERSION13*/): string;
63
111
  export function create(options: Options, callback: DatabaseCallback): void;
64
112
  export function attachOrCreate(options: Options, callback: DatabaseCallback): void;
65
113
  export function pool(max: number, options: Options): ConnectionPool;
@@ -207,18 +255,18 @@ declare module 'node-firebird' {
207
255
  backup(options: BackupOptions, callback: ReadableCallback): void;
208
256
  nbackup(options: BackupOptions, callback: ReadableCallback): void;
209
257
  restore(options: NRestoreOptions, callback: ReadableCallback): void;
210
- nrestore(options, callback): void;
258
+ nrestore(options: any, callback: Function): void;
211
259
  setDialect(db: string, dialect: 1 | 3, callback: ReadableCallback): void;
212
- setSweepinterval(db: string, interval: number, callback): void; // gfix -h INTERVAL
213
- setCachebuffer(db: string, nbpages, callback: ReadableCallback): void; // gfix -b NBPAGES
260
+ setSweepinterval(db: string, interval: number, callback: Function): void; // gfix -h INTERVAL
261
+ setCachebuffer(db: string, nbpages: any, callback: ReadableCallback): void; // gfix -b NBPAGES
214
262
  BringOnline(db: string, callback: ReadableCallback): void; // gfix -o
215
263
  Shutdown(db: string, kind: ShutdownKind, delay: number, mode: ShutdownMode, callback: ReadableCallback): void; // server version >= 2.0
216
264
  Shutdown(db: string, kind: ShutdownKind, delay: number, callback: ReadableCallback): void; // server version < 2.0
217
265
  setShadow(db: string, val: boolean, callback: ReadableCallback): void;
218
266
  setForcewrite(db: string, val: boolean, callback: ReadableCallback): void; // gfix -write
219
267
  setReservespace(db: string, val: boolean, callback: ReadableCallback): void; // true: gfix -use reserve, false: gfix -use full
220
- setReadonlyMode(db: string, callback: ReadableCallback): void; // gfix -mode read_only
221
- setReadwriteMode(db: string, callback: ReadableCallback): void; // gfix -mode read_write
268
+ setReadonlyMode(db: string, callback: ReadableCallback): void; // gfix -mode read_only
269
+ setReadwriteMode(db: string, callback: ReadableCallback): void; // gfix -mode read_write
222
270
  validate(options: ValidateOptions, callback: ReadableCallback): void; // gfix -validate
223
271
  commit(db: string, transactid: number, callback: ReadableCallback): void; // gfix -commit
224
272
  rollback(db: string, transactid: number, callback: ReadableCallback): void;