Skip to content

Commit

Permalink
use prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
yuimarudev committed Jan 28, 2024
1 parent a8a0749 commit 90c8942
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
.env
.env
prisma/*.sqlite*
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"dotenv": "^16.3.2",
"etcd3": "^1.1.2",
"lefthook": "^1.5.7",
"prisma": "^5.8.1",
"typescript": "^5.3.3"
},
"dependencies": {
"@prisma/client": "5.8.1"
}
}
56 changes: 56 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions prisma/migrations/20240128011745_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- CreateTable
CREATE TABLE "Synthesizer" (
"userId" TEXT NOT NULL PRIMARY KEY,
"speed" REAL NOT NULL,
"pitch" REAL NOT NULL,
"voice" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "Dictionary" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"guildId" TEXT NOT NULL,
"word" TEXT NOT NULL,
"read" TEXT NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "Dictionary_word_key" ON "Dictionary"("word");
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
25 changes: 25 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

model Synthesizer {
userId String @id
speed Float
pitch Float
voice String
}

model Dictionary {
id Int @id @default(autoincrement())
guildId String
word String @unique
read String
}
45 changes: 0 additions & 45 deletions src/db/helper.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/db/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/db/init.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client, GatewayIntentBits } from "@discordjs/core";
import { REST } from "@discordjs/rest";
import { WebSocketManager } from "@discordjs/ws";
import { PrismaClient } from "@prisma/client";
import "dotenv/config";
import handlers from "./handlers/index.js";

Expand All @@ -20,6 +21,7 @@ const gateway = new WebSocketManager({
rest,
});
const client = new Client({ rest, gateway });
const prisma = new PrismaClient();

for (const [event, fn] of Object.entries(handlers)) {
client.on(
Expand All @@ -29,5 +31,7 @@ for (const [event, fn] of Object.entries(handlers)) {
}

await gateway.connect();
await prisma.$connect();

export { gateway };
export { prisma };
2 changes: 1 addition & 1 deletion src/synthesizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class Synthesizer {
toJSON() {
return JSON.stringify({
voice: this.voice,
spped: this.speed,
speed: this.speed,
userId: this.userId,
pitch: this.pitch,
});
Expand Down
8 changes: 4 additions & 4 deletions src/voice/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { WebSocketManager } from "@discordjs/ws";
import { Mutex } from "async-mutex";
import { except } from "../common/functions.js";
import { getJSON } from "../db/helper.js";
import { prisma } from "../index.js";
import Synthesizer from "../synthesizer/index.js";
import voiceAdapterCreator from "./voiceAdapterCreator.js";

Expand Down Expand Up @@ -51,9 +51,9 @@ export default class Room {
const release = await this.audioResourceLock.acquire();

try {
const userConfig = await getJSON<Synthesizer>(
`synthesizers/${message.author.id}`,
);
const userConfig = await prisma.synthesizer.findFirst({
where: { userId: message.author.id },
});
const synthesizer = new Synthesizer(
except(process.env["key"]),
except(process.env["region"]),
Expand Down

0 comments on commit 90c8942

Please sign in to comment.