Change to only include base class when using npm

This commit is contained in:
danbulant 2019-09-28 19:30:41 +02:00
parent 4c37e62385
commit 377d1ba3e7
5 changed files with 54 additions and 3 deletions

View file

@ -1,5 +1,5 @@
const fs = require("fs");
const sql2csv = require("./sql2csv");
const sql2csv = require("./lib/sql2csv");
const mysql = require("mysql");
const configLoc = "config.yml";
var config = {};

39
lib/README.md Normal file
View file

@ -0,0 +1,39 @@
# Installation
(!https://img.shields.io/npm/v/auto-sql2csv/latest)[https://www.npmjs.com/package/auto-sql2csv]
Run `npm install auto-sql2csv`.
# Why?
This project was made for database reporting.
Auto in the first is because that sql2csv is already taken by CLI abandoned 5 year old project.
# Usage
Usage is pretty straight forward. Currently this package has support only for mysql driver, but others may work when they have similar syntax (conn.query(str, (err, result)=>{})).
## Options
| name | default | description |
|----------------|--------------|----------------------------------------------------------------------|
| prefix | '[SQL2CSV] ' | Prefix to use when logging |
| conn | null | Connection to use, must be created outside |
| colors | true | Whether to use colors or not when logging |
| crlf | false | Use windows crlf instead of linux lf on line ends |
| skipMysqlCheck | false | Skip check for mysql driver (doesn't do anything other than warning) |
| showNames | false | Show column names in first row |
| logging | false | Log to console |
## Methods
| name | parameters | description |
|---------------|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| log | string to log | Logs to console using prefix + string |
| colorLog | string to log, color | Same as log but with color prefix parameter, used to disable coloring when colors: false |
| warn | string to warn | Same as log but with yellow color |
| constructor | options | Run when class instanciated, options are optional |
| query | sql | This is where magic happens. Runs MySQL query and converts result (if any) to csv. Using promise. Rejected when empty result or error happens. |
| setOption | option name, new value | Sets new value to option |
| setOptions | options | Overwrites options object with the one provided |
| setConnection | conn | Sets new connection |

11
lib/package.json Normal file
View file

@ -0,0 +1,11 @@
{
"name": "auto-sql2csv",
"version": "1.0.1",
"description": "Convert MySQL output to csv format, without dependencies",
"main": "sql2csv.js",
"scripts": {},
"author": "Daniel Bulant (https://danbulant.eu)",
"license": "MIT",
"repository": "https://github.com/danbulant/sql2csv",
"dependencies": {}
}

View file

@ -1,5 +1,5 @@
{
"name": "sql2csv",
"name": "auto-sql2csv",
"version": "1.0.0",
"description": "Convert MySQL output to csv format, without dependencies",
"main": "index.js",
@ -7,7 +7,8 @@
"start": "node index.js"
},
"author": "Daniel Bulant (https://danbulant.eu)",
"license": "ISC",
"license": "MIT",
"repository": "https://github.com/danbulant/sql2csv",
"dependencies": {
"mysql": "^2.17.1"
}