Documentation

API

Overview

This page documents the public API of the core runtime and ORM used by the demo application. The example server implementation is server.mjs (example only). Primary implementations to integrate with are src/app.mjs and src/orm.mjs.

App (src/app.mjs)

`App` is a lightweight HTTP application class that provides routing, template rendering and request/response helpers.

Quick example

      
        const app = new App('localhost', 3000, 'demo/templates');

        app.route('/hello/', (req, res) => {
          res.setContentType('text/html');
          return app.renderTemplate('index.html', { name: 'World' });
        });

        app.serve();
      
    

ORM (src/orm.mjs)

`DbObject` is a minimal active-record style base class for SQLite (uses node:sqlite DatabaseSync). Subclasses must declare static tableName and fieldNames (array of field names) to map query results to instances.

ORM example

      
        DbObject.setDb('./data/db.sqlite');

        class User extends DbObject {
          User.tableName = 'users';
          User.fieldNames = ['id','firstName','lastName','email'];
        }

        const u = User.create({ firstName: 'Sam', lastName: 'Smith', email: 's@e' });
        const found = User.getByFilter({ firstName: 'Sam' });
        u.email = 'sam@example.com';
        u.save();
      
    

For production usage, ensure proper SQL schema creation and consider prepared statements and transactional safety. The ORM is intentionally small and synchronous for simplicity.