Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdbtools argument compatibility #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Mdb.prototype.toCSV = function(table, cb) {
)
}

Mdb.prototype.toSQL = function(table, cb) {
var cmd = spawn('mdb-export', ['-I -R ;\r\n', this.file, table])
Mdb.prototype.toSQL = function(table, cb, backend) {
var cmd = spawn('mdb-export', ['-I', backend ? backend : 'mysql', this.file, table])
cmd.stdout.pipe(
concat(function(err, out) {
if (err) return cb(err)
Expand All @@ -36,7 +36,7 @@ Mdb.prototype.toSQL = function(table, cb) {

Mdb.prototype.tables = function(cb) {
var self = this
var cmd = spawn('mdb-tables', ['-d' + this.tableDelimiter, this.file])
var cmd = spawn('mdb-tables', ['-d', this.tableDelimiter, this.file])
cmd.stdout.pipe(
concat(function(err, out) {
if (err) return cb(err.toString())
Expand Down
57 changes: 48 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,53 @@ also as of this writing `mdbtools` supports `.mdb` and `.accdb` files up through

### usage

var fruit = mdb('fruit.mdb')

fruit.tables(function(err, tables) {
tables.forEach(function(table) {
fruit.toCSV(table, function(err, csv) {
console.log(err, table, csv.split('\n').length - 1 + " lines")
})
})
})
#### Get tables

tables(callback)

Example
````javascript
var fruit = mdb('fruit.mdb')
fruit.tables(function(err, tables) {
tables.forEach(function (table) {
console.log(table);
});
});
````

#### Convert table rows to CSV rows

toCSV(table, callback)

Example

````javascript
var fruit = mdb('fruit.mdb')
fruit.tables(function(err, tables) {
tables.forEach(function(table) {
fruit.toCSV(table, function(err, csv) {
console.log(err, table, csv.split('\n').length - 1 + " lines")
});
});
});
````
#### Convert table rows to SQL INSERT statements

toSQL(table, function, backend)

Currently defaults to `mdb-export -I mysql` "mysql" backend; so generates mysql compatible INSERT statements. See [mdb-export -I](https://github.com/brianb/mdbtools/blob/master/doc/mdb-export.txt) for more backends.

````javascript
var fruit = mdb('fruit.mdb')

fruit.tables(function(err, tables) {
tables.forEach(function(table) {
fruit.toSQL(table, function(err, sql) {
console.log(err, table, sql.split('\n').length - 1 + " lines")
});
});
});
````


MIT LICENSE