From a036cb76a2b68b5eda13701a70876f336ce329e9 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Thu, 1 Aug 2024 21:08:46 -0400 Subject: [PATCH] Remove the database code, focus on flat file blog. --- db/blog.sqlite | Bin 40960 -> 0 bytes src/db/init.ts | 110 --------------------- src/db/memory.ts | 4 - src/services/database.ts | 3 - src/services/repository/post-repository.ts | 29 ------ 5 files changed, 146 deletions(-) delete mode 100644 db/blog.sqlite delete mode 100644 src/db/init.ts delete mode 100644 src/db/memory.ts delete mode 100644 src/services/database.ts delete mode 100644 src/services/repository/post-repository.ts diff --git a/db/blog.sqlite b/db/blog.sqlite deleted file mode 100644 index cd949cd4e781273987d74563de7a5c4a5ceeb875..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 40960 zcmeHQOLH5?b|(Fzjf(ATTwL5un^sKHmjrd~+^R&R=}U>Qj0#Q35*^27IlutZ0Oo2i z1J4Wyqf)MvayO~`g#45&@(;4gpU67dWRXR_?{v?D04Py!UEXF<0x{^v>F+%HoEcPq zcfUCbGOc=XGW0U_+0vgcEiW(qPN}7(r4{_E;a~pqCjNLMe}mWM%HQYxxw2G0{pWYz z|KFvRKl}To_x|Vo|9J0T-h1ag@7+zjbw3UPhk!%CA>a^j2si{B0uBL(z@g3@1QA5qNRU0*>0$(+cPZ~EH zchv1W&94vce6Rkd@%n3z>acOtfG{@>?%p^!Y}7U%{P@<&>W3dL|KZJIDQPS7`YA^; zf33_dz+4yE(X<5tjWi1co)yrvKO-M!TPz;e`!vf_waveMV`cS&50)RiFU#Xp{P*UW zCGpB56oDqPM)mD+^P6vh+xnYtt?quXyc9&f{yF_AM77!S##t=y1;EyCIPP2h*H>15 z^{eFve<1>($skTr`|`#aG3>=hND_HNUBIn}UJ%MVX!5(|mDSbNA8 z(j(@`f-E$XsN-8F>iFBEBdQ_|#}$IB$ zqb!J{Lio|R69(x(`z_x?t$qk6VbjE$w5mp4+uVHZt<}$0&%@dn>Tl%bb%dF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>#yZ`ZQ?qz zR5s*@wD*E=unjUn$*XudXF|1+kR!CDL-=xk5!ci>zxVMwIpLoL|wNPwN zSPgPq6e39d?0gtPFz1d__!(324HgxK{LxY?LX|_I_XZbtWRO)x$WmxrzOVJj@CH-E z{R*dPaeu0f;e)67Zt>jOFb%xf85V@^DVndAxFT@fh2@{DO;8 zxj9=cOy$BeEKV2Qc6_FVs=Ys1rs8(Sms7LyA>yK1(mYZ;rwA&Zr!4MiAF~(1<|(V# zxo@&ms@S!CQ{wX5DUT><&G!}_TGcMRbzCeXe=dUp*EF2Xl^;@`6gqxLt!o5aQ1Dj1 zaq%=&?*&))hyu8HP%>Kv=TFdPO5w#&JtQZ}VV2uz+^CuO<+1cRRK*sS1^$>X^(o6_ zJIqC&3Y8URUL;@YDw=!9lNQp}Q~I*s1vwO%>@e@~mS8gu=4Bq;l<;i~3 zBLsw!G8(dDdgUIk2$Gw~cQ%^Tsc= O;GYxy@oRqx3I7iz*l||? diff --git a/src/db/init.ts b/src/db/init.ts deleted file mode 100644 index 7cf4704..0000000 --- a/src/db/init.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { PostFileService } from '@blog/services/post-file'; -import { db } from '@blog/services/database'; - -const createPostSql: string = ` -CREATE TABLE IF NOT EXISTS posts ( - id INTEGER PRIMARY KEY, - title TEXT NOT NULL, - slug TEXT NOT NULL UNIQUE, - is_draft INTEGER DEFAULT 0, - description TEXT, - published_date DATE, - raw_content TEXT -) -`; - -const createAuthorSql: string = ` -CREATE TABLE IF NOT EXISTS authors ( - id INTEGER PRIMARY KEY, - name TEXT, - email TEXT -) -`; - -const createTagsSql: string = ` -CREATE TABLE IF NOT EXISTS tags ( - id INTEGER PRIMARY KEY, - tag TEXT UNIQUE -) -`; - -const createPostsTagsSql: string = ` -CREATE TABLE IF NOT EXISTS posts_tags ( - tag_id TEXT, - post_id INTEGER, - - FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE, - FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE -) -`; - -const createPostHtmlCache = ` -CREATE TABLE IF NOT EXISTS post_html_cache ( - id INTEGER PRIMARY KEY, - post_id INTEGER, - content TEXT, - - FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE -); -`; - -export async function setupDb(): Promise { - console.log({ message: "Setting up the Database..." }); - console.log({ message: "Creating the Posts table..." }); - db.query(createPostSql).run(); - - console.log({ message: "Creating Authors table..." }); - db.query(createAuthorSql).run(); - - console.log({ message: "Creating Tags table..." }); - db.query(createTagsSql).run(); - - console.log({ message: "Creating Post and Tags relationships..." }); - db.query(createPostsTagsSql).run(); - - console.log({ message: "Creating HTML cache table..." }); - db.query(createPostHtmlCache).run(); -} - - -export async function readPostsToDatabase(): Promise { - const postService = await PostFileService.create(); - const createPostSql: string = ` - INSERT INTO posts (title, slug, description, is_draft, - published_date, raw_content) - VALUES ($title, $slug, $description, $is_draft, - $published_date, $raw_content);`; - - const createPostHtmlCacheSql: string = ` - INSERT INTO post_html_cache (post_id, content) - VALUES ($posId, $content);`; - - for (const [ slug, post ] of postService.getPosts().entries()) { - const postQuery = db.prepare(createPostSql); - const { lastInsertRowId } = postQuery.run({ - $title: post.meta.title, - $slug: slug, - $description: post.meta.description, - $is_draft: post.meta.draft ?? false, - $published_date: post.meta.date.toString(), - $raw_content: post.content - }); - - const htmlCacheQuery = db.prepare(createPostHtmlCacheSql); - htmlCacheQuery.run({ $postId: lastInsertRowId, $content: post.html }) - - console.log({ message: "Added " + post.meta.title + " to the database." }); - } -} - -async function main() { - await setupDb(); - await readPostsToDatabase(); -} - -main() - .then(() => process.exit(0)) - .catch(e => { - console.log(e); - throw e; - }); diff --git a/src/db/memory.ts b/src/db/memory.ts deleted file mode 100644 index a48a547..0000000 --- a/src/db/memory.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Database } from 'bun:sqlite'; - -const db = new Database(":memory:"); -export default db; diff --git a/src/services/database.ts b/src/services/database.ts deleted file mode 100644 index 796eea4..0000000 --- a/src/services/database.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Database } from "bun:sqlite"; -import { SQLITE_DATABASE_FILE } from "@blog/config"; -export const db = new Database(SQLITE_DATABASE_FILE); diff --git a/src/services/repository/post-repository.ts b/src/services/repository/post-repository.ts deleted file mode 100644 index 933e527..0000000 --- a/src/services/repository/post-repository.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Post } from '@blog/models/Post'; -import { db } from '@blog/services/database'; - -export class PostRepository { - public async getPost(id: number): Promise { - const queryString = ` -SELECT title, slug, is_draft, description, published_date, raw_content -FROM posts -WHERE id = $id -`; - const query = db.query(queryString); - const results = query.get({ $id: id }); - - return { - meta: { - title: results.title, - slug: results.slug, - description: results.description, - date: new Date(results.published_date), - draft: results.is_draft, - }, - content: results.raw_content, - } - } - - public async getPostBySlug(slug: string): Post { - - } -}