Runo — Overview & setup
Runo is the database engine for the Lunaris framework, but it works as a standalone library. It is intentionally not an ORM: a thin utility layer over PDO for executing plain SQL, binding values, hydrating rows into objects, casting, and managing transactions.
Philosophy
Runo does not provide high-level abstractions like other ORMs. Instead, it
encourages writing queries in plain SQL while providing bare-metal utilities
such as a PDO wrapper. Raw SQL through DB::prepare() is a
first-class path; the optional Sql builder is a convenience, not
a requirement.
Features
- Static connection facade backed by one PDO instance
- Fluent prepared statements with typed value binding
- Plain SQL as the primary query path
- Optional SQL builder for
SELECT,INSERT,UPDATE, andDELETE - Reusable query classes with per-query casts and record classes
- Automatic hydration of rows into
Recordobjects - Column casting for integers, floats, booleans, JSON, and date/time classes
- Result collections with iteration, counting,
first(),pluck(), andtoArray() - Query metadata: last insert ID, affected row count, and execution time
- Closure-based and manual transaction APIs
- No runtime dependencies beyond PHP and PDO
- PSR-4 autoloading under the
Runo\namespace
Requirements
- PHP 8.0 or newer (Docker image uses PHP 8.3)
- The
PDOextension and the PDO driver for your database (pdo_mysqlrequired for MySQL/MariaDB) - MySQL or MariaDB
- Composer for installation and autoloading
Installation
Install with Composer:
composer require lunaris/runo
Load the Composer autoloader:
require __DIR__ . '/vendor/autoload.php';
For local development against a checked-out copy, add a Composer path
repository pointing to ../runo.
Quick start
<?php
require __DIR__ . '/vendor/autoload.php';
use Runo\DB;
DB::init([
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => 3306,
'database' => 'app',
'username' => 'root',
'password' => 'secret',
]);
$posts = DB::prepare(
'SELECT id, title FROM posts ORDER BY id DESC'
)->execute();
foreach ($posts as $post) {
echo $post->id . ': ' . $post->title . PHP_EOL;
}
echo 'Rows: ' . $posts->count() . PHP_EOL;
Configuration
| Key | Required | Example | Description |
|---|---|---|---|
driver | Yes | mysql | PDO driver used as the DSN prefix. |
host | Yes | 127.0.0.1 | Database server hostname or IP address. |
port | Yes | 3306 | Database server port. |
database | Yes | app | Database name. |
username | Yes | root | Database username. |
password | Yes | secret | Database password. Can be an empty string. |
The generated DSN is always {driver}:host={host};port={port};dbname={database};charset=utf8mb4. PDO is configured with ERRMODE_EXCEPTION, FETCH_OBJ, and EMULATE_PREPARES=false.
Connection lifecycle
- The connection is stored in a static property and shared by every
DBcall. DB::init()only creates a connection when none exists; later calls are silently ignored.- There is no public method to close, reset, or replace the connection.
DB::prepare()throwsException("Database not initialized.")ifDB::init()has not been called.DB::commit()andDB::rollback()assume a connection already exists.
Architecture
Raw SQL or Runo\Support\Sql
|
v
DB::prepare()
|
v
Runo\Database\Statement (args / cast / as)
|
v
PDO prepares and executes
|
v
Runo\Support\Hydrator
|
v
Runo\Support\Result (items: Record[], meta(): Attributes)
Project structure
runo/
├── composer.json
├── readme.md
├── src/
│ ├── DB.php
│ ├── Database/
│ │ ├── Query.php
│ │ └── Statement.php
│ └── Support/
│ ├── Attributes.php
│ ├── Hydrator.php
│ ├── Raw.php
│ ├── Record.php
│ ├── Result.php
│ └── Sql.php
└── docker/ (local dev environment)
Local development with Docker
From the project root: docker compose -f docker/docker-compose.yml up --build. Services include PHP 8.3 + Apache on :8080 and MariaDB 10.11 on :3306.
Known limitations
- Only MySQL/MariaDB is targeted by the built-in DSN; one connection only.
- All results are fetched eagerly; no lazy/streaming cursor.
Sqlis a builder only (no execution). When used withQuery, bindings must be passed explicitly.- Nested
where()groups can collide with placeholder names;where()requires an explicit operator. whereIn([])produces invalid SQL;offset()withoutlimit()may fail on MySQL.update()/delete()withoutwhere()affect every row.- No nested transactions/savepoints; identifiers/Raw are not escaped.
- Last insert ID is only detected for statements starting with
INSERT.
Part of the Lunaris documentation · Source on Codeberg · MIT License
Part of the Lunaris documentation · Source on Codeberg · MIT License