From 808138de633e410c1d3867d4fb7cb74967647605 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Tue, 30 Jul 2024 16:54:10 +0100 Subject: chore: remove ui directory (#2329) This is still in development, but rather than clutter the commit history and issues with an unreleased project I've split the UI into its own repo. Once ready for release, I'll either merge the ui code back in, or just make the repo public. --- ui/src/state/runbooks/runbook.ts | 124 --------------------------------------- 1 file changed, 124 deletions(-) delete mode 100644 ui/src/state/runbooks/runbook.ts (limited to 'ui/src/state/runbooks') diff --git a/ui/src/state/runbooks/runbook.ts b/ui/src/state/runbooks/runbook.ts deleted file mode 100644 index 8555f4ea..00000000 --- a/ui/src/state/runbooks/runbook.ts +++ /dev/null @@ -1,124 +0,0 @@ -import Database from "@tauri-apps/plugin-sql"; -import { uuidv7 } from "uuidv7"; - -export default class Runbook { - id: string; - created: Date; - updated: Date; - - private _name: string; - private _content: string; - - set name(value: string) { - this.updated = new Date(); - this._name = value; - } - - set content(value: string) { - this.updated = new Date(); - this._content = value; - } - - get content() { - return this._content; - } - - get name() { - return this._name; - } - - constructor( - id: string, - name: string, - content: string, - created: Date, - updated: Date, - ) { - this.id = id; - this._name = name; - this._content = content; - this.created = created; - this.updated = updated; - } - - /// Create a new Runbook, and automatically generate an ID. - public static async create(): Promise { - let now = new Date(); - - // Initialize with the same value for created/updated, to avoid needing null. - let runbook = new Runbook(uuidv7(), "", "", now, now); - await runbook.save(); - - return runbook; - } - - public static async load(id: String): Promise { - const db = await Database.load("sqlite:runbooks.db"); - - let res = await db.select("select * from runbooks where id = $1", [ - id, - ]); - - if (res.length == 0) return null; - - let rb = res[0]; - - return new Runbook( - rb.id, - rb.name, - rb.content, - new Date(rb.created / 1000000), - new Date(rb.updated / 1000000), - ); - } - - static async all(): Promise { - const db = await Database.load("sqlite:runbooks.db"); - - let res = await db.select( - "select * from runbooks order by updated desc", - ); - - return res.map((i) => { - return new Runbook( - i.id, - i.name, - i.content, - new Date(i.created / 1000000), - new Date(i.updated / 1000000), - ); - }); - } - - public async save() { - const db = await Database.load("sqlite:runbooks.db"); - - await db.execute( - `insert into runbooks(id, name, content, created, updated) - values ($1, $2, $3, $4, $5) - - on conflict(id) do update - set - name=$2, - content=$3, - updated=$5`, - - // getTime returns a timestamp as unix milliseconds - // we won't need or use the resolution here, but elsewhere Atuin stores timestamps in sqlite as nanoseconds since epoch - // let's do that across the board to avoid mistakes - [ - this.id, - this._name, - this._content, - this.created.getTime() * 1000000, - this.updated.getTime() * 1000000, - ], - ); - } - - public static async delete(id: string) { - const db = await Database.load("sqlite:runbooks.db"); - - await db.execute("delete from runbooks where id=$1", [id]); - } -} -- cgit v1.3.1