Skip to content

Commit

Permalink
switch to turso database
Browse files Browse the repository at this point in the history
  • Loading branch information
tinypell3ts committed Aug 13, 2024
1 parent 530d0a3 commit c954cbd
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ REWARD_TOKEN_ID=
PRIVATE_KEY=

# Location of the Database. See prisma/schema.prisma
DATABASE_URL="file:./dev.db"
TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=

# CORS allowed origins, comma delimited
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001,https://wordle-staging.vercel.app,https://wordle.openformat.tech
4 changes: 0 additions & 4 deletions backend/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ primary_region = 'lhr'
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

[[mounts]]
source = 'data'
destination = '/data'
2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"start": "bun run src/index.ts"
},
"dependencies": {
"@libsql/client": "^0.9.0",
"@openformat/sdk": "^1.4.0",
"@prisma/adapter-libsql": "^5.18.0",
"@prisma/client": "^5.7.1",
"@privy-io/server-auth": "^1.9.6",
"@types/validator": "^13.11.7",
Expand Down
6 changes: 3 additions & 3 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-musl-arm64-openssl-3.0.x", "linux-musl-openssl-3.0.x"]
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
url = "file:./dev.db"
}

model User {
Expand Down
4 changes: 1 addition & 3 deletions backend/src/middlewares/privyAuth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { PrismaClient } from "@prisma/client";
import { PrivyClient, User } from "@privy-io/server-auth";
import { Context, Next } from "hono";
import { prisma } from "../services/db";

const privy = new PrivyClient(
process.env.PRIVY_APP_ID!,
process.env.PRIVY_APP_SECRET!
);

const prisma = new PrismaClient();

export const privyAuthMiddleware = async (c: Context, next: Next) => {
const authToken = c.req
.header("Authorization")
Expand Down
3 changes: 1 addition & 2 deletions backend/src/routes/api/v1/leaderboard.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PrismaClient } from "@prisma/client";
import dayjs from "dayjs";
import { Hono } from "hono";
import { leaderboardData } from "../../../queries/leaderboard";
import { sdk } from "../../../services/SDK";
import { prisma } from "../../../services/db";
import {
convertToTimestamps,
generateLeaderboard,
Expand All @@ -14,7 +14,6 @@ enum Status {
}

const leaderboard = new Hono();
const prisma = new PrismaClient();

leaderboard.onError((err, c) => {
console.error(`${err}`);
Expand Down
3 changes: 1 addition & 2 deletions backend/src/routes/api/v1/profile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PrismaClient } from "@prisma/client";
import { User } from "@privy-io/server-auth";
import { Hono } from "hono";
import { prisma } from "../../../services/db";
import { getOnChainProfile } from "../../../utils/profile";

enum Status {
Expand All @@ -9,7 +9,6 @@ enum Status {
}

const profile = new Hono<{ Variables: { user: User } }>();
const prisma = new PrismaClient();

profile.onError((err, c) => {
console.error(`${err}`);
Expand Down
11 changes: 11 additions & 0 deletions backend/src/services/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createClient } from "@libsql/client";
import { PrismaLibSQL } from "@prisma/adapter-libsql";
import { PrismaClient } from "@prisma/client";

const libsql = createClient({
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN,
});

const adapter = new PrismaLibSQL(libsql);
export const prisma = new PrismaClient({ adapter });
Binary file modified bun.lockb
Binary file not shown.

0 comments on commit c954cbd

Please sign in to comment.