diff --git a/index.js b/index.js index b335796..58ac3dd 100644 --- a/index.js +++ b/index.js @@ -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 = {}; diff --git a/lib/README.md b/lib/README.md new file mode 100644 index 0000000..99b37b1 --- /dev/null +++ b/lib/README.md @@ -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 | diff --git a/lib/package.json b/lib/package.json new file mode 100644 index 0000000..37b53f5 --- /dev/null +++ b/lib/package.json @@ -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": {} +} diff --git a/sql2csv.js b/lib/sql2csv.js similarity index 100% rename from sql2csv.js rename to lib/sql2csv.js diff --git a/package.json b/package.json index 15f27c7..3d47db4 100644 --- a/package.json +++ b/package.json @@ -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" }