k-kinzal / sql-faker
Faker Provider for generating syntactically valid SQL statements
Requires
- php: ^8.1
- fakerphp/faker: ^1.23
Requires (Dev)
- brianium/paratest: ^6.11 || ^7
- friendsofphp/php-cs-fixer: ^3.92
- infection/infection: ^0.28 || ^0.29 || ^0.30 || ^0.31 || ^0.32
- k-kinzal/testcontainers-php: ^0.5.1
- nikic/php-fuzzer: ^0.0.11
- phpbench/phpbench: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5 || ^11 || ^12 || ^13
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
SQL Faker is a grammar-based SQL generator for MySQL, PostgreSQL, and SQLite. It derives random statements and SQL fragments from official grammar definitions and provides both a FakerPHP provider interface and a direct SqlGenerator interface. Generation plans let you select syntax and constrain its structure. Generated SQL does not require a database connection; its execution and semantic validity are subject to the algorithm's limitations.
Requirements
- PHP 8.1 or higher
- fakerphp/faker ^1.23
Support Syntax
The following grammar versions are bundled. Pass the version tag to select a grammar; omitting it uses the default for that database. Syntax availability depends on the selected version.
MySQL
| Version | Version tag | Default |
|---|---|---|
| 5.6.51 | mysql-5.6.51 |
|
| 5.7.44 | mysql-5.7.44 |
|
| 8.0.44 | mysql-8.0.44 |
|
| 8.1.0 | mysql-8.1.0 |
|
| 8.2.0 | mysql-8.2.0 |
|
| 8.3.0 | mysql-8.3.0 |
|
| 8.4.7 | mysql-8.4.7 |
Yes |
| 9.0.1 | mysql-9.0.1 |
|
| 9.1.0 | mysql-9.1.0 |
PostgreSQL
| Version | Version tag | Default |
|---|---|---|
| 17.2 | pg-17.2 |
Yes |
SQLite
| Version | Version tag | Default |
|---|---|---|
| 3.47.2 | sqlite-3.47.2 |
Yes |
Installation
composer require --dev k-kinzal/sql-faker
Usage
use Faker\Factory; use SqlFaker\MySqlProvider; $faker = Factory::create(); $faker->addProvider(new MySqlProvider($faker)); $sql = $faker->sql(maxDepth: 6); $select = $faker->selectStatement(maxDepth: 6);
License
MIT License. See LICENSE for details.