Skip to content
No-More-RPPublic

About

nanos world package bundling Norm — a dependency-free Lua ORM — and exporting it server-side. Models, relations, query builder, migrations, hooks, soft deletes. Adapters for SQLite / MariaDB / MySQL; promises auto-detected via nmrp-promise.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

18 Commits

Folders and files

Repository files navigation

nmrp-norm

A nanos world package that bundles Norm — a dependency-free Lua ORM — and exports it server-side. The ORM is vendored as a git submodule and is fully self-contained (light-class is embedded), so there is nothing else to install.

Norm talks to a database, so it is server-side only. This package lives in Server/ and exports a global Norm.

Full documentation: https://justgodwork.github.io/norm-docs/

Setup

git submodule update --init --recursive    # pull the vendored Norm

Server/Index.lua loads the bundle and exports it:

local Norm = require 'vendor/norm/dist/norm.lua' -- embeds light-class, exposes `Norm`
Package.Export('Norm', Norm)                     -- available to other packages' server scripts

Add nmrp-norm to your package's packages_requirements, and Norm is global:

local db = Norm.new({
    adapter = Norm.adapters.nanos.new({ engine = DatabaseEngine.SQLite, connection = "./database.db" }),
})

local User = db:define("users", {
    id   = Norm.types.id(),
    name = Norm.types.string({ length = 64, nullable = false }),
})

coroutine.wrap(function()
    db:sync():await()
    local u = User:create({ name = "John" }):await()
    Console.Log("user #%d", u.id)
end)()

The full ORM API is documented in the core README: Server/vendor/norm/README.md — models, relations, the query builder, transactions, migrations, hooks, soft deletes, and the rest.

nanos specifics

These are handled for you by the nanos adapter / auto-detection:

  • Adapter — Norm.adapters.nanos.new({ engine, connection, pool_size? }) opens a pooled Database(engine, connection_string, pool_size) and logs the connection.
  • Promises — nmrp-promise is optional. If it's loaded (global Promise), Norm returns nanos promises; otherwise it uses its built-in one. promise:await() works the same either way — prefer it for code that's identical across providers.
  • Atomic insert ids — on SQLite (and MariaDB ≥ 10.5, auto-detected via SELECT VERSION()) Norm fetches new ids via INSERT … RETURNING, which is pool-safe. Real MySQL has no RETURNING, so it falls back to a best-effort LAST_INSERT_ID().
  • JSON columns — automatically use the nanos global JSON (stringify/parse).
  • Transactions — nanos' Database exposes no transaction API, so db:transaction(...) throws there. Check db:supports_transactions() first.

Rebuilding the bundle

The bundle is vendored so the package runs out of the box. After editing the core sources (Server/vendor/norm/src/), rebuild it:

cd Server/vendor/norm && lua build.lua   # regenerates dist/norm.lua + dist/norm.min.lua

License

MIT © 2026 JustGodWork. Vendored submodules (light-class, Norm) keep their own licenses.

About

nanos world package bundling Norm — a dependency-free Lua ORM — and exporting it server-side. Models, relations, query builder, migrations, hooks, soft deletes. Adapters for SQLite / MariaDB / MySQL; promises auto-detected via nmrp-promise.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages