forked from bingomanatee/hive-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.json
38 lines (38 loc) · 5.49 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
"name": "hive-model",
"version": "0.1.2",
"description": "A local-memory model/database system for storing and retrieving object based data",
"main": "index.js",
"dependencies": {
"hive-component": "*",
"underscore": "~1.4.3",
"tap": "*",
"gate": "*",
"support": "*"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/bingomanatee/hive-model.git"
},
"keywords": [
"model",
"node",
"hive"
],
"author": {
"name": "Dave Edelhart"
},
"license": "BSD",
"readme": "hive-model\n==========\n\nA javascript based database for local memory based storage of data or resources.\n\nModels are lists of data a la backbone collections.\nThey can contain any sort of data.\n\n\nModels are not designed for any specific backend. They are designed to\nprovide real-time node repositories of records for transient information management.\n\nThere is no structural schema for model data or structure, beyond the existence\nof a unique identifying key identified by the _pk property (that defaults to 'id').\nAlthough the default _make_pk assumes integer based IDs, you can easily override this\nfor a different index basis.\n\nDataspaces\n----------\n\nModels are stored in dataspaces, which ensure/maintain uniqueness of model name within the dataspace.\nDataspaces are hive-components that store models by name in their config.\n\nQueries\n-------\n\nMany methods of the model have optional callbacks that if omitted result in a query object being returned.\nQuery objects allow you to compound filtering operations such as\n\n<code>\n\tvar hive_model = require('hive-model');\n\n\tvar ds = hive_model.Dataspace();\n\n\tvar myModel = hive_model.Model({data: [\n\t\t\t{id: 1, name: 'alpha', weight: 200},\n\t\t\t{id: 2, name: 'beta', weight: 100},\n\t\t\t{id: 3, name: 'delta', weight: 0},\n\t\t\t{id: 4, name: 'gamma': weight: 100},\n\t\t]\n\t}, {name: 'foos'}, ds);\n\n\tvar lightweights = myModel.find(function(record){ return record.weight <= 100; });\n\n\t// note - lightweights is not an array of objects: it is a query object.\n\t// There is no guarantee of ordering of the records returned .. yet.\n\n\tvar lightweight_records = lightweights.records();\n\n\t// these are the records from the query object.\n\n\tvar sorted_lightweights = lightweights.sort('name');\n\n\t// sorted_lightweights is another query;\n\n\tvar sorted_lightweight_records = sorted_lightweights.records();\n\n\t// HERE we have the desired result - all foos that weight up to 100, ordered by name.\n\n\t// the practical way to use queries is to chain commands and end with a records output.\n\n\tvar slr_faster = myModel.find(function(record){ return record.weight <= 100;}).sort('name').records()\n\n</code>\n\nCreating a Model\n----------------\n\nModels are instances of the hive-component Component system.\nA hive-component Component is created with the following API:\n\n<code>\n\tvar hive_component = require('hive-component');\n\n\tvar mixins = {\n\t\tincrement: function(){\n\t\t\tvar c = this.get_config('value') + 1;\n\t\t\tthis.set_config(c);\n\t\t\treturn c;\n\t\t}\n\t}\n\n\tvar config = {\n\t\tvalue: 0;\n\t}\n\n\t// you can think of the API as \"hive_component({methods}, {properties})\" -- usually -- but once in a while\n\t// you will need to pass data in as a mixin, as is the case with model data.\n\tvar MyCompFactory = hive_component(mixins, config);\n\n\tvar mycomp = MyComp():\n\n\tmycomp.get_config('value') // 0;\n\tmycomp.increment();\n\tmycomp.get_config('value') // 1;\n</code>\n\nThe Model function allows for a third argument, to pass the dataspace in seperately, as shown aboe.\nYou can also create a service that buries the dataspace in closure as in:\n\n<code>\n\tvar hive_model = require('hive-model');\n\n\tvar ds = hive_model.Dataspace();\n\n\tvar ds_factory = Model.factory(ds);\n\n\nvar _model_bar_mixin = {\n\tname: 'bar_model',\n\tdata: [\n\t\t{id: 1, name: 'a', weight: 100}\n\t\t,\n\t\t{id: 2, name: 'b', weight: 150}\n\t\t,\n\t\t{id: 3, name: 'c', weight: 200}\n\t\t,\n\t\t{id: 4, name: 'aa', weight: 125}\n\t\t,\n\t\t{id: 5, name: 'ab', weight: 175}\n\t\t,\n\t\t{id: 6, name: 'ba', weight: 50}\n\t\t,\n\t\t{id: 7, name: 'bb', weight: 75}\n\t\t]\n\t}\n\n\tvar bar_model = ds_factory(_model_bar_mixin, {_pk: 'id'});\n</code>\n\nTHE NAME IS REQUIRED in the first parameter. Its how dataspace indeses the model. You don't have to pass data\nin, though if you have it its a convenient way to start up your model.\n\nThe second parameter (config) has no mandataory properties, unless you want to use an object whose _pk (primary key)\nis different than \"id\".\n\nAdding Data\n-----------\n\nYou can add data to a model in one of three ways:\n\n1) initally, as in the example above.\n2) record by record via my_model.put({foo: 1, bar: 2});\n3) in an array of data viar my_model.add([{}, {}]);\n\nEach of these actions will emit('record', record) for each individual record. If you want to hook your data to a real\n repo, you can do so by listening for this event.\n\n Updating Data\n -------------\n\n Putting data in that already has a PK value will overwrite / update a record; you can also call update\n to update a single record based on its ID, or by calling my_model.update(filter_function,\n\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/bingomanatee/hive-model/issues"
},
"homepage": "https://github.com/bingomanatee/hive-model",
"_id": "[email protected]",
"_from": "hive-model@"
}