SQLite Email Storage Utilities

Simple utilities for storing and retrieving email data in SQLite on Val Town.

Functions

createTable(tableName: string)

Creates a table with the following schema:

  • id - INTEGER PRIMARY KEY
  • timestamp - INTEGER NOT NULL (Unix timestamp)
  • data - TEXT NOT NULL (JSON string)

insertEmail(tableName: string, data: Email)

Inserts an email object into the specified table with the current timestamp.

getLatestEmail(tableName: string): Promise<Email>

Retrieves the most recently inserted email from the specified table, ordered by timestamp.

getAllEmails(tableName: string): Promise<Email[]>

Retrieves all emails from the specified table as an array of Email objects.

Usage

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

Requirements

  • Val Town SQLite standard library
  • Email objects must be JSON serializable