Reputation: 11
An error occurs when i start development server trying to connect to the database using a combination of prisma and turso-db . I tried to do everything according to the official documentation https://docs.turso.tech/sdk/ts/orm/prisma , but I still get an error. I tried to change the provider in the schema.prisma to libsql and sqlite, that didnt help.
GITHUB:https://github.com/nikitodeon/Error-prisma-turso.git
example.env
TURSO_AUTH_TOKEN="eyJhbGciOi....4LALvigvSfrXuUjbAg"
TURSO_DATABASE_URL="libsql://<name>.turso.io"
prisma-client.ts
import { PrismaClient } from "@prisma/client";
import { PrismaLibSQL } from "@prisma/adapter-libsql";
import { createClient } from "@libsql/client";
const libsql = createClient({
url: process.env.TURSO_DATABASE_URL as string,
authToken: process.env.TURSO_AUTH_TOKEN as string,
});
const adapter = new PrismaLibSQL(libsql);
const prisma = new PrismaClient({ adapter });
export { prisma };
schema.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
datasource db {
provider = "postgresql"
url = env("TURSO_DATABASE_URL") // uses connection pooling
// directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}
model User {
id Int @id @default(autoincrement())
fullName String
email String @unique
password String
role UserRole @default(USER)
verified DateTime?
provider String?
providerId String?
cart Cart?
orders Order[]
verificationCode VerificationCode?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Category {
id Int @id @default(autoincrement())
name String @unique
products Product[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Product {
id Int @id @default(autoincrement())
name String
imageUrl String
ingredients Ingredient[]
items ProductItem[]
category Category @relation(fields: [categoryId], references: [id])
categoryId Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model ProductItem {
id Int @id @default(autoincrement())
price Int
size Int?
pizzaType Int?
cartItems CartItem[]
product Product @relation(fields: [productId], references: [id])
productId Int
}
model Ingredient {
id Int @id @default(autoincrement())
name String
price Int
imageUrl String
products Product[]
cartItems CartItem[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Cart {
id Int @id @default(autoincrement())
user User? @relation(fields: [userId], references: [id])
userId Int? @unique
items CartItem[]
token String
totalAmount Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model CartItem {
id Int @id @default(autoincrement())
cart Cart @relation(fields: [cartId], references: [id])
cartId Int
productItem ProductItem @relation(fields: [productItemId], references: [id])
productItemId Int
quantity Int @default(1)
ingredients Ingredient[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Order {
id Int @id @default(autoincrement())
user User? @relation(fields: [userId], references: [id])
userId Int?
token String
totalAmount Int
status OrderStatus
paymentId String?
items Json
fullName String
email String
phone String
address String
comment String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model VerificationCode {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int @unique
code String
createdAt DateTime @default(now())
@@unique([userId, code])
}
model Story {
id Int @id @default(autoincrement())
previewImageUrl String
items StoryItem[]
createdAt DateTime @default(now())
}
model StoryItem {
id Int @id @default(autoincrement())
storyId Int
story Story @relation(fields: [storyId], references: [id])
sourceUrl String
createdAt DateTime @default(now())
}
enum OrderStatus {
PENDING
SUCCEEDED
CANCELLED
}
enum UserRole {
USER
ADMIN
}
package.json
{
"name": "next-pizza",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"prisma:push": "prisma db push",
"prisma:studio": "prisma studio",
"prisma:seed": "prisma db seed",
"postinstall": "prisma generate"
},
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
},
"dependencies": {
"@hookform/resolvers": "^3.4.2",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slider": "^1.1.2",
"@radix-ui/react-slot": "^1.0.2",
"@types/bcrypt": "^5.0.2",
"@types/qs": "^6.9.15",
"axios": "^1.6.8",
"bcrypt": "^5.1.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.38.3",
"lucide-react": "^0.376.0",
"next": "14.2.3",
"next-auth": "^4.24.7",
"nextjs-toploader": "^1.6.12",
"qs": "^6.12.1",
"react": "^18",
"react-dadata": "^2.23.1",
"react-dom": "^18",
"react-hook-form": "^7.51.5",
"react-hot-toast": "^2.4.1",
"react-insta-stories": "^2.7.0",
"react-use": "^17.5.0",
"resend": "^3.2.0",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"ts-node": "^10.9.2",
"vaul": "^0.9.0",
"zod": "^3.23.8",
"zustand": "^4.5.2",
"@libsql/client": "^0.14.0",
"@prisma/adapter-libsql": "^6.1.0",
"@prisma/client": "^5.4.2"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"drizzle-kit": "^0.30.1",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5",
"prisma": "^5.4.2"
}
}
I've tried different versions of dependencies in package.json
Upvotes: 0
Views: 35