Add piece editor page

This commit is contained in:
2024-11-23 15:58:21 +01:00
parent d934136839
commit c561df7e3c
6 changed files with 256 additions and 94 deletions

View File

@@ -1,6 +1,6 @@
import { Database as BunSqliteDatabase } from "bun:sqlite";
import { AttachmentId, PieceId, RequestId, SessionId, Sha256, UserId } from "common";
import { ColumnType, CompiledQuery, CreateTableBuilder, Kysely } from "kysely";
import { ColumnType, CompiledQuery, CreateTableBuilder, Kysely, Selectable } from "kysely";
import { BunSqliteDialect } from "kysely-bun-sqlite";
export function generateSessionId(byteLength: number = 32): SessionId {
@@ -35,14 +35,14 @@ export interface AccessLogTable {
ip: ColumnType<string | null, string | null, never>;
}
export interface Attachment {
export interface AttachmentData {
pieceId: ColumnType<PieceId, PieceId, never>;
sha256: Sha256;
filename: string;
mediaType: string;
}
export interface AttachmentTable extends Attachment, SystemInformation {
export interface AttachmentTable extends AttachmentData, SystemInformation {
attachmentId: ColumnType<AttachmentId, AttachmentId, never>;
}
@@ -51,22 +51,22 @@ export interface FileTable {
data: ColumnType<Uint8Array, Uint8Array, never>;
}
export interface Piece {
export interface PieceData {
name: string;
composer: string | null;
lyricist: string | null;
arranger: string | null;
}
export interface PieceTable extends Piece, SystemInformation {
export interface PieceTable extends PieceData, SystemInformation {
pieceId: ColumnType<PieceId, PieceId, never>;
}
export interface Session {
export interface SessionData {
userId: UserId;
}
export interface SessionTable extends Session {
export interface SessionTable extends SessionData {
sessionId: ColumnType<SessionId, SessionId, never>;
expiresAt: string;
}
@@ -78,6 +78,13 @@ export interface UserTable {
admin: number;
}
export type AccessLog = Selectable<AccessLogTable>;
export type Attachment = Selectable<AttachmentTable>;
export type File = Selectable<FileTable>;
export type Piece = Selectable<PieceTable>;
export type Session = Selectable<SessionTable>;
export type User = Selectable<UserTable>;
function systemInformation<TB extends string, C extends string>(schema: CreateTableBuilder<TB, C>) {
return schema
.addColumn("createdBy", "text", (c) => c.references("User.userId").onDelete("set null").onUpdate("cascade"))