Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/katsew/oq-mapper
- Owner: katsew
- Created: 2017-06-29T04:57:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-20T11:50:29.000Z (over 7 years ago)
- Last Synced: 2025-01-14T21:00:14.707Z (29 days ago)
- Topics: javascript, json, mapper, nodejs, parser, pegjs, sql, sql-parser
- Language: JavaScript
- Homepage:
- Size: 74.2 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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"
}
]
}
]
...
]
```