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` is a lightweight HTTP application class that provides routing, template rendering and request/response helpers.
new App(host, port, templateDir)
// defaults: host='localhost', port=3000, templateDir='templates'
hostporttemplateDirglobalssessionsession.setValue / session.getValue.staticPath/static/).routesstatusPages/posts/<id>/).setStatus(code)addHeader(key, value)setContentType(type)send404(context)sendFileFromDir(path)redirect(url, status=302)Location header and status code.application/x-www-form-urlencoded into request.form, and basic multipart/form-data into request.form and request.files (files include filename, contentType, and data Buffer).
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();
`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.
ResultErrorDbObject.setDb(path)DatabaseSync instance at path.DbObject.databaseconstructor(results)fieldNames.props(includeUndefined=true)false.static getAll()static getByFilter(filter, config)field__lte, field__in).static first(filter, config)static create(item)save()id exists; otherwise insert and return the persisted instance.delete()id).
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.