Replies: 2 comments 3 replies
-
Hi there, I managed to access the sqlite database file in production by getting the current working directory before configuring the Prisma client. Here's how: import { PrismaClient } from '@prisma/client';
import path from 'path';
declare global {
// eslint-disable-next-line no-var
var cachedPrisma: PrismaClient;
}
// Workaround to find the db file in production
const filePath = path.join(process.cwd(), 'prisma/local.db');
const config = {
datasources: {
db: {
url: 'file:' + filePath,
},
},
};
let prisma: PrismaClient;
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient(config);
} else {
if (!global.cachedPrisma) {
global.cachedPrisma = new PrismaClient(config);
}
prisma = global.cachedPrisma;
}
export const db = prisma; Let me know how it worked out for you ;). |
Beta Was this translation helpful? Give feedback.
2 replies
-
where we have to copy this code |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I have seen the example of application running sqlite in read-only mode deployed to Vercel. From what I've seen it's rewriting the path to the db when instantiating PrismaClient.. but when I tried this in pure Next.js app it did not work. Does anyone have any experience with it or could elaborate on how it was done in Keystone? I am trying to replicate the functionality as it seems way faster than file based (MDX) structure for data but I am not ready to rewrite it in Keystone.. yet.
Thank you.
Here's the link to working SQLite example of my site but it's without a DB access: https://github.com/ethernal/personal-site/tree/posts-to-db
I had a separate branch when I needed to commit the DB but it would not work either so I am curious what is it that I am missing. Also having it read only is quite fine as this is only a performance and feature unlock (can query for related data etc).
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions