Something went wrong. Try again.
A self-hosted web platform for applications & services with design based on Google's Material 3 Expressive. (Work In Progress)
self-hosted typescript
Something went wrong. Try again.
2.1 kB · 65 lines
TypeScript
at commit 1c2fc44a
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import postgres from "postgres";import type { Instance } from "../index.ts";import System from "../system.ts";
export default class DatabaseSystem extends System { databaseConnections: { [connectionId: string]: postgres.Sql };
constructor(instance: Instance) { super("database", instance);
this.databaseConnections = {}; }
// private sqlite(connectionId: string) { // if (this.databaseConnections[connectionId]) return this.databaseConnections[connectionId];
// const conPath = `sqlite://${path.join(this.instance.sys.filesystem.FS_ROOT, connectionId)}.sqlite`;
// const con = new SQL({ // adapter: "sqlite", // readwrite: true, // create: true, // filename: conPath, // });
// this.databaseConnections[connectionId] = con;
// return con; // }
postgres() { if (this.databaseConnections.postgres) return this.databaseConnections.postgres;
this.log.info( `Connecting to database @ '${this.instance.sys.configuration.databases.postgres.host}' named '${this.instance.sys.configuration.databases.postgres.database}'`, );
const con = postgres({ db: this.instance.sys.configuration.databases.postgres.database, hostname: this.instance.sys.configuration.databases.postgres.host, port: this.instance.sys.configuration.databases.postgres.port, user: this.instance.sys.configuration.databases.postgres.user, password: this.instance.sys.configuration.databases.postgres.password,
onnotice: (message) => { if (message.severity === "NOTICE") return;
console.log(message); }, });
this.databaseConnections.postgres = con;
this.log.info( `Established connection to database @ '${this.instance.sys.configuration.databases.postgres.host}' named '${this.instance.sys.configuration.databases.postgres.database}'`, );
return con; }
override async startup(): Promise<boolean> { this.log.info("Starting up..."); return true; }}