an experiment in putting together a wiki and an object-oriented mud.
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.
 
 
 
the-forest/db/initialize_db.js

42 lines
1023 B

const libsql = require("@libsql/client");
const showdown = require("showdown");
const createPages = `
create table if not exists pages (
id integer primary key,
title varchar(255),
description text,
html text
)
`;
async function initDb() {
const config = {
url: "http://127.0.0.1:8000"
};
const db = libsql.createClient(config);
const converter = new showdown.Converter();
console.log(await db.execute(createPages));
console.log("finding pages that havent been rendered");
const rows = (await db.execute(`select * from pages where html is null`)).rows;
console.log(rows);
rows.forEach(async ({id, title, description, html}) => {
console.log(`rendering page number ${id}`)
console.log(`${id}. ${title}: ${description} ( ${html} )`);
const renderedPage = converter.makeHtml(description);
await db.execute({
sql: `replace into pages (id, title, description, html) values (?, ?, ?, ?)`,
args: [id, title, description, renderedPage]
});
});
}
initDb();