Access Local Files in Server Action
Unanswered
Asian black bear posted this in #help-forum
Asian black bearOP
I'm trying to setup a local SQLite database using libSQL and Drizzle.
I have my database client that I export and access from within the server action, but the paths seem wacky in server actions.
I have no idea what the [project] directory is or the [app-rsc] (ecmascript)
I have my database client that I export and access from within the server action, but the paths seem wacky in server actions.
import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import * as schema from './schema';
import path from 'path';
const db_path = path.resolve(__dirname, 'myDB.db');
console.log({ db_path });
const client = createClient({ url: db_path });
export const db = drizzle(client, { schema });
{
db_path: '/Users/skollie/RSC/[project]/database/db.ts [app-rsc] (ecmascript)/myDB.db'
}
I have no idea what the [project] directory is or the [app-rsc] (ecmascript)
8 Replies
What are you trying to do
Because libSQL implementation with Drizzle is as simple as:
import { drizzle } from 'drizzle-orm/libsql';
import { createClient } from '@libsql/client';
const client = createClient({ url: process.env.DATABASE_URL, authToken: process.env.DATABASE_AUTH_TOKEN });
const db = drizzle(client);
const result = await db.execute('select 1');
@Masai Lion Because libSQL implementation with Drizzle is as simple as:
js
import { drizzle } from 'drizzle-orm/libsql';
import { createClient } from '@libsql/client';
const client = createClient({ url: process.env.DATABASE_URL, authToken: process.env.DATABASE_AUTH_TOKEN });
const db = drizzle(client);
const result = await db.execute('select 1');
Asian black bearOP
Yeah I tried that. So basically the issue is with the paths in a Server Action when trying to access a local file
Asian black bearOP
You can replicate it by trying to access a file in your codebase using fs from a server action
@Asian black bear Yeah I tried that. So basically the issue is with the paths in a Server Action when trying to access a local file
Masai Lion
But do you really need an absolute path?
@Masai Lion But do you really need an absolute path?
Asian black bearOP
Only tried the absolute path because just doing "file:./myDB.db" didn't work. Trust me that was the first thing I tried.
If not an absolute path, how would you access a local file in your codebase within a server action?