How to use kysely in edge runtime (like NextJS 14 middleware)?

Error: The edge runtime does not support Node.js 'crypto' module. Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime Full log: https://pastebin.com/JSXBNRxv I need to verify if the user has access to the resources they are trying to visit, the middleware seemed to be the best place for this. However, I am not able to query the database as it is throwing the above error.
Pastebin
web:dev: ⚠ ../../node_modules/.pnpm/pg@8.11.3/node_modules/pg/lib/...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
koskimas
koskimas82d ago
Kysely doesn't import the crypto module. That error comes from somewhere else.
Saif
Saif82d ago
It's from the pg package:
import { Database } from "@/lib/kysely/types";
import { Pool } from "pg";
import { Kysely, PostgresDialect } from "kysely";

const dbClientSingleton = () => {
const dialect = new PostgresDialect({
pool: new Pool({
max: 10,
connectionString: process.env.DATABASE_URL!,
}),
});

return new Kysely<Database>({
log(event) {
if (event.level === "query") {
console.log(event.query.sql);
console.log(event.query.parameters);
}
},
dialect,
});
};

declare global {
var db: undefined | ReturnType<typeof dbClientSingleton>;
}

const db = globalThis.db ?? dbClientSingleton();

export default db;

if (process.env.NODE_ENV !== "production") globalThis.db = db;
import { Database } from "@/lib/kysely/types";
import { Pool } from "pg";
import { Kysely, PostgresDialect } from "kysely";

const dbClientSingleton = () => {
const dialect = new PostgresDialect({
pool: new Pool({
max: 10,
connectionString: process.env.DATABASE_URL!,
}),
});

return new Kysely<Database>({
log(event) {
if (event.level === "query") {
console.log(event.query.sql);
console.log(event.query.parameters);
}
},
dialect,
});
};

declare global {
var db: undefined | ReturnType<typeof dbClientSingleton>;
}

const db = globalThis.db ?? dbClientSingleton();

export default db;

if (process.env.NODE_ENV !== "production") globalThis.db = db;
Unknown User
Unknown User81d ago
Message Not Public
Sign In & Join Server To View
Saif
Saif81d ago
Sure, let me try
Want results from more Discord servers?
Add your server
More Posts
how to write not (array1 && array2)Hi again, how to write following code? I would love to use not(expression) Expected result: ``` noPartial compileHello everyone, is it possible (somehow) to generate only part of the compiled query? I have an edgeQuerying on jsonArrayFromHi. So i need to fetch posts with comments from a database that are written by a set group of authorWhy does `.stream()` return a single result when I pass in a `chunkSize` option ?I'm guessing it returns `chunkSize` mount of rows for each iteration, but shouldn't it be an array iIs there a way to keep full date precision?It appears that selecting dates from Postgresql loses some precision, which wreaks havoc with my pagHow can I get total row count without blowing up types?I have a simple query function that is in charge of generating a list of ids so that it can be passeIs there a way to handle migrations with .sql files?I enjoy being able to control the specific queries in the migration files. To do this, I use postgraPostgres: Transaction not honouring previous queriesHi, I have a table with unique constraint on some columns. In a transaction, I am deleting all the How do I specify a MySQL index hint?Hi, I am trying to build the following query (as a CTE, as part of a larger query), but I can not woquestion about transaction isolation levelI am not sure if the way I do queries with transaction with kysely is the right way. I would be gladcase when column = another columnI have a semi-complex query, and I'm trying to use a case() that includes a when() where the two valWebstorm warning with multiple joins```ts const organizationsWithAdminUser = await db .selectFrom("organizations") .How do I use `WHERE NOT EXISTS`?I am trying to write the followng where condition: ```sql INSERT INTO Filing (location_id, filing_datransforming database values to JS values (dates in sqlite)hi. is it possible to transform database values with any driver into any JS value? such as integers