aral, to SmallWeb
@aral@mastodon.ar.al avatar

Just published Kitten’s¹ new database² commands:

  • kitten db [table name] to see info the database/a specific table
  • kitten db delete [table name] to delete the database/a specific table
  • kitten db tail <table name> to follow a specific table

Full docs: https://codeberg.org/kitten/app#database-commands

¹ https://codeberg.org/kitten/app
² https://codeberg.org/small-tech/jsdb

aral, (edited ) to SmallWeb
@aral@mastodon.ar.al avatar

Sitting at the hotel bar in Paris, sipping some red wine and adding a new database command to the Kitten¹ command-line interface.

You can now tail JavaScript Database (JSDB)² tables with:

kitten db <table name>

(Remember that JSDB writes its tables as append-only JavaScript logs.)

¹ https://codeberg.org/kitten/app
² https://codeberg.org/small-tech/jsdb

#Kitten #SmallWeb #JavaScript #database #JSDB

aral, to programming
@aral@mastodon.ar.al avatar

There are times I think JavaScript (and Node.js) do deserve their reputation…

(Ok, ok, I don’t, but what is this, really?)

“Date.prototype.toISOString called on incompatible receiver [object Date]”

smh

#nodeJS #javaScript #js #web #dev

aral,
@aral@mastodon.ar.al avatar

So in case anyone was following this: it appears that built-in objects like Date in JavaScript have some internal magic (read: inconsistencies)* that means you can’t proxy them as you would normally.

More info: https://codeberg.org/small-tech/jsdb/issues/5

Not sure if this is fixable in . The “solution” might be to discourage use of Date objects and instead persist timestamps. Which is, quite frankly, a pain in the ass.

I’ll keep looking for a workaround…

  • internal slots

aral, (edited )
@aral@mastodon.ar.al avatar

Right, implemented workaround for JavaScript’s Proxy / Date object incompatibility in JavaScript Database (JSDB)¹ and released in version 3.0.2².

Calling methods on persisted Date objects read back into memory now works as it should.

Workaround (diff): https://codeberg.org/small-tech/jsdb/commit/9e039e76f7a149df2fa7ecbbf626f813e44c0ab2
3.0.2 update (diff): https://codeberg.org/small-tech/jsdb/commit/f212566f8da4327d0b91d81e8cc6f5058ce63c47

Kudos to Pravin Divraniya for https://stackoverflow.com/a/57958494

¹ https://codeberg.org/small-tech/jsdb
² https://www.npmjs.com/package/@small-tech/jsdb

aral, (edited ) to SmallWeb
@aral@mastodon.ar.al avatar

I do rather love being able to run tail¹ on my database tables² as I work on building Domain³ with Kitten⁴ ;)

(JSDB keeps tables in an append-only JavaScript log which are read fully into memory when the database is opened. And yes, if you noticed the class names, you can store custom objects.)

¹ Actually: tail -f <database path>/table.js | bat --paging=never --language=js
² https://codeberg.org/small-tech/jsdb
³ https://codeberg.org/domain/app
https://codeberg.org/kitten/app

#SmallWeb #JSDB #Domain #Kitten #databases

aral, to javascript
@aral@mastodon.ar.al avatar

An interesting JavaScript Database (JSDB) edge case I just encountered:

If you’re persisting custom objects, please do NOT use setter methods (set something () {…}).

Use regular methods instead (setSomething () {…}) for predictable behaviour that likely matches your conceptual model of how things should work.

(This is due to how setters interact with proxies.)

Details: https://codeberg.org/small-tech/jsdb#custom-data-types

#JavaScriptDatabase #javascript #database #jsdb #accessors #SmallTech #SmallWeb #web #dev

aral, to programming
@aral@mastodon.ar.al avatar

Want strong typing without a build process?

(Hint: you don’t need to use TypeScript.)

  1. Use a modern editor like Helix Editor or VSCodium that supports the TypeScript Language Server (LSP).

  2. Add this line to the top of your JavaScript file (without the backticks, if you see any):

// @ts-check  
  1. Go read up on JSDoc ;)

¹ https://helix-editor.com
² https://jsdoc.app/about-getting-started.html

#javaScript #typeSafety #JSDoc #lsp #HelixEditor #typeScript #web #dev

aral,
@aral@mastodon.ar.al avatar

@Shini92 Nice. One very similar use case for me is database schemas for JavaScript Database (JSDB)¹, which is part of Kitten² :)

https://codeberg.org/domain/app/src/branch/main/app_modules/database/database.js

¹ https://codeberg.org/small-tech/jsdb
² https://codeberg.org/kitten/app

#jsdb #kitten #SmallWeb #database #web #dev

aral, to programming
@aral@mastodon.ar.al avatar

Just released #JavaScript #Database (#JSDB)¹ version 3.0.0

Breaking change²: data is now evaluated in virtual machine contexts.

If you were persisting custom objects³ and referencing classes from global scope (globalThis) to have your objects keep their types when read, you must now explicitly register your list of custom classes using the new classes property of the options object when calling JSDB.open().

¹ https://codeberg.org/small-tech/jsdb#javascript-database-jsdb
² https://codeberg.org/small-tech/jsdb/src/branch/main/CHANGELOG.md#3-0-0-2023-04-28
³ https://codeberg.org/small-tech/jsdb#custom-data-types

aral, (edited )
@aral@mastodon.ar.al avatar

This is quite a major change internally but since has 100% code coverage, I’m pretty certain I didn’t break anything else.

Then again, JSDB had 100% code coverage before this too and the issue this update fixes was around for several years. (Likely because no one, including me, was really persisting custom objects… something I’m now starting to use while building .)

Just goes to stress that 100% code coverage in no way means “bug free.” ;)

¹ https://codeberg.org/domain/app

aral,
@aral@mastodon.ar.al avatar

PS. I’ll update Kitten¹ with the latest JSDB today.

¹ https://codeberg.org/kitten/app

#Kitten #Domain #JSDB #SmallWeb #SmallTech #web #dev #nodeJS #database

aral,
@aral@mastodon.ar.al avatar

Right, I just updated Kitten so it includes JSDB version 3.0.0 and it now has built-in support for database app modules.

A database app module is an app module¹ for your database where you can provide a schema for it using JavaScript class hierarchies and register those classes with the database so your custom objects maintain their types when they are written and read in.

You can see it in use in Domain here: https://codeberg.org/domain/app/src/branch/main/app_modules/database/database.js#L198

¹ https://codeberg.org/kitten/app#app-modules

  • All
  • Subscribed
  • Moderated
  • Favorites
  • provamag3
  • thenastyranch
  • magazineikmin
  • ethstaker
  • GTA5RPClips
  • InstantRegret
  • rosin
  • love
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • everett
  • DreamBathrooms
  • megavids
  • osvaldo12
  • tester
  • cisconetworking
  • tacticalgear
  • ngwrru68w68
  • Durango
  • cubers
  • mdbf
  • normalnudes
  • anitta
  • modclub
  • Leos
  • JUstTest
  • All magazines