eden / sql
SQL core methods for MySQL, Posgres and SQLite
Installs: 14 150
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 13
Forks: 7
Open Issues: 3
Requires
- php: >=5.4.1
- eden/array: 4.*
- eden/collection: 4.*
- eden/core: 4.*
- eden/model: 4.*
- eden/string: 4.*
README
====
Install
composer install eden/sql
====
Introduction
SQL is an abstract package used in:
See these documentations for more details. The following API methods are common amongst all SQL type databases.
====
API
====
bind
Binds a value and returns the bound key
Usage
eden('sql')->bind(*string|array|number|null $value);
Parameters
*string|array|number|null $value
- What to bind
Returns string
Example
eden('sql')->bind('foo');
====
collection
Returns collection
Usage
eden('sql')->collection(array $data);
Parameters
array $data
- Initial collection data
Returns Eden\Sql\Collection
Example
eden('sql')->collection();
====
delete
Returns the delete query builder
Usage
eden('sql')->delete(*string|null $table);
Parameters
*string|null $table
- The table name
Returns Eden\Sql\Delete
Example
eden('sql')->delete('foo');
====
deleteRows
Removes rows that match a filter
Usage
eden('sql')->deleteRows(*string|null $table, array|string $filters);
Parameters
*string|null $table
- The table namearray|string $filters
- Filters to test against
Returns Eden\Sql\Collection
Example
eden('sql')->deleteRows('foo');
====
getBinds
Returns all the bound values of this query
Usage
eden('sql')->getBinds();
Parameters
Returns array
====
getConnection
Returns the connection object if no connection has been made it will attempt to make it
Usage
eden('sql')->getConnection();
Parameters
Returns resource
- PDO connection resource
====
getLastInsertedId
Returns the last inserted id
Usage
eden('sql')->getLastInsertedId(string|null $column);
Parameters
string|null $column
- A particular column name
Returns int
- the id
Example
eden('sql')->getLastInsertedId();
====
getModel
Returns a model given the column name and the value
Usage
eden('sql')->getModel(*string $table, *string $name, *scalar|null $value);
Parameters
*string $table
- Table name*string $name
- Column name*scalar|null $value
- Column value
Returns Eden\Sql\Model|null
Example
eden('sql')->getModel('foo', 'foo', $value);
====
getQueries
Returns the history of queries made still in memory
Usage
eden('sql')->getQueries(int|string|null $index);
Parameters
int|string|null $index
- A particular index to return
Returns array|null
- the queries
Example
eden('sql')->getQueries();
====
getRow
Returns a 1 row result given the column name and the value
Usage
eden('sql')->getRow(*string $table, *string $name, *scalar|null $value);
Parameters
*string $table
- Table name*string $name
- Column name*scalar|null $value
- Column value
Returns array|null
Example
eden('sql')->getRow('foo', 'foo', $value);
====
insert
Returns the insert query builder
Usage
eden('sql')->insert(string|null $table);
Parameters
string|null $table
- Name of table
Returns Eden\Sql\Insert
Example
eden('sql')->insert();
====
insertRow
Inserts data into a table and returns the ID
Usage
eden('sql')->insertRow(*string $table, *array $setting, bool|array $bind);
Parameters
*string $table
- Table name*array $setting
- Key/value array matching table columnsbool|array $bind
- Whether to compute with binded variables
Returns Eden\Sql\Index
Example
eden('sql')->insertRow('foo', array('foo' => 'bar'));
====
insertRows
Inserts multiple rows into a table
Usage
eden('sql')->insertRows(*string $table, array $setting, bool|array $bind);
Parameters
*string $table
- Table namearray $setting
- Key/value 2D array matching table columnsbool|array $bind
- Whether to compute with binded variables
Returns Eden\Sql\Index
Example
eden('sql')->insertRows('foo');
====
model
Returns model
Usage
eden('sql')->model(array $data);
Parameters
array $data
- The initial data to set
Returns Eden\Sql\Model
Example
eden('sql')->model();
====
query
Queries the database
Usage
eden('sql')->query(*string $query, array $binds);
Parameters
*string $query
- The query to ranarray $binds
- List of binded values
Returns array
Example
eden('sql')->query('foo');
====
search
Returns search
Usage
eden('sql')->search(string|null $table);
Parameters
string|null $table
- Table name
Returns Eden\Sql\Search
Example
eden('sql')->search();
====
select
Returns the select query builder
Usage
eden('sql')->select(string|array $select);
Parameters
string|array $select
- Column list
Returns Eden\Sql\Select
Example
eden('sql')->select();
====
setBinds
Sets all the bound values of this query
Usage
eden('sql')->setBinds(*array $binds);
Parameters
*array $binds
- key/values to bind
Returns Eden\Sql\Index
Example
eden('sql')->setBinds(array('foo' => 'bar'));
====
setCollection
Sets default collection
Usage
eden('sql')->setCollection(*string $collection);
Parameters
*string $collection
- Collection class name
Returns Eden\Sql\Index
Example
eden('sql')->setCollection('foo');
====
setModel
Sets the default model
Usage
eden('sql')->setModel(*string Model);
Parameters
*string Model
- class name
Returns Eden\Sql\Index
Example
eden('sql')->setModel('foo');
====
setRow
Sets only 1 row given the column name and the value
Usage
eden('sql')->setRow(*string $table, *string $name, *scalar|null $value, *array $setting);
Parameters
*string $table
- Table name*string $name
- Column name*scalar|null $value
- Column value*array $setting
- Key/value array matching table columns
Returns Eden\Sql\Index
Example
eden('sql')->setRow('foo', 'foo', $value, array('foo' => 'bar'));
====
update
Returns the update query builder
Usage
eden('sql')->update(string|null $table);
Parameters
string|null $table
- Name of table
Returns Eden\Sql\Update
Example
eden('sql')->update();
====
updateRows
Updates rows that match a filter given the update settings
Usage
eden('sql')->updateRows(*string $table, *array $setting, array|string $filters, bool|array $bind);
Parameters
*string $table
- Table name*array $setting
- Key/value array matching table columnsarray|string $filters
- Filters to test againstbool|array $bind
- Whether to compute with binded variables
Returns Eden\Sql\Index
Example
eden('sql')->updateRows('foo', array('foo' => 'bar'));
====
Contributions to Eden are following the Github work flow. Please read up before contributing.
##Setting up your machine with the Eden repository and your fork
- Fork the repository
- Fire up your local terminal create a new branch from the
v4
branch of your fork with a branch name describing what your changes are. Possible branch name types:- bugfix
- feature
- improvement
- Make your changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message")
##Making pull requests
- Please ensure to run
phpunit
before making a pull request. - Push your code to your remote forked version.
- Go back to your forked version on GitHub and submit a pull request.
- An Eden developer will review your code and merge it in when it has been classified as suitable.