Aral Balkan<p>While working on porting the Small Technology Foundation web site¹ to Kitten², I took the opportunity to pull out base Model and Collection classes that I’ll likely end up including in Kitten proper:</p><p>• Model: <a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/Model.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/Model.js</span></a><br>• Collection: <a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/Collection.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/Collection.js</span></a></p><p>To see them in use, here’s the base Posts class (with RSS generation) that extends Collection:<br><a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/Posts.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/Posts.js</span></a> </p><p>And here’s the concrete EventPosts collection class that extends Posts:<br><a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/EventPosts.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/EventPosts.js</span></a></p><p>And the EventPost (showing an implementation of a calculated property):<br><a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/EventPost.js" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/EventPost.js</span></a></p><p>So all this is possible (persisting and reading back typed model collections, etc.) thanks to JSDB¹ (JavaScript database), a zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database I wrote for the Small Web that persists to a JavaScript transaction log and is included as as first-class citizen in Kitten.</p><p><a href="https://codeberg.org/small-tech/jsdb" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="">codeberg.org/small-tech/jsdb</span><span class="invisible"></span></a></p><p>And if you want to know how the magic mapping of classes happens, see the Database App Module:</p><p><a href="https://codeberg.org/small-tech/site/src/branch/kitten/app_modules/database/database.js#L34" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">codeberg.org/small-tech/site/s</span><span class="invisible">rc/branch/kitten/app_modules/database/database.js#L34</span></a></p><p>PS. For a much gentler introduction to persistence in Kitten, see the Kitten Persistence tutorial:<br><a href="https://kitten.small-web.org/tutorials/persistence/" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">kitten.small-web.org/tutorials</span><span class="invisible">/persistence/</span></a></p><p>Enjoy! :kitten:💕</p><p>¹ <a href="https://small-tech.org" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="">small-tech.org</span><span class="invisible"></span></a><br>² <a href="https://kitten.small-web.org" rel="nofollow noopener" translate="no" target="_blank"><span class="invisible">https://</span><span class="">kitten.small-web.org</span><span class="invisible"></span></a></p><p><a href="https://mastodon.ar.al/tags/Kitten" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>Kitten</span></a> <a href="https://mastodon.ar.al/tags/SmallWeb" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>SmallWeb</span></a> <a href="https://mastodon.ar.al/tags/SmallTech" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>SmallTech</span></a> <a href="https://mastodon.ar.al/tags/JavaScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JavaScript</span></a> <a href="https://mastodon.ar.al/tags/database" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>database</span></a> <a href="https://mastodon.ar.al/tags/JSDB" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDB</span></a> <a href="https://mastodon.ar.al/tags/typeSafety" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>typeSafety</span></a> <a href="https://mastodon.ar.al/tags/JSDoc" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>JSDoc</span></a> <a href="https://mastodon.ar.al/tags/closureCompiler" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>closureCompiler</span></a> <a href="https://mastodon.ar.al/tags/TypeScript" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>TypeScript</span></a> <a href="https://mastodon.ar.al/tags/workInProgress" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>workInProgress</span></a></p>