afanasy / db3 Goto Github PK
View Code? Open in Web Editor NEWCommunication framework
License: MIT License
Communication framework
License: MIT License
Needed to skip "created" field.
field = _.map(field, function (d, i) {return mysql.escapeId(field)}).join(', ')
should be
field = _.map(field, function (d, i) {return mysql.escapeId(d)}).join(', ')
It should be called when data matching filter
(handled by db3-where) has been changed with insert/update/delete (and truncate/drop table in the future)
before example from your test.js
before(function (done) {
db.dropTable('test', function () {
db.createTable('test', function () {
db.dropTable('person', function () {
db.createTable('person', ['id', 'name', 'gender'], function () {
async.eachSeries(person, function (item, done) {db.insert('person', item, function () {done()})}, done)
})
})
})
})
})
but users want to use async
here:
before(function (done) {
async.series([
db.dropTable.bind(db, 'test'),
db.createTable.bind(db, 'test'),
db.dropTable.bind(db, 'person'),
db.createTable.bind(db, 'person'),
async.series.bind(async, person, db.insert.bind(db, 'person'));
], done);
});
this is impossible with your api, because you pass result as first arg, but node convention waits err
as first argument.
After you start to support node style you feel free to add some other features to your functions call. It may be promises
or carreing
For example after carreing
, previous code will look like:
before(function (done) {
async.series([
db.dropTable('test'),
db.createTable('test'),
db.dropTable('person'),
db.createTable('person'),
async.eachSeries.bind(async, person, db.insert('person'));
], done);
});
Or shortly:
function series() {
return async.series.bind.apply(async.series, [async].concat(arguments));
}
function map(obj, func) {
return Object.keys(obj).map(function(key) {
return func(obj[key]);
})
}
before(series([
db.dropTable('test'),
db.createTable('test'),
db.dropTable('person'),
db.createTable('person'),
series(map(person, db.insert('person')));
]));
Look at ramda if you want to expose functional programming api in your lib.
So using promises your before
statement can look like:
before(function(done) {
db.dropTable('test')
.createTable('test')
.dropTable('person')
.createTable('person')
.then(function(resolve, reject) {
async.eachSeries(person, db.insert.bind(db, 'person'), function(err, result) {
if (err) return reject(err);
resolve(result)
});
})
.then(done);
});
So keep in mind, that I don't read all your code at current time. This is only fast review and maybe I missed the main reason why you doesn't use node function style.
Alias to {table: 'workLog', orderBy: {id: 'desc'}, limit: 1}
It maybe useful to expose table level api.
For example now you have db.createTable
and db.select
methods.
Expected behavior:
db.createTable('person', function(error, result) {
// result is Table object
// or maybe result contains table object
//result.table.select
result.select({name: 'Bob'}, ['name', 'gender'], function (error, data) {
if (error)
return console.error(error);
console.log('selected name, gender fields from table `person`, where `name` = "Bob"')
console.log(data)
})
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.