typicaljoe / taffydb

TaffyDB - an open source JavaScript Database for your browser
http://taffydb.com
MIT License
2.21k stars 285 forks source link

capped databases #12

Closed tobsn closed 12 years ago

tobsn commented 12 years ago

https://gist.github.com/2601361

took the liberty of creating it myself.

it works, but i never used taffy before so I don't know if that is the best way to do this or not.

would be nice to have this in the lib.

typicaljoe commented 12 years ago

Does this cap the number of records?

tobsn commented 12 years ago

yep.

typicaljoe commented 12 years ago

I'm going to keep thinking on this. What would a good use case be? I'd like to bake it into insert and merge so that a db that is capped is truly capped.

tobsn commented 12 years ago

well, the right way to do it would be by capping it on byte size rather than item count, which the snippet does I put on gist. I wasn't sure about multibyte counting so I just did an item count. just so you know, I haven't used taffydb yet, I just read through the code and quickly implemented that workaround just to see if it's possible.

as example: let's say I run a script in a browser, like you would do it with a chrome extension. you would have only a limited amount of storage but the app runs "forever" or rather stores "forever". assume your quota is 2MB just for the sake of the example. obviously you don't want to max out the database size and lose data. you maybe need to handle like 10 dbs with various data, then each db can only get 200kb in size (everything included, like indexes etc.) and you can't go over a safe limit without corrupting. I assume you understand it now a bit better, why row/size capping would be useful in a JS app. :)

typicaljoe commented 12 years ago

Ok, that makes sense. I don't really like putting that into a function though. I don't know a lot about cookie (or other size limits) but what about some kind of an asset manager? So rather than having a capped function you use .store() and tell it what you want to do (store up to 200kb of whole records order by insert, for example)?

typicaljoe commented 12 years ago

I'm going to close this for now. In a future version we will do a deep dive into how to better support different types of storage including cookies and server side storage, but for now it is a way off as we work on the core library.