This repo is @deprecated - please use https://github.com/querytechnology/tqc-php instead
With TinyQueries you can create a REST API in which the endpoints are mapped directly to database queries, without an intermediate object layer. The queries can be created either by plain SQL or by a compiler which compiles object oriented notation into SQL. It's based on two components:
- A query compiler - it's like a Less for SQL, so you create SQL queries by compiling them.
- A simple and powerful syntax to combine the output of queries into nested structures.
Why
Although you can create REST API's with ORM frameworks as well, TinyQueries has several advantages:
- It's much faster than ORM.
- As a developer you are not bothered with setting up a complex object hierarchy.
- TinyQueries can be connected to any existing database, which is much harder with ORM.
- You still have the advantage of object oriented notation for queries.
- You still have all freedom to do any SQL you want - even in object notation - which is impossible with ORM.
System Requirements
- PHP 5.3 or higher
- PHP's PDO database layer should be installed
- PHP's cURL lib should be enabled
- A SQL database
Installation
NOTE: This package is especially usefull if you want to integrate TinyQueries with an existing PHP application. However if you want to start from scratch it's recommended to use TinyQueries API version instead which requires less configuration.
-
If you use Composer then update your composer.json file as follows:
composer require tiny-queries/tiny-queries:^v3
Alternatively, instead of using Composer you could just download the ZIP-file and put the content in the folder where you put your libs.
-
Create a folder
queries
in your project folder. Within this folder create three subfolderssql
,interface
andtiny
. So you have:-
queries
the main query folder -
queries/interface
this folder will be used to store compiled json files -
queries/sql
this folder will be used to store compiled SQL files -
queries/tiny
this folder will be used to store your TinyQueries source files
Ensure that this folder is not accessible through http (so in case you use Apache add a .htaccess file)
-
-
Use the file
config/config.template.xml
to set the database credentials and save it asconfig/config.xml
. -
In
config.xml
you should specify the path to the folderqueries/tiny
in<compiler input="[path-to-queries-tiny-folder]" />
-
In
config.xml
you should specify the path to the folderqueries
in<compiler output="[path-to-queries-folder]" />
-
Create a file
_model.json
inside the folderqueries/tiny
which has the following content:/** * Model for my project * */ { }
-
Create a file
_project.json
inside the folderqueries/tiny
which has the following content:/** * Projectfile * */ { id: "my-project" }
Your project is now ready to be compiled. You can choose to compile using the online IDE or compile from the commandline. Please check http://docs.tinyqueries.com for more info.