Ahmed Eid
Ahmed Eid
Explore posts from servers
CDCloudflare Developers
Created by henrikhlind on 11/6/2024 in #workers-help
Nest.js as Worker
I believe it should work just fine, any specific issues ?
3 replies
CDCloudflare Developers
Created by Ahmed Eid on 11/6/2024 in #workers-help
Error: [unenv] fs.readFile is not implemented yet when getting presigned url with s3 packages.
unable to tell what I am doing wrong.
2 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/31/2024 in #workers-help
database connection doesn't work in / behave strangely in global context.
I change it to this
export const databaseMiddleware = (): MiddlewareHandler =>
createMiddleware<Env>(async (c, next) => {
const hv = c.env.db;
const db = new Kysely<DB>({
dialect: new PostgresJSDialect({
postgres: postgres(hv.connectionString),
}),
});
const end = performance.now();
c.set("db", db);
await next();
});
export const databaseMiddleware = (): MiddlewareHandler =>
createMiddleware<Env>(async (c, next) => {
const hv = c.env.db;
const db = new Kysely<DB>({
dialect: new PostgresJSDialect({
postgres: postgres(hv.connectionString),
}),
});
const end = performance.now();
c.set("db", db);
await next();
});
9 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/31/2024 in #workers-help
database connection doesn't work in / behave strangely in global context.
I think so, I am new to this TBH. I am still learning.
9 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
same issue thou when I try to cache the connection db
let _db: Kysely<DB> | undefined;

export const databaseMiddleware = (): MiddlewareHandler =>
createMiddleware<Env>(async (c, next) => {
const hv = c.env.db;

if (!_db) {
_db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({ connectionString: hv.connectionString }),
}),
});
}

c.set("db", _db);
await next();
});
let _db: Kysely<DB> | undefined;

export const databaseMiddleware = (): MiddlewareHandler =>
createMiddleware<Env>(async (c, next) => {
const hv = c.env.db;

if (!_db) {
_db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({ connectionString: hv.connectionString }),
}),
});
}

c.set("db", _db);
await next();
});
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/31/2024 in #workers-help
database connection doesn't work in / behave strangely in global context.
I looked into hyperdrive ( still don't understand it fully .. ) do you think this is performant enough ?
type Env = {
Bindings: { db: Hyperdrive };
Variables: { db: Kysely<DB> };
};

export const databaseMiddleware = (): MiddlewareHandler =>
createMiddleware<Env>(async (c, next) => {
const hv = c.env.db;
const db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({ connectionString: hv.connectionString }),
}),
});
c.set("db", db);
await next();
});
type Env = {
Bindings: { db: Hyperdrive };
Variables: { db: Kysely<DB> };
};

export const databaseMiddleware = (): MiddlewareHandler =>
createMiddleware<Env>(async (c, next) => {
const hv = c.env.db;
const db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({ connectionString: hv.connectionString }),
}),
});
c.set("db", db);
await next();
});
9 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
how does this look ?
type Env = {
Bindings: { db: Hyperdrive };
Variables: { db: Kysely<DB> };
};

export const databaseMiddleware = (): MiddlewareHandler =>
createMiddleware<Env>(async (c, next) => {
const hv = c.env.db;
const db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({ connectionString: hv.connectionString }),
}),
});
c.set("db", db);
await next();
});
type Env = {
Bindings: { db: Hyperdrive };
Variables: { db: Kysely<DB> };
};

export const databaseMiddleware = (): MiddlewareHandler =>
createMiddleware<Env>(async (c, next) => {
const hv = c.env.db;
const db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({ connectionString: hv.connectionString }),
}),
});
c.set("db", db);
await next();
});
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
yeah, I am looking how to use it right now. thanks.
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/31/2024 in #workers-help
database connection doesn't work in / behave strangely in global context.
this unfortunately doesn't work either. it's weird, cuz one request works & the 2nd one doesn't...
9 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
should I init a new db connection per request, can't I cache the connection somehow to reuse it between requests ?
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
this works
app.get("/", async (c) => {
const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
plugins: [new ParseJSONResultsPlugin()],
log: (event) => {
if (event.level === "error") {
console.log(event.error);
}
},
});

const langs = await db.selectFrom("Language").selectAll().executeTakeFirst();
return c.json(langs);
});
app.get("/", async (c) => {
const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
plugins: [new ParseJSONResultsPlugin()],
log: (event) => {
if (event.level === "error") {
console.log(event.error);
}
},
});

const langs = await db.selectFrom("Language").selectAll().executeTakeFirst();
return c.json(langs);
});
but this doesn't
const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
plugins: [new ParseJSONResultsPlugin()],
log: (event) => {
if (event.level === "error") {
console.log(event.error);
}
},
});

app.get("/", async (c) => {
const langs = await db.selectFrom("Language").selectAll().executeTakeFirst();
return c.json(langs);
});
const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
plugins: [new ParseJSONResultsPlugin()],
log: (event) => {
if (event.level === "error") {
console.log(event.error);
}
},
});

app.get("/", async (c) => {
const langs = await db.selectFrom("Language").selectAll().executeTakeFirst();
return c.json(langs);
});
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
it's not because of pg moving the db connection to the route and destroying it in the route. works perfectly.
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
@Walshy ideas ? it's weird cuz 1 request works another doesn't.
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
could it be because of "pg" ?
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
is there something wrong with exporting connections from the global scope like so ? utils/db.ts
import pg from "pg";
import { Kysely, ParseJSONResultsPlugin, PostgresDialect } from "kysely";

import type { DB } from "../types";

const { Pool } = pg;

const connectionString ="postgresql:";

export const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
plugins: [new ParseJSONResultsPlugin()],
log: (event) => {
if (event.level === "error") {
console.log(event.error);
}
},
});
import pg from "pg";
import { Kysely, ParseJSONResultsPlugin, PostgresDialect } from "kysely";

import type { DB } from "../types";

const { Pool } = pg;

const connectionString ="postgresql:";

export const db = new Kysely<DB>({
dialect: new PostgresDialect({ pool: new Pool({ connectionString }) }),
plugins: [new ParseJSONResultsPlugin()],
log: (event) => {
if (event.level === "error") {
console.log(event.error);
}
},
});
24 replies
CDCloudflare Developers
Created by Ahmed Eid on 10/25/2024 in #general-help
my worker is throwing too many, error 1101.
unfortunately I am still facing this issue.
24 replies