feat: add basic webui

This commit is contained in:
2024-12-30 06:39:09 +08:00
parent 608a7fb9c6
commit a4c549e7c3
462 changed files with 35900 additions and 2491 deletions

3
packages/database/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env

View File

@@ -0,0 +1,47 @@
import { promises as fs } from 'node:fs';
import path from 'node:path';
import {
FileMigrationProvider,
Kysely,
Migrator,
PostgresDialect,
// biome-ignore lint/nursery/noExportedImports: <explanation>
type PostgresPool,
} from 'kysely';
import { Pool } from 'pg';
import type { Database } from './schema/database';
export type { PostgresPool };
export const buildPool = (connectionString: string): PostgresPool => {
return new Pool({
connectionString,
max: 10,
});
};
export const buildDatabase = (connectionString: string) => {
const pool = buildPool(connectionString);
const dialect = new PostgresDialect({
pool,
});
return {
db: new Kysely<Database>({
dialect,
}),
pool,
dialect,
};
};
export const buildMigrator = (db: Kysely<Database>) =>
new Migrator({
db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder: path.resolve(__dirname, 'migrations'),
}),
});

View File

@@ -0,0 +1,12 @@
import { env } from '@konobangu/env';
import { buildDatabase } from './builder';
// Database interface is passed to Kysely's constructor, and from now on, Kysely
// knows your database structure.
// Dialect is passed to Kysely's constructor, and from now on, Kysely knows how
// to communicate with your database.
const { db, dialect, pool } = buildDatabase(env.DATABASE_URL);
export const database = db;
export { db, dialect, pool };

View File

View File

@@ -0,0 +1,15 @@
import type { Kysely } from 'kysely';
import type { Database } from 'schema/database';
export async function up(db: Kysely<Database>): Promise<void> {
await db.schema
.createTable('page')
.ifNotExists()
.addColumn('id', 'serial', (cb) => cb.primaryKey())
.addColumn('name', 'text', (cb) => cb.notNull())
.execute();
}
export async function down(db: Kysely<Database>): Promise<void> {
await db.schema.dropTable('page').ifExists().execute();
}

View File

@@ -0,0 +1,25 @@
{
"name": "@konobangu/database",
"version": "0.0.0",
"main": "./index.ts",
"types": "./index.ts",
"scripts": {
"clean": "git clean -xdf .cache .turbo dist node_modules",
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"dependencies": {
"@konobangu/env": "workspace:*",
"@next/env": "^15.1.3",
"kysely": "^0.27.5",
"pg": "^8.13.1",
"server-only": "^0.0.1",
"undici": "^7.1.0"
},
"devDependencies": {
"@konobangu/typescript-config": "workspace:*",
"@types/node": "22.10.1",
"@types/pg": "^8.11.10",
"bufferutil": "^4.0.8",
"typescript": "^5.7.2"
}
}

View File

@@ -0,0 +1,5 @@
import type { PageTable } from './page';
export interface Database {
page: PageTable;
}

View File

@@ -0,0 +1,10 @@
import type { Generated, Insertable, Selectable, Updateable } from 'kysely';
export interface PageTable {
id: Generated<number>;
name: string | null;
}
export type Persion = Selectable<PageTable>;
export type PersionNew = Insertable<PageTable>;
export type PersionUpdate = Updateable<PageTable>;

View File

@@ -0,0 +1,8 @@
{
"extends": "@konobangu/typescript-config/react-library.json",
"compilerOptions": {
"baseUrl": "."
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}