The backend is installed on top of any database (MySQL/MariaDB, PostgreSQL, MS SQL, Sqlite) and allows you to query and modify records in all tables in JSON:API-way.
Get some records from table TABLE
http://your-server/TABLE/
Get record with id 123 from table TABLE
http://your-server/TABLE/123
Get list of tables in your DB:
http://your-server/information_schema/tables/
You can query records follow JSON:API specification.
Also, you can use filter expressions to query data.
http://your-server/TABLE/?filter=and(eq(lastName,'Smith'),gte(modified,'2021-01-01'))
Grab the code by composer and point your web server root to the folder public
Put the file directee-backend.phar
on your web server root folder and create the file index.php
<?php
require "directee-backend.phar";
Put the required settings either:
- to the file
./directee-settings.php
or../config/directee-settings.php
<?php // file directee-settings.php
return [
'data-url' => 'sqlite://path/to/database',
];
- to the global variable
$GLOBALS['directee-settings']
(usually for phar-distribution)
<?php // index.php
$GLOBALS['directee-settings'] = [
'data-url' => 'sqlite://path/to/DB',
];
require "directee-backend.phar";
Specify database connection with Doctrine database URL. Default value: sqlite://:memory:
.
'data-url' => 'pdo-mysql://user:secret@localhost:3306/mydb?charset=utf8mb4',
Specify application mode, default value: production
. In non-production mode it will show detailed error messages.
'app-mode' => 'develop',
Specify the text that will be displayed on the root entry point /
. Default value: the Directee motto.
You can specify, for example, the content of some file, for the server help page, or for the data access frontend (put others files to the web server root folder).
'front-stub' => \file_get_contents('index.html'),
Specify additional server http headers. Default value: empty.
'custom-headers' => [
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => '*',
'Access-Control-Allow-Headers' => '*',
],
You can use filter expressions (?filter=
) to query records.
/employees/?filter=and(eq(sex,'male'),lt(age,'18'))
Filter expressions are composed using the following functions:
Operation | Function | Example |
---|---|---|
Equality | eq | ?filter=eq(lastName,'Smith') |
Less than | lt | ?filter=lt(age,'25') |
Less than or equal to | lte | ?filter=lte(lastModified,'2001-01-01') |
Greater than | gt | ?filter=gt(quantity,'500') |
Greater than or equal to | gte | ?filter=gte(percentage,'33.33') |
Not equal | ne | ?filter=ne(sex,'female') |
Contains text | contains | ?filter=contains(description,'cooking') |
Starts with text | starts_with | ?filter=starts_with(description,'The') |
Ends with text | ends_with | ?filter=ends_with(description,'End') |
Equals on value from set | in | ?filter=in(chapter,'Intro','Summary','Conclusion') |
Not equal on any value from set | nin | ?filter=nin(answer,'yes','no') |
Check value in closed interval | between | ?filter=between(value,'50','59') |
Negation | not | ?filter=not(eq(lastName,null)) |
Conditional logical OR | or | ?filter=or(eq(mode,'prod'),lt(date,'2022-06-01')) |
Conditional logical AND | and | ?filter=and(eq(sex,'male'),lt(age,'18')) |
- work Level two — authorization/authentication for requests
- work level one — db schema specification for requests
- work level zero — query any databases for all its tables in jsonapi-way
Assembly directee.phar
with Box
box compile
- adopt Directee\Interfaces
- change the license to AGPL-3.0
- many fixes after field testing
- entrypoint
/information_schema/tables
to retrieve the list of tables - directee-settings (custom-headers, front-stub, app-mode)
- work level zero
AGPL-3.0