diff --git a/packages/database/.env.example b/packages/database/.env.example index 0aad0a1..6bb5d4a 100644 --- a/packages/database/.env.example +++ b/packages/database/.env.example @@ -1,2 +1,5 @@ # Postgres database url DATABASE_URL="" + +# Redis url +REDIS_URL="" diff --git a/packages/database/package.json b/packages/database/package.json index 4e2681e..53ef024 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -22,6 +22,7 @@ "dependencies": { "@lbf-bot/utils": "workspace:*", "drizzle-orm": "0.44.7", + "ioredis": "5.8.2", "pg": "8.16.3", "zod": "4.1.11" }, diff --git a/packages/database/src/env.ts b/packages/database/src/env.ts index e186489..5b64032 100644 --- a/packages/database/src/env.ts +++ b/packages/database/src/env.ts @@ -3,4 +3,5 @@ import { parseEnv } from "@lbf-bot/utils"; export const env = parseEnv({ DATABASE_URL: z.url().min(1, "Required"), + REDIS_URL: z.url().min(1, "Required"), }); diff --git a/packages/database/src/index.ts b/packages/database/src/index.ts index 31b9385..df9ab83 100644 --- a/packages/database/src/index.ts +++ b/packages/database/src/index.ts @@ -1,4 +1,4 @@ -import { drizzle } from "drizzle-orm/postgres-js"; +import { drizzle } from "drizzle-orm/node-postgres"; import { env } from "~/env"; import * as tables from "~/schema/tables"; import * as relations from "~/schema/relations"; @@ -8,3 +8,6 @@ export { tables }; export const db = drizzle(env.DATABASE_URL, { schema: { ...tables, ...relations }, }); + +export { redis } from "~/redis"; +export * from "drizzle-orm"; diff --git a/packages/database/src/redis.ts b/packages/database/src/redis.ts new file mode 100644 index 0000000..cc47c8b --- /dev/null +++ b/packages/database/src/redis.ts @@ -0,0 +1,4 @@ +import Redis from "ioredis"; +import { env } from "~/env"; + +export const redis = new Redis(env.REDIS_URL); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1b902fa..791bbd0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: apps/discord-bot: dependencies: + '@lbf-bot/database': + specifier: workspace:* + version: link:../../packages/database discord.js: specifier: ^14.21.0 version: 14.25.1 @@ -44,7 +47,10 @@ importers: version: link:../utils drizzle-orm: specifier: 0.44.7 - version: 0.44.7(pg@8.16.3) + version: 0.44.7(pg@8.16.3)(postgres@3.4.7) + ioredis: + specifier: 5.8.2 + version: 5.8.2 pg: specifier: 8.16.3 version: 8.16.3 @@ -566,6 +572,9 @@ packages: cpu: [x64] os: [win32] + '@ioredis/commands@1.4.0': + resolution: {integrity: sha512-aFT2yemJJo+TZCmieA7qnYGQooOS7QfNmYrzGtsYd3g9j5iDP8AimYYAesf79ohjbLG12XxC4nG5DyEnC88AsQ==} + '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -623,6 +632,10 @@ packages: resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} engines: {node: '>= 8.10.0'} + cluster-key-slot@1.1.2: + resolution: {integrity: sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==} + engines: {node: '>=0.10.0'} + commander@9.5.0: resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==} engines: {node: ^12.20.0 || >=14} @@ -636,6 +649,10 @@ packages: supports-color: optional: true + denque@2.1.0: + resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==} + engines: {node: '>=0.10'} + dir-glob@3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} @@ -801,6 +818,10 @@ packages: resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==} engines: {node: '>= 4'} + ioredis@5.8.2: + resolution: {integrity: sha512-C6uC+kleiIMmjViJINWk80sOQw5lEzse1ZmvD+S/s8p8CWapftSaC+kocGTx6xrbrJ4WmYQGC08ffHLr6ToR6Q==} + engines: {node: '>=12.22.0'} + is-binary-path@2.1.0: resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==} engines: {node: '>=8'} @@ -817,6 +838,12 @@ packages: resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} engines: {node: '>=0.12.0'} + lodash.defaults@4.2.0: + resolution: {integrity: sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==} + + lodash.isarguments@3.1.0: + resolution: {integrity: sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg==} + lodash.snakecase@4.1.1: resolution: {integrity: sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==} @@ -907,6 +934,10 @@ packages: resolution: {integrity: sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==} engines: {node: '>=0.10.0'} + postgres@3.4.7: + resolution: {integrity: sha512-Jtc2612XINuBjIl/QTWsV5UvE8UHuNblcO3vVADSrKsrc6RqGX6lOW1cEo3CM2v0XG4Nat8nI+YM7/f26VxXLw==} + engines: {node: '>=12'} + prettier@3.6.2: resolution: {integrity: sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==} engines: {node: '>=14'} @@ -923,6 +954,14 @@ packages: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} + redis-errors@1.2.0: + resolution: {integrity: sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==} + engines: {node: '>=4'} + + redis-parser@3.0.0: + resolution: {integrity: sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A==} + engines: {node: '>=4'} + resolve-pkg-maps@1.0.0: resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} @@ -948,6 +987,9 @@ packages: resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==} engines: {node: '>= 10.x'} + standard-as-callback@2.1.0: + resolution: {integrity: sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==} + to-regex-range@5.0.1: resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} engines: {node: '>=8.0'} @@ -1287,6 +1329,8 @@ snapshots: '@esbuild/win32-x64@0.27.0': optional: true + '@ioredis/commands@1.4.0': {} + '@nodelib/fs.scandir@2.1.5': dependencies: '@nodelib/fs.stat': 2.0.5 @@ -1345,12 +1389,16 @@ snapshots: optionalDependencies: fsevents: 2.3.3 + cluster-key-slot@1.1.2: {} + commander@9.5.0: {} debug@4.4.3: dependencies: ms: 2.1.3 + denque@2.1.0: {} + dir-glob@3.0.1: dependencies: path-type: 4.0.0 @@ -1387,9 +1435,10 @@ snapshots: transitivePeerDependencies: - supports-color - drizzle-orm@0.44.7(pg@8.16.3): + drizzle-orm@0.44.7(pg@8.16.3)(postgres@3.4.7): optionalDependencies: pg: 8.16.3 + postgres: 3.4.7 esbuild-register@3.6.0(esbuild@0.25.12): dependencies: @@ -1521,6 +1570,20 @@ snapshots: ignore@5.3.2: {} + ioredis@5.8.2: + dependencies: + '@ioredis/commands': 1.4.0 + cluster-key-slot: 1.1.2 + debug: 4.4.3 + denque: 2.1.0 + lodash.defaults: 4.2.0 + lodash.isarguments: 3.1.0 + redis-errors: 1.2.0 + redis-parser: 3.0.0 + standard-as-callback: 2.1.0 + transitivePeerDependencies: + - supports-color + is-binary-path@2.1.0: dependencies: binary-extensions: 2.3.0 @@ -1533,6 +1596,10 @@ snapshots: is-number@7.0.0: {} + lodash.defaults@4.2.0: {} + + lodash.isarguments@3.1.0: {} + lodash.snakecase@4.1.1: {} lodash@4.17.21: {} @@ -1605,6 +1672,9 @@ snapshots: dependencies: xtend: 4.0.2 + postgres@3.4.7: + optional: true + prettier@3.6.2: {} queue-lit@1.5.2: {} @@ -1615,6 +1685,12 @@ snapshots: dependencies: picomatch: 2.3.1 + redis-errors@1.2.0: {} + + redis-parser@3.0.0: + dependencies: + redis-errors: 1.2.0 + resolve-pkg-maps@1.0.0: {} reusify@1.1.0: {} @@ -1634,6 +1710,8 @@ snapshots: split2@4.2.0: {} + standard-as-callback@2.1.0: {} + to-regex-range@5.0.1: dependencies: is-number: 7.0.0