Download the PHP package trehinos/thor-pdo-table without Composer
On this page you can find all versions of the php package trehinos/thor-pdo-table. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download trehinos/thor-pdo-table
More information about trehinos/thor-pdo-table
Files in trehinos/thor-pdo-table
Package thor-pdo-table
Short Description A simple table abstraction for PDO.
License MIT
Informations about the package thor-pdo-table
Thor PDO Table
Lightweight utilities to map plain PHP objects (rows) to SQL tables using PHP 8 attributes, with a thin CRUD helper and optional in-memory caching.
This package builds on trehinos/thor-pdo-extension to provide:
- Declarative table and column metadata via PHP attributes
- A CrudHelper to perform typed CRUD operations and hydrate objects
- Drivers to generate DDL (CREATE TABLE/INDEX) for MySQL and SQLite
- A small write-back cache to batch updates
Requirements
- PHP 8.1+
- ext-pdo enabled and a PDO driver (mysql or sqlite)
- trehinos/thor-pdo-extension (installed automatically by Composer)
Installation
Install via Composer:
Core concepts
- Row and RowInterface: a Row represents a table row; hydration/serialization is handled by PdoRowTrait.
- Attributes: use PHP 8 attributes (Table, Column, Index) to describe the table schema.
- Primary keys: single or composite primary keys are supported via the Table(primaryKeys: [...]) declaration.
- Traits: HasIdTrait adds an auto-increment integer id; HasPublicIdTrait adds a GUID-like public_id suitable for exposure.
- CrudHelper: thin helper around ArrayCrud to perform create/read/update/delete and to instantiate rows.
Quick start
1) Define a row class with attributes
Row already provides helper methods through PdoRowTrait to convert to/from arrays.
2) Use CrudHelper
3) Optional cache
Schema generation
Use SchemaHelper with a driver (MySQL or SQLite) to create/drop tables from your attributes. Debug mode returns SQL instead of executing it.
Drivers
Two drivers help you generate DDL from your attributes:
- MySql: generates CREATE TABLE and related statements for MySQL
- Sqlite: generates CREATE TABLE and CREATE INDEX for SQLite
Both rely on AttributesReader to parse your row class.
Tips and gotchas
- Composite keys: pass ordered values to CrudHelper::readOne([...]) in the same order as declared in Table(primaryKeys: [...]).
- Public ID: when using HasPublicIdTrait, remember to call generatePublicId() before insert if you need a deterministic public_id.
- Requester access: CrudHelper::getRequester() lets you run custom queries alongside CRUD operations.
Development
- PHP 8.1+
- Run tests with PHPUnit if present in your project
- This package depends on trehinos/thor-pdo-extension
License
MIT Copyright (c) 2021-2025 Sébastien Geldreich