https://github.com/qazcetelic/sqlimagine
A DSL for quickly and easily designing SQL databases 🗃️.
https://github.com/qazcetelic/sqlimagine
antlr4 domain-specific-language kotlin parser prototyping-tool relational-databases sql
Last synced: 10 months ago
JSON representation
A DSL for quickly and easily designing SQL databases 🗃️.
- Host: GitHub
- URL: https://github.com/qazcetelic/sqlimagine
- Owner: QazCetelic
- License: lgpl-2.1
- Created: 2022-03-13T13:26:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T12:30:43.000Z (over 2 years ago)
- Last Synced: 2025-03-30T21:45:53.734Z (over 1 year ago)
- Topics: antlr4, domain-specific-language, kotlin, parser, prototyping-tool, relational-databases, sql
- Language: Kotlin
- Homepage:
- Size: 638 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#  SQLImagine
A tool for quickly and easily designing SQL databases using a DSL and export it to [SQL](#sql-script-export).
## Domain Specific Language
### Syntax
SQLImagine allows for defining tables, attributes, and relationships.
I recommend using [YAML](https://yaml.org) syntax highlighting because the DSL's syntax has a few similarities.
The recommended file extension is `.sqli`.
```yaml
# It's possible to add comments.
Car:
# The '!' means it's a primary key field.
!name (Str)
produced (Date)
manufacturer (Str) -> Manufacturer.name
color (Str)
price (Dec)
self_driving (Bool)
Manufacturer:
name (Str)
founded (Date)
headquarters (Str)
employees (Int)
# The '?' signifies it's nullable.
parent_company? (Str) -> Manufacturer.name
```
### Usage
Parsing is done using the `ParseInstance` class. It's created with a script as a string.
```kotlin
val scriptFile: File = …
val script: String = scriptFile.readText()
val parsed = ParseInstance(sqli)
// Print out a formatted version of the script.
println(parsed)
```
The parser is also able to reformat existing scripts by calling `.serialize()` on the created `ParseInstance`.
The class also has several accessible properties:
| Property | Description |
|:----------:|:-----------------------------------------------------------------|
| `tables` | All parsed tables |
| `errors` | All errors, issues that prevent the script from properly parsing |
| `warnings` | All warnings, issues that aren't critical but do require changes |
| `success` | Whether there are any critical issues |
| `time` | The amount of milliseconds it took to parse the DSL |
## SQL script export
You can export the parsed DSL as a SQL script by using the `Sequelizer` class on the parsed DSL.
```kotlin
val sequelizer = Sequelizer("test_db")
val sql: String = sequelizer.sequelize(parsed)
```
