RedRoss
RedRoss
Explore posts from servers
PPrisma
Created by RedRoss on 11/11/2024 in #help-and-questions
How generete enum type from hasura?
No description
10 replies
PPrisma
Created by RedRoss on 10/23/2024 in #help-and-questions
how can I implement an abstract class to apply the repository pattern?
I use nestjs and would like to implement the pattern repository as it is used in typeorm
import { Prisma, PrismaClient } from '@prisma/client';
import { BaseInterfaceRepository } from './base.interface.repository';

export abstract class BaseAbstractRepository<T, CreateInput>
implements BaseInterfaceRepository<T, CreateInput>
{
protected readonly prisma: PrismaClient;
protected modelName: T; // What type should I use?

protected constructor(prisma: PrismaClient, modelName: T) {
this.prisma = prisma;
this.modelName = modelName;
}

public async create(
data: CreateInput,
transaction?: Prisma.TransactionClient,
): Promise<T> {
try {
if (transaction) {
return await transaction[this.modelName].create({ data });
}
return await this.modelName.create({ data });
} catch (error) {
throw new Error(`Failed to create entity: ${error.message}`);
}
}

public async findOneById(
id: number,
transaction?: Prisma.TransactionClient,
): Promise<T | null> {
try {
if (transaction) {
return await transaction[this.modelName].findUnique({ where: { id } });
}
return await this.modelName.findUnique({ where: { id } });
} catch (error) {
throw new Error(`Failed to find entity with id ${id}: ${error.message}`);
}
}

public async remove(
id: number,
transaction?: Prisma.TransactionClient,
): Promise<T> {
try {
if (transaction) {
return await transaction[this.modelName].delete({ where: { id } });
}
return await this.modelName.delete({ where: { id } });
} catch (error) {
throw new Error(
`Failed to remove entity with id ${id}: ${error.message}`,
);
}
}
}
import { Prisma, PrismaClient } from '@prisma/client';
import { BaseInterfaceRepository } from './base.interface.repository';

export abstract class BaseAbstractRepository<T, CreateInput>
implements BaseInterfaceRepository<T, CreateInput>
{
protected readonly prisma: PrismaClient;
protected modelName: T; // What type should I use?

protected constructor(prisma: PrismaClient, modelName: T) {
this.prisma = prisma;
this.modelName = modelName;
}

public async create(
data: CreateInput,
transaction?: Prisma.TransactionClient,
): Promise<T> {
try {
if (transaction) {
return await transaction[this.modelName].create({ data });
}
return await this.modelName.create({ data });
} catch (error) {
throw new Error(`Failed to create entity: ${error.message}`);
}
}

public async findOneById(
id: number,
transaction?: Prisma.TransactionClient,
): Promise<T | null> {
try {
if (transaction) {
return await transaction[this.modelName].findUnique({ where: { id } });
}
return await this.modelName.findUnique({ where: { id } });
} catch (error) {
throw new Error(`Failed to find entity with id ${id}: ${error.message}`);
}
}

public async remove(
id: number,
transaction?: Prisma.TransactionClient,
): Promise<T> {
try {
if (transaction) {
return await transaction[this.modelName].delete({ where: { id } });
}
return await this.modelName.delete({ where: { id } });
} catch (error) {
throw new Error(
`Failed to remove entity with id ${id}: ${error.message}`,
);
}
}
}
5 replies
CDCloudflare Developers
Created by RedRoss on 2/22/2024 in #pages-help
How do I generate the mp4 link to watch my video that I uploaded on cloudflare stream?
No description
3 replies
CDCloudflare Developers
Created by RedRoss on 2/8/2024 in #general-help
how can I retrieve the url when I upload a video with tus client js?
No description
1 replies
CDCloudflare Developers
Created by RedRoss on 1/25/2024 in #general-help
With react native what are the steps to take to upload a cloudflare video?
No description
2 replies