json2mysql

0.3.3 • Public • Published

json2mysql

NPM version Build Status Downloads Code Style

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

Install

npm i json2mysql

Usage

import json2mysql from "json2mysql"
 
const dbconfig = {}
const jm = json2mysql(dbconfig)
jm.load(tableName, file)
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:
  CREATE TABLE `user` (
     `id` mediumint(9NOT NULL AUTO_INCREMENT,
     `name` text,
     `team_id` int(11) DEFAULT NULL,
     PRIMARY KEY (`id`)
   ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  • npm test

License

MIT © [chopperlee]

/json2mysql/

    Package Sidebar

    Install

    npm i json2mysql

    Weekly Downloads

    7

    Version

    0.3.3

    License

    MIT

    Last publish

    Collaborators

    • chopperlee2011