Download the PHP package windwalker/datamapper without Composer
On this page you can find all versions of the php package windwalker/datamapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download windwalker/datamapper
More information about windwalker/datamapper
Files in windwalker/datamapper
Package datamapper
Short Description Windwalker DataMapper package
License LGPL-2.0-or-later
Homepage https://github.com/ventoviro/windwalker-datamapper
Informations about the package datamapper
Windwalker DataMapper
Installation via Composer
Add this to the require block in your composer.json
.
Getting Started
Prepare Windwalker Database object
The DatabaseDriver will be cached in Factory, now DataMapper will auto load database driver.
See Database
Create DataMapper
Inject DB to DataMapper
Custom primary keys:
Extend It
You can also create a class to operate specific table:
Or using facade:
Find Records
Find method will fetch rows from table, and return DataSet
class.
find()
Get id = 1 record
Fetch published = 1, and sort by date
Fetch published = 1, language = en-US, sort by date
DESC and start with 30
, limit 10
.
Using array, will be IN
condition:
findOne()
Just return one row.
findAll()
Equal to find(array(), $order, $start, $limit)
.
Find With Custom Query
The available query methods.
join($type = 'LEFT', $alias, $table, $condition = null, $prefix = null)
leftJoin($alias, $table, $condition = null, $prefix = null)
rightJoin($alias, $table, $condition = null, $prefix = null)
nnerJoin($alias, $table, $condition = null, $prefix = null)
outerJoin($alias, $table, $condition = null, $prefix = null)
call($columns)
group($columns)
order($columns)
limit($limit = null, $offset = null)
select($columns)
where($conditions, ...$args)
orWhere($conditions)
having($conditions, ...$args)
orHaving($conditions)
clear($clause = null)
bind($key = null, $value = null, $dataType = \PDO::PARAM_STR, $length = 0, $driverOptions = array())
See Query Format
Create Records
Using DataSet to wrap every data, then send this object to create() method, these data will insert to table.
create()
The return value will be whole dataset and add inserted ids.
createOne()
Only insert one row, do not need DataSet.
Update Records
Update methods help us update rows in table.
update()
updateOne()
Just update one row.
updateAll()
UpdateAll is different from update method, we just send one data object, but using conditions as where to update every row match these conditions. We don't need primary key for updateAll().
Delete
Delete rows by conditions.
delete()
Join Tables
Use newRelation()
to create a DataMapper and join other tables.
The Join query will be:
Where condition will auto add alias if not provided.
Reset all tables and query:
Using OR Condition
Group
Compare objects
Using Compare objects help us set some where conditions which hard to use array to defind.
This will generate where conditions like below:
Available compares:
Name | Description | Operator |
---|---|---|
EqCompare | Equal | = |
NeqCompare | Not Equal | != |
GtCompare | Greater than | > |
GteCompare | Greater than or Equal | >= |
LtCompare | Less than | < |
LteCompare | Less than or Equal | <= |
InCompare | In | IN |
NinCompare | Not In | IN |
Custom Compare
Will be
See: https://github.com/ventoviro/windwalker-compare
Using Data and DataSet
See: https://github.com/ventoviro/windwalker-data
Hooks
Add "windwalker/event": "~3.0"
to composer.json
.
Then we are able to use hooks after every operations.
Extends DataMapper:
Available events:
- onBeforeFind
- onAfterFind
- onBeforeFindAll
- onAfterFindAll
- onBeforeFindOne
- onAfterFindOne
- onBeforeFindColumn
- onAfterFindColumn
- onBeforeCreate
- onAfterCreate
- onBeforeCreateOne
- onAfterCreateOne
- onBeforeUpdate
- onAfterUpdate
- onBeforeUpdateOne
- onAfterUpdateOne
- onBeforeUpdateBatch
- onAfterUpdateBatch
- onBeforeSave
- onAfterSave
- onBeforeSaveOne
- onAfterSaveOne
- onBeforeFlush
- onAfterFlush
- onBeforeDelete
- onAfterDelete
More about Event: Windwalker Event
All versions of datamapper with dependencies
windwalker/database Version ~3.0
windwalker/data Version ~3.0
ext-json Version *
ext-pdo Version *