Skip to content

make api node style#5

Open
plrthink wants to merge 2 commits intodarkrishabh:masterfrom
plrthink:master
Open

make api node style#5
plrthink wants to merge 2 commits intodarkrishabh:masterfrom
plrthink:master

Conversation

@plrthink
Copy link
Copy Markdown

@plrthink plrthink commented Oct 9, 2015

By making callback node style, the first argument of callback is error, users can use something like bluebird.promisify to convert the callback style to the promise style.

@darkrishabh
Copy link
Copy Markdown
Owner

This is a good change but it might be a breaking change for many.
I am kind of involved with some other stuff these days will merge it soon. untill then you can fix/ make sure it doesn't break the current applications

@kylegoetz
Copy link
Copy Markdown

It's been two years and this hasn't been merged. For anyone coming to this who only knows how to promisify using Bluebird or another third-party promisify function, here's how you do it with the add function as an example:

function myAdd(item) {
    return new Promise(resolve => db.add(item, result => resolve(result)))
}

myAdd will now return a promise that resolves to what db inserted.

collection.add(data_to_add, function(added_data_id){
if(callback){
callback(added_data_id)
callback(null, added_data_id)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning (95% confidence)

Inconsistency: The 'add_all' method calls 'callback(added_data)' without the error-first argument 'null', unlike all other methods in the file. This breaks the Node.js convention established in this PR.


Posted by PR Code Reviewer — AI-powered code review

@@ -125,7 +125,7 @@ RNDBModel.create_db = function(db){
ReactNativeStore.table(me.db_name).then(function(collection){
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning (85% confidence)

The 'erase_db' method calls 'collection.remove' which is likely intended to be 'collection.databaseData[me.db_name] = []' or a specific clear method. Calling 'remove' without a query might remove all items or behave unexpectedly depending on the underlying store implementation, and errors are not propagated to the callback.


Posted by PR Code Reviewer — AI-powered code review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants