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.
- package/README.md +7 -4
- package/dist/lib/impl/attachment.d.ts +4 -4
- package/dist/lib/impl/attachment.js +8 -6
- package/dist/lib/impl/attachment.js.map +1 -1
- package/dist/lib/impl/blob.d.ts +0 -1
- package/dist/lib/impl/blob.js.map +1 -1
- package/dist/lib/impl/client.js +3 -2
- package/dist/lib/impl/client.js.map +1 -1
- package/dist/lib/impl/date-time.js +6 -6
- package/dist/lib/impl/date-time.js.map +1 -1
- package/dist/lib/impl/events.js +2 -1
- package/dist/lib/impl/events.js.map +1 -1
- package/dist/lib/impl/fb-util.d.ts +2 -2
- package/dist/lib/impl/fb-util.js +107 -88
- package/dist/lib/impl/fb-util.js.map +1 -1
- package/dist/lib/impl/resultset.js +11 -5
- package/dist/lib/impl/resultset.js.map +1 -1
- package/dist/lib/impl/statement.js +4 -2
- package/dist/lib/impl/statement.js.map +1 -1
- package/dist/lib/impl/time-zones.js +7 -6
- package/dist/lib/impl/time-zones.js.map +1 -1
- package/dist/lib/impl/transaction.js +2 -1
- package/dist/lib/impl/transaction.js.map +1 -1
- package/dist/lib/index.d.ts +8 -2
- package/dist/lib/index.js +7 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/test/tests.js +177 -70
- package/dist/test/tests.js.map +1 -1
- package/package.json +6 -5
- package/src/lib/impl/attachment.ts +290 -253
- package/src/lib/impl/blob.ts +37 -35
- package/src/lib/impl/client.ts +60 -61
- package/src/lib/impl/date-time.ts +33 -33
- package/src/lib/impl/events.ts +17 -18
- package/src/lib/impl/fb-util.ts +552 -448
- package/src/lib/impl/resultset.ts +94 -86
- package/src/lib/impl/statement.ts +154 -127
- package/src/lib/impl/time-zones.ts +643 -641
- package/src/lib/impl/transaction.ts +37 -38
- package/src/lib/index.ts +325 -285
- package/src/test/tests.ts +996 -860
- package/tsconfig.json +7 -13
package/src/lib/impl/blob.ts
CHANGED
|
@@ -2,41 +2,43 @@ import { AbstractAttachment } from './attachment';
|
|
|
2
2
|
|
|
3
3
|
import { Blob, BlobSeekWhence, BlobStream } from '..';
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
/** AbstractBlobStream implementation. */
|
|
7
6
|
export abstract class AbstractBlobStream extends BlobStream {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
7
|
+
protected constructor(
|
|
8
|
+
blob: Blob,
|
|
9
|
+
public attachment: AbstractAttachment,
|
|
10
|
+
) {
|
|
11
|
+
super(blob);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get length(): Promise<number> {
|
|
15
|
+
return this.internalGetLength();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async close(): Promise<void> {
|
|
19
|
+
return await this.internalClose();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async cancel(): Promise<void> {
|
|
23
|
+
return await this.internalCancel();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async seek(offset: number, whence?: BlobSeekWhence): Promise<number> {
|
|
27
|
+
return await this.internalSeek(offset, whence);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async read(buffer: Buffer): Promise<number> {
|
|
31
|
+
return await this.internalRead(buffer);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async write(buffer: Buffer): Promise<void> {
|
|
35
|
+
return await this.internalWrite(buffer);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected abstract internalGetLength(): Promise<number>;
|
|
39
|
+
protected abstract internalClose(): Promise<void>;
|
|
40
|
+
protected abstract internalCancel(): Promise<void>;
|
|
41
|
+
protected abstract internalSeek(offset: number, whence?: BlobSeekWhence): Promise<number>;
|
|
42
|
+
protected abstract internalRead(buffer: Buffer): Promise<number>;
|
|
43
|
+
protected abstract internalWrite(buffer: Buffer): Promise<void>;
|
|
42
44
|
}
|
package/src/lib/impl/client.ts
CHANGED
|
@@ -1,87 +1,86 @@
|
|
|
1
1
|
import { AbstractAttachment } from './attachment';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
Client,
|
|
5
|
+
ConnectOptions,
|
|
6
|
+
CreateDatabaseOptions,
|
|
7
|
+
ExecuteOptions,
|
|
8
|
+
ExecuteQueryOptions,
|
|
9
|
+
FetchOptions,
|
|
10
|
+
PrepareOptions,
|
|
11
|
+
TransactionOptions,
|
|
12
12
|
} from '..';
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
/** AbstractClient implementation. */
|
|
16
15
|
export abstract class AbstractClient implements Client {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
connected = true;
|
|
17
|
+
attachments = new Set<AbstractAttachment>();
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/** Default connect options. */
|
|
20
|
+
defaultConnectOptions: ConnectOptions;
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
/** Set default create database options. */
|
|
23
|
+
defaultCreateDatabaseOptions: CreateDatabaseOptions;
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/** Default transaction options. */
|
|
26
|
+
defaultTransactionOptions: TransactionOptions;
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
/** Default query's prepare options. */
|
|
29
|
+
defaultPrepareOptions: PrepareOptions;
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
/** Default query's execute options. */
|
|
32
|
+
defaultExecuteOptions: ExecuteOptions;
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
/** Default query's executeQuery options. */
|
|
35
|
+
defaultExecuteQueryOptions: ExecuteQueryOptions;
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
/** Default result set's fetch options. */
|
|
38
|
+
defaultFetchOptions: FetchOptions;
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
/** Disposes this client's resources. */
|
|
41
|
+
async dispose(): Promise<void> {
|
|
42
|
+
this.check();
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
44
|
+
try {
|
|
45
|
+
await Promise.all(Array.from(this.attachments).map((attachment) => attachment.disconnect()));
|
|
46
|
+
} finally {
|
|
47
|
+
this.attachments.clear();
|
|
48
|
+
}
|
|
51
49
|
|
|
52
|
-
|
|
50
|
+
await this.internalDispose();
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
this.connected = false;
|
|
53
|
+
}
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
/** Connects to a database. */
|
|
56
|
+
async connect(uri: string, options?: ConnectOptions): Promise<AbstractAttachment> {
|
|
57
|
+
this.check();
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
const attachment = await this.internalConnect(uri, options || this.defaultConnectOptions);
|
|
60
|
+
this.attachments.add(attachment);
|
|
61
|
+
return attachment;
|
|
62
|
+
}
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
/** Creates a database. */
|
|
65
|
+
async createDatabase(uri: string, options?: CreateDatabaseOptions): Promise<AbstractAttachment> {
|
|
66
|
+
this.check();
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
const attachment = await this.internalCreateDatabase(uri, options || this.defaultCreateDatabaseOptions);
|
|
69
|
+
this.attachments.add(attachment);
|
|
70
|
+
return attachment;
|
|
71
|
+
}
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
get isValid(): boolean {
|
|
74
|
+
return !!this.connected;
|
|
75
|
+
}
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
private check() {
|
|
78
|
+
if (!this.isValid) {
|
|
79
|
+
throw new Error('Client is already disposed.');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
protected abstract internalDispose(): Promise<void>;
|
|
84
|
+
protected abstract internalConnect(uri: string, options?: ConnectOptions): Promise<AbstractAttachment>;
|
|
85
|
+
protected abstract internalCreateDatabase(uri: string, options?: CreateDatabaseOptions): Promise<AbstractAttachment>;
|
|
87
86
|
}
|
|
@@ -25,55 +25,55 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
25
25
|
|
|
26
26
|
/** Decode a date. */
|
|
27
27
|
export function decodeDate(date: number) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
let nday = date + 678882;
|
|
29
|
+
const century = Math.trunc((4 * nday - 1) / 146097);
|
|
30
|
+
nday = 4 * nday - 1 - 146097 * century;
|
|
31
|
+
let day = Math.trunc(nday / 4);
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
nday = Math.trunc((4 * day + 3) / 1461);
|
|
34
|
+
day = 4 * day + 3 - 1461 * nday;
|
|
35
|
+
day = Math.trunc((day + 4) / 4);
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
let month = Math.trunc((5 * day - 3) / 153);
|
|
38
|
+
day = 5 * day - 3 - 153 * month;
|
|
39
|
+
day = Math.trunc((day + 5) / 5);
|
|
40
|
+
let year = 100 * century + nday;
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
if (month < 10) {
|
|
43
|
+
month += 3;
|
|
44
|
+
} else {
|
|
45
|
+
month -= 9;
|
|
46
|
+
year += 1;
|
|
47
|
+
}
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
return { year, month, day };
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/** Encode a date. */
|
|
53
53
|
export function encodeDate(year: number, month: number, day: number): number {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
const i = month + 9;
|
|
55
|
+
let jy = year + Math.trunc(i / 12) - 1;
|
|
56
|
+
const jm = i % 12;
|
|
57
|
+
const c = Math.trunc(jy / 100);
|
|
58
|
+
jy -= 100 * c;
|
|
59
|
+
const j = Math.trunc((146097 * c) / 4) + Math.trunc((1461 * jy) / 4) + Math.trunc((153 * jm + 2) / 5) + day - 678882;
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
return j;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/** Descode a time. */
|
|
65
65
|
export function decodeTime(time: number) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
let seconds = Math.trunc(time / 10000);
|
|
67
|
+
let minutes = Math.trunc(seconds / 60);
|
|
68
|
+
const hours = Math.trunc(minutes / 60);
|
|
69
|
+
minutes = minutes % 60;
|
|
70
|
+
seconds = seconds % 60;
|
|
71
|
+
const fractions = time % 10000;
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
return { hours, minutes, seconds, fractions };
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/** Encode a time. */
|
|
77
77
|
export function encodeTime(hours: number, minutes: number, seconds: number, fractions: number): number {
|
|
78
|
-
|
|
78
|
+
return (hours * 3600 + minutes * 60 + seconds) * 10000 + fractions;
|
|
79
79
|
}
|
package/src/lib/impl/events.ts
CHANGED
|
@@ -2,30 +2,29 @@ import { AbstractAttachment } from './attachment';
|
|
|
2
2
|
|
|
3
3
|
import { Events } from '..';
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
/** AbstractStatement implementation. */
|
|
7
6
|
export abstract class AbstractEvents implements Events {
|
|
8
|
-
|
|
9
|
-
}
|
|
7
|
+
protected constructor(public attachment?: AbstractAttachment) {}
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/** Cancel this events' resources. */
|
|
10
|
+
async cancel(): Promise<void> {
|
|
11
|
+
this.check();
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
await this.internalCancel();
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
this.attachment?.events.delete(this);
|
|
16
|
+
this.attachment = undefined;
|
|
17
|
+
}
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
get isValid(): boolean {
|
|
20
|
+
return !!this.attachment;
|
|
21
|
+
}
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
private check() {
|
|
24
|
+
if (!this.isValid) {
|
|
25
|
+
throw new Error('Events are already cancelled.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
protected abstract internalCancel(): Promise<void>;
|
|
31
30
|
}
|