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.
| Setting | Meaning |
|---|---|
WISP_DATA | Data folder: .wisp/data in dev, data in release, /data in the Docker image. |
WISP_DATA=off | Memory (tests, edge). |
WISP_FSYNC | second (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:Nonedeletes.
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 envWISP_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,Vecorbool. - An
Imagefield is adata: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?