All Projects → mmzp → sql-parser

mmzp / sql-parser

Licence: Apache-2.0 License
解析 mysql create table 语句,用于通过建表语句生成 model 代码文件。

Programming Languages

javascript
184084 projects - #8 most used programming language
Nearley
35 projects
HTML
75241 projects

Projects that are alternatives of or similar to 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 (+35.29%)
Mutual labels:  sql-parser
sql-ddl-to-json-schema
SQL DDL to JSON Schema Converter
Stars: ✭ 138 (+711.76%)
Mutual labels:  sql-parser
sqlfun
Modern SQL parser using Bison (Yacc) and Flex
Stars: ✭ 63 (+270.59%)
Mutual labels:  sql-parser
lacquer
SQL Parser derived from Presto, written in Python with the PLY framework
Stars: ✭ 29 (+70.59%)
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 (+347.06%)
Mutual labels:  sql-parser
SQLParser
SQL-Parser
Stars: ✭ 13 (-23.53%)
Mutual labels:  sql-parser
postgresql-parser
Pure Golang PostgreSQL (SQL:2011, SQL:2008, SQL:2003, SQL:1999, and SQL-92 Standard) Parser
Stars: ✭ 165 (+870.59%)
Mutual labels:  sql-parser

sql-parser

解析 mysql create table 语句,用于通过建表语句生成 model 代码文件。

yarn install @mmzp/sql-parser
yarn dev

npm i @mmzp/sql-parser
npm run dev
// 构建支持浏览器环境的代码文件,浏览器端直接引用构建出来的 browser/sql-parser.min.js 文件即可,browser/demo.html 为调用示例

yarn browser
或
npm run browser

在线示例 https://mmzp.github.io/sql-parser/browser/demo.html


解析结果如下:

[
    {
        "type": "create_table",
        "name": "tbl1",
        "columns": [
            {
                "type": "column",
                "name": "id",
                "data_type": {
                    "type": "INT",
                    "params": [10],
                    "unsigned": true
                },
                "allow_null": false,
                "comment": "",
                "auto_increment": true
            },
            {
                "type": "column",
                "name": "name",
                "data_type": {
                    "type": "VARCHAR",
                    "params": [50]
                },
                "allow_null": true,
                "comment": "",
                "default_value": ""
            },
            {
                "type": "column",
                "name": "weight",
                "data_type": {
                    "type": "DECIMAL",
                    "params": [5, 2]
                },
                "allow_null": true,
                "comment": ""
            },
            {
                "type": "column",
                "name": "roles_BIT",
                "data_type": {
                    "type": "BIT",
                    "params": [10]
                },
                "allow_null": true,
                "comment": ""
            },
            {
                "type": "column",
                "name": "size",
                "data_type": {
                    "type": "ENUM",
                    "params": ["x-small", "small", "medium", "large", "x-large"]
                },
                "allow_null": true,
                "comment": ["尺寸"]
            },
            {
                "type": "column",
                "name": "type",
                "data_type": {
                    "type": "TINYINT",
                    "params": [3],
                    "unsigned": true
                },
                "allow_null": false,
                "comment": "客户端类型,0:未知;1:微信小程序;",
                "default_value": 0
            },
            {
                "type": "column",
                "name": "t",
                "data_type": {
                    "type": "TIMESTAMP"
                },
                "allow_null": false,
                "comment": "",
                "default_value": "CURRENT_TIMESTAMP"
            },
            {
                "type": "column",
                "name": "url",
                "data_type": {
                    "type": "VARCHAR",
                    "params": [255]
                },
                "allow_null": false,
                "comment": "地址",
                "default_value": "",
                "charset": "utf8"
            },
            {
                "type": "primary_key",
                "fields": ["id"]
            },
            {
                "type": "unique_key",
                "name": "uniq_name",
                "fields": ["name"]
            },
            {
                "type": "index_key",
                "name": "idx_app_id",
                "fields": ["app_id", "id"]
            }
        ],
        "options": [
            {
                "key": "ENGINE",
                "value": "InnoDB"
            },
            {
                "key": "AUTO_INCREMENT",
                "value": 2
            },
            {
                "key": "CHARSET",
                "value": "utf8mb4"
            },
            {
                "key": "COMMENT",
                "value": "应用表"
            }
        ]
    }
]
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].