From 1c3b0e62a99840d2ee72ff8cd15684e6d1a78ec3 Mon Sep 17 00:00:00 2001 From: Silk Rose Date: Fri, 8 Mar 2024 23:16:21 -0500 Subject: [PATCH] Add prequel id and run commands to fimfic stats --- fimficstats/fimfic-stats.ts | 9 ++++++++- fimficstats/sql-patterns.ts | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/fimficstats/fimfic-stats.ts b/fimficstats/fimfic-stats.ts index c350d90..3be3ed2 100644 --- a/fimficstats/fimfic-stats.ts +++ b/fimficstats/fimfic-stats.ts @@ -4,13 +4,20 @@ import "@total-typescript/ts-reset"; import { Database } from "bun:sqlite"; import * as cheerio from "cheerio"; import z from "zod"; -import * as sql from "./sql-patterns.ts" +import * as sql from "./sql-patterns.ts"; import * as plib from "./lib.ts"; import fs from "fs"; const db = new Database("./fimfic-stats.db", { create: true }); +db.prepare(sql.index_table).run(); db.prepare(sql.authors_table).run(); db.prepare(sql.stories_table).run(); +db.prepare(sql.tags_table).run(); +db.prepare(sql.tag_links_table).run(); +db.prepare(sql.chapters_table).run(); +db.prepare(sql.stats_table).run(); +db.prepare(sql.referral_sites_table).run(); +db.prepare(sql.referrals_table).run(); // Schema for the story API response. const api_schema = z.object({ diff --git a/fimficstats/sql-patterns.ts b/fimficstats/sql-patterns.ts index 3894047..c146a11 100644 --- a/fimficstats/sql-patterns.ts +++ b/fimficstats/sql-patterns.ts @@ -3,14 +3,14 @@ export const index_table = `CREATE TABLE IF NOT EXISTS Index ( status text NOT NULL, version integer NOT NULL, timestamp integer NOT NULL -)` +)`; export const authors_table = `CREATE TABLE IF NOT EXISTS Authors ( id integer PRIMARY KEY, name text NOT NULL, followers integer NOT NULL, blogs integer NOT NULL -)` +)`; export const stories_table = `CREATE TABLE IF NOT EXISTS Stories ( id integer PRIMARY KEY, @@ -29,13 +29,14 @@ export const stories_table = `CREATE TABLE IF NOT EXISTS Stories ( likes integer NOT NULL, dislikes integer NOT NULL, author_id integer NOT NULL, + prequel_id integer, CONSTRAINT stories_author_id_fk FOREIGN KEY (author_id) REFERENCES Authors (id), CONSTRAINT story_index_id_fk FOREIGN KEY (id) REFERENCES Index (story_id) -)` +)`; export const tags_table = `CREATE TABLE IF NOT EXISTS Tags ( id integer PRIMARY KEY, @@ -43,7 +44,7 @@ export const tags_table = `CREATE TABLE IF NOT EXISTS Tags ( type text NOT NULL, text text NOT NULL, href text NOT NULL -)` +)`; export const tag_links_table = `CREATE TABLE IF NOT EXISTS Tags_links ( story_id integer, @@ -55,7 +56,7 @@ export const tag_links_table = `CREATE TABLE IF NOT EXISTS Tags_links ( REFERENCES Tags (id), CONSTRAINT tag_links_pk PRIMARY KEY (story_id, tag_id) -)` +)`; export const chapters_table = `CREATE TABLE IF NOT EXISTS Chapters ( story_id integer NOT NULL, @@ -70,7 +71,7 @@ export const chapters_table = `CREATE TABLE IF NOT EXISTS Chapters ( REFERENCES Stories (id), CONSTRAINT chapters_pk PRIMARY KEY (story_id, chapter_num) -)` +)`; export const stats_table = `CREATE TABLE IF NOT EXISTS Stats ( story_id integer NOT NULL, @@ -83,12 +84,12 @@ export const stats_table = `CREATE TABLE IF NOT EXISTS Stats ( REFERENCES Stories (id), CONSTRAINT stats_pk PRIMARY KEY (story_id, date) -)` +)`; export const referral_sites_table = `CREATE TABLE IF NOT EXISTS Referral_sites ( id integer PRIMARY KEY, site string NOT NULL -)` +)`; export const referrals_table = `CREATE TABLE IF NOT EXISTS Referrals ( story_id integer NOT NULL, @@ -102,4 +103,4 @@ export const referrals_table = `CREATE TABLE IF NOT EXISTS Referrals ( REFERENCES Referral_sites (id), CONSTRAINT referrals_pk PRIMARY KEY (story_id, referral_site_id) -)` +)`;