Search by

k-kinzal / sql-faker

kinzal

Faker Provider for generating syntactically valid SQL statements

v0.1.1 2026-03-06 16:07 UTC

This package is auto-updated.

Last update: 2026-09-12 15:30:41 UTC


README

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

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.