aareon-france / sql-attributes-parser
Parser of SQL attributes, which offers the ability to add metadata on SQL queries.
Requires
- php: >=8.3
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.56.1
- phpstan/extension-installer: 1.3.1
- phpstan/phpstan: 1.11.0
- phpstan/phpstan-deprecation-rules: 1.2.0
- phpstan/phpstan-phpunit: 1.4.0
- phpstan/phpstan-strict-rules: 1.6.0
- phpstan/phpstan-symfony: 1.4.0
- phpunit/phpunit: 10.5.20
- roave/security-advisories: dev-latest
- vimeo/psalm: 5.24.0
This package is auto-updated.
Last update: 2024-08-16 12:30:22 UTC
README
This repository provides a way to parse SQL attributes, which offers the ability to add metadata on SQL queries.
Table of contents
SQL attributes syntax
This parser will allow you to parse SQL attributes that are attached to any SQL statement or expression into an SQL query. SQL attributes are unofficial ways to add some metadata on SQL statements and expressions in order to apply specific behaviors or automated processes regarding the SQL query the attributes are attached on. In this way, they acts like PHP Attributes.
Examples
Attributes are applicable on statements:
#[StatementAttribute] CREATE TABLE `myTable`…
They are also applicable on expressions:
SELECT #[ExprAttribute] `myField` FROM `myTable`;
Attributes can own arguments to vary the specific behaviors the processors of those attributes may have:
#[Since(version: 8.0.5, dbms_list: 'mysql,pgsql,oracle')]
The arguments are mandatory to be named, and their values are always interpreted as strings. To allow characters
separators like :
or ,
in your values, you must wrap the value of your argument with simple quotes ('
) or double
quotes ("
).
SQL Attribute definition
The EBNF for the syntax of attributes is:
attribute = "#[", attribute-name, [ attribute-arguments ], "]"; attribute-name = uppercase-letter, { letter / digit }; attribute-arguments = "(", { attribute-argument, ",{[ ]}" }, ")"; attribute-argument = {letter / digit / "_" / "-"}, ":{[ ]}", ["'" / '"'], STRING, ["'" / '"']; uppercase-letter = "A" .. "Z"; lowercase-letter = "a" .. "z"; letter = [uppercase-letter / lowercase-letter] digit = "0" .. "9";
Installation
Via composer, you can add the repository in your composer.json by doing:
composer require aareon-france/sql-attributes-parser