documentSQL Faker

README.md

SQL Faker

License: MIT Docs PHP Version Ask DeepWiki

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

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

VersionVersion tagDefault
5.6.51mysql-5.6.51
5.7.44mysql-5.7.44
8.0.44mysql-8.0.44
8.1.0mysql-8.1.0
8.2.0mysql-8.2.0
8.3.0mysql-8.3.0
8.4.7mysql-8.4.7Yes
9.0.1mysql-9.0.1
9.1.0mysql-9.1.0

PostgreSQL

VersionVersion tagDefault
17.2pg-17.2Yes

SQLite

VersionVersion tagDefault
3.47.2sqlite-3.47.2Yes

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.