Skip to content

Instantly share code, notes, and snippets.

@hideo55
Created May 6, 2014 12:50
Show Gist options
  • Save hideo55/c0780ecb346dffdd6115 to your computer and use it in GitHub Desktop.
Save hideo55/c0780ecb346dffdd6115 to your computer and use it in GitHub Desktop.
[Note] node-unqlite Cursor API

#Cursor API

Iteration

var db = new unqlite.Database('/path/to/db');
db.open(function(){
  var cursor = db.cursor();
  for(cursor.first(); cursor.isValid(); cursor.next()){
    cursor.getKeyValue(function(err, key, value) {
        ...
    });
  }
});

Search

var db = new unqlite.Database('/path/to/db');
db.open(function(){
  var cursor = db.cursor();
  cursor.seek('foo', unqlite.CURSOR_MATCH_LE, function(err) {
    while(cursor.isValid()){
      cursor.getKeyValue(function(err, key, value){
          ....
      });
      cursor.next();
    }
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment