prql-php

prql-php offers PHP bindings to prqlc 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
  2. use Prql\Compiler\Compiler;
  3. $prql = new Compiler();
  4. $result = $prql->compile("from employees");
  5. 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_c,
  • copies libprqlc_c.* into lib,
  • copies prqlc.h into lib.

Tests

  1. task build-php
  2. task test-php

Code style

  1. ./vendor/bin/phpcs --standard=PSR12 src tests