Skip to content

Commit

Permalink
Merge pull request #50 from sora-vp/processor-independent-db
Browse files Browse the repository at this point in the history
Perbaikan vote processor
  • Loading branch information
reacto11mecha authored Jul 3, 2024
2 parents d796402 + 570af43 commit 47ff7d3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"@trpc/client": "11.0.0-rc.364",
"@trpc/server": "11.0.0-rc.364",
"amqplib": "^0.10.4",
"drizzle-orm": "^0.30.10",
"mysql2": "^3.9.8",
"pino": "^9.0.0",
"pino-pretty": "^11.0.0",
"superjson": "2.2.1",
Expand Down
19 changes: 19 additions & 0 deletions apps/processor/src/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

import * as schema from "@sora-vp/db/schema/main";

import { env } from "./env";

const connectionStr = new URL(`mysql://${env.DB_HOST}/${env.DB_NAME}`);
connectionStr.username = env.DB_USERNAME;
connectionStr.password = env.DB_PASSWORD;

const poolConnection = mysql.createPool(connectionStr.toString());

export const db = drizzle(poolConnection, {
schema,
mode: "default",
});

export { schema };
4 changes: 4 additions & 0 deletions apps/processor/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const env = createEnv({
client: {},

server: {
DB_HOST: z.string(),
DB_NAME: z.string(),
DB_PASSWORD: z.string(),
DB_USERNAME: z.string(),
AMQP_URL: z.string().url(),
PROCESSOR_API_URL: z.string().url(),
},
Expand Down
3 changes: 2 additions & 1 deletion apps/processor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-misused-promises */
import amqp from "amqplib";
import { eq, sql } from "drizzle-orm";
import { z } from "zod";

import { db, eq, schema, sql } from "@sora-vp/db";
import { validateId } from "@sora-vp/id-generator";

import { api } from "./api";
import { db, schema } from "./db";
import { env } from "./env";
import { logger } from "./logger";
import { canVoteNow } from "./utils";
Expand Down
3 changes: 2 additions & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
".": {
"types": "./dist/index.d.ts",
"default": "./src/index.ts"
}
},
"./*": "./src/*.ts"
},
"license": "MIT",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2688,7 +2688,9 @@ __metadata:
"@types/node": "npm:^20.12.9"
amqplib: "npm:^0.10.4"
dotenv-cli: "npm:^7.4.1"
drizzle-orm: "npm:^0.30.10"
eslint: "npm:^9.6.0"
mysql2: "npm:^3.9.8"
pino: "npm:^9.0.0"
pino-pretty: "npm:^11.0.0"
prettier: "npm:^3.2.5"
Expand Down

0 comments on commit 47ff7d3

Please sign in to comment.