feat: add basic webui
This commit is contained in:
3
packages/database/.gitignore
vendored
Normal file
3
packages/database/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
# Keep environment variables out of version control
|
||||
.env
|
||||
47
packages/database/builder.ts
Normal file
47
packages/database/builder.ts
Normal 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'),
|
||||
}),
|
||||
});
|
||||
12
packages/database/index.ts
Normal file
12
packages/database/index.ts
Normal 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 };
|
||||
0
packages/database/migrate/migrator.ts
Normal file
0
packages/database/migrate/migrator.ts
Normal file
15
packages/database/migrations/m20241229_000001_init.ts
Normal file
15
packages/database/migrations/m20241229_000001_init.ts
Normal 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();
|
||||
}
|
||||
25
packages/database/package.json
Normal file
25
packages/database/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
5
packages/database/schema/database.ts
Normal file
5
packages/database/schema/database.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { PageTable } from './page';
|
||||
|
||||
export interface Database {
|
||||
page: PageTable;
|
||||
}
|
||||
10
packages/database/schema/page.ts
Normal file
10
packages/database/schema/page.ts
Normal 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>;
|
||||
8
packages/database/tsconfig.json
Normal file
8
packages/database/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@konobangu/typescript-config/react-library.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user