@prisma/adapter-mariadb 6.11.0-dev.20

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @prisma/adapter-mariadb
2
+
3
+ This package contains the driver adapter for Prisma ORM that enables usage of the [`mariadb`](https://github.com/mariadb-corporation/mariadb-connector-nodejs) database driver for MariaDB and MySQL databases.
4
+
5
+ `mariadb` is the official MariaDB connector for Node.js, providing high-performance access to MariaDB and MySQL databases. It can be used with any MariaDB or MySQL database that's accessed via TCP, including cloud-hosted instances.
6
+
7
+ ## Usage
8
+
9
+ This section explains how you can use it with Prisma ORM and the `@prisma/adapter-mariadb` driver adapter. Be sure that the `DATABASE_URL` environment variable is set to your MariaDB/MySQL connection string (e.g. in a `.env` file).
10
+
11
+ ### 1. Enable the `driverAdapters` Preview feature flag
12
+
13
+ Since driver adapters are currently in Preview, you need to enable its feature flag on the `datasource` block in your Prisma schema:
14
+
15
+ ```prisma
16
+ // schema.prisma
17
+ generator client {
18
+ provider = "prisma-client-js"
19
+ previewFeatures = ["driverAdapters"]
20
+ }
21
+
22
+ datasource db {
23
+ provider = "mysql"
24
+ url = env("DATABASE_URL")
25
+ }
26
+ ```
27
+
28
+ Once you have added the feature flag to your schema, re-generate Prisma Client:
29
+
30
+ ```
31
+ npx prisma generate
32
+ ```
33
+
34
+ ### 2. Install the dependencies
35
+
36
+ Next, install the MariaDB Prisma ORM driver adapter:
37
+
38
+ ```
39
+ npm install @prisma/adapter-mariadb
40
+ ```
41
+
42
+ ### 3. Instantiate Prisma Client using the driver adapter
43
+
44
+ ```ts
45
+ import { PrismaMariaDb } from '@prisma/adapter-mariadb'
46
+ import { PrismaClient } from '@prisma/client'
47
+
48
+ const adapter = new PrismaMariaDb({
49
+ host: 'localhost', // your database host
50
+ user: 'your_username', // your database username
51
+ password: 'your_password', // your database password
52
+ database: 'your_database', // optional, your database name
53
+ })
54
+ const prisma = new PrismaClient({ adapter })
55
+ ```
56
+
57
+ ## Feedback
58
+
59
+ We encourage you to create an issue if you find something missing or run into a bug.
60
+
61
+ If you have any feedback, leave a comment in [this GitHub discussion](https://github.com/prisma/prisma/discussions/22899).
@@ -0,0 +1,19 @@
1
+ import * as mariadb from 'mariadb';
2
+ import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
+ import type { SqlDriverAdapterFactory } from '@prisma/driver-adapter-utils';
4
+
5
+ export declare class PrismaMariaDb implements SqlDriverAdapterFactory {
6
+ #private;
7
+ private readonly config;
8
+ private readonly options?;
9
+ readonly provider = "mysql";
10
+ readonly adapterName: string;
11
+ constructor(config: mariadb.PoolConfig | string, options?: PrismaMariadbOptions | undefined);
12
+ connect(): Promise<SqlDriverAdapter>;
13
+ }
14
+
15
+ declare type PrismaMariadbOptions = {
16
+ database?: string;
17
+ };
18
+
19
+ export { }
@@ -0,0 +1,19 @@
1
+ import * as mariadb from 'mariadb';
2
+ import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
+ import type { SqlDriverAdapterFactory } from '@prisma/driver-adapter-utils';
4
+
5
+ export declare class PrismaMariaDb implements SqlDriverAdapterFactory {
6
+ #private;
7
+ private readonly config;
8
+ private readonly options?;
9
+ readonly provider = "mysql";
10
+ readonly adapterName: string;
11
+ constructor(config: mariadb.PoolConfig | string, options?: PrismaMariadbOptions | undefined);
12
+ connect(): Promise<SqlDriverAdapter>;
13
+ }
14
+
15
+ declare type PrismaMariadbOptions = {
16
+ database?: string;
17
+ };
18
+
19
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,403 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name2 in all)
10
+ __defProp(target, name2, { get: all[name2], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ PrismaMariaDb: () => PrismaMariaDbAdapterFactory
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/mariadb.ts
38
+ var import_driver_adapter_utils2 = require("@prisma/driver-adapter-utils");
39
+ var mariadb = __toESM(require("mariadb"));
40
+
41
+ // package.json
42
+ var name = "@prisma/adapter-mariadb";
43
+
44
+ // src/conversion.ts
45
+ var import_driver_adapter_utils = require("@prisma/driver-adapter-utils");
46
+ var UNSIGNED_FLAG = 1 << 5;
47
+ var BINARY_FLAG = 1 << 7;
48
+ function mapColumnType(field) {
49
+ switch (field.type) {
50
+ case "TINY" /* TINY */:
51
+ case "SHORT" /* SHORT */:
52
+ case "INT24" /* INT24 */:
53
+ case "YEAR" /* YEAR */:
54
+ return import_driver_adapter_utils.ColumnTypeEnum.Int32;
55
+ case "INT" /* INT */:
56
+ if (field.flags.valueOf() & UNSIGNED_FLAG) {
57
+ return import_driver_adapter_utils.ColumnTypeEnum.Int64;
58
+ } else {
59
+ return import_driver_adapter_utils.ColumnTypeEnum.Int32;
60
+ }
61
+ case "LONG" /* LONG */:
62
+ case "BIGINT" /* BIGINT */:
63
+ return import_driver_adapter_utils.ColumnTypeEnum.Int64;
64
+ case "FLOAT" /* FLOAT */:
65
+ return import_driver_adapter_utils.ColumnTypeEnum.Float;
66
+ case "DOUBLE" /* DOUBLE */:
67
+ return import_driver_adapter_utils.ColumnTypeEnum.Double;
68
+ case "TIMESTAMP" /* TIMESTAMP */:
69
+ case "TIMESTAMP2" /* TIMESTAMP2 */:
70
+ case "DATETIME" /* DATETIME */:
71
+ case "DATETIME2" /* DATETIME2 */:
72
+ return import_driver_adapter_utils.ColumnTypeEnum.DateTime;
73
+ case "DATE" /* DATE */:
74
+ case "NEWDATE" /* NEWDATE */:
75
+ return import_driver_adapter_utils.ColumnTypeEnum.Date;
76
+ case "TIME" /* TIME */:
77
+ return import_driver_adapter_utils.ColumnTypeEnum.Time;
78
+ case "DECIMAL" /* DECIMAL */:
79
+ case "NEWDECIMAL" /* NEWDECIMAL */:
80
+ return import_driver_adapter_utils.ColumnTypeEnum.Numeric;
81
+ case "VARCHAR" /* VARCHAR */:
82
+ case "VAR_STRING" /* VAR_STRING */:
83
+ case "STRING" /* STRING */:
84
+ if (field.flags.valueOf() & BINARY_FLAG) {
85
+ return import_driver_adapter_utils.ColumnTypeEnum.Bytes;
86
+ } else {
87
+ return import_driver_adapter_utils.ColumnTypeEnum.Text;
88
+ }
89
+ case "ENUM" /* ENUM */:
90
+ return import_driver_adapter_utils.ColumnTypeEnum.Enum;
91
+ case "JSON" /* JSON */:
92
+ return import_driver_adapter_utils.ColumnTypeEnum.Json;
93
+ case "BLOB" /* BLOB */:
94
+ case "TINY_BLOB" /* TINY_BLOB */:
95
+ case "MEDIUM_BLOB" /* MEDIUM_BLOB */:
96
+ case "BIT" /* BIT */:
97
+ case "GEOMETRY" /* GEOMETRY */:
98
+ return import_driver_adapter_utils.ColumnTypeEnum.Bytes;
99
+ case "NULL" /* NULL */:
100
+ return import_driver_adapter_utils.ColumnTypeEnum.Int32;
101
+ default:
102
+ throw new Error(`Unsupported column type: ${field.type}`);
103
+ }
104
+ }
105
+ function mapArg(arg) {
106
+ if (arg instanceof Uint8Array) {
107
+ return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
108
+ }
109
+ return arg;
110
+ }
111
+ function mapRow(row, fields) {
112
+ return row.map((value, i) => {
113
+ const type = fields?.[i].type;
114
+ if (value === null && type !== "JSON" /* JSON */) {
115
+ return null;
116
+ }
117
+ if (typeof value === "boolean" && type === "BIT" /* BIT */) {
118
+ return value ? [1] : [0];
119
+ }
120
+ switch (type) {
121
+ case "TIMESTAMP" /* TIMESTAMP */:
122
+ case "TIMESTAMP2" /* TIMESTAMP2 */:
123
+ case "DATETIME" /* DATETIME */:
124
+ case "DATETIME2" /* DATETIME2 */:
125
+ return (/* @__PURE__ */ new Date(`${value}Z`)).toISOString();
126
+ case "JSON" /* JSON */:
127
+ return JSON.stringify(value);
128
+ }
129
+ if (Buffer.isBuffer(value)) {
130
+ return Array.from(value);
131
+ }
132
+ if (typeof value === "bigint") {
133
+ return value.toString();
134
+ }
135
+ return value;
136
+ });
137
+ }
138
+
139
+ // src/errors.ts
140
+ function convertDriverError(error) {
141
+ if (!isDbError(error)) {
142
+ throw error;
143
+ }
144
+ switch (error.errno) {
145
+ case 1062: {
146
+ const index = error.sqlMessage?.split(" ").pop()?.split("'").at(1)?.split(".").pop();
147
+ return {
148
+ kind: "UniqueConstraintViolation",
149
+ constraint: index !== void 0 ? { index } : void 0
150
+ };
151
+ }
152
+ case 1451:
153
+ case 1452: {
154
+ const field = error.sqlMessage?.split(" ").at(17)?.split("`").at(1);
155
+ return {
156
+ kind: "ForeignKeyConstraintViolation",
157
+ constraint: field !== void 0 ? { fields: [field] } : void 0
158
+ };
159
+ }
160
+ case 1263: {
161
+ const index = error.sqlMessage?.split(" ").pop()?.split("'").at(1);
162
+ return {
163
+ kind: "NullConstraintViolation",
164
+ constraint: index !== void 0 ? { index } : void 0
165
+ };
166
+ }
167
+ case 1264:
168
+ return {
169
+ kind: "ValueOutOfRange",
170
+ cause: error.sqlMessage ?? "N/A"
171
+ };
172
+ case 1364:
173
+ case 1048: {
174
+ const field = error.sqlMessage?.split(" ").at(1)?.split("'").at(1);
175
+ return {
176
+ kind: "NullConstraintViolation",
177
+ constraint: field !== void 0 ? { fields: [field] } : void 0
178
+ };
179
+ }
180
+ case 1049: {
181
+ const db = error.sqlMessage?.split(" ").pop()?.split("'").at(1);
182
+ return {
183
+ kind: "DatabaseDoesNotExist",
184
+ db
185
+ };
186
+ }
187
+ case 1007: {
188
+ const db = error.sqlMessage?.split(" ").at(3)?.split("'").at(1);
189
+ return {
190
+ kind: "DatabaseAlreadyExists",
191
+ db
192
+ };
193
+ }
194
+ case 1044: {
195
+ const db = error.sqlMessage?.split(" ").pop()?.split("'").at(1);
196
+ return {
197
+ kind: "DatabaseAccessDenied",
198
+ db
199
+ };
200
+ }
201
+ case 1045: {
202
+ const user = error.sqlMessage?.split(" ").at(4)?.split("@").at(0)?.split("'").at(1);
203
+ return {
204
+ kind: "AuthenticationFailed",
205
+ user
206
+ };
207
+ }
208
+ case 1146: {
209
+ const table = error.sqlMessage?.split(" ").at(1)?.split("'").at(1)?.split(".").pop();
210
+ return {
211
+ kind: "TableDoesNotExist",
212
+ table
213
+ };
214
+ }
215
+ case 1054: {
216
+ const column = error.sqlMessage?.split(" ").at(2)?.split("'").at(1);
217
+ return {
218
+ kind: "ColumnNotFound",
219
+ column
220
+ };
221
+ }
222
+ case 1406: {
223
+ const column = error.sqlMessage?.split(" ").flatMap((part) => part.split("'")).at(6);
224
+ return {
225
+ kind: "LengthMismatch",
226
+ column
227
+ };
228
+ }
229
+ case 1191:
230
+ return {
231
+ kind: "MissingFullTextSearchIndex"
232
+ };
233
+ case 1213:
234
+ return {
235
+ kind: "TransactionWriteConflict"
236
+ };
237
+ case 1040:
238
+ case 1203:
239
+ return {
240
+ kind: "TooManyConnections",
241
+ cause: error.sqlMessage ?? "N/A"
242
+ };
243
+ default:
244
+ return {
245
+ kind: "mysql",
246
+ code: error.errno,
247
+ message: error.sqlMessage ?? "N/A",
248
+ state: error.sqlState ?? "N/A"
249
+ };
250
+ }
251
+ }
252
+ function isDbError(error) {
253
+ return typeof error.errno === "number" && (typeof error.sqlMessage === "string" || error.sqlMessage === null) && (typeof error.sqlState === "string" || error.sqlState === null);
254
+ }
255
+
256
+ // src/mariadb.ts
257
+ var debug = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:mariadb");
258
+ var MariaDbQueryable = class {
259
+ constructor(client) {
260
+ this.client = client;
261
+ }
262
+ provider = "mysql";
263
+ adapterName = name;
264
+ async queryRaw(query) {
265
+ const tag = "[js::query_raw]";
266
+ debug(`${tag} %O`, query);
267
+ const result = await this.performIO(query);
268
+ return {
269
+ columnNames: result.meta?.map((field) => field.name()) ?? [],
270
+ columnTypes: result.meta?.map(mapColumnType) ?? [],
271
+ rows: Array.isArray(result) ? result.map((row) => mapRow(row, result.meta)) : [],
272
+ lastInsertId: result.insertId?.toString()
273
+ };
274
+ }
275
+ async executeRaw(query) {
276
+ const tag = "[js::execute_raw]";
277
+ debug(`${tag} %O`, query);
278
+ return (await this.performIO(query)).affectedRows ?? 0;
279
+ }
280
+ async performIO(query) {
281
+ const { sql, args: values } = query;
282
+ try {
283
+ return await this.client.query(
284
+ {
285
+ sql,
286
+ dateStrings: true,
287
+ rowsAsArray: true
288
+ },
289
+ values.map(mapArg)
290
+ );
291
+ } catch (e) {
292
+ const error = e;
293
+ onError(error);
294
+ }
295
+ }
296
+ };
297
+ function onError(error) {
298
+ debug("Error in performIO: %O", error);
299
+ throw new import_driver_adapter_utils2.DriverAdapterError(convertDriverError(error));
300
+ }
301
+ var MariaDbTransaction = class extends MariaDbQueryable {
302
+ constructor(conn, options) {
303
+ super(conn);
304
+ this.options = options;
305
+ }
306
+ async commit() {
307
+ debug(`[js::commit]`);
308
+ await this.client.end();
309
+ }
310
+ async rollback() {
311
+ debug(`[js::rollback]`);
312
+ await this.client.end();
313
+ }
314
+ };
315
+ var PrismaMariaDbAdapter = class extends MariaDbQueryable {
316
+ constructor(client, capabilities, options) {
317
+ super(client);
318
+ this.capabilities = capabilities;
319
+ this.options = options;
320
+ }
321
+ executeScript(_script) {
322
+ throw new Error("Not implemented yet");
323
+ }
324
+ getConnectionInfo() {
325
+ return {
326
+ schemaName: this.options?.database,
327
+ supportsRelationJoins: this.capabilities.supportsRelationJoins
328
+ };
329
+ }
330
+ async startTransaction(isolationLevel) {
331
+ const options = {
332
+ usePhantomQuery: false
333
+ };
334
+ const tag = "[js::startTransaction]";
335
+ debug("%s options: %O", tag, options);
336
+ const conn = await this.client.getConnection().catch((error) => onError(error));
337
+ try {
338
+ const tx = new MariaDbTransaction(conn, options);
339
+ if (isolationLevel) {
340
+ await tx.executeRaw({
341
+ sql: `SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`,
342
+ args: [],
343
+ argTypes: []
344
+ });
345
+ }
346
+ await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
347
+ return tx;
348
+ } catch (error) {
349
+ await conn.end();
350
+ onError(error);
351
+ }
352
+ }
353
+ async dispose() {
354
+ await this.client.end();
355
+ }
356
+ };
357
+ var PrismaMariaDbAdapterFactory = class {
358
+ constructor(config, options) {
359
+ this.config = config;
360
+ this.options = options;
361
+ }
362
+ provider = "mysql";
363
+ adapterName = name;
364
+ #capabilities;
365
+ async connect() {
366
+ const pool = mariadb.createPool(this.config);
367
+ if (this.#capabilities === void 0) {
368
+ this.#capabilities = await getCapabilities(pool);
369
+ }
370
+ return new PrismaMariaDbAdapter(pool, this.#capabilities, this.options);
371
+ }
372
+ };
373
+ async function getCapabilities(pool) {
374
+ const tag = "[js::getCapabilities]";
375
+ try {
376
+ const [rows] = await pool.query({
377
+ sql: `SELECT VERSION()`,
378
+ rowsAsArray: true
379
+ });
380
+ const version = rows[0][0];
381
+ debug(`${tag} MySQL version: %s from %o`, version, rows);
382
+ const capabilities = inferCapabilities(version);
383
+ debug(`${tag} Inferred capabilities: %O`, capabilities);
384
+ return capabilities;
385
+ } catch (e) {
386
+ debug(`${tag} Error while checking capabilities: %O`, e);
387
+ return { supportsRelationJoins: false };
388
+ }
389
+ }
390
+ function inferCapabilities(version) {
391
+ if (typeof version !== "string") {
392
+ return { supportsRelationJoins: false };
393
+ }
394
+ const [versionStr, suffix] = version.split("-");
395
+ const [major, minor, patch] = versionStr.split(".").map((n) => parseInt(n, 10));
396
+ const isMariaDB = suffix?.toLowerCase()?.includes("mariadb") ?? false;
397
+ const supportsRelationJoins = !isMariaDB && (major > 8 || major === 8 && minor >= 0 && patch >= 13);
398
+ return { supportsRelationJoins };
399
+ }
400
+ // Annotate the CommonJS export names for ESM import in node:
401
+ 0 && (module.exports = {
402
+ PrismaMariaDb
403
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,366 @@
1
+ // src/mariadb.ts
2
+ import { Debug, DriverAdapterError } from "@prisma/driver-adapter-utils";
3
+ import * as mariadb from "mariadb";
4
+
5
+ // package.json
6
+ var name = "@prisma/adapter-mariadb";
7
+
8
+ // src/conversion.ts
9
+ import { ColumnTypeEnum } from "@prisma/driver-adapter-utils";
10
+ var UNSIGNED_FLAG = 1 << 5;
11
+ var BINARY_FLAG = 1 << 7;
12
+ function mapColumnType(field) {
13
+ switch (field.type) {
14
+ case "TINY" /* TINY */:
15
+ case "SHORT" /* SHORT */:
16
+ case "INT24" /* INT24 */:
17
+ case "YEAR" /* YEAR */:
18
+ return ColumnTypeEnum.Int32;
19
+ case "INT" /* INT */:
20
+ if (field.flags.valueOf() & UNSIGNED_FLAG) {
21
+ return ColumnTypeEnum.Int64;
22
+ } else {
23
+ return ColumnTypeEnum.Int32;
24
+ }
25
+ case "LONG" /* LONG */:
26
+ case "BIGINT" /* BIGINT */:
27
+ return ColumnTypeEnum.Int64;
28
+ case "FLOAT" /* FLOAT */:
29
+ return ColumnTypeEnum.Float;
30
+ case "DOUBLE" /* DOUBLE */:
31
+ return ColumnTypeEnum.Double;
32
+ case "TIMESTAMP" /* TIMESTAMP */:
33
+ case "TIMESTAMP2" /* TIMESTAMP2 */:
34
+ case "DATETIME" /* DATETIME */:
35
+ case "DATETIME2" /* DATETIME2 */:
36
+ return ColumnTypeEnum.DateTime;
37
+ case "DATE" /* DATE */:
38
+ case "NEWDATE" /* NEWDATE */:
39
+ return ColumnTypeEnum.Date;
40
+ case "TIME" /* TIME */:
41
+ return ColumnTypeEnum.Time;
42
+ case "DECIMAL" /* DECIMAL */:
43
+ case "NEWDECIMAL" /* NEWDECIMAL */:
44
+ return ColumnTypeEnum.Numeric;
45
+ case "VARCHAR" /* VARCHAR */:
46
+ case "VAR_STRING" /* VAR_STRING */:
47
+ case "STRING" /* STRING */:
48
+ if (field.flags.valueOf() & BINARY_FLAG) {
49
+ return ColumnTypeEnum.Bytes;
50
+ } else {
51
+ return ColumnTypeEnum.Text;
52
+ }
53
+ case "ENUM" /* ENUM */:
54
+ return ColumnTypeEnum.Enum;
55
+ case "JSON" /* JSON */:
56
+ return ColumnTypeEnum.Json;
57
+ case "BLOB" /* BLOB */:
58
+ case "TINY_BLOB" /* TINY_BLOB */:
59
+ case "MEDIUM_BLOB" /* MEDIUM_BLOB */:
60
+ case "BIT" /* BIT */:
61
+ case "GEOMETRY" /* GEOMETRY */:
62
+ return ColumnTypeEnum.Bytes;
63
+ case "NULL" /* NULL */:
64
+ return ColumnTypeEnum.Int32;
65
+ default:
66
+ throw new Error(`Unsupported column type: ${field.type}`);
67
+ }
68
+ }
69
+ function mapArg(arg) {
70
+ if (arg instanceof Uint8Array) {
71
+ return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
72
+ }
73
+ return arg;
74
+ }
75
+ function mapRow(row, fields) {
76
+ return row.map((value, i) => {
77
+ const type = fields?.[i].type;
78
+ if (value === null && type !== "JSON" /* JSON */) {
79
+ return null;
80
+ }
81
+ if (typeof value === "boolean" && type === "BIT" /* BIT */) {
82
+ return value ? [1] : [0];
83
+ }
84
+ switch (type) {
85
+ case "TIMESTAMP" /* TIMESTAMP */:
86
+ case "TIMESTAMP2" /* TIMESTAMP2 */:
87
+ case "DATETIME" /* DATETIME */:
88
+ case "DATETIME2" /* DATETIME2 */:
89
+ return (/* @__PURE__ */ new Date(`${value}Z`)).toISOString();
90
+ case "JSON" /* JSON */:
91
+ return JSON.stringify(value);
92
+ }
93
+ if (Buffer.isBuffer(value)) {
94
+ return Array.from(value);
95
+ }
96
+ if (typeof value === "bigint") {
97
+ return value.toString();
98
+ }
99
+ return value;
100
+ });
101
+ }
102
+
103
+ // src/errors.ts
104
+ function convertDriverError(error) {
105
+ if (!isDbError(error)) {
106
+ throw error;
107
+ }
108
+ switch (error.errno) {
109
+ case 1062: {
110
+ const index = error.sqlMessage?.split(" ").pop()?.split("'").at(1)?.split(".").pop();
111
+ return {
112
+ kind: "UniqueConstraintViolation",
113
+ constraint: index !== void 0 ? { index } : void 0
114
+ };
115
+ }
116
+ case 1451:
117
+ case 1452: {
118
+ const field = error.sqlMessage?.split(" ").at(17)?.split("`").at(1);
119
+ return {
120
+ kind: "ForeignKeyConstraintViolation",
121
+ constraint: field !== void 0 ? { fields: [field] } : void 0
122
+ };
123
+ }
124
+ case 1263: {
125
+ const index = error.sqlMessage?.split(" ").pop()?.split("'").at(1);
126
+ return {
127
+ kind: "NullConstraintViolation",
128
+ constraint: index !== void 0 ? { index } : void 0
129
+ };
130
+ }
131
+ case 1264:
132
+ return {
133
+ kind: "ValueOutOfRange",
134
+ cause: error.sqlMessage ?? "N/A"
135
+ };
136
+ case 1364:
137
+ case 1048: {
138
+ const field = error.sqlMessage?.split(" ").at(1)?.split("'").at(1);
139
+ return {
140
+ kind: "NullConstraintViolation",
141
+ constraint: field !== void 0 ? { fields: [field] } : void 0
142
+ };
143
+ }
144
+ case 1049: {
145
+ const db = error.sqlMessage?.split(" ").pop()?.split("'").at(1);
146
+ return {
147
+ kind: "DatabaseDoesNotExist",
148
+ db
149
+ };
150
+ }
151
+ case 1007: {
152
+ const db = error.sqlMessage?.split(" ").at(3)?.split("'").at(1);
153
+ return {
154
+ kind: "DatabaseAlreadyExists",
155
+ db
156
+ };
157
+ }
158
+ case 1044: {
159
+ const db = error.sqlMessage?.split(" ").pop()?.split("'").at(1);
160
+ return {
161
+ kind: "DatabaseAccessDenied",
162
+ db
163
+ };
164
+ }
165
+ case 1045: {
166
+ const user = error.sqlMessage?.split(" ").at(4)?.split("@").at(0)?.split("'").at(1);
167
+ return {
168
+ kind: "AuthenticationFailed",
169
+ user
170
+ };
171
+ }
172
+ case 1146: {
173
+ const table = error.sqlMessage?.split(" ").at(1)?.split("'").at(1)?.split(".").pop();
174
+ return {
175
+ kind: "TableDoesNotExist",
176
+ table
177
+ };
178
+ }
179
+ case 1054: {
180
+ const column = error.sqlMessage?.split(" ").at(2)?.split("'").at(1);
181
+ return {
182
+ kind: "ColumnNotFound",
183
+ column
184
+ };
185
+ }
186
+ case 1406: {
187
+ const column = error.sqlMessage?.split(" ").flatMap((part) => part.split("'")).at(6);
188
+ return {
189
+ kind: "LengthMismatch",
190
+ column
191
+ };
192
+ }
193
+ case 1191:
194
+ return {
195
+ kind: "MissingFullTextSearchIndex"
196
+ };
197
+ case 1213:
198
+ return {
199
+ kind: "TransactionWriteConflict"
200
+ };
201
+ case 1040:
202
+ case 1203:
203
+ return {
204
+ kind: "TooManyConnections",
205
+ cause: error.sqlMessage ?? "N/A"
206
+ };
207
+ default:
208
+ return {
209
+ kind: "mysql",
210
+ code: error.errno,
211
+ message: error.sqlMessage ?? "N/A",
212
+ state: error.sqlState ?? "N/A"
213
+ };
214
+ }
215
+ }
216
+ function isDbError(error) {
217
+ return typeof error.errno === "number" && (typeof error.sqlMessage === "string" || error.sqlMessage === null) && (typeof error.sqlState === "string" || error.sqlState === null);
218
+ }
219
+
220
+ // src/mariadb.ts
221
+ var debug = Debug("prisma:driver-adapter:mariadb");
222
+ var MariaDbQueryable = class {
223
+ constructor(client) {
224
+ this.client = client;
225
+ }
226
+ provider = "mysql";
227
+ adapterName = name;
228
+ async queryRaw(query) {
229
+ const tag = "[js::query_raw]";
230
+ debug(`${tag} %O`, query);
231
+ const result = await this.performIO(query);
232
+ return {
233
+ columnNames: result.meta?.map((field) => field.name()) ?? [],
234
+ columnTypes: result.meta?.map(mapColumnType) ?? [],
235
+ rows: Array.isArray(result) ? result.map((row) => mapRow(row, result.meta)) : [],
236
+ lastInsertId: result.insertId?.toString()
237
+ };
238
+ }
239
+ async executeRaw(query) {
240
+ const tag = "[js::execute_raw]";
241
+ debug(`${tag} %O`, query);
242
+ return (await this.performIO(query)).affectedRows ?? 0;
243
+ }
244
+ async performIO(query) {
245
+ const { sql, args: values } = query;
246
+ try {
247
+ return await this.client.query(
248
+ {
249
+ sql,
250
+ dateStrings: true,
251
+ rowsAsArray: true
252
+ },
253
+ values.map(mapArg)
254
+ );
255
+ } catch (e) {
256
+ const error = e;
257
+ onError(error);
258
+ }
259
+ }
260
+ };
261
+ function onError(error) {
262
+ debug("Error in performIO: %O", error);
263
+ throw new DriverAdapterError(convertDriverError(error));
264
+ }
265
+ var MariaDbTransaction = class extends MariaDbQueryable {
266
+ constructor(conn, options) {
267
+ super(conn);
268
+ this.options = options;
269
+ }
270
+ async commit() {
271
+ debug(`[js::commit]`);
272
+ await this.client.end();
273
+ }
274
+ async rollback() {
275
+ debug(`[js::rollback]`);
276
+ await this.client.end();
277
+ }
278
+ };
279
+ var PrismaMariaDbAdapter = class extends MariaDbQueryable {
280
+ constructor(client, capabilities, options) {
281
+ super(client);
282
+ this.capabilities = capabilities;
283
+ this.options = options;
284
+ }
285
+ executeScript(_script) {
286
+ throw new Error("Not implemented yet");
287
+ }
288
+ getConnectionInfo() {
289
+ return {
290
+ schemaName: this.options?.database,
291
+ supportsRelationJoins: this.capabilities.supportsRelationJoins
292
+ };
293
+ }
294
+ async startTransaction(isolationLevel) {
295
+ const options = {
296
+ usePhantomQuery: false
297
+ };
298
+ const tag = "[js::startTransaction]";
299
+ debug("%s options: %O", tag, options);
300
+ const conn = await this.client.getConnection().catch((error) => onError(error));
301
+ try {
302
+ const tx = new MariaDbTransaction(conn, options);
303
+ if (isolationLevel) {
304
+ await tx.executeRaw({
305
+ sql: `SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`,
306
+ args: [],
307
+ argTypes: []
308
+ });
309
+ }
310
+ await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
311
+ return tx;
312
+ } catch (error) {
313
+ await conn.end();
314
+ onError(error);
315
+ }
316
+ }
317
+ async dispose() {
318
+ await this.client.end();
319
+ }
320
+ };
321
+ var PrismaMariaDbAdapterFactory = class {
322
+ constructor(config, options) {
323
+ this.config = config;
324
+ this.options = options;
325
+ }
326
+ provider = "mysql";
327
+ adapterName = name;
328
+ #capabilities;
329
+ async connect() {
330
+ const pool = mariadb.createPool(this.config);
331
+ if (this.#capabilities === void 0) {
332
+ this.#capabilities = await getCapabilities(pool);
333
+ }
334
+ return new PrismaMariaDbAdapter(pool, this.#capabilities, this.options);
335
+ }
336
+ };
337
+ async function getCapabilities(pool) {
338
+ const tag = "[js::getCapabilities]";
339
+ try {
340
+ const [rows] = await pool.query({
341
+ sql: `SELECT VERSION()`,
342
+ rowsAsArray: true
343
+ });
344
+ const version = rows[0][0];
345
+ debug(`${tag} MySQL version: %s from %o`, version, rows);
346
+ const capabilities = inferCapabilities(version);
347
+ debug(`${tag} Inferred capabilities: %O`, capabilities);
348
+ return capabilities;
349
+ } catch (e) {
350
+ debug(`${tag} Error while checking capabilities: %O`, e);
351
+ return { supportsRelationJoins: false };
352
+ }
353
+ }
354
+ function inferCapabilities(version) {
355
+ if (typeof version !== "string") {
356
+ return { supportsRelationJoins: false };
357
+ }
358
+ const [versionStr, suffix] = version.split("-");
359
+ const [major, minor, patch] = versionStr.split(".").map((n) => parseInt(n, 10));
360
+ const isMariaDB = suffix?.toLowerCase()?.includes("mariadb") ?? false;
361
+ const supportsRelationJoins = !isMariaDB && (major > 8 || major === 8 && minor >= 0 && patch >= 13);
362
+ return { supportsRelationJoins };
363
+ }
364
+ export {
365
+ PrismaMariaDbAdapterFactory as PrismaMariaDb
366
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@prisma/adapter-mariadb",
3
+ "version": "6.11.0-dev.20",
4
+ "description": "Prisma's driver adapter for \"mariadb\"",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "import": {
15
+ "types": "./dist/index.d.mts",
16
+ "default": "./dist/index.mjs"
17
+ }
18
+ }
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/prisma/prisma.git",
23
+ "directory": "packages/adapter-planetscale"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md"
28
+ ],
29
+ "keywords": [],
30
+ "author": "Jacek Malec <malec@prisma.io>",
31
+ "license": "Apache-2.0",
32
+ "sideEffects": false,
33
+ "dependencies": {
34
+ "mariadb": "3.4.2",
35
+ "@prisma/driver-adapter-utils": "6.11.0-dev.20"
36
+ },
37
+ "devDependencies": {
38
+ "vitest": "3.0.9"
39
+ },
40
+ "scripts": {
41
+ "dev": "DEV=true tsx helpers/build.ts",
42
+ "build": "tsx helpers/build.ts",
43
+ "test": "vitest run"
44
+ }
45
+ }