Skip to content

Commit

Permalink
Add prequel id and run commands to fimfic stats
Browse files Browse the repository at this point in the history
  • Loading branch information
SilkRose committed Mar 9, 2024
1 parent b499009 commit 1c3b0e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
9 changes: 8 additions & 1 deletion fimficstats/fimfic-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
19 changes: 10 additions & 9 deletions fimficstats/sql-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,21 +29,22 @@ 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,
title text NOT NULL,
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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
)`
)`;

0 comments on commit 1c3b0e6

Please sign in to comment.