Download the PHP package zethika/virtual-sql without Composer
On this page you can find all versions of the php package zethika/virtual-sql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package virtual-sql
Virtual SQL
Virtual SQL is a class-based abstraction layer for MySQL, designed to help with programmatically writing MySQL
queries.
It allows working with query structures via a singular VirtualSqlQuery class, abstracting the actual MySQL syntax away
from consideration.
Installation
Table definitions
Virtual SQL provides a class (VirtualSqlTable) for defining a database table and its columns, which needs to be used
when working with queries towards those tables.
These table definitions can be generated at runtime, by providing a PDO instance to the
VirtualSqlTableDefinitionGenerator Singleton.
It can then extract the CREATE TABLE definition directly from the database and provide an instance representing a given
table.
The CREATE TABLE statements extracted from the database is kept in memory, to minimize excess SQL queries from repeated calls to the same table.
Queries
Queries are built using child classes of VirtualSqlQuery and is the programmatic interface, with which the runtime
builds the query.
They provide a series of helper functions, depending on which type of query that's being built, for easier manipulation
of the query parts.
Query instances can be generated by providing the VirtualSqlQuery::factory method a type constant, and a VirtualSqlTable
instance for the base table.
Supported types are TYPE_SELECT, TYPE_INSERT, TYPE_UPDATE and TYPE_DELETE
Query config parameter
A third parameter can be provided to the factory method, an associative array $config.
This can be used to set most values in a query at instantiation.
The possible keys for it depends on the specific Query type. All values set via the $config parameter can also be manipulated via method calls after instantiation.
SELECT
INSERT
UPDATE
DELETE
Full example
Helpers
Depending on which type of VirtualSqlQuery is being worked, there are a number of helper methods present on the instance to add / manipulate the various parts.
For example to create joins on a select query, there is "innerJoin", "leftJoin", "rightJoin" and "outerJoin" methods which take a $from & $to column, as well as optionally a condition set
Conditions
Virtual SQL uses VirtualSqlCondition instances to describe individual conditions and VirtualSqlConditionSet to describe sets of conditions.
To help build them, there are 3 helper methods on VirtualSqlQuery "andX", "orX" and "condition".
"andX" and "orX" takes an arbitrary number of parameters of either VirtualSqlCondition or VirtualSqlConditionSets.
After instantiation, conditions may still be manipulated and added / removed to, as would be expected.
All versions of virtual-sql with dependencies
ext-pdo Version *
ext-mbstring Version *