@sqb/mariadb 6.0.7 → 6.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/LICENSE +30 -191
- package/README.md +4 -3
- package/constants.d.ts +3 -0
- package/constants.js +3 -0
- package/index.d.ts +11 -0
- package/index.js +11 -0
- package/mariadb-adapter.d.ts +11 -0
- package/mariadb-adapter.js +11 -0
- package/mariadb-connection.d.ts +24 -0
- package/mariadb-connection.js +26 -0
- package/mariadb-cursor.d.ts +7 -0
- package/mariadb-cursor.js +7 -0
- package/package.json +10 -7
package/LICENSE
CHANGED
|
@@ -1,191 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"Object" form shall mean any form resulting from mechanical
|
|
32
|
-
transformation or translation of a Source form, including but
|
|
33
|
-
not limited to compiled object code, generated documentation,
|
|
34
|
-
and conversions to other media types.
|
|
35
|
-
|
|
36
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
-
Object form, made available under the License, as indicated by a
|
|
38
|
-
copyright notice that is included in or attached to the work
|
|
39
|
-
(an example is provided in the Appendix below).
|
|
40
|
-
|
|
41
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
-
form, that is based on (or derived from) the Work and for which the
|
|
43
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
-
of this License, Derivative Works shall not include works that remain
|
|
46
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
-
the Work and Derivative Works thereof.
|
|
48
|
-
|
|
49
|
-
"Contribution" shall mean any work of authorship, including
|
|
50
|
-
the original version of the Work and any modifications or additions
|
|
51
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
-
means any form of electronic, verbal, or written communication sent
|
|
56
|
-
to the Licensor or its representatives, including but not limited to
|
|
57
|
-
communication on electronic mailing lists, source code control systems,
|
|
58
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
-
excluding communication that is conspicuously marked or otherwise
|
|
61
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
-
|
|
63
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
-
subsequently incorporated within the Work.
|
|
66
|
-
|
|
67
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
-
Work and such Derivative Works in Source or Object form.
|
|
73
|
-
|
|
74
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
-
(except as stated in this section) patent license to make, have made,
|
|
78
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
-
where such license applies only to those patent claims licensable
|
|
80
|
-
by such Contributor that are necessarily infringed by their
|
|
81
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
-
institute patent litigation against any entity (including a
|
|
84
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
-
or contributory patent infringement, then any patent licenses
|
|
87
|
-
granted to You under this License for that Work shall terminate
|
|
88
|
-
as of the date such litigation is filed.
|
|
89
|
-
|
|
90
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
-
modifications, and in Source or Object form, provided that You
|
|
93
|
-
meet the following conditions:
|
|
94
|
-
|
|
95
|
-
(a) You must give any other recipients of the Work or
|
|
96
|
-
Derivative Works a copy of this License; and
|
|
97
|
-
|
|
98
|
-
(b) You must cause any modified files to carry prominent notices
|
|
99
|
-
stating that You changed the files; and
|
|
100
|
-
|
|
101
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
-
that You distribute, all copyright, patent, trademark, and
|
|
103
|
-
attribution notices from the Source form of the Work,
|
|
104
|
-
excluding those notices that do not pertain to any part of
|
|
105
|
-
the Derivative Works; and
|
|
106
|
-
|
|
107
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
-
distribution, then any Derivative Works that You distribute must
|
|
109
|
-
include a readable copy of the attribution notices contained
|
|
110
|
-
within such NOTICE file, excluding those notices that do not
|
|
111
|
-
pertain to any part of the Derivative Works, in at least one
|
|
112
|
-
of the following places: within a NOTICE text file distributed
|
|
113
|
-
as part of the Derivative Works; within the Source form or
|
|
114
|
-
documentation, if provided along with the Derivative Works; or,
|
|
115
|
-
within a display generated by the Derivative Works, if and
|
|
116
|
-
wherever such third-party notices normally appear. The contents
|
|
117
|
-
of the NOTICE file are for informational purposes only and
|
|
118
|
-
do not modify the License. You may add Your own attribution
|
|
119
|
-
notices within Derivative Works that You distribute, alongside
|
|
120
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
-
that such additional attribution notices cannot be construed
|
|
122
|
-
as modifying the License.
|
|
123
|
-
|
|
124
|
-
You may add Your own copyright statement to Your modifications and
|
|
125
|
-
may provide additional or different license terms and conditions
|
|
126
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
-
the conditions stated in this License.
|
|
130
|
-
|
|
131
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
-
this License, without any additional terms or conditions.
|
|
135
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
-
the terms of any separate license agreement you may have executed
|
|
137
|
-
with Licensor regarding such Contributions.
|
|
138
|
-
|
|
139
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
-
except as required for reasonable and customary use in describing the
|
|
142
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
-
|
|
144
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
-
implied, including, without limitation, any warranties or conditions
|
|
149
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
-
appropriateness of using or redistributing the Work and assume any
|
|
152
|
-
risks associated with Your exercise of permissions under this License.
|
|
153
|
-
|
|
154
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
-
unless required by applicable law (such as deliberate and grossly
|
|
157
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
-
liable to You for damages, including any direct, indirect, special,
|
|
159
|
-
incidental, or consequential damages of any character arising as a
|
|
160
|
-
result of this License or out of the use or inability to use the
|
|
161
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
-
other commercial damages or losses), even if such Contributor
|
|
164
|
-
has been advised of the possibility of such damages.
|
|
165
|
-
|
|
166
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
-
or other liability obligations and/or rights consistent with this
|
|
170
|
-
License. However, in accepting such obligations, You may act only
|
|
171
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
-
defend, and hold each Contributor harmless for any liability
|
|
174
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
-
of your accepting any such warranty or additional liability.
|
|
176
|
-
|
|
177
|
-
END OF TERMS AND CONDITIONS
|
|
178
|
-
|
|
179
|
-
Copyright 2013-2018 Docker, Inc.
|
|
180
|
-
|
|
181
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
-
you may not use this file except in compliance with the License.
|
|
183
|
-
You may obtain a copy of the License at
|
|
184
|
-
|
|
185
|
-
https://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
-
|
|
187
|
-
Unless required by applicable law or agreed to in writing, software
|
|
188
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
-
See the License for the specific language governing permissions and
|
|
191
|
-
limitations under the License.
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Panates
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
notice, this list of conditions and the following disclaimer in the
|
|
14
|
+
documentation and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
23
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
24
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
25
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
26
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
27
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
28
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
29
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
30
|
+
POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
|
|
2
|
+
<p style="text-align: center;">
|
|
3
|
+
<img src="https://sqb.panates.com/img/github-hero.webp" width="1280" alt="SQB" />
|
|
3
4
|
</p>
|
|
4
5
|
|
|
5
6
|
<br>
|
|
@@ -61,5 +62,5 @@ SQB is available under [MIT](LICENSE) license.
|
|
|
61
62
|
[downloads-url]: https://npmjs.org/package/@sqb/mariadb
|
|
62
63
|
[ci-test-image]: https://github.com/panates/sqb/actions/workflows/test.yml/badge.svg
|
|
63
64
|
[ci-test-url]: https://github.com/panates/sqb/actions/workflows/test.yml
|
|
64
|
-
[coveralls-image]: https://coveralls.io/repos/github/
|
|
65
|
+
[coveralls-image]: https://coveralls.io/repos/github/panates/sqb/badge.svg?branch=dev
|
|
65
66
|
[coveralls-url]: https://coveralls.io/github/sqbjs/sqb?branch=master
|
package/constants.d.ts
ADDED
package/constants.js
ADDED
package/index.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sqb/mariadb - `@sqb/connect` database driver for MariaDB, backed by the
|
|
3
|
+
* `mariadb` npm package.
|
|
4
|
+
*
|
|
5
|
+
* Importing this package (even without using any of its exports) registers
|
|
6
|
+
* {@link MariadbAdapter} with `@sqb/connect`'s `AdapterRegistry` as a side
|
|
7
|
+
* effect (and, via `@sqb/mariadb-dialect`, `@sqb/builder`'s
|
|
8
|
+
* `SerializerRegistry`), making `new SqbClient({ dialect: 'mariadb', ... })`
|
|
9
|
+
* work.
|
|
10
|
+
*/
|
|
1
11
|
import '@sqb/mariadb-dialect';
|
|
12
|
+
export * from './constants.js';
|
|
2
13
|
export * from './mariadb-adapter.js';
|
|
3
14
|
export * from './mariadb-connection.js';
|
|
4
15
|
export * from './mariadb-cursor.js';
|
package/index.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sqb/mariadb - `@sqb/connect` database driver for MariaDB, backed by the
|
|
3
|
+
* `mariadb` npm package.
|
|
4
|
+
*
|
|
5
|
+
* Importing this package (even without using any of its exports) registers
|
|
6
|
+
* {@link MariadbAdapter} with `@sqb/connect`'s `AdapterRegistry` as a side
|
|
7
|
+
* effect (and, via `@sqb/mariadb-dialect`, `@sqb/builder`'s
|
|
8
|
+
* `SerializerRegistry`), making `new SqbClient({ dialect: 'mariadb', ... })`
|
|
9
|
+
* work.
|
|
10
|
+
*/
|
|
1
11
|
import '@sqb/mariadb-dialect';
|
|
2
12
|
import { AdapterRegistry } from '@sqb/connect';
|
|
3
13
|
import { MariadbAdapter } from './mariadb-adapter.js';
|
|
14
|
+
export * from './constants.js';
|
|
4
15
|
export * from './mariadb-adapter.js';
|
|
5
16
|
export * from './mariadb-connection.js';
|
|
6
17
|
export * from './mariadb-cursor.js';
|
package/mariadb-adapter.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import '@sqb/mariadb-dialect';
|
|
2
2
|
import type { Adapter, ClientConfiguration } from '@sqb/connect';
|
|
3
|
+
/**
|
|
4
|
+
* `@sqb/connect` {@link Adapter} for MariaDB, wrapping the `mariadb` npm
|
|
5
|
+
* package. Registered automatically as a side effect of importing this
|
|
6
|
+
* package - see `index.ts`.
|
|
7
|
+
*/
|
|
3
8
|
export declare class MariadbAdapter implements Adapter {
|
|
4
9
|
driver: string;
|
|
5
10
|
dialect: string;
|
|
6
11
|
features: Adapter.Features;
|
|
12
|
+
/**
|
|
13
|
+
* Opens a new `mariadb` driver connection, configured for named
|
|
14
|
+
* placeholders and JS-`number` results for decimal/bigint/insert-id
|
|
15
|
+
* values (rather than the driver's default of strings/`BigInt`, for
|
|
16
|
+
* result-shape parity with `@sqb/mysql`).
|
|
17
|
+
*/
|
|
7
18
|
connect(config: ClientConfiguration): Promise<Adapter.Connection>;
|
|
8
19
|
}
|
package/mariadb-adapter.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import '@sqb/mariadb-dialect';
|
|
2
2
|
import { createConnection } from 'mariadb';
|
|
3
3
|
import { MariadbConnection } from './mariadb-connection.js';
|
|
4
|
+
/**
|
|
5
|
+
* `@sqb/connect` {@link Adapter} for MariaDB, wrapping the `mariadb` npm
|
|
6
|
+
* package. Registered automatically as a side effect of importing this
|
|
7
|
+
* package - see `index.ts`.
|
|
8
|
+
*/
|
|
4
9
|
export class MariadbAdapter {
|
|
5
10
|
driver = 'mariadb';
|
|
6
11
|
dialect = 'mariadb';
|
|
@@ -8,6 +13,12 @@ export class MariadbAdapter {
|
|
|
8
13
|
cursor: true,
|
|
9
14
|
positionalParams: true,
|
|
10
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Opens a new `mariadb` driver connection, configured for named
|
|
18
|
+
* placeholders and JS-`number` results for decimal/bigint/insert-id
|
|
19
|
+
* values (rather than the driver's default of strings/`BigInt`, for
|
|
20
|
+
* result-shape parity with `@sqb/mysql`).
|
|
21
|
+
*/
|
|
11
22
|
async connect(config) {
|
|
12
23
|
const cfg = { ...config.driverOptions };
|
|
13
24
|
if (config.host)
|
package/mariadb-connection.d.ts
CHANGED
|
@@ -1,18 +1,42 @@
|
|
|
1
1
|
import type { Adapter, QueryRequest } from '@sqb/connect';
|
|
2
2
|
import type { Connection as MariadbDriverConnection } from 'mariadb';
|
|
3
|
+
/**
|
|
4
|
+
* `@sqb/connect` {@link Adapter.Connection} wrapping a raw `mariadb` driver
|
|
5
|
+
* connection: translates `QueryRequest`s into driver calls (including
|
|
6
|
+
* cursor-mode streaming and `RETURNING`-on-`UPDATE` emulation, since
|
|
7
|
+
* MariaDB doesn't support that natively) and normalizes results/column
|
|
8
|
+
* metadata back into SQB's portable shape.
|
|
9
|
+
*/
|
|
3
10
|
export declare class MariadbConnection implements Adapter.Connection {
|
|
4
11
|
private intlcon?;
|
|
5
12
|
private _inTransaction;
|
|
6
13
|
constructor(conn: MariadbDriverConnection);
|
|
7
14
|
get sessionId(): any;
|
|
15
|
+
/** Forcibly destroys the underlying connection - see the inline comment for why not a graceful `end()`. */
|
|
8
16
|
close(): Promise<void>;
|
|
17
|
+
/** Rolls back any open transaction, readying the connection to be pooled/reused. */
|
|
9
18
|
reset(): Promise<void>;
|
|
19
|
+
/** Begins a transaction (`BEGIN`). */
|
|
10
20
|
startTransaction(): Promise<void>;
|
|
21
|
+
/** Commits the current transaction. */
|
|
11
22
|
commit(): Promise<void>;
|
|
23
|
+
/** Rolls back the current transaction. */
|
|
12
24
|
rollback(): Promise<void>;
|
|
13
25
|
getInTransaction(): boolean;
|
|
26
|
+
/** Validates the connection with a trivial `SELECT 1`. */
|
|
14
27
|
test(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Executes one query: in cursor mode, wraps the driver's row stream in a
|
|
30
|
+
* {@link MariadbCursor}; for an `UPDATE ... RETURNING`, executes the
|
|
31
|
+
* update then runs a synthesized follow-up `SELECT` (MariaDB has no
|
|
32
|
+
* native `RETURNING` on `UPDATE`); otherwise executes directly, reading
|
|
33
|
+
* result rows/metadata off the driver's response (which carries a result
|
|
34
|
+
* set for any statement with a `RETURNING` clause or a plain `SELECT`,
|
|
35
|
+
* and just an affected-row count otherwise).
|
|
36
|
+
*/
|
|
15
37
|
execute(query: QueryRequest): Promise<Adapter.Response>;
|
|
38
|
+
/** Runs a synthesized `SELECT` and copies its rows/fields onto `out` - used to emulate `RETURNING` on `UPDATE`. */
|
|
16
39
|
private _fillSelectResult;
|
|
40
|
+
/** Converts the driver's column metadata into SQB's portable {@link Adapter.Field} shape via {@link typeMap}. */
|
|
17
41
|
private _convertFields;
|
|
18
42
|
}
|
package/mariadb-connection.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MariadbCursor } from './mariadb-cursor.js';
|
|
2
|
+
/** Maps the `mariadb` driver's column type names to SQB's portable `{ dataType, jsType }` pair. */
|
|
2
3
|
const typeMap = {
|
|
3
4
|
DECIMAL: { dataType: 'DECIMAL', jsType: 'number' },
|
|
4
5
|
NEWDECIMAL: { dataType: 'DECIMAL', jsType: 'number' },
|
|
@@ -32,6 +33,13 @@ const typeMap = {
|
|
|
32
33
|
GEOMETRY: { dataType: 'GEOMETRY', jsType: 'Buffer' },
|
|
33
34
|
NULL: { dataType: 'UNKNOWN', jsType: 'any' },
|
|
34
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* `@sqb/connect` {@link Adapter.Connection} wrapping a raw `mariadb` driver
|
|
38
|
+
* connection: translates `QueryRequest`s into driver calls (including
|
|
39
|
+
* cursor-mode streaming and `RETURNING`-on-`UPDATE` emulation, since
|
|
40
|
+
* MariaDB doesn't support that natively) and normalizes results/column
|
|
41
|
+
* metadata back into SQB's portable shape.
|
|
42
|
+
*/
|
|
35
43
|
export class MariadbConnection {
|
|
36
44
|
intlcon;
|
|
37
45
|
_inTransaction = false;
|
|
@@ -41,6 +49,7 @@ export class MariadbConnection {
|
|
|
41
49
|
get sessionId() {
|
|
42
50
|
return this.intlcon?.threadId;
|
|
43
51
|
}
|
|
52
|
+
/** Forcibly destroys the underlying connection - see the inline comment for why not a graceful `end()`. */
|
|
44
53
|
async close() {
|
|
45
54
|
if (!this.intlcon)
|
|
46
55
|
return;
|
|
@@ -51,9 +60,11 @@ export class MariadbConnection {
|
|
|
51
60
|
// and would hang in that case.
|
|
52
61
|
conn.destroy();
|
|
53
62
|
}
|
|
63
|
+
/** Rolls back any open transaction, readying the connection to be pooled/reused. */
|
|
54
64
|
async reset() {
|
|
55
65
|
return this.rollback();
|
|
56
66
|
}
|
|
67
|
+
/** Begins a transaction (`BEGIN`). */
|
|
57
68
|
async startTransaction() {
|
|
58
69
|
assertDefined(this.intlcon);
|
|
59
70
|
// MariaDB implicitly commits any already-active transaction when BEGIN
|
|
@@ -61,12 +72,14 @@ export class MariadbConnection {
|
|
|
61
72
|
await this.intlcon.beginTransaction();
|
|
62
73
|
this._inTransaction = true;
|
|
63
74
|
}
|
|
75
|
+
/** Commits the current transaction. */
|
|
64
76
|
async commit() {
|
|
65
77
|
assertDefined(this.intlcon);
|
|
66
78
|
// COMMIT outside of an active transaction is a no-op in MariaDB.
|
|
67
79
|
await this.intlcon.commit();
|
|
68
80
|
this._inTransaction = false;
|
|
69
81
|
}
|
|
82
|
+
/** Rolls back the current transaction. */
|
|
70
83
|
async rollback() {
|
|
71
84
|
assertDefined(this.intlcon);
|
|
72
85
|
await this.intlcon.rollback();
|
|
@@ -75,10 +88,20 @@ export class MariadbConnection {
|
|
|
75
88
|
getInTransaction() {
|
|
76
89
|
return this._inTransaction;
|
|
77
90
|
}
|
|
91
|
+
/** Validates the connection with a trivial `SELECT 1`. */
|
|
78
92
|
async test() {
|
|
79
93
|
assertDefined(this.intlcon);
|
|
80
94
|
await this.intlcon.query('select 1');
|
|
81
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Executes one query: in cursor mode, wraps the driver's row stream in a
|
|
98
|
+
* {@link MariadbCursor}; for an `UPDATE ... RETURNING`, executes the
|
|
99
|
+
* update then runs a synthesized follow-up `SELECT` (MariaDB has no
|
|
100
|
+
* native `RETURNING` on `UPDATE`); otherwise executes directly, reading
|
|
101
|
+
* result rows/metadata off the driver's response (which carries a result
|
|
102
|
+
* set for any statement with a `RETURNING` clause or a plain `SELECT`,
|
|
103
|
+
* and just an affected-row count otherwise).
|
|
104
|
+
*/
|
|
82
105
|
async execute(query) {
|
|
83
106
|
assertDefined(this.intlcon);
|
|
84
107
|
const intlcon = this.intlcon;
|
|
@@ -147,6 +170,7 @@ export class MariadbConnection {
|
|
|
147
170
|
}
|
|
148
171
|
return out;
|
|
149
172
|
}
|
|
173
|
+
/** Runs a synthesized `SELECT` and copies its rows/fields onto `out` - used to emulate `RETURNING` on `UPDATE`. */
|
|
150
174
|
async _fillSelectResult(out, sql, params, query) {
|
|
151
175
|
assertDefined(this.intlcon);
|
|
152
176
|
const rowsAsArray = !query.objectRows;
|
|
@@ -155,6 +179,7 @@ export class MariadbConnection {
|
|
|
155
179
|
out.rowType = query.objectRows ? 'object' : 'array';
|
|
156
180
|
out.rows = result;
|
|
157
181
|
}
|
|
182
|
+
/** Converts the driver's column metadata into SQB's portable {@link Adapter.Field} shape via {@link typeMap}. */
|
|
158
183
|
_convertFields(fields) {
|
|
159
184
|
const result = [];
|
|
160
185
|
for (const f of fields) {
|
|
@@ -169,6 +194,7 @@ export class MariadbConnection {
|
|
|
169
194
|
return result;
|
|
170
195
|
}
|
|
171
196
|
}
|
|
197
|
+
/** Throws if the connection has already been closed. */
|
|
172
198
|
function assertDefined(d) {
|
|
173
199
|
if (d == null)
|
|
174
200
|
throw new Error('DB session is closed');
|
package/mariadb-cursor.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
2
|
import type { Adapter, RowType } from '@sqb/connect';
|
|
3
|
+
/**
|
|
4
|
+
* `@sqb/connect` {@link Adapter.Cursor} wrapping the `mariadb` driver's
|
|
5
|
+
* `queryStream()` result: consumes it via its async iterator, `fetch(n)`
|
|
6
|
+
* pulling up to `n` rows at a time.
|
|
7
|
+
*/
|
|
3
8
|
export declare class MariadbCursor implements Adapter.Cursor {
|
|
4
9
|
private _iterator?;
|
|
5
10
|
private readonly _rowType;
|
|
@@ -9,6 +14,8 @@ export declare class MariadbCursor implements Adapter.Cursor {
|
|
|
9
14
|
});
|
|
10
15
|
get isClosed(): boolean;
|
|
11
16
|
get rowType(): RowType;
|
|
17
|
+
/** Stops consuming the stream - see the inline comment for why this uses the stream's own `close()` rather than just dropping the iterator. */
|
|
12
18
|
close(): Promise<void>;
|
|
19
|
+
/** Pulls up to `nRows` more rows from the stream, or `undefined` once it's exhausted. */
|
|
13
20
|
fetch(nRows: number): Promise<any[] | undefined>;
|
|
14
21
|
}
|
package/mariadb-cursor.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sqb/connect` {@link Adapter.Cursor} wrapping the `mariadb` driver's
|
|
3
|
+
* `queryStream()` result: consumes it via its async iterator, `fetch(n)`
|
|
4
|
+
* pulling up to `n` rows at a time.
|
|
5
|
+
*/
|
|
1
6
|
export class MariadbCursor {
|
|
2
7
|
_iterator;
|
|
3
8
|
_rowType;
|
|
@@ -13,6 +18,7 @@ export class MariadbCursor {
|
|
|
13
18
|
get rowType() {
|
|
14
19
|
return this._rowType;
|
|
15
20
|
}
|
|
21
|
+
/** Stops consuming the stream - see the inline comment for why this uses the stream's own `close()` rather than just dropping the iterator. */
|
|
16
22
|
async close() {
|
|
17
23
|
this._iterator = undefined;
|
|
18
24
|
// mariadb's stream exposes a custom close() that stops pulling further
|
|
@@ -20,6 +26,7 @@ export class MariadbCursor {
|
|
|
20
26
|
// leave it paused mid-backpressure.
|
|
21
27
|
this._stream.close?.();
|
|
22
28
|
}
|
|
29
|
+
/** Pulls up to `nRows` more rows from the stream, or `undefined` once it's exhausted. */
|
|
23
30
|
async fetch(nRows) {
|
|
24
31
|
if (!this._iterator)
|
|
25
32
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/mariadb",
|
|
3
3
|
"description": "SQB adapter for the mariadb driver",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.10",
|
|
5
5
|
"author": "Panates",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "BSD-3-Clause",
|
|
7
|
+
"homepage": "https://www.sqbjs.org",
|
|
7
8
|
"dependencies": {
|
|
8
9
|
"tslib": "^2.8.1"
|
|
9
10
|
},
|
|
10
11
|
"peerDependencies": {
|
|
11
|
-
"@sqb/builder": "^6.0.
|
|
12
|
-
"@sqb/connect": "^6.0.
|
|
13
|
-
"@sqb/mariadb-dialect": "^6.0.
|
|
12
|
+
"@sqb/builder": "^6.0.10",
|
|
13
|
+
"@sqb/connect": "^6.0.10",
|
|
14
|
+
"@sqb/mariadb-dialect": "^6.0.10",
|
|
14
15
|
"mariadb": "^3.5.4"
|
|
15
16
|
},
|
|
16
17
|
"type": "module",
|
|
@@ -28,7 +29,9 @@
|
|
|
28
29
|
},
|
|
29
30
|
"contributors": [
|
|
30
31
|
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
31
|
-
"Ilker Gurelli <i.gurelli@panates.com>"
|
|
32
|
+
"Ilker Gurelli <i.gurelli@panates.com>",
|
|
33
|
+
"Onur Tokel <o.tokel@panates.com>",
|
|
34
|
+
"Bircan Yuruk <b.yuruk@panates.com>"
|
|
32
35
|
],
|
|
33
36
|
"repository": {
|
|
34
37
|
"type": "git",
|
|
@@ -48,4 +51,4 @@
|
|
|
48
51
|
"publishConfig": {
|
|
49
52
|
"access": "public"
|
|
50
53
|
}
|
|
51
|
-
}
|
|
54
|
+
}
|