| 123456789101112131415161718192021 |
- /*---
- title: Key-value database
- group: Data
- summary: Store a visit counter in the system database. Run it twice.
- ---*/
- /*
- The database outlives a run, as on a server: run this script a few
- times and watch the counter grow. The Database tab of the output shows
- every table; clear it from the menu at the top right.
- */
- newDBTableIfNotExists("playground_visits");
- var key = USERNAME;
- var count = parseInt(readDBItem("playground_visits", key) || "0", 10) + 1;
- writeDBItem("playground_visits", key, String(count));
- writeDBItem("playground_visits", key + "_last", new Date().toISOString());
- sendJSONResp({
- visits: count,
- table: listDBTable("playground_visits")
- });
|