Giter Club home page Giter Club logo

json2mysql's Introduction

json2mysql

Allows to write a JSON-Object as fields into a mysql-table.

IMPORTANT: Use one instance for one type of object with one table.
If you want to use multiple json-types, create multiple instances!

Installation

Just use npm install lib-json2mysql

Usage

The Usage is simple, the config is extensive :-)

const JSON2MySQL = require('lib-json2mysql')

let j2m = new JSON2MySQL(config)

j2m.setup(callback)

Insert an Object

Just use:

j2m.add(json, callback)

Config

There are a lot of config parameters to give.
Just see config.sample.json for a full example of all options.

Required

  • table: The Name of the Table in the Database to use
  • fields: An Array of json-names mapped to MySQL-Database-Field-Types
  • mysql: An open Connection to a MySQL-Database

Optional

  • indices: An Array of fields that should be indexed
  • primary: An Array of fields that should be used as a (combined) Primary Key
  • partioning: Allows for Partioning, expects the fields "on" (name of the field) and "count"(Number of partitions)
  • engine: The Engine to use. Default is InnoDB
  • ignoreInsertError: Ignore any Insert Errors. Default is false

Testing

To Test you may install the dev-dependencies, then fire up a local database.
Then just run npm run test

json2mysql's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.