All Projects → crodas → SQLParser

crodas / SQLParser

Licence: MIT license
SQL-Parser

Programming Languages

PHP
23972 projects - #3 most used programming language
Yacc
648 projects

Projects that are alternatives of or similar to SQLParser

postgresql-parser
Pure Golang PostgreSQL (SQL:2011, SQL:2008, SQL:2003, SQL:1999, and SQL-92 Standard) Parser
Stars: ✭ 165 (+1169.23%)
Mutual labels:  sql-parser
sql-parser
解析 mysql create table 语句,用于通过建表语句生成 model 代码文件。
Stars: ✭ 17 (+30.77%)
Mutual labels:  sql-parser
PHP-Light-SQL-Parser
This class can parse SQL to get query type, tables, field values, etc.. It takes an string with a SQL statements and parses it to extract its different components. Currently the class can extract the SQL query method, the names of the tables involved in the query and the field values that are passed as parameters. This parser is pretty light re…
Stars: ✭ 23 (+76.92%)
Mutual labels:  sql-parser
sql-ddl-to-json-schema
SQL DDL to JSON Schema Converter
Stars: ✭ 138 (+961.54%)
Mutual labels:  sql-parser
sqlfun
Modern SQL parser using Bison (Yacc) and Flex
Stars: ✭ 63 (+384.62%)
Mutual labels:  sql-parser
lacquer
SQL Parser derived from Presto, written in Python with the PLY framework
Stars: ✭ 29 (+123.08%)
Mutual labels:  sql-parser
simple-ddl-parser
Simple DDL Parser to parse SQL (HQL, TSQL, AWS Redshift, BigQuery, Snowflake and other dialects) ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc. & table properties, types, domains, etc.
Stars: ✭ 76 (+484.62%)
Mutual labels:  sql-parser

SQLParser

SQL-Parser

Why?

Sometimes we need to parse and validate SQL.

What does it do?

It parses SQL (mostly MySQL's SQL) and returns the SQL query as an object. This object can be modified programmatically to generate another SQL query.

How to install?

composer install crodas/sql-parser

How to use it?

require __DIR__ . "/vendor/autoload.php";

$parser = new SQLParser;
$queries = $parser->parse("SELECT * FROM table1 WHERE id = :id");
var_dump(get_class($queries[0])); // string(16) "SQLParser\Select"
var_dump($queries[0]->getTable()[0]->getValue()); // string(6) "table1"
/*
 array(1) {
   [0] =>
   string(2) "id"
   }
*/
var_dump($queries[0]->getVariables()); 

// SELECT * FROM 'table1' WHERE 'id' = :id
echo $queries[0] . "\n";

SQLParser\Writer\SQL::setInstance(new SQLParser\Writer\MySQL);

// SELECT * FROM `table1` WHERE `id` = :id
echo $queries[0] . "\n";

TODO:

  1. Better documentation
  2. Fluent-Interface to generate SQL statements and alter the parsed content
  3. parse CREATE TABLE/ALTER TABLE (for SQLite, MySQL and PostgreSQL flavors)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].