Gathering detailed insights and metrics for tiny
Gathering detailed insights and metrics for tiny
Gathering detailed insights and metrics for tiny
Gathering detailed insights and metrics for tiny
npm install tiny
Typescript
Module System
Min. Node Version
NPM Version
78.5
Supply Chain
99.6
Quality
75.5
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
214,774
Last Day
214
Last Week
2,451
Last Month
13,736
Last Year
151,522
111 Stars
163 Commits
14 Forks
7 Watching
2 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
0.0.10
Package Id
tiny@0.0.10
Size
16.67 kB
NPM Version
1.4.9
Publised On
01 Jun 2014
Cumulative downloads
Total Downloads
Last day
-36.9%
214
Compared to previous day
Last week
-2.3%
2,451
Compared to previous week
Last month
-8.2%
13,736
Compared to previous month
Last year
589.4%
151,522
Compared to previous year
1
tiny is an in-process document/object store for node.js.
It is largely inspired by nStore, however, its goal was to implement real querying which goes easy on the memory.
Tiny is very simple, there are no schemas, just store your objects. It supports mongo-style querying, or alternatively a "mapreduce-like" interface similar to CouchDB's views.
1$ npm install tiny
Tiny takes advantage of the fact that, normally, when you query for records in a database, you're only comparing small properties (<128b) in the query itself. For example, when you query for articles on a weblog, you'll usually only be comparing the timestamp of the article, the title, the author, the category, the tags, etc. - pretty much everything except the content of the article itself.
Tiny stores each document/object's property individually in the DB file and caches all the small properties into memory when the DB loads, leaving anything above 128b behind. When a query is performed, Tiny only lets you compare the properties stored in memory, which is what you were going to do anyway. Once the query is complete, Tiny will perform lookups on the FD to grab the large properties and put them in their respective objects before results are returned to you.
This my attempt at combining what I think the best aspects of nStore and node-dirty are. node-dirty is incredibly fast and simple (everything is in-memory), and nStore is very memory effecient, (but this only lasts until you perform a query). node-tiny allows for queries that perform lookups on the db file, and it selectively caches properties as well, so it's fast and easier on memory.
1var Tiny = require('./tiny'); 2Tiny('articles.tiny', function(err, db) { 3 var time = Date.now() 4 , low = time - (60*60*1000) 5 , high = time - (30*60*1000); 6 7 // mongo-style query 8 db.find({$or: [ 9 { timestamp: { $lte: low } }, 10 { timestamp: { $gte: high } } 11 ]}) 12 .desc('timestamp') 13 .limit(3)(function(err, results) { 14 console.log('Results:', results); 15 }); 16 17 // is equivalent to... 18 db.fetch({ 19 desc: 'timestamp', 20 limit: 3 21 }, function(doc, key) { 22 if (doc.timestamp <= low 23 || doc.timestamp >= high) { 24 console.log('Found:', key); 25 return true; 26 } 27 }, function(err, results) { 28 console.log('Results:', results); 29 }); 30});
The mongo-style querying should be fairly self-explanatory. The second query is
supposed to be similar to a mapreduce interface, but it's the rough equivalent
of a .filter
function.
Note: there is a shallow
parameter for .fetch
, .find
, and .get
, wherein
it will only lookup properties that are under 128b in size. This is to go
easy on the memory. .each
and .all
are shallow by default, but they do have
a deep
parameter, (which I don't recommend using).
1// save a document 2db.set('myDocument', { 3 title: 'a document', 4 content: 'hello world' 5}, function(err) { 6 console.log('set!'); 7}); 8 9// .each will iterate through 10// every object in the database 11// it is shallow by default 12db.each(function(doc) { 13 console.log(doc.title); 14}); 15 16// returns every object in the DB 17// in an array, this is shallow 18// by default 19db.all(function(err, docs) { 20 console.log(docs.length); 21}); 22 23// remove a doc 24db.remove('myDocument', function(err) { 25 console.log('deleted'); 26}); 27 28// retrieve an object from the database 29db.get('someOtherThing', function(err, data) { 30 // data._key is a property which 31 // holds the key of every object 32 console.log('found:', data._key); 33}); 34 35// updates the object 36// without overwriting its other properties 37db.update('article_1', { 38 title: 'new title' 39}, function(err) { 40 console.log('done'); 41}); 42 43// close the file descriptor 44db.close(function(err) { 45 console.log('db closed'); 46}); 47 48// clean up the mess 49db.compact(function(err) { 50 console.log('done'); 51}); 52 53// dump the entire database to a JSON file 54// in the same directory as the DB file 55// (with an optional pretty-print parameter) 56db.dump(true, function(err) { 57 console.log('dump complete'); 58});
Because of the way Tiny works, there are ways to alter your data to make it more memory efficient. For example, if you have several properties on your objects that aren't necessary to for queries, its best to nest them in an object.
1user: { 2 name: 'joe', 3 prop1: 'data', 4 prop2: 'data', 5 prop3: 'data' 6} 7 8user: { 9 name: 'joe', 10 data: { 11 prop1: 'data', 12 prop2: 'data', 13 prop3: 'data' 14 } 15}
That way, the data will not be cached if it exceeds 128b collectively.
Eventually there may be an ignore
method or an index
method, which will be
explicitly inclusive or exclusive to which properties are cached and which
properties are able to be referenced within a query.
Creates and returns a database with the given name.
Arguments
Example
1var db; 2Tiny('./articles.tiny', function(err, db_) { 3 if (err) throw err; 4 db = db_; 5 ... 6});
Dumps the a database to a JSON file with the name as name.json. Pretty specifies whether to indent each line with two spaces or not. Alternatively, dump(func) can be called.
Arguments
Example
1db.dump(true, function(err) { 2 console.log('dump complete'); 3});
Closes the Tiny database file handle. A new Tiny object must be made to reopen the file.
Arguments
Example
1db.close(function(err) { 2 console.log('db closed'); 3});
Closes the Tiny database file, deletes the file and all the data in the database, and then creates a new database with the same name and file.
Arguments
Example
1db.kill(function(err) { 2 console.log('db has been destroyed and a new db has been loaded'); 3});
Saves a object doc
to database under the key docKey
. Ideally, docKey should
be 128b or smaller.
Arguments
Example
1db.set('myDocument', { 2 title: 'a document', 3 content: 'hello world' 4}, function(err) { 5 console.log('set!'); 6});
Iterates through every object in the database.
Arguments
doc
from the databasetrue
if every object should be returned, false
or unset if only
cacheable objects should be returned (ones smaller than 128b)Example
1db.each(function(doc) { 2 console.log(doc.title); 3}, function() { 4 console.log('done'); 5});
If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. </legalese>
Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License)
See LICENSE for more info.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More