0.3.0 • Published 7 years ago

oq-mapper v0.3.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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 <file> <output>

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,

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"
          }
      ]
    }
  ]
  ...
]
0.3.0

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago