Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit 0839330

Browse files
committed
feat(store): add store repos functionality
This commit introduces the ability to manage store repositories within the application. It includes: - Creation of a table in the database to store repository information (slug and base URL). - Implementation of functions to add, retrieve, and delete store repositories from the database. - Creation of a new handler to expose store repository management functionalities via API.
1 parent 3c4a0c3 commit 0839330

10 files changed

Lines changed: 844 additions & 173 deletions

File tree

bun.lock

Lines changed: 515 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/database/database.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export function init() {
9191
CREATE TABLE IF NOT EXISTS config (
9292
keep_data_for NUMBER NOT NULL,
9393
fetching_interval NUMBER NOT NULL );
94+
95+
CREATE TABLE IF NOT EXISTS store_repos (
96+
slug TEXT NOT NULL,
97+
base TEXT NOT NULL
98+
);
9499
`);
95100

96101
const configRow = db
@@ -112,6 +117,17 @@ export function init() {
112117
"INSERT INTO docker_hosts (name, hostAddress, secure) VALUES (?, ?, ?)",
113118
).run("Localhost", "localhost:2375", false);
114119
}
120+
121+
const storeRow = db
122+
.prepare("SELECT COUNT(*) AS count FROM store_repos")
123+
.get() as { count: number };
124+
125+
if (storeRow.count === 0) {
126+
db.prepare("INSERT INTO store_repos (slug, base) VALUES (?, ?)").run(
127+
"DockStacks",
128+
"https://raw.githubusercontent.com/Its4Nik/DockStacks/refs/heads/main/Index.json",
129+
);
130+
}
115131
}
116132

117133
init();

src/core/database/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as dockerHosts from "~/core/database/dockerHosts";
99
import * as hostStats from "~/core/database/hostStats";
1010
import * as logs from "~/core/database/logs";
1111
import * as stacks from "~/core/database/stacks";
12+
import * as stores from "~/core/database/stores";
1213

1314
export const dbFunctions = {
1415
...dockerHosts,
@@ -18,6 +19,7 @@ export const dbFunctions = {
1819
...hostStats,
1920
...stacks,
2021
...backup,
22+
...stores,
2123
};
2224

2325
export type dbFunctions = typeof dbFunctions;

src/core/database/stores.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { db } from "./database";
2+
import { executeDbOperation } from "./helper";
3+
4+
const stmt = {
5+
insert: db.prepare(`
6+
INSERT INTO store_repos (slug, base) VALUES (?, ?)
7+
`),
8+
selectAll: db.prepare(`
9+
SELECT slug, base FROM store_repos
10+
`),
11+
delete: db.prepare(`
12+
DELETE FROM store_repos WHERE slug = ?
13+
`),
14+
};
15+
16+
export function getStoreRepos() {
17+
return executeDbOperation("Get Store Repos", () => stmt.selectAll.all()) as {
18+
slug: string;
19+
base: string;
20+
}[];
21+
}
22+
23+
export function addStoreRepo(slug: string, base: string) {
24+
return executeDbOperation("Add Store Repo", () =>
25+
stmt.insert.run(slug, base),
26+
);
27+
}
28+
29+
export function deleteStoreRepo(slug: string) {
30+
return executeDbOperation("Delete Store Repo", () => stmt.delete.run(slug));
31+
}

0 commit comments

Comments
 (0)