You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
const sqlite = require("better-sqlite3");
|
|
const showdown = require("showdown");
|
|
const db = new sqlite('./the_big_db.db', { verbose: console.log });
|
|
|
|
const converter = new showdown.Converter();
|
|
|
|
const createPages = db.prepare(`
|
|
create table if not exists pages (
|
|
id integer primary key,
|
|
title varchar(255),
|
|
description text,
|
|
html text
|
|
)
|
|
`);
|
|
|
|
const createUsers = db.prepare(`
|
|
create table if not exists users (
|
|
name varchar(64) primary key,
|
|
password varchar(128)
|
|
)
|
|
`);
|
|
|
|
|
|
function initDb() {
|
|
console.log("creating page table")
|
|
console.log(createPages.run());
|
|
|
|
console.log("finding pages that havent been rendered");
|
|
rows = db.prepare(`select * from pages where html is null`).all();
|
|
console.log(rows);
|
|
|
|
const insertPage = db.prepare(`replace into pages (id, title, description, html) values (:id, :title, :description, :html)`);
|
|
|
|
rows.forEach((pageData) => {
|
|
const {id, title, description, html} = pageData;
|
|
console.log(`rendering page number ${id}`)
|
|
console.log(`${id}. ${title}: ${description} ( ${html} )`);
|
|
|
|
const renderedPage = converter.makeHtml(description);
|
|
|
|
insertPage.run({...pageData, html: renderedPage});
|
|
});
|
|
|
|
console.log("creating user table");
|
|
console.log(createUsers.run());
|
|
}
|
|
|
|
initDb(); |