Gg
Gg
Explore posts from servers
PPrisma
Created by Gg on 8/31/2024 in #help-and-questions
Prisma Client: Injectable Setup Outside NestJS (with/without DI)?
In NestJS, the Prisma Client can be made injectable by extending PrismaClient and implementing lifecycle hooks like onModuleInit to manage connections. Here's how it's typically done in NestJS:
import { Injectable, OnModuleInit, INestApplication } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
}
}
import { Injectable, OnModuleInit, INestApplication } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
}
}
1. How would a similar Prisma Client setup be implemented in a non-NestJS application (for example, an Express app) without using a dependency injection tool? 2. How would this setup change if you were to use a dependency injection tool (like Tsyringe or any other DI library) in your non-NestJS application?
2 replies
HHono
Created by Gg on 8/27/2024 in #help
Sharing the app type from my hono api to my client in a monorepo
I'm trying to share types between my Hono API and Svelte app. Currently doing this:
// Hono app - apps/api/src/index.ts
import { Hono } from "hono";
const app = new Hono()
.get("/", ...
...

export default app;
export type AppRouter = typeof app;
// Hono app - apps/api/src/index.ts
import { Hono } from "hono";
const app = new Hono()
.get("/", ...
...

export default app;
export type AppRouter = typeof app;
// Svelte app - apps/web/...
import { hc } from "hono/client";
import type { AppRouter } from "../../../api/src/index.ts";
export const client = hc<AppRouter>("http://localhost:8787/");
// Svelte app - apps/web/...
import { hc } from "hono/client";
import type { AppRouter } from "../../../api/src/index.ts";
export const client = hc<AppRouter>("http://localhost:8787/");
Importing directly from another app like this feels off. What's a better way to share types in a Turborepo setup? Thanks!
14 replies
HHono
Created by Gg on 8/26/2024 in #help
background jobs with Hono + Bun
Hi all, I'm planning on building a backend with Hono and I'm looking for a solution to do background jobs (backed by a queue). Are there any recommendations in the bun ecosystem for doing this? So far, I've mostly seen BullMQ in the node ecosystem, but bun is not officially supported as far as I know. Is there an alternative for bun?
5 replies