@sqb/mariadb 6.0.9 → 6.0.11

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 CHANGED
@@ -62,5 +62,5 @@ SQB is available under [MIT](LICENSE) license.
62
62
  [downloads-url]: https://npmjs.org/package/@sqb/mariadb
63
63
  [ci-test-image]: https://github.com/panates/sqb/actions/workflows/test.yml/badge.svg
64
64
  [ci-test-url]: https://github.com/panates/sqb/actions/workflows/test.yml
65
- [coveralls-image]: https://coveralls.io/repos/github/sqbjs/sqb/badge.svg?branch=master
65
+ [coveralls-image]: https://coveralls.io/repos/github/panates/sqb/badge.svg?branch=dev
66
66
  [coveralls-url]: https://coveralls.io/github/sqbjs/sqb?branch=master
package/constants.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /** This package's own version, kept in step with its `package.json` by `rman version`
2
+ * (see `.rmanrc` `version.stamp`) - never edit it by hand. */
3
+ export declare const version = "6.0.11";
package/constants.js ADDED
@@ -0,0 +1,3 @@
1
+ /** This package's own version, kept in step with its `package.json` by `rman version`
2
+ * (see `.rmanrc` `version.stamp`) - never edit it by hand. */
3
+ export const version = '6.0.11';
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';
@@ -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
  }
@@ -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)
@@ -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
  }
@@ -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');
@@ -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,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/mariadb",
3
3
  "description": "SQB adapter for the mariadb driver",
4
- "version": "6.0.9",
4
+ "version": "6.0.11",
5
5
  "author": "Panates",
6
6
  "license": "BSD-3-Clause",
7
7
  "homepage": "https://www.sqbjs.org",
@@ -9,9 +9,9 @@
9
9
  "tslib": "^2.8.1"
10
10
  },
11
11
  "peerDependencies": {
12
- "@sqb/builder": "^6.0.9",
13
- "@sqb/connect": "^6.0.9",
14
- "@sqb/mariadb-dialect": "^6.0.9",
12
+ "@sqb/builder": "^6.0.11",
13
+ "@sqb/connect": "^6.0.11",
14
+ "@sqb/mariadb-dialect": "^6.0.11",
15
15
  "mariadb": "^3.5.4"
16
16
  },
17
17
  "type": "module",
@@ -29,7 +29,9 @@
29
29
  },
30
30
  "contributors": [
31
31
  "Eray Hanoglu <e.hanoglu@panates.com>",
32
- "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>"
33
35
  ],
34
36
  "repository": {
35
37
  "type": "git",
@@ -49,4 +51,4 @@
49
51
  "publishConfig": {
50
52
  "access": "public"
51
53
  }
52
- }
54
+ }