Git Product home page Git Product logo

db3's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

db3's Issues

Add .change(filter, callback) method

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)

Node frendly functions

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.

Table level api

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)
  })
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.