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();