Braveheart
Braveheart13mo ago

Prisma and deno

getting this
error: could not find package '.prisma' from referrer 'file:///Users/nikos/WebstormProjects/vanillajs-patterns/backend/node_modules/.deno/@prisma+client@5.0.0/node_modules/@prisma/client/index.js'.
error: could not find package '.prisma' from referrer 'file:///Users/nikos/WebstormProjects/vanillajs-patterns/backend/node_modules/.deno/@prisma+client@5.0.0/node_modules/@prisma/client/index.js'.
from this
import { Prisma, PrismaClient } from '@prisma/client';

import { config } from 'https://deno.land/std@0.163.0/dotenv/mod.ts';
import * as bcrypt from 'https://deno.land/x/bcrypt/mod.ts';

const envVars = await config();

const prisma = new PrismaClient({
datasources: {
db: {
url: envVars.DATABASE_URL,
},
},
});

const seedData: Prisma.UserCreateInput[] = [
{
name: 'Tony',
email: 'tony@test.com',
passwordHash: await bcrypt.hash('password', 10),
emailVerified: true,
customFields: {
test: 'field',
},
},
{
name: 'Nikos',
email: 'nikos@test.com',
passwordHash: await bcrypt.hash('password', 10),
emailVerified: true,
},
];

/**
* Seed the database.
*/

for (const u of seedData) {
const dinosaur = await prisma.user.create({
data: u,
});
console.log(`Created dinosaur with id: ${dinosaur.id}`);
}
console.log(`Seeding finished.`);

await prisma.$disconnect();
import { Prisma, PrismaClient } from '@prisma/client';

import { config } from 'https://deno.land/std@0.163.0/dotenv/mod.ts';
import * as bcrypt from 'https://deno.land/x/bcrypt/mod.ts';

const envVars = await config();

const prisma = new PrismaClient({
datasources: {
db: {
url: envVars.DATABASE_URL,
},
},
});

const seedData: Prisma.UserCreateInput[] = [
{
name: 'Tony',
email: 'tony@test.com',
passwordHash: await bcrypt.hash('password', 10),
emailVerified: true,
customFields: {
test: 'field',
},
},
{
name: 'Nikos',
email: 'nikos@test.com',
passwordHash: await bcrypt.hash('password', 10),
emailVerified: true,
},
];

/**
* Seed the database.
*/

for (const u of seedData) {
const dinosaur = await prisma.user.create({
data: u,
});
console.log(`Created dinosaur with id: ${dinosaur.id}`);
}
console.log(`Seeding finished.`);

await prisma.$disconnect();
following https://github.com/denoland/examples/tree/main/with-prisma
GitHub
examples/with-prisma at main · denoland/examples
A simple todo app using Deno and React. Contribute to denoland/examples development by creating an account on GitHub.
15 Replies
abi
abi13mo ago
I tried really hard to get Prisma working on Deno before but it seems it’s basically not worth the effort. There is an open issue on Prisma GitHub about Deno support.
DrPotat
DrPotat13mo ago
Yeah, we managed to get Prisma working on Deno but I'm not sure it was worth the effort.. or if we'll keep it @.braveheart I think the issue is that your Prisma client is being generated inside node_modules - IIRC that doesn't well with Deno (but not sure why)
DrPotat
DrPotat13mo ago
This is our folder structure - we've got everything Prisma related inside ./prisma And inside ./prisma/schema.prisma we have:
generator client {
provider = "prisma-client-js"
previewFeatures = ["deno"]
output = "./client"
}

datasource db {
provider = "mysql"
url = env("PRISMA_PROXY_DATABASE_URL")
directUrl = env("DATABASE_URL")
relationMode = "prisma"
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["deno"]
output = "./client"
}

datasource db {
provider = "mysql"
url = env("PRISMA_PROXY_DATABASE_URL")
directUrl = env("DATABASE_URL")
relationMode = "prisma"
}
So the Prisma client is generated in ./prisma/client
DrPotat
DrPotat13mo ago
Then inside deno.json we've got a custom import for $prisma so we can do import { PrismaClient } from "$prisma";
"imports": {
"$prisma": "./prisma/client/deno/edge.ts",
},
"imports": {
"$prisma": "./prisma/client/deno/edge.ts",
},
We've faced a couple issues with Prisma on Deno: 1 Difficulties importing enums from Prisma client. There seems to be some typing mismatch that prevents us from importing them 2 We need to use Prisma Data Proxy to connect to the database. Otherwise, the Prisma Client generation doesn't work.
Braveheart
Braveheart13mo ago
thanks ill try that
Braveheart
Braveheart13mo ago
stuff it, im gonna use drizzle https://www.youtube.com/watch?v=Qo-RXkSwOtc
Marius Espejo
YouTube
Drizzle ORM First impressions - migrations, relations, queries!
In this video we take a quick look at the drizzle ORM to see if it's good enough to replace other options like prisma, typeorm, and Kysely. We'll create a simple application to test out creating migrations, running introspection, creating queries, and using relations. If you're looking for an orm for database queries that has very good typescrip...
Braveheart
Braveheart13mo ago
anyone used deno with it?
DrPotat
DrPotat13mo ago
Drizzle looks really interesting, thanks for sharing it We're still in early stages and not quite convinced with Prisma on Deno
DrPotat
DrPotat13mo ago
Seems like there's interest in Drizzle on Deno but not sure how well it works atm: https://github.com/drizzle-team/drizzle-orm/issues/252
GitHub
Add Deno support · Issue #252 · drizzle-team/drizzle-orm
Currently, the ORM part should work fine with Deno since it's runtime-agnostic, but the migrator won't work since it relies on Node API.
DrPotat
DrPotat13mo ago
If you get it working, can you share how?
Braveheart
Braveheart13mo ago
prisma is ESM hell yeh ill make it prob in part 7 or 8 of my videso
Braveheart
Braveheart13mo ago
Nikos Tech Downtime
YouTube
Vanilla.CSS Design System - No BlackBox Web Development - Part 6
You don't need a massive #figma based design system before you start your project. Just let your own design system evolve as you need it. It's much more extensible and customisable for your needs. #vanillajs Live demo: https://quantuminformation.github.io/vanillajs-patterns/ Full VanillaJS playlist: https://www.youtube.com/playlist?list=PLual...
Braveheart
Braveheart13mo ago
what u guys building?
DrPotat
DrPotat13mo ago
That's really cool. I'll have a look We're building an iOS app + web app for splitting bills and stuff
Braveheart
Braveheart13mo ago
im doing it in sqlite now, just vanill everything drillze wont work yet with deno the migrations part