Permalink
Browse files

new commands, utf8 everywhere, fixed some bugs, added test.js, improv…

…ed readme
  • Loading branch information...
1 parent a4f8ee5 commit 10caa1e378ccafc5ab30f3bdcec982a0164100d2 @stagas committed Nov 10, 2010
Showing with 334 additions and 113 deletions.
  1. +1 −1 LICENCE
  2. +0 −94 README
  3. +82 −0 README.md
  4. +2 −2 bench.js
  5. +184 −14 chaos.js
  6. +2 −2 package.json
  7. +63 −0 test.js
View
@@ -1,4 +1,4 @@
-Copyright (c) 2010 George Stagakis. All rights reserved.
+Copyright (c) 2010 George Stagakis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
94 README
@@ -1,94 +0,0 @@
--=-=-=-=-=-=-=-
-
- .:[ chaos ]:.
-
--=-=-=-=-=-=-=-
-
- - by stagas -
-
----------------
-
-chaos is a filesystem hash based database for node.js
-
-why chaos? because we exploit the sha1 chaotic randomness to store the keys evenly in the filesystem.
-
-
-
-the idea:
----------
-
-the first 2 characters of the sha1 hash of a key become the top dir in the tree, the next 1 becomes the
-child dir in the tree and the rest of the hash becomes the filename. This means that the 1st time you
-create a database, it will create 4,096 directories so it can then store keys/files in them. it
-also means that while the sha1 has trillions of combinations, the filesystem has limitations way lower
-than that. It depends on the filesystem but in general, but my guess is that less than 30,000 files in
-a folder should perform really well. This translates to a max 122,880,000 keys. Cool, eh?
-Plus you can store any utf8 string or number you want, it's just a proxy to fs.readFile() and fs.writeFile().
-
-
-
-installation:
--------------
-
-npm install chaos
-
-
-
-usage:
-------
-
-var db = require('chaos')('mydbname')
-
-
-
-commands:
----------
-
-Set key value pair:
- db.set(key, val, function(err) {})
-
-
-Get the value of a key:
- db.get(key, function(err, val) {})
-
-
-Delete a key:
- db.del(key, function(err) {})
-
-
-Increment a key:
- db.incr(key, function(err, new_number) {})
-
- If a key doesn't exist or its value isn't a number it will be created starting from 0. Therefore will return 1
-
-
-Decrement a key:
- db.decr(key, function(err, new_number) {})
-
- If a key doesn't exist or its value isn't a number it will be created starting from 0. Therefore will return -1
-
-
-Get a key's value and set another afterwards:
- db.getset(key, val, function(err, old_val) {})
-
-
-Get a key's value and delete it afterwards:
- db.getdel(key, function(err, val) {})
-
-
-Get a key's value or if it doesn't exist, set the value and get it afterwards:
- db.getorsetget(key, default_value, function(err, val) {})
-
-
-
-future:
--------
-
-- better tests
-- optimizations maybe
-- who knows?
-
-it's still just a proof of concept, no real life tests are done.
-contributions are welcome! :)
-
-questions? Find me on Twitter @stagas and IRC freenode.net #node.js as stagas
View
@@ -0,0 +1,82 @@
+chaos - a node.js database
+==========================
+
+Why chaos? Because we exploit the sha1 chaotic randomness to store the keys evenly in the filesystem.
+
+## The idea
+
+The first 2 characters of the sha1 hash of a key become the top dir in the tree, the next 1 becomes the
+child dir in the tree and the rest of the hash becomes the filename. This means that the 1st time you
+create a database, it will create 4,096 directories so it can then store keys/files in them. It
+also means that while the sha1 has trillions of combinations, the filesystem has limitations way lower
+than that. It depends on the filesystem but in general, but my guess is that less than 30,000 files in
+a folder should perform really well. This translates to a max 122,880,000 keys. Cool, eh?
+Plus you can store any utf8 string or number you want, it's just a proxy to fs.readFile() and fs.writeFile().
+
+## Installation
+
+ npm install chaos
+
+## Usage
+
+ var db = require('chaos')('your database name')
+
+## Commands
+
+### db.set(key, val, function(err) {})
+
+Sets a key value pair.
+
+### db.get(key, function(err, val) {})
+
+Gets the value of a key.
+
+### db.del(key, function(err) {})
+
+Deletes a key.
+
+### db.incr(key, function(err, new_number) {})
+### db.decr(key, function(err, new_number) {})
+
+Increment or decrement a key value by 1 and return the new number. If a key doesn't exist or its value isn't a number it will be created starting from 0. Therefore will return 1 or -1 respectively.
+
+### db.getset(key, val, function(err, old_val) {})
+Get a key value and set another afterwards.
+
+### db.getdel(key, function(err, val) {})
+Get a key value and delete it afterwards.
+
+### db.getorsetget(key, default_value, function(err, val) {})
+Get a key's value or if it doesn't exist, set the value and get it afterwards.
+
+### db.hset(hkey, field, val, function(err) {})
+Set a hkey field value.
+
+### db.hget(hkey, field, function(err, val) {})
+Get the value of a hkey field.
+
+### db.hgetall(hkey, function(err, field_value_object) {})
+Get all field value pairs from an hkey (returns an object with fields as keys and their values).
+
+### db.hkeys(hkey, function(err, fields_array) {})
+Get all field names from an hkey. Returns an unsorted array with the field names.
+
+### db.hvals(hkey, function(err, values_array) {})
+Get all field values from an hkey. Returns an unsorted array with the field values.
+
+## Future
+
+* More commands
+* Better tests
+* Optimizations
+* Who knows?
+
+Contributions are welcome! :)
+
+## Disclaimer
+
+It's still just a proof of concept, no real life tests are done.
+
+## Questions?
+
+Find me on Twitter @stagas and IRC freenode.net #node.js as stagas
View
@@ -1,6 +1,6 @@
-//
+// bench for chaos
-var db = require('./chaos')('test')
+var db = require('./chaos')('benchtest')
, assert = require('assert')
var best = {writes: 0, reads: 0}
Oops, something went wrong.

0 comments on commit 10caa1e

Please sign in to comment.