A Docker-like CLI and HTTP API for managing headless VMs
1import { Database as Sqlite } from "@db/sqlite";
2import { DenoSqlite3Dialect } from "@soapbox/kysely-deno-sqlite";
3import { Kysely } from "kysely";
4import { CONFIG_DIR } from "./constants.ts";
5import type { STATUS } from "./types.ts";
6
7export const createDb = (location: string): Database => {
8 Deno.mkdirSync(CONFIG_DIR, { recursive: true });
9 return new Kysely<DatabaseSchema>({
10 dialect: new DenoSqlite3Dialect({
11 database: new Sqlite(location),
12 }),
13 });
14};
15
16export type DatabaseSchema = {
17 virtual_machines: VirtualMachine;
18 images: Image;
19 volumes: Volume;
20};
21
22export type VirtualMachine = {
23 id: string;
24 name: string;
25 bridge?: string;
26 macAddress: string;
27 memory: string;
28 cpus: number;
29 cpu: string;
30 diskSize: string;
31 drivePath?: string;
32 diskFormat: string;
33 isoPath?: string;
34 portForward?: string;
35 version?: string;
36 status: STATUS;
37 pid: number;
38 volume?: string;
39 seed?: string;
40 createdAt?: string;
41 updatedAt?: string;
42};
43
44export type Image = {
45 id: string;
46 repository: string;
47 tag: string;
48 size: number;
49 path: string;
50 format: string;
51 digest?: string;
52 createdAt?: string;
53};
54
55export type Volume = {
56 id: string;
57 name: string;
58 baseImageId: string;
59 path: string;
60 size?: string;
61 createdAt?: string;
62};
63
64export type Database = Kysely<DatabaseSchema>;