oq-mapper
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

Abstract

Object/Query mapper for Node.js.

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

Package Sidebar

Install

npm i oq-mapper

Weekly Downloads

0

Version

0.3.0

License

MIT

Last publish

Collaborators

  • katsew