From a8ecd4269630686583064b9131f1293a76d89574 Mon Sep 17 00:00:00 2001 From: Arash Date: Fri, 19 Apr 2024 15:58:26 -0600 Subject: [PATCH 1/5] feat(connector): mysql2 --- docs/2.connectors/mysql.md | 27 ++++++++-- examples/mysql/index.ts | 34 ++++++++++++ examples/mysql/package.json | 10 ++++ package.json | 4 +- pnpm-lock.yaml | 95 ++++++++++++++++++++++++++++++++-- src/connectors/mysql2.ts | 47 +++++++++++++++++ test/connectors/mysql2.test.ts | 17 ++++++ 7 files changed, 224 insertions(+), 10 deletions(-) create mode 100644 examples/mysql/index.ts create mode 100644 examples/mysql/package.json create mode 100644 src/connectors/mysql2.ts create mode 100644 test/connectors/mysql2.test.ts diff --git a/docs/2.connectors/mysql.md b/docs/2.connectors/mysql.md index adec516..1acaae4 100644 --- a/docs/2.connectors/mysql.md +++ b/docs/2.connectors/mysql.md @@ -4,10 +4,27 @@ icon: simple-icons:mysql # MySQL -> Connect DB0 to Mysql Database +> Connect DB0 to Mysql Database using mysql2 -:read-more{to="https://github.com/sidorares/node-mysql2"} +## Usage -::read-more{to="https://github.com/unjs/db0/issues/32"} -This connector is planned to be supported. Follow up via [unjs/db0#32](https://github.com/unjs/db0/issues/32). -:: +For this connector, you need to install [`mysql2`](https://www.npmjs.com/package/mysql2) dependency: + +:pm-install{name="mysql2"} + +Use `mysql2` connector: + +```js +import { createDatabase, sql } from "db0"; +import mysql from "db0/connectors/mysql2"; + +const db = createDatabase( + mysql({ + /* options */ + }), +); +``` + +## Options + +:read-more{to="https://github.com/sidorares/node-mysql2/blob/master/typings/mysql/lib/Connection.d.ts#L82-L329"} diff --git a/examples/mysql/index.ts b/examples/mysql/index.ts new file mode 100644 index 0000000..7e9af18 --- /dev/null +++ b/examples/mysql/index.ts @@ -0,0 +1,34 @@ +import { createDatabase } from "../../src"; +import mysqlConnector from "../../src/connectors/mysql2" + + +async function main() { + const db = createDatabase(mysqlConnector({ + host: "localhost", + user: "root", + password: "root", + database: "db0", + })); + + await db.sql`CREATE TABLE IF NOT EXISTS users ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(255) NOT NULL + )`; + + await db.sql`INSERT INTO users (name) VALUES (${randomValue()})`; + + const users = await db.sql`SELECT * FROM users`; + + console.log({ rows: users.rows }); +} + +// eslint-disable-next-line unicorn/prefer-top-level-await +main().catch((error) => { + console.error(error); + // eslint-disable-next-line unicorn/no-process-exit + process.exit(1); +}); + +function randomValue() { + return Math.random().toString(36).slice(7); +} diff --git a/examples/mysql/package.json b/examples/mysql/package.json new file mode 100644 index 0000000..456df05 --- /dev/null +++ b/examples/mysql/package.json @@ -0,0 +1,10 @@ +{ + "name": "db0-with-mysql", + "private": true, + "scripts": { + "start": "jiti ./index.ts" + }, + "devDependencies": { + "db0": "latest" + } +} diff --git a/package.json b/package.json index cdf4b57..dc58032 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "build": "unbuild", "db0": "pnpm jiti src/cli", "dev": "vitest", + "start": "f () { pnpm --filter db0-with-${1:-'*'} start ;}; f", "lint": "eslint --ext .ts . && prettier -c src test", "lint:fix": "eslint --ext .ts . --fix && prettier -w src test", "prepack": "pnpm build", @@ -64,6 +65,7 @@ "eslint": "^8.57.0", "eslint-config-unjs": "^0.2.1", "jiti": "^1.21.0", + "mysql2": "^3.9.6", "pg": "^8.11.5", "prettier": "^3.2.5", "typescript": "^5.4.5", @@ -87,4 +89,4 @@ } }, "packageManager": "pnpm@8.15.6" -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5775910..06b2567 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,7 +40,7 @@ importers: version: 16.4.5 drizzle-orm: specifier: ^0.30.8 - version: 0.30.8(@libsql/client@0.6.0)(@types/better-sqlite3@7.6.9)(@types/pg@8.11.5)(better-sqlite3@9.5.0)(pg@8.11.5) + version: 0.30.8(@libsql/client@0.6.0)(@types/better-sqlite3@7.6.9)(@types/pg@8.11.5)(better-sqlite3@9.5.0)(mysql2@3.9.6)(pg@8.11.5) eslint: specifier: ^8.57.0 version: 8.57.0 @@ -50,6 +50,9 @@ importers: jiti: specifier: ^1.21.0 version: 1.21.0 + mysql2: + specifier: ^3.9.6 + version: 3.9.6 pg: specifier: ^8.11.5 version: 8.11.5 @@ -76,11 +79,23 @@ importers: version: 0.20.14 drizzle-orm: specifier: ^0.29.4 - version: 0.29.4(@libsql/client@0.6.0)(@types/better-sqlite3@7.6.9)(@types/pg@8.11.5)(better-sqlite3@9.5.0)(pg@8.11.5) + version: 0.29.4(@libsql/client@0.6.0)(@types/better-sqlite3@7.6.9)(@types/pg@8.11.5)(better-sqlite3@9.5.0)(mysql2@3.9.6)(pg@8.11.5) jiti: specifier: ^1.21.0 version: 1.21.0 + examples/mysql: + devDependencies: + db0: + specifier: latest + version: link:../.. + + examples/sqlite: + devDependencies: + db0: + specifier: latest + version: link:../.. + packages: /@aashutoshrathi/word-wrap@1.2.6: @@ -2351,6 +2366,11 @@ packages: resolution: {integrity: sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg==} dev: true + /denque@2.1.0: + resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==} + engines: {node: '>=0.10'} + dev: true + /destr@2.0.3: resolution: {integrity: sha512-2N3BOUU4gYMpTP24s5rF5iP7BDr7uNTCs4ozw3kf/eKfvWSIu93GEBi5m427YoyJoeOzQ5smuu4nNAPGb8idSQ==} dev: true @@ -2468,7 +2488,7 @@ packages: - supports-color dev: true - /drizzle-orm@0.29.4(@libsql/client@0.6.0)(@types/better-sqlite3@7.6.9)(@types/pg@8.11.5)(better-sqlite3@9.5.0)(pg@8.11.5): + /drizzle-orm@0.29.4(@libsql/client@0.6.0)(@types/better-sqlite3@7.6.9)(@types/pg@8.11.5)(better-sqlite3@9.5.0)(mysql2@3.9.6)(pg@8.11.5): resolution: {integrity: sha512-ZnSM8TAxFhzH7p1s3+w3pRE/eKaOeNkH9SKitm717pubDVVcV2I0BCDBPGKV+pe02+wMfw37ntlTcCyo2rA3IA==} peerDependencies: '@aws-sdk/client-rds-data': '>=3' @@ -2543,10 +2563,11 @@ packages: '@types/better-sqlite3': 7.6.9 '@types/pg': 8.11.5 better-sqlite3: 9.5.0 + mysql2: 3.9.6 pg: 8.11.5 dev: true - /drizzle-orm@0.30.8(@libsql/client@0.6.0)(@types/better-sqlite3@7.6.9)(@types/pg@8.11.5)(better-sqlite3@9.5.0)(pg@8.11.5): + /drizzle-orm@0.30.8(@libsql/client@0.6.0)(@types/better-sqlite3@7.6.9)(@types/pg@8.11.5)(better-sqlite3@9.5.0)(mysql2@3.9.6)(pg@8.11.5): resolution: {integrity: sha512-9pBJA0IjnpPpzZ6s9jlS1CQAbKoBmbn2GJesPhXaVblAA/joOJ4AWWevYcqvLGj9SvThBAl7WscN8Zwgg5mnTw==} peerDependencies: '@aws-sdk/client-rds-data': '>=3' @@ -2630,6 +2651,7 @@ packages: '@types/better-sqlite3': 7.6.9 '@types/pg': 8.11.5 better-sqlite3: 9.5.0 + mysql2: 3.9.6 pg: 8.11.5 dev: true @@ -3474,6 +3496,12 @@ packages: resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==} dev: true + /generate-function@2.3.1: + resolution: {integrity: sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==} + dependencies: + is-property: 1.0.2 + dev: true + /gensync@1.0.0-beta.2: resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==} engines: {node: '>=6.9.0'} @@ -3724,6 +3752,13 @@ packages: engines: {node: '>=16.17.0'} dev: true + /iconv-lite@0.6.3: + resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} + engines: {node: '>=0.10.0'} + dependencies: + safer-buffer: 2.1.2 + dev: true + /ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} dev: true @@ -3895,6 +3930,10 @@ packages: resolution: {integrity: sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==} dev: true + /is-property@1.0.2: + resolution: {integrity: sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==} + dev: true + /is-reference@1.2.1: resolution: {integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==} dependencies: @@ -4184,6 +4223,10 @@ packages: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} dev: true + /long@5.2.3: + resolution: {integrity: sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==} + dev: true + /loupe@2.3.7: resolution: {integrity: sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==} dependencies: @@ -4203,6 +4246,16 @@ packages: yallist: 4.0.0 dev: true + /lru-cache@7.18.3: + resolution: {integrity: sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==} + engines: {node: '>=12'} + dev: true + + /lru-cache@8.0.5: + resolution: {integrity: sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==} + engines: {node: '>=16.14'} + dev: true + /lru-queue@0.1.0: resolution: {integrity: sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==} dependencies: @@ -4410,6 +4463,27 @@ packages: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} dev: true + /mysql2@3.9.6: + resolution: {integrity: sha512-9NYUMLQv6yXnu+5hUh8PZ5CdKoG6VWDzXbojIdTyob8upNZXU3rBNQK9viaEqfgw+LMifhd+53VEZPxZk3bTWA==} + engines: {node: '>= 8.0'} + dependencies: + denque: 2.1.0 + generate-function: 2.3.1 + iconv-lite: 0.6.3 + long: 5.2.3 + lru-cache: 8.0.5 + named-placeholders: 1.1.3 + seq-queue: 0.0.5 + sqlstring: 2.3.3 + dev: true + + /named-placeholders@1.1.3: + resolution: {integrity: sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==} + engines: {node: '>=12.0.0'} + dependencies: + lru-cache: 7.18.3 + dev: true + /nanoid@3.3.7: resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} @@ -5473,6 +5547,10 @@ packages: regexp-tree: 0.1.27 dev: true + /safer-buffer@2.1.2: + resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} + dev: true + /scule@1.3.0: resolution: {integrity: sha512-6FtHJEvt+pVMIB9IBY+IcCJ6Z5f1iQnytgyfKMhDKgmzYG+TeH/wx1y3l27rshSbLiSanrR9ffZDrEsmjlQF2g==} dev: true @@ -5495,6 +5573,10 @@ packages: lru-cache: 6.0.0 dev: true + /seq-queue@0.0.5: + resolution: {integrity: sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==} + dev: true + /set-function-length@1.2.1: resolution: {integrity: sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g==} engines: {node: '>= 0.4'} @@ -5627,6 +5709,11 @@ packages: engines: {node: '>= 10.x'} dev: true + /sqlstring@2.3.3: + resolution: {integrity: sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==} + engines: {node: '>= 0.6'} + dev: true + /stackback@0.0.2: resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} dev: true diff --git a/src/connectors/mysql2.ts b/src/connectors/mysql2.ts new file mode 100644 index 0000000..005d8a5 --- /dev/null +++ b/src/connectors/mysql2.ts @@ -0,0 +1,47 @@ +import mysql from "mysql2/promise"; + +import type { Connector, Statement } from "../types"; + +export default function mysqlConnector(opts: mysql.ConnectionOptions) { + let _connection: mysql.Connection | undefined; + const getConnection = async () => { + if (_connection) { + return _connection; + } + + _connection = await mysql.createConnection({ + ...opts, + }) + + return _connection; + }; + + return { + name: "mysql", + exec(sql: string) { + return getConnection().then((c) => c.query(sql).then((res) => res[0])); + }, + prepare(sql: string) { + const stmt = { + _sql: sql, + _params: [], + bind(...params) { + if (params.length > 0) { + this._params = params; + } + return stmt; + }, + all(...params) { + return getConnection().then((c) => c.query(this._sql, params || this._params).then((res) => res[0])); + }, + run(...params) { + return getConnection().then((c) => c.query(this._sql, params || this._params).then((res) => res[0])); + }, + get(...params) { + return getConnection().then((c) => c.query(this._sql, params || this._params).then((res) => res[0][0])); + }, + }; + return stmt; + }, + }; +} diff --git a/test/connectors/mysql2.test.ts b/test/connectors/mysql2.test.ts new file mode 100644 index 0000000..2cd906a --- /dev/null +++ b/test/connectors/mysql2.test.ts @@ -0,0 +1,17 @@ +import { describe } from "vitest"; +import connector from "../../src/connectors/mysql2"; +import { testConnector } from "./_tests"; + +describe.runIf(process.env.POSTGRESQL_URL)( + "connectors: mysql2.test", + () => { + testConnector({ + connector: connector({ + host: "localhost", + user: "root", + password: "root", + database: "db0", + }), + }); + }, +); From f836b37474a9a110ab9d9847ccedea343b80b1c2 Mon Sep 17 00:00:00 2001 From: Arash Date: Fri, 19 Apr 2024 22:47:49 -0600 Subject: [PATCH 2/5] chore: add mysql to currently supported connectors list --- docs/2.connectors/1.index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/2.connectors/1.index.md b/docs/2.connectors/1.index.md index 85fadec..b765c3d 100644 --- a/docs/2.connectors/1.index.md +++ b/docs/2.connectors/1.index.md @@ -12,6 +12,7 @@ Currently supported connectors: - [Cloudflare D1](/connectors/cloudflare) - [LibSQL](/connectors/libsql) - [PostgreSQL](/connectors/postgresql) +- [MySQL](/connectors/mysql) - [SQLite](/connectors/sqlite) ::read-more{to="https://github.com/unjs/db0/issues/32"} From 707ed68204756ff49cd0780f4186b32e98da710e Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 9 Oct 2024 23:28:59 +0200 Subject: [PATCH 3/5] update --- examples/mysql/index.ts | 34 ---------------------------------- examples/mysql/package.json | 10 ---------- src/connectors/mysql2.ts | 1 + test/connectors/mysql2.test.ts | 1 + 4 files changed, 2 insertions(+), 44 deletions(-) delete mode 100644 examples/mysql/index.ts delete mode 100644 examples/mysql/package.json diff --git a/examples/mysql/index.ts b/examples/mysql/index.ts deleted file mode 100644 index 7e9af18..0000000 --- a/examples/mysql/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { createDatabase } from "../../src"; -import mysqlConnector from "../../src/connectors/mysql2" - - -async function main() { - const db = createDatabase(mysqlConnector({ - host: "localhost", - user: "root", - password: "root", - database: "db0", - })); - - await db.sql`CREATE TABLE IF NOT EXISTS users ( - id INT PRIMARY KEY AUTO_INCREMENT, - name VARCHAR(255) NOT NULL - )`; - - await db.sql`INSERT INTO users (name) VALUES (${randomValue()})`; - - const users = await db.sql`SELECT * FROM users`; - - console.log({ rows: users.rows }); -} - -// eslint-disable-next-line unicorn/prefer-top-level-await -main().catch((error) => { - console.error(error); - // eslint-disable-next-line unicorn/no-process-exit - process.exit(1); -}); - -function randomValue() { - return Math.random().toString(36).slice(7); -} diff --git a/examples/mysql/package.json b/examples/mysql/package.json deleted file mode 100644 index 456df05..0000000 --- a/examples/mysql/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "db0-with-mysql", - "private": true, - "scripts": { - "start": "jiti ./index.ts" - }, - "devDependencies": { - "db0": "latest" - } -} diff --git a/src/connectors/mysql2.ts b/src/connectors/mysql2.ts index 005d8a5..14fa17d 100644 --- a/src/connectors/mysql2.ts +++ b/src/connectors/mysql2.ts @@ -18,6 +18,7 @@ export default function mysqlConnector(opts: mysql.ConnectionOptions) { return { name: "mysql", + dialect: "mysql", exec(sql: string) { return getConnection().then((c) => c.query(sql).then((res) => res[0])); }, diff --git a/test/connectors/mysql2.test.ts b/test/connectors/mysql2.test.ts index 2cd906a..aa9c0e2 100644 --- a/test/connectors/mysql2.test.ts +++ b/test/connectors/mysql2.test.ts @@ -6,6 +6,7 @@ describe.runIf(process.env.POSTGRESQL_URL)( "connectors: mysql2.test", () => { testConnector({ + dialect: "mysql", connector: connector({ host: "localhost", user: "root", From eaa2d8302e2c4097e6a15d5b064799a009654e43 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 9 Oct 2024 23:29:41 +0200 Subject: [PATCH 4/5] update test env --- .env.example | 2 +- test/connectors/mysql2.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 5009770..e68216d 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ POSTGRESQL_URL=postgresql://:@localhost:5432/db0 +MYSQL_URL= # PlanetScale PLANETSCALE_HOST=aws.connect.psdb.cloud PLANETSCALE_USERNAME=username PLANETSCALE_PASSWORD=password - \ No newline at end of file diff --git a/test/connectors/mysql2.test.ts b/test/connectors/mysql2.test.ts index aa9c0e2..99579f1 100644 --- a/test/connectors/mysql2.test.ts +++ b/test/connectors/mysql2.test.ts @@ -2,7 +2,7 @@ import { describe } from "vitest"; import connector from "../../src/connectors/mysql2"; import { testConnector } from "./_tests"; -describe.runIf(process.env.POSTGRESQL_URL)( +describe.runIf(process.env.MYSQL_URL)( "connectors: mysql2.test", () => { testConnector({ From 744b33cc5fa683c8d89b2464fc0b16acfeb12e1a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 9 Oct 2024 23:31:51 +0200 Subject: [PATCH 5/5] add dep --- package.json | 7 ++- pnpm-lock.yaml | 128 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 127 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 60d2005..77d367e 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "eslint": "^9.12.0", "eslint-config-unjs": "^0.4.1", "jiti": "^2.3.3", + "mysql2": "^3.11.3", "pg": "^8.13.0", "prettier": "^3.3.3", "typescript": "^5.6.3", @@ -74,7 +75,8 @@ "peerDependencies": { "@libsql/client": "*", "better-sqlite3": "*", - "drizzle-orm": "*" + "drizzle-orm": "*", + "mysql2": "*" }, "peerDependenciesMeta": { "@libsql/client": { @@ -85,6 +87,9 @@ }, "drizzle-orm": { "optional": true + }, + "mysql2": { + "optional": true } }, "packageManager": "pnpm@9.12.1" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 42cb2e6..45164d2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,13 +37,13 @@ importers: version: 0.5.7(magicast@0.3.5) db0: specifier: ^0.1.4 - version: 0.1.4(@libsql/client@0.14.0)(better-sqlite3@11.3.0)(drizzle-orm@0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(pg@8.13.0)) + version: 0.1.4(@libsql/client@0.14.0)(better-sqlite3@11.3.0)(drizzle-orm@0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0)) dotenv: specifier: ^16.4.5 version: 16.4.5 drizzle-orm: specifier: ^0.34.1 - version: 0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(pg@8.13.0) + version: 0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0) eslint: specifier: ^9.12.0 version: 9.12.0(jiti@2.3.3) @@ -53,6 +53,9 @@ importers: jiti: specifier: ^2.3.3 version: 2.3.3 + mysql2: + specifier: ^3.11.3 + version: 3.11.3 pg: specifier: ^8.13.0 version: 8.13.0 @@ -73,13 +76,13 @@ importers: devDependencies: db0: specifier: latest - version: 0.1.4(@libsql/client@0.14.0)(better-sqlite3@9.6.0)(drizzle-orm@0.29.4(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@9.6.0)(bun-types@1.1.30)(pg@8.13.0)) + version: 0.1.4(@libsql/client@0.14.0)(better-sqlite3@9.6.0)(drizzle-orm@0.29.4(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@9.6.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0)) drizzle-kit: specifier: ^0.20.14 version: 0.20.14 drizzle-orm: specifier: ^0.29.4 - version: 0.29.4(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@9.6.0)(bun-types@1.1.30)(pg@8.13.0) + version: 0.29.4(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@9.6.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0) jiti: specifier: ^1.21.0 version: 1.21.0 @@ -1294,6 +1297,10 @@ packages: peerDependencies: postcss: ^8.1.0 + aws-ssl-profiles@1.1.2: + resolution: {integrity: sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==} + engines: {node: '>= 6.0.0'} + balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} @@ -1626,6 +1633,10 @@ packages: defu@6.1.4: resolution: {integrity: sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg==} + denque@2.1.0: + resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==} + engines: {node: '>=0.10'} + destr@2.0.3: resolution: {integrity: sha512-2N3BOUU4gYMpTP24s5rF5iP7BDr7uNTCs4ozw3kf/eKfvWSIu93GEBi5m427YoyJoeOzQ5smuu4nNAPGb8idSQ==} @@ -2081,6 +2092,9 @@ packages: function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} + generate-function@2.3.1: + resolution: {integrity: sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==} + gensync@1.0.0-beta.2: resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==} engines: {node: '>=6.9.0'} @@ -2114,6 +2128,7 @@ packages: glob@8.1.0: resolution: {integrity: sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==} engines: {node: '>=12'} + deprecated: Glob versions prior to v9 are no longer supported globals@11.12.0: resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==} @@ -2173,6 +2188,10 @@ packages: resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==} engines: {node: '>=16.17.0'} + iconv-lite@0.6.3: + resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} + engines: {node: '>=0.10.0'} + ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} @@ -2194,6 +2213,7 @@ packages: inflight@1.0.6: resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} + deprecated: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} @@ -2260,6 +2280,9 @@ packages: is-promise@2.2.2: resolution: {integrity: sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==} + is-property@1.0.2: + resolution: {integrity: sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==} + is-reference@1.2.1: resolution: {integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==} @@ -2358,6 +2381,7 @@ packages: libsql@0.4.6: resolution: {integrity: sha512-F5M+ltteK6dCcpjMahrkgT96uFJvVI8aQ4r9f2AzHQjC7BkAYtvfMSTWGvRBezRgMUIU2h1Sy0pF9nOGOD5iyA==} + cpu: [x64, arm64, wasm32] os: [darwin, linux, win32] lilconfig@3.1.2: @@ -2390,6 +2414,9 @@ packages: lodash.uniq@4.5.0: resolution: {integrity: sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==} + long@5.2.3: + resolution: {integrity: sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==} + loupe@3.1.2: resolution: {integrity: sha512-23I4pFZHmAemUnz8WZXbYRSKYj801VDaNv9ETuMh7IrMc7VuVVSo+Z9iLE3ni30+U48iDWfi30d3twAXBYmnCg==} @@ -2403,9 +2430,17 @@ packages: resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} engines: {node: '>=10'} + lru-cache@7.18.3: + resolution: {integrity: sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==} + engines: {node: '>=12'} + lru-queue@0.1.0: resolution: {integrity: sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==} + lru.min@1.1.1: + resolution: {integrity: sha512-FbAj6lXil6t8z4z3j0E5mfRlPzxkySotzUHwRXjlpRh10vc6AI6WN62ehZj82VG7M20rqogJ0GLwar2Xa05a8Q==} + engines: {bun: '>=1.0.0', deno: '>=1.30.0', node: '>=8.0.0'} + magic-string@0.30.11: resolution: {integrity: sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==} @@ -2533,6 +2568,14 @@ packages: ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + mysql2@3.11.3: + resolution: {integrity: sha512-Qpu2ADfbKzyLdwC/5d4W7+5Yz7yBzCU05YWt5npWzACST37wJsB23wgOSo00qi043urkiRwXtEvJc9UnuLX/MQ==} + engines: {node: '>= 8.0'} + + named-placeholders@1.1.3: + resolution: {integrity: sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==} + engines: {node: '>=12.0.0'} + nanoid@3.3.7: resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} @@ -3071,6 +3114,9 @@ packages: safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + safer-buffer@2.1.2: + resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} + scule@1.3.0: resolution: {integrity: sha512-6FtHJEvt+pVMIB9IBY+IcCJ6Z5f1iQnytgyfKMhDKgmzYG+TeH/wx1y3l27rshSbLiSanrR9ffZDrEsmjlQF2g==} @@ -3092,6 +3138,9 @@ packages: engines: {node: '>=10'} hasBin: true + seq-queue@0.0.5: + resolution: {integrity: sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==} + shebang-command@2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} engines: {node: '>=8'} @@ -3151,6 +3200,10 @@ packages: resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==} engines: {node: '>= 10.x'} + sqlstring@2.3.3: + resolution: {integrity: sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==} + engines: {node: '>= 0.6'} + stackback@0.0.2: resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} @@ -4454,6 +4507,8 @@ snapshots: postcss: 8.4.47 postcss-value-parser: 4.2.0 + aws-ssl-profiles@1.1.2: {} + balanced-match@1.0.2: {} base64-js@1.5.1: {} @@ -4783,11 +4838,17 @@ snapshots: data-uri-to-buffer@4.0.1: {} - db0@0.1.4(@libsql/client@0.14.0)(better-sqlite3@11.3.0)(drizzle-orm@0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(pg@8.13.0)): + db0@0.1.4(@libsql/client@0.14.0)(better-sqlite3@11.3.0)(drizzle-orm@0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0)): optionalDependencies: '@libsql/client': 0.14.0 better-sqlite3: 11.3.0 - drizzle-orm: 0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(pg@8.13.0) + drizzle-orm: 0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0) + + db0@0.1.4(@libsql/client@0.14.0)(better-sqlite3@9.6.0)(drizzle-orm@0.29.4(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@9.6.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0)): + optionalDependencies: + '@libsql/client': 0.14.0 + better-sqlite3: 9.6.0 + drizzle-orm: 0.29.4(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@9.6.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0) db0@0.1.4(@libsql/client@0.14.0)(better-sqlite3@9.6.0)(drizzle-orm@0.29.4(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@9.6.0)(bun-types@1.1.30)(pg@8.13.0)): optionalDependencies: @@ -4826,6 +4887,8 @@ snapshots: defu@6.1.4: {} + denque@2.1.0: {} + destr@2.0.3: {} detect-libc@1.0.3: {} @@ -4891,6 +4954,17 @@ snapshots: transitivePeerDependencies: - supports-color + drizzle-orm@0.29.4(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@9.6.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0): + optionalDependencies: + '@libsql/client': 0.14.0 + '@planetscale/database': 1.19.0 + '@types/better-sqlite3': 7.6.11 + '@types/pg': 8.11.10 + better-sqlite3: 9.6.0 + bun-types: 1.1.30 + mysql2: 3.11.3 + pg: 8.13.0 + drizzle-orm@0.29.4(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@9.6.0)(bun-types@1.1.30)(pg@8.13.0): optionalDependencies: '@libsql/client': 0.14.0 @@ -4900,8 +4974,9 @@ snapshots: better-sqlite3: 9.6.0 bun-types: 1.1.30 pg: 8.13.0 + optional: true - drizzle-orm@0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(pg@8.13.0): + drizzle-orm@0.34.1(@libsql/client@0.14.0)(@planetscale/database@1.19.0)(@types/better-sqlite3@7.6.11)(@types/pg@8.11.10)(better-sqlite3@11.3.0)(bun-types@1.1.30)(mysql2@3.11.3)(pg@8.13.0): optionalDependencies: '@libsql/client': 0.14.0 '@planetscale/database': 1.19.0 @@ -4909,6 +4984,7 @@ snapshots: '@types/pg': 8.11.10 better-sqlite3: 11.3.0 bun-types: 1.1.30 + mysql2: 3.11.3 pg: 8.13.0 eastasianwidth@0.2.0: {} @@ -5289,6 +5365,10 @@ snapshots: function-bind@1.1.2: {} + generate-function@2.3.1: + dependencies: + is-property: 1.0.2 + gensync@1.0.0-beta.2: {} get-stream@8.0.1: {} @@ -5385,6 +5465,10 @@ snapshots: human-signals@5.0.0: {} + iconv-lite@0.6.3: + dependencies: + safer-buffer: 2.1.2 + ieee754@1.2.1: {} ignore@5.3.2: {} @@ -5452,6 +5536,8 @@ snapshots: is-promise@2.2.2: {} + is-property@1.0.2: {} + is-reference@1.2.1: dependencies: '@types/estree': 1.0.6 @@ -5571,6 +5657,8 @@ snapshots: lodash.uniq@4.5.0: {} + long@5.2.3: {} + loupe@3.1.2: {} lru-cache@10.4.3: {} @@ -5583,10 +5671,14 @@ snapshots: dependencies: yallist: 4.0.0 + lru-cache@7.18.3: {} + lru-queue@0.1.0: dependencies: es5-ext: 0.10.62 + lru.min@1.1.1: {} + magic-string@0.30.11: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 @@ -5722,6 +5814,22 @@ snapshots: ms@2.1.3: {} + mysql2@3.11.3: + dependencies: + aws-ssl-profiles: 1.1.2 + denque: 2.1.0 + generate-function: 2.3.1 + iconv-lite: 0.6.3 + long: 5.2.3 + lru.min: 1.1.1 + named-placeholders: 1.1.3 + seq-queue: 0.0.5 + sqlstring: 2.3.3 + + named-placeholders@1.1.3: + dependencies: + lru-cache: 7.18.3 + nanoid@3.3.7: {} napi-build-utils@1.0.2: {} @@ -6254,6 +6362,8 @@ snapshots: safe-buffer@5.2.1: {} + safer-buffer@2.1.2: {} + scule@1.3.0: {} semver@5.7.2: {} @@ -6266,6 +6376,8 @@ snapshots: semver@7.6.3: {} + seq-queue@0.0.5: {} + shebang-command@2.0.0: dependencies: shebang-regex: 3.0.0 @@ -6315,6 +6427,8 @@ snapshots: split2@4.2.0: {} + sqlstring@2.3.3: {} + stackback@0.0.2: {} std-env@3.7.0: {}