项目作者: ChopperLee2011

项目描述 :
Load a JSON/JS object file to Mysql.
高级语言: JavaScript
项目地址: git://github.com/ChopperLee2011/json2mysql.git
创建时间: 2017-06-15T12:01:22Z
项目社区:https://github.com/ChopperLee2011/json2mysql

开源协议:MIT License

下载


json2mysql

NPM version
Build Status
Downloads
Code Style

A tool to load a JSON/JS object file to Mysql.

Install

  1. npm i json2mysql

Usage

  1. import json2mysql from "json2mysql"
  2. const dbconfig = {}
  3. const jm = json2mysql(dbconfig)
  4. jm.load(tableName, file)
  5. jm.replace(tableName, file)

Methods

  • load: this will disable foreign key, remove table rows , then load json and enable foreign key
  • replace: this will replace table rows with json file, by comparing table id with array index

Test

  • docker-compose up -d will create database container
  • create a test table in your database:
    1. CREATE TABLE `user` (
    2. `id` mediumint(9) NOT NULL AUTO_INCREMENT,
    3. `name` text,
    4. `team_id` int(11) DEFAULT NULL,
    5. PRIMARY KEY (`id`)
    6. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  • npm test

License

MIT © [chopperlee]