prql-php
prql-php offers PHP bindings to prql-compiler crate through FFI.
It provides the Compiler class which contains compile, prqlToPL, plToRQ and rqToSQL functions.
It’s still at an early stage, and isn’t published to Composer. Contributions are welcome.
Installation
The PHP FFI extension needs to be enabled. Set ffi.enable in your php.ini configuration file to "true".
Usage
1. <?php
3. use Prql\Compiler\Compiler;
5. $prql = new Compiler();
6. $result = $prql->compile("from employees");
8. echo $result->output;
Development
Environment
A way to establish a dev environment with PHP, the ext-ffi extension and Composer is to use a nix flake. After installing nix, enable experimental flakes feature:
1. mkdir -p ~/.config/nix
2. echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
Now you can spawn a shell from prql-php/:
1. nix shell github:loophp/nix-shell#env-php81 --impure
This will pull-in ext-ffi extension, because it’s declared in composer.json.
Building
There is a task build-php script that:
- runs cargo to build
libprqlc_lib, - copies
libprqlc_lib.*intolib, - copies
libprqlc_lib.hintolib.
Tests
1. task build-php
2. task test-php
Code style
1. ./vendor/bin/phpcs --standard=PSR12 src tests
