diff --git a/db/blog.sqlite b/db/blog.sqlite deleted file mode 100644 index cd949cd..0000000 Binary files a/db/blog.sqlite and /dev/null differ 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 { - - } -}