https://github.com/webdad/json2mysql
Allows to write a JSON-Object as fields into a mysql-table
https://github.com/webdad/json2mysql
Last synced: about 1 month ago
JSON representation
Allows to write a JSON-Object as fields into a mysql-table
- Host: GitHub
- URL: https://github.com/webdad/json2mysql
- Owner: WebDaD
- Created: 2019-01-10T08:43:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-16T10:16:39.000Z (over 7 years ago)
- Last Synced: 2025-02-19T04:28:37.373Z (over 1 year ago)
- Language: JavaScript
- Size: 35.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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`