1. Go to this page and download the library: Download ddbase3/php-struql library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ddbase3 / php-struql example snippets
use Struql\Processor\NormalizePhaseProcessor;
use Struql\Processor\CompilePhaseProcessor;
use Struql\Handler\DollarFieldToFieldHandler;
use Struql\Handler\FieldsToWhereHandler;
use Struql\Handler\SqlCompilerHandler;
use Struql\Handler\SqlDialect;
// Normalization
$normalize = new NormalizePhaseProcessor();
$normalize->addHandler(new DollarFieldToFieldHandler());
$normalize->addHandler(new FieldsToWhereHandler());
$query = $normalize->process([
'type' => 'selectUser',
'$user!optional.status' => 'active',
'limit' => 10,
'offset' => 20,
'orderBy' => [
(object)[ 'type' => 'field', 'table' => 'user', 'name' => 'id', 'direction' => 'DESC' ]
]
]);
// Compilation
$compile = new CompilePhaseProcessor();
$compile->addHandler(new SqlCompilerHandler(SqlDialect::MySQL));
$sql = $compile->process($query);
echo $sql;
class MyCustomHandler extends AbstractHandler {
public function supportedTypes(): array {
return ['object'];
}
public function run(mixed $input, array &$context): mixed {
// Transform the $input as needed
return $input;
}
}