Download the PHP package preflow/data without Composer
On this page you can find all versions of the php package preflow/data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package data
Short Description Preflow data — storage drivers, models, migrations
License MIT
Informations about the package data
preflow/data
Multi-storage data layer for Preflow. Supports JSON files and SQLite out of the box; different models can use different backends simultaneously.
Installation
Requires PHP 8.4+, ext-pdo, ext-pdo_sqlite.
What it does
Models are annotated with PHP attributes. DataManager is the single entry point — it reads model metadata via reflection, selects the right storage driver, and returns typed results. QueryBuilder provides a fluent API for filtering, sorting, searching, and pagination. Migrations are handled by Schema + Table + Migrator.
API
Attributes
| Attribute | Target | Description |
|---|---|---|
#[Entity(table: 'posts', storage: 'sqlite')] |
Class | Maps model to a table/collection and a named driver. storage defaults to 'default'. |
#[Id] |
Property | Marks the primary key field. Works on any property — use string $uuid for UUIDs or int $id for auto-increment. |
#[Field(searchable: true)] |
Property | Marks a field; searchable: true includes it in full-text search. |
#[Timestamps] |
Class | Adds created_at / updated_at handling. |
Model
DataManager
save() detects an empty ID field and automatically issues an INSERT, then reads back lastInsertId() into the model — no need to pre-generate IDs for auto-increment tables.
QueryBuilder
All methods return $this for chaining except the terminal methods.
Storage drivers
| Class | Backend |
|---|---|
JsonFileDriver |
One .json file per record at {basePath}/{table}/{id}.json |
SqliteDriver |
PDO-based SQLite via PdoDriver + QueryCompiler |
Migrations
Schema methods: create(string $table, callable $callback), drop(string $table).
Table builder: uuid, string, text, integer, boolean, json, timestamps, nullable(), primary(), index().
Auto-increment IDs
Place #[Id] on an int property and leave it at 0 (or unset). save() / insert() will issue an INSERT and read the generated ID back via lastInsertId().
Raw SQL
Use raw() to run a query that the fluent builder cannot express. Results are returned as plain arrays.
Usage
Model:
Querying:
Saving:
Migration:
Multi-storage setup:
Models with #[Entity(storage: 'sqlite')] use SQLite; all others fall back to 'default'.
All versions of data with dependencies
ext-pdo Version *
ext-pdo_sqlite Version *
preflow/core Version ^0.1 || @dev
preflow/validation Version ^0.1 || @dev