Created
May 5, 2012 10:19
-
-
Save tobsn/2601361 to your computer and use it in GitHub Desktop.
capping taffydb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TAFFY.extend( 'capped', function( i, runInsert, runRemove ) { | |
var c = this.getDBI().cap || false; | |
if( c && ( c < ( this.count() + 1 ) ) ) { | |
while( c < ( this.count() + 1 ) ) { | |
this.getDBI().remove( this.context().results[0].___id ); | |
this.context({ | |
run: null | |
}); | |
this.getDBI().removeCommit( runRemove ); | |
} | |
} | |
return this.getDBI().insert( i, runInsert ); | |
}); | |
var db = TAFFY(); | |
db().getDBI().cap = 20; | |
for(var i = 0; i < 10; i++ ) { | |
db.insert({field:i}); | |
} | |
for(var i = 10; i < 40; i++ ) { | |
db().capped({field:i}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment