Reference sections
Reference āŗ Database
Kitten has an integrated JSDB database thatās available from all your routes as kitten.db.
JSDB is a transparent, in-memory, streaming write-on-update JavaScript database for the Small Web that persists to a JavaScript transaction log.
Tables in JSDB are simply JavaScript objects or arrays and JSDB writes to plain old JavaScript files.
You can also create type-safe databases. To learn how to do so, read the Database App Modules tutorial.
You can inspect and alter your database from the Kittenās interactive shell while your app/site is running.
You can also get information about the database and specific tables, delete the whole database and specific tables, and tail specific tables using the command-line interface via the db info [tableName] (or just db [tableName], which is a convenience alias), db delete [tableName] and db tail <tableName> commands.
To access the JavaScript source code of your database, follow the āOpen app data folderā link in Kittenās initial terminal output.
Your databases are located under the main data folder:
~/.local/share/small-tech.org/kitten/data/
Each project gets its own folder in there with a name based on the absolute path to your project on your disk. e.g., A Kitten project stored in /var/home/aral/projects/my-project and served at localhost, port 443, will have its database in a folder called var.home.aral.projects.my-project.localhost.443 in the main data folder. (A different domain or port gives the project a different folder.)
In Kitten, you have a number of different scopes, with varying lifetimes, where you can store data.
These are, from most limited and ephemeral to widest and most permanent:
| Scope | Lifetime | Availability | Usage | Example |
|---|---|---|---|---|
| Page storage | Life of a single page loaded in a browser window/tab | Only on live pages (a stateful page, or a stateless page that exports an event handler) | Keep data in instance properties in your kitten.Page or kitten.Component subclass. In stateless pages, this within exported event handlers references the live page, so you can do the same thing there. | Streaming date |
| Session storage | Common to all pages within a client-side browser session (e.g., multiple pages open in tabs in the same browser) until the server restarts. | On any handler that receives a request property | Store data on the session object you have on the request property youāre passed in your page route and page onConnect() handlers. | Sessions tutorial |
| Route globals | Shares state between all handler calls of a route but is ephemeral (destroyed on server restart) | Any route | Create a file-level variable. | Draw Together |
| Globals | Shares state within your application but is ephemeral | Anywhere | Create a global variable (e.g., globalThis.myVariable) | n/a |
| Persisted | Kept in the app database (persisted to disk; survives server restarts) | Anywhere | See Database section, below. | Persistence tutorial |