packagek-kinzal/sql-semantics-mysql

MySQL statement models, SQL reconstruction, and schema binding for SQL Semantics

Namespaces§

Documents 1§

README§

SQL Semantics for MySQL

License: MIT Docs PHP Version Ask DeepWiki

SQL Semantics for MySQL adds MySQL to SQL Semantics: the typed statement models of the official MySQL grammars and the MySQL rules for schema binding. Installing it also installs the shared SQL Semantics runtime, and Dialect::MySql selects MySQL in the runtime's Semantics, Schema, and Binder. No database connection is needed.

Requirements

  • PHP 8.1+ with the zlib extension

Support Syntax

The following grammar versions are supported. Pass the version tag as the second argument of Semantics or the third argument of Schema; omitting it uses the default. State declarations support all listed versions; SELECT binding with Binder requires MySQL 8.0 or later.

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

Installation

composer require k-kinzal/sql-semantics-mysql

Usage

use SqlSemantics\Facade\Semantics;
use SqlSemantics\Platform\MySql\Dialect;

$statement = (new Semantics(Dialect::MySql))->analyze("INSERT INTO users (id, name) VALUES (1, 'Alice') ON DUPLICATE KEY UPDATE name = 'Alice'");

$statement->toString(); // "INSERT INTO users ( id , name ) VALUES( 1 , 'Alice' ) ON DUPLICATE KEY UPDATE name = 'Alice'"

See the SQL Semantics documentation for statement models and schema binding.

License

MIT License. See LICENSE for details.