Skip to content

Commit 1a969fc

Browse files
committed
1.0.0: Initial commit
- buffer mode is now working; depends on gulp-buffer
1 parent 06727d2 commit 1a969fc

21 files changed

+385
-811
lines changed

.vscode/launch.json

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,13 @@
3838
"request": "launch",
3939
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
4040
"stopOnEntry": false,
41-
"args": ["--gulpfile", "./debug/gulpfile.ts", "runTapCsvBuffer"],
41+
"args": ["--gulpfile", "./debug/gulpfile.ts", "runMysqlAdapterBuffer"],
4242
"cwd": "${workspaceRoot}",
4343
"runtimeArgs": [
4444
"--nolazy", "-r", "ts-node/register"
4545
],
4646
"console": "internalConsole",
4747
"env": {"DEBUG_LEVEL":"debug"}
4848
},
49-
{
50-
"name": "csvParseWithoutGulp",
51-
"type": "node",
52-
"request": "launch",
53-
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
54-
"stopOnEntry": false,
55-
"args": ["--gulpfile", "./debug/gulpfile.ts", "csvParseWithoutGulp"],
56-
"cwd": "${workspaceRoot}",
57-
"runtimeArgs": [
58-
"--nolazy", "-r", "ts-node/register"
59-
],
60-
"console": "internalConsole",
61-
"env": {"DEBUG_LEVEL":"info"}
62-
},
63-
{
64-
"name": "aws-doParse: debug TS w/o transpile using ts-node",
65-
"type": "node",
66-
"request": "launch",
67-
"args": ["src/aws/dev-handler.ts"],
68-
"runtimeArgs": ["-r", "ts-node/register"],
69-
"cwd": "${workspaceRoot}",
70-
"protocol": "inspector",
71-
"internalConsoleOptions": "openOnSessionStart",
72-
},
7349
]
7450
}

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# gulp-etl-tap-mysql #
1+
# gulp-etl-mysql-adapter #
22

3-
This plugin connects to **MySQL** databases, running SQL queries and extracting the results to **gulp-etl** **Message Stream** files. It is a **gulp-etl** wrapper for [mysql](https://www.npmjs.com/package/mysql).
3+
This plugin connects to **MySQL** databases, running SQL queries and extracting the resulting rows to **gulp-etl** **Message Stream** files. It is a **gulp-etl** wrapper for [mysql](https://www.npmjs.com/package/mysql).
44

55
This is a **[gulp-etl](https://gulpetl.com/)** tap, but unlike most of the other gulp-etl modules it is not a [gulp](https://gulpjs.com/) **[plugin](https://gulpjs.com/docs/en/getting-started/using-plugins)**; it is actually a **[vinyl adapter](https://gulpjs.com/docs/en/api/concepts#vinyl-adapters)**--it features a replacement for **[gulp.src()](https://gulpjs.com/docs/en/api/src)**. **gulp-etl** plugins and adapters work with [ndjson](http://ndjson.org/) data streams/files which we call **Message Streams** and which are compliant with the [Singer specification](https://github.com/singer-io/getting-started/blob/master/docs/SPEC.md#output). In the **gulp-etl** ecosystem, **taps** tap into an outside format or system (in this case, a MySQL database) and convert their contents/output to a Message Stream, and **targets** convert/output Message Streams to an outside format or system. In this way, these modules can be stacked to convert from one format or system to another, either directly or with tranformations or other parsing in between. Message Streams look like this:
66

@@ -16,7 +16,7 @@ This is a **[gulp-etl](https://gulpetl.com/)** tap, but unlike most of the other
1616
### Usage
1717
**gulp** adapters take two parameters: a glob, which is used to locate file(s) in the file system, and an optional config object with settings specific to the adapter. For example: ```src('*.txt', {buffer:false})```
1818

19-
Since this adapter doesn't pull from an existing file, the "glob" parameter is a virtual filename (with optional path info) which is assigned to the data file extracted from the server, e.g. ```mysqlData.ndjson```. And the configObj should look like this:
19+
Since this adapter doesn't pull from an existing file, the "glob" parameter is a "pretend" filename (with optional path info) which is assigned to the data file extracted from the server, e.g. ```mysqlData.ndjson```. And the configObj should look like this:
2020
##### configObj / mysql-settings.json
2121
```
2222
{
@@ -37,14 +37,14 @@ You *could* embed this information in your gulpfile, but we recommend storing it
3737
/* Run select query on the server and save the results in a local CSV file */
3838
3939
var gulp = require('gulp')
40-
var tapMysql = require('gulp-etl-tap-mysql')
40+
var mysqlAdapter = require('gulp-etl-mysql-adapter')
4141
var targetCsv = require('gulp-etl-target-csv').targetCsv
4242
4343
// contains secure info; store in parent folder of this project, outside of repo
4444
let configObj = require('../../mysql-settings.json')
4545
4646
exports.default = function() {
47-
return tapMysql.src('mysqlResults.ndjson',configObj)
47+
return mysqlAdapter.src('mysqlResults.ndjson',configObj)
4848
.pipe(targetCsv({ columns:true }))
4949
.pipe(gulp.dest('output/'));
5050
}

debug/gulpfile.ts

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,54 @@ import * as tapMysql from '../src/plugin'
33

44
import * as loglevel from 'loglevel'
55
const log = loglevel.getLogger('gulpfile')
6-
log.setLevel((process.env.DEBUG_LEVEL || 'warn') as log.LogLevelDesc)
6+
log.setLevel((process.env.DEBUG_LEVEL || 'warn') as loglevel.LogLevelDesc)
77
// if needed, you can control the plugin's logging level separately from 'gulpfile' logging above
88
// const pluginLog = loglevel.getLogger(PLUGIN_NAME)
99
// pluginLog.setLevel('debug')
1010

11-
import * as rename from 'gulp-rename'
1211
const errorHandler = require('gulp-error-handle'); // handle all errors in one handler, but still stop the stream if there are errors
1312

1413
const pkginfo = require('pkginfo')(module); // project package.json info into module.exports
1514
const PLUGIN_NAME = module.exports.name;
1615

1716
import Vinyl = require('vinyl')
1817

19-
let gulpBufferMode = false;
2018

21-
function switchToBuffer(callback: any) {
22-
gulpBufferMode = true;
19+
// contains secure info; store in parent folder of this project, outside of repo
20+
let configObj = require('../../mysql-settings.json')
2321

24-
callback();
22+
/*
23+
let configObj =
24+
// mysql-settings.json should look like this:
25+
{
26+
"sql": "SELECT * FROM customers LIMIT 2;",
27+
"connection": {
28+
"host" : "example.org",
29+
"user" : "bob",
30+
"password" : "secret",
31+
"database" : "schemaName"
32+
}
2533
}
2634
27-
export function csvParseWithoutGulp(callback: any) {
35+
*/
2836

29-
const parse = require('csv-parse')
37+
function switchToStream(callback: any) {
38+
// buffer is true by default; we switch to stream mode by setting buffer to false here
39+
configObj.buffer = false;
3040

31-
var parser = parse({delimiter: ',', columns:true});
32-
33-
require('fs').createReadStream('../testdata/cars.csv').pipe(parser)
34-
.on("data",(data:any)=>{
35-
console.log(data)
36-
});
37-
41+
callback();
3842
}
3943

40-
41-
42-
function testAdapter(callback: any) {
44+
function runMysqlAdapter(callback: any) {
4345
log.info('gulp task starting for ' + PLUGIN_NAME)
4446

4547
try {
4648

47-
// contains secure info; store in parent folder of this project, outside of repo
48-
let configObj = require('../../mysql-settings.json')
49-
50-
/*
51-
let configObj =
52-
// mysql-settings.json should look like this:
53-
{
54-
"sql": "SELECT * FROM customers LIMIT 2;",
55-
"connection": {
56-
"host" : "example.org",
57-
"user" : "bob",
58-
"password" : "secret",
59-
"database" : "schemaName"
60-
}
61-
}
62-
63-
*/
64-
6549
return tapMysql.src('mysqlResults',configObj)
6650
.pipe(errorHandler(function(err:any) {
6751
log.error('Error: ' + err)
6852
callback(err)
6953
}))
70-
.on('data', function (file:Vinyl) {
71-
log.info('Starting processing on ' + file.basename)
72-
})
73-
// .pipe(tapCsv({raw:true/*, info:true */}))
74-
// .pipe(rename({
75-
// extname: ".ndjson",
76-
// }))
7754
.pipe(gulp.dest('../testdata/processed'))
7855
.on('data', function (file:Vinyl) {
7956
log.info('Finished processing on ' + file.basename)
@@ -90,5 +67,5 @@ function testAdapter(callback: any) {
9067

9168
}
9269

93-
exports.default = gulp.series(testAdapter)
94-
exports.runTapCsvBuffer = gulp.series(switchToBuffer, testAdapter)
70+
exports.default = gulp.series(switchToStream, runMysqlAdapter)
71+
exports.runMysqlAdapterBuffer = runMysqlAdapter

dist/js/aws/dev-handler.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

dist/js/aws/dev-handler.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/js/aws/handler.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)