Saif
Saif
KKysely
Created by Saif on 2/26/2024 in #help
How to use kysely in edge runtime (like NextJS 14 middleware)?
Sure, let me try
7 replies
KKysely
Created by Saif on 2/26/2024 in #help
How to use kysely in edge runtime (like NextJS 14 middleware)?
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;
7 replies
KKysely
Created by Saif on 2/14/2024 in #help
Postgres: Transaction not honouring previous queries
I was doing the deletion before inserting the data. However, I was making a bulk insert and the array had duplicate data. Nothing to do with transaction.
7 replies
KKysely
Created by Saif on 2/12/2024 in #help
Webstorm warning with multiple joins
I mean it works, and the query is right too. But am I missing something and due to which I am getting this warning, or is it just webstorm acting up?
4 replies