Wisp is in pre-release, self-hosted since GitHub suspended us. Install it, or see the changelog.

Wisp

Where Rows Are Kept

Storage

A change is saved before memory changes. Each table has a log file in WISP_DATA (note.log, a line per change), read at first use and rewritten at twice its rows. One process uses a data folder: the first holds a lock on .lock, and a second process's tables answer 500 ("another process uses the data folder"). Give each replica its own folder, or use a database store. Table names differing only in case are refused at load.

SettingMeaning
WISP_DATAData folder: .wisp/data in dev, data in release, /data in the Docker image.
WISP_DATA=offMemory (tests, edge).
WISP_FSYNCsecond (default), always, off.

Tables hold every row in memory. For larger data or database-side queries, write the handlers.

Load never panics. A torn last line is dropped, a corrupt middle line is skipped with one warning, and a row that no longer reads as its type is skipped with a warning naming it (its id stays taken and its line stays, to fix or migrate).

Any Database

Call wisp::store(Db) in init. Implement wisp::Store:

  • load(&self, table) -> Result<Vec<(u64, String)>>: id and JSON of each row.
  • save(&self, table, id, json: Option<&str>) -> Result: None deletes.

For example, over Mutex<rusqlite::Connection> (create table if not exists {table} (id integer primary key, json text), insert or replace, delete).

  • Calls are blocking, one per change, under the table lock.
  • A POST of an array calls save_many(table, &[(id, json)]). The default saves each row in turn and undoes earlier ones on failure; override it with one transaction. A failure is a 500 and nothing is kept. The built-in file store writes the batch behind one mark, so a crash part way through replays none of it. A table name is letters, digits, _ and -, and never a Windows device name (con, nul, aux, prn, com1-com9, lpt1-lpt9), on every OS.
  • On the edge each instance has its own memory, so tables are caches. Use D1/KV through wisp::edge::fetch, or env WISP_STORE=d1:DB|deno-kv|libsql://….

A Page's Own Table

static TODOS: Table<Todo> = Table::saved(); (named from the static, or Table::saved("todos")).

  • A field added to a saved type must be Option, Vec or bool.
  • An Image field is a data: URL.

Paging

POSTS.page(cx, 10) is the rows ?page=N asks for, newest first. It reads as its rows and has number, prev, next (hrefs, None at the ends), total and pages() (at least 1):

{#each posts as post}<p>${post.title}</p>{/each}
{#if let Some(href) = posts.next}<a ${href}>Older</a>{/if}

{@pager posts} writes both links. POSTS.page_where(cx, 10, |p| p.title.contains(&q)) pages the rows f is true for (total counts the matches). Page::of(cx, 10, rows) pages rows you sorted yourself. Search and sort links with no script: With JavaScript off. TABLE.add_unless(|t| t.slug == slug, value) keeps value only if no row is taken (checked while locked), returns Ok(None) if one is, and errs as add does.

Is This Page Useful?

View This Page's Source

Type to search every docs page and heading.