Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/katsew/oq-mapper

Object/Query mapper for Node.js
https://github.com/katsew/oq-mapper

javascript json mapper nodejs parser pegjs sql sql-parser

Last synced: 23 days ago
JSON representation

Object/Query mapper for Node.js

Awesome Lists containing this project

README

        

# Abstract

Object/Query mapper for Node.js.

:zap: Currently support only `CREATE TABLE` statement.

# Use the module as command-line tool

Install via npm.

```
npm install -g oq-mapper
```

Then, run command

```
oq-mapper
```

Output file is compatible with JSON.

# Behaviour

This query outputs...

```

CREATE TABLE IF NOT EXISTS `dvd_collection`.`movies` (
`movie_id` INT NOT NULL AUTO_INCREMENT,
`movie_title` VARCHAR(45) NOT NULL,
`release_date` DATE NULL,
PRIMARY KEY (`movie_id`))
ENGINE = InnoDB

```

This kind of object structure!

```

[
{
"dbName": "dvd_collection",
"tableName": "movies",
"pk": [
"movie_id"
],
"fields": [
{
"name": "movie_id",
"type": "int",
"sign": "signed",
"length": 0,
"min": -2147483648,
"max": 2147483647,
"bites": 4,
"allowNull": false,
"default": 0,
"autoIncrement": true
},
{
"name": "movie_title",
"type": "varchar",
"length": 0,
"allowNull": false,
"default": "",
"autoIncrement": false
},
{
"name": "release_date",
"type": "date",
"allowNull": true,
"default": "CURRENT_TIMESTAMP",
"autoIncrement": false
}
],
"constraint": [],
"index": []
}
]

```

# Features

## Parse tags in comment

When you add comment with tags, like [Go#StructTag](https://golang.org/pkg/reflect/#example_StructTag),

```

CREATE TABLE IF NOT EXISTS `dvd_collection`.`movies` (
`movie_id` INT NOT NULL AUTO_INCREMENT,
`movie_title` VARCHAR(45) NOT NULL,
`is_sold` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '`types:"0,1" strategy:"random"`',
`release_date` DATE NULL,
PRIMARY KEY (`movie_id`))
ENGINE = InnoDB

```

parse that tag, and create object like following.

```
[
...
"fields": [
{
"name": "is_sold",
...
"comment": "`types:'0, 1' strategy:'random'`",
"tags": [
{
"types": "0,1"
},
{
"strategy": "random"
}
]
}
]
...
]
```