JavaScript Database (JSDB) logo: it’s the common flowchart symbol for a database (stacked cylinders based on the disk packs used in early computing) on the lower right-hand corner of a yellow background. The yellow is the colour of the JavaScript icon and the location of the database symbol matches where the JS letters are on the JavaScript logo.
🥳 JavaScript Database (JSDB)¹ version 7.0.0 released
Breaking change JSTable.PERSIST event now uses a parameter object with properties for type, keypath, value, change, and table. This should make listening for events on your databases much nicer to author. e.g., a snippet from Catalyst² I’m working on:
const settingsTable = db.settings['__table__']
const JSTable = settingsTable.constructor
settingsTable.addListener(JSTable.PERSIST, ({ keypath, value }) => {
switch (keypath) {
case 'servers.serverPoolSize':
console.info('New server pool size requested', value)
this.updateServerPool()
break
// etc.
}
})
This new version of JSDB is not in the latest Kitten³ yet as it is a breaking change and I want to make sure I update my sites/apps first if needed. I should have it integrated tomorrow.
To see the simple use case for JSDB in Kitten (the default untyped database that’s easy to get started with and perfect for quick experiments, little sites, etc.), see: https://kitten.small-web.org/tutorials/persistence/
I haven’t added an example of how you implement migrations with Kitten’s¹ built-in JSDB database² yet but here’s one that I just used when renaming a field (property) in a table (JavaScript object) from “account” to “data” that illustrates the general granular approach you should take within persisted instances of JavaScript classes.
This is, of course, an advanced use case of the built-in JavaScript database that all Kitten apps have.
Kitten is simple for simple use cases. So check out the Persistence tutorial, for example, to see how easy it is to get started with JSDB in Kitten:
Screenshot of code for app_modules/database/Model.js.
The following code is highlighted with a pink border:
/**
Optional hook: override this to perform initialisation
at constructor time. (Do not override the constructor
or the automatic property assignment will fail.)
*/
initialise () {}
Full code listing:
/**
Base model class.
(To use, extend this with your own model classes.)
When adding properties in subclasses, make sure you
only set values after checking if the value already
exists:
e.g.,
class MyModelObject extends Model {
mySpecialProperty = this.mySpecialProperty || ''
}
(This way, you will get type safety while authoring
without accidentally overwriting any values populated by
the superclass when model objects are recreated when a
JSDB table is read into memory.)
*/
export default class Model {
id = crypto.randomUUID()
/**
Optional hook: override this to perform initialisation
at constructor time. (Do not override the constructor
or the automatic property assignment will fail.)
*/
initialise () {}
}
As Site.js reached an evolutionary dead-end, and as I learned from my experiements with replicated data types that replicated data types are not a prerequisite for a decentralised web (actual topological decentralisation and ease of use are), I started writing a new server/platform called Kitten from scratch while still making use of the tried and tested modules listed above.
Last week, I switched over our last site using Site.js to Kitten and, with that, today I’ve sunset³ Site.js:
• JSDB¹ versions 6.0.0 and below suffer from potential data corruption/arbitrary code execution as string keys were not being sanitised in the same way string values were² (so this is relevant to you if you’re storing untrusted data as keys in your data structures in JSDB and/or Kitten databases without carrying out any of your own sanitisation at the application level).
• The latest Kitten release uses JSDB version 6.0.1. Your deployment servers will automatically update in the next few hours. On your development machines, please run kitten update in your terminal or use the Update feature in Kitten Settings from your browser.
• If you are using Kitten’s Database App Modules³ feature in your apps, you will have installed JSDB manually and you should update your installation to version 6.0.1.
• Fixes #236¹: The data preview pages in Kitten’s settings how handle circular references in the deserialised data (which may contain your custom classes if that’s what you were persisting in the database).
PS. Those pages are very rudimentary at the moment and are good for getting quick visual overview of the data you’re persisting. For a fully interactive view, use Kitten’s interactive shell (REPL)² to explore your data until I’ve had a chance to implement a more comprehensive visual interface.
PPS. You persist data in Kitten using the built-in JavaScript Database (JSDB)³ (Or, of course, you can install and use any other database.)
Your web server having an interactive shell (REPL) where you can live update entries in your site/app’s database is pretty neat (if I do say so myself) :)
(I’m porting the Small Technology Foundation site¹ from Site.js² – and hence from being a static site generated via Site.js’s integrated Hugo³ – to Kitten⁴. In the process, I’m creating an admin panel⁵ for the news, events, and videos sections, which will make them easier to update, and storing the data in Kitten’s internal JavaScript Database⁶.)
Just updated the Database App Modules tutorial in the Kitten documentation to fix a few bugs, update to latest Kitten syntax, and improve the instructions: