grill-blog/database.ts

23 lines
680 B
TypeScript
Raw Normal View History

2024-05-13 22:50:54 +01:00
import { Option, Result } from "./utils.ts";
export type User = {
id: number;
username: string;
passwordHash: string;
};
export type Session = {
id: number;
userId: number;
};
export interface Database {
createUser(init: Omit<User, "id">): Promise<Result<User, string>>;
userWithId(id: number): Promise<Result<Option<User>, string>>;
userWithUsername(username: string): Promise<Result<Option<User>, string>>;
userWithUsernameExists(username: string): Promise<Result<boolean, string>>;
createSession(init: Omit<Session, "id">): Promise<Result<Session, string>>;
sessionWithId(id: number): Promise<Result<Option<Session>, string>>;
}