import { drizzle } from 'drizzle-orm/durable-sqlite';
import * as schema from '@/features/workspace/database/workspace.schema';
import { type Workspace, type CreateWorkspace, workspaces } from '@/features/workspace/database/workspace.schema';
import { eq, and, isNull } from 'drizzle-orm';
import { WorkspaceRepositoryInterface } from './workspace-repository.interface';
export class WorkspaceRepository implements WorkspaceRepositoryInterface {
private readonly db;
constructor(private readonly storage: DurableObjectStorage) {
this.db = drizzle(this.storage, { schema });
}
async save(workspace: CreateWorkspace): Promise<void> {
await this.db.insert(workspaces).values(workspace).returning();
}
async findOneBy(field: keyof Workspace, value: string): Promise<Workspace | null> {
const result = await this.db.query.workspaces.findFirst({
where: eq(workspaces[field], value),
});
return result ?? null;
}
}
import { drizzle } from 'drizzle-orm/durable-sqlite';
import * as schema from '@/features/workspace/database/workspace.schema';
import { type Workspace, type CreateWorkspace, workspaces } from '@/features/workspace/database/workspace.schema';
import { eq, and, isNull } from 'drizzle-orm';
import { WorkspaceRepositoryInterface } from './workspace-repository.interface';
export class WorkspaceRepository implements WorkspaceRepositoryInterface {
private readonly db;
constructor(private readonly storage: DurableObjectStorage) {
this.db = drizzle(this.storage, { schema });
}
async save(workspace: CreateWorkspace): Promise<void> {
await this.db.insert(workspaces).values(workspace).returning();
}
async findOneBy(field: keyof Workspace, value: string): Promise<Workspace | null> {
const result = await this.db.query.workspaces.findFirst({
where: eq(workspaces[field], value),
});
return result ?? null;
}
}