Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sassman/edu-sql-parser-rs

SQL Types transpiles `CREATE TABLE` SQL code into type definitions in other languages such as TypeScript or Rust.
https://github.com/sassman/edu-sql-parser-rs

compiler languages parser rust sql sql-parser transpiler typegen typescript

Last synced: 3 days ago
JSON representation

SQL Types transpiles `CREATE TABLE` SQL code into type definitions in other languages such as TypeScript or Rust.

Awesome Lists containing this project

README

        

## SQL Types

WIP: SQL Types transpiles `CREATE TABLE` SQL code into type definitions in other languages such as TypeScript or Rust.

## Syntax

Basic syntax rules:
```ebnf
::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

::= a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

::= !!any character.

::= $

::= "

::= _

::= |

::= { | } [{ | | | | }...]

::= ...

// note: original definition is instead of
::=
```

### Create Table Syntax

Currently Work in progress

```
// simplified version
CREATE [ ]
[
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[COMMENT ]
[]
[]

// simplified version
::= [ COLUMN ] TABLE
::= [.]

// simplified version
::=
(, ...) []

::=
[ ]
|

::= { | }
[ ]
[ ]
[ ]
[ | ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ COMMENT ]
[ ]
[ ]

::=

::=
DATE
| TIME
| SECONDDATE
| TIMESTAMP
| TINYINT
| SMALLINT
| INT
| BIGINT
| SMALLDECIMAL
| REAL
| DOUBLE
| TEXT
| BINTEXT
| VARCHAR [ () ]
| NVARCHAR [ () ]
| ALPHANUM [ () ]
| VARBINARY [ () ]
| SHORTTEXT [ () ]
| DECIMAL [ ( [, ]) ]
| FLOAT [ () ]
| BOOLEAN

::= DEFAULT

::=
NULL
|
|
|

::=
CURRENT_DATE
| CURRENT_TIME
| CURRENT_TIMESTAMP
| CURRENT_UTCDATE
| CURRENT_UTCTIME
| CURRENT_UTCTIMESTAMP

::=

::=
NULL
| NOT NULL
| { HIDDEN | NOT HIDDEN }
| [ ]
| [ ]

::=
UNIQUE [ ]
| PRIMARY KEY [ | ]

::= { BTREE | CPBTREE }
::= INVERTED [ ]
::= { HASH | VALUE | INDIVIDUAL }

```

[hana/sql]: https://help.sap.com/doc/9b40bf74f8644b898fb07dabdd2a36ad/2.0.04/en-US/SAP_HANA_SQL_Reference_Guide_en.pdf

## Usage

there is a little interactive shell to enter SQL and get parsed AST expressions back.

```sh
❯ cargo run
>>> x
Parsing error at line 1 column 1. No repair sequences found.
>>> CREATE TABLE abc(A INT)
Expr (create table): abc
```

## License

- **[GNU GPL v3 license](https://www.gnu.org/licenses/gpl-3.0)**
- Copyright 2020 © [Sven Assmann][2].

[2]: https://www.d34dl0ck.me
[4]: https://github.com/sassman/sql-types-rs/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22
[5]: https://github.com/sassman/sql-types-rs/issues/new/choose