Simple utilities for storing and retrieving email data in SQLite on Val Town.
Creates a table with the following schema:
id - INTEGER PRIMARY KEYtimestamp - INTEGER NOT NULL (Unix timestamp)data - TEXT NOT NULL (JSON string)Inserts an email object into the specified table with the current timestamp.
Retrieves the most recently inserted email from the specified table, ordered by timestamp.
Retrieves all emails from the specified table as an array of Email objects.
import {
createTable,
getAllEmails,
getLatestEmail,
insertEmail,
} from "https://esm.town/v/nbbaier/serialize-email/main.ts";
// Create table
await createTable("my_emails");
// Insert email data
await insertEmail("my_emails", emailObject);
// Get the latest email
const latestEmail = await getLatestEmail("my_emails");
// Get all emails
const allEmails = await getAllEmails("my_emails");