Download the PHP package tithely/picomapper without Composer
On this page you can find all versions of the php package tithely/picomapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tithely/picomapper
More information about tithely/picomapper
Files in tithely/picomapper
Package picomapper
Short Description Minimalist data mapper built on PicoDb
License MIT
Informations about the package picomapper
PicoMapper
PicoMapper is a minimalist data mapper built on PicoDb.
Features
- Built on PicoDb
- No configuration files
- License: MIT
Requirements
- PHP >= 7.3
- PDO extension
- Sqlite, Mssql, Mysql or Postgresql
Documentation
Installation
Setup
Concepts
Definition
In order to map to or from the database, a mapping must be built from a definition. A definition consists of a table, a primary key (one or more columns that uniquely identifies a record), columns, children (other definitions) and special options that control things like what is considered a deleted record.
Consider a blog system with posts, comments and authors. A post has one author and many comments, a comment has one author. Assuming posts, comments and authors have their own tables, a suitable definition would look like the following:
The second constructor argument for Definition
is an array of columns that uniquely identify a record within the table.
By default it's ['id']
.
Data to be set on insert and update can be set by calling withCreationData()
and withModificationData()
respectively. For example if you wanted to add a date_entered
and date_modified
columns to the $post
definition, you would enter it as follows:
Mapping
Mappings have the same interface as PicoDb's Table
class. That is, you can chain conditions and call findOne()
or
findAll()
to fetch records or insert()
, update()
, remove()
and save()
to modify records. In all cases, the
definition will be used to intelligently return or accept a structured array.
In the example above you could fetch or save a post using the following structured array, and all table relationships will be followed automatically.
Hooks
Hooks are callbacks that can be triggered when a mapping performs the successful insert, update or removal of a record. A hook registered against a mapper will be used for all top level mappings it creates.