Socket
Socket
Sign inDemoInstall

entity-wharf

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

entity-wharf

Store data as entity attribute values in memory. Fast queries and manipulation of state.


Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

What it does

Stores your data in an elegant way that will give you great flexibility and leverage. This library is designed to be used as a state management solution for applications that need to be performant for quickly mutating state over many different types of entities with similar characteristics. Applications such as games and simulations. If performance isn't this crucial then check out DataScript which provides immutability, versioning, undo/redo, and a powerful datalog query engine.

All data stored in Wharf is organized uniformly as

  • Entity - just an id (i.e. 1)
  • Attribute - an attribute of the entity (i.e. name or age)
  • Value - the value of the attribute (i.e. "bob" or 50)

For example let's describe some shapes.

  • entity 1 is a blue square
  • entity 2 is a red triangle
  • entity 3 is a red circle
EntityAttributeValue
1colorblue
1width20
1height20
1n_edges4
2colorred
2base10
2height40
2n_edges3
3colorred
3radius20
3n_edges0

Although there are 3 distinct types we can perform generic queries that cross types.

All entities that have a height attribute returns [ 1, 2 ]

EntityAttributeValue
1height20
2height40

All entities that have a height and a width attribute returns [ 1 ]

EntityAttributeValue
1width20
1height20

All entities with a value 20 returns [ 1, 3 ]

EntityAttributeValue
1width20
1height20
3radius20

All entities where color == red returns [ 2, 3 ]

EntityAttributeValue
2colorred
3colorred

How to use it

var db = Wharf();//make a new "db" to work with

//create some entities
var square_id   = db.add({color: "blue", width: 20, height: 20, n_edges: 4});// (returns false on failure)
var triangle_id = db.add({color: "red", base: 10, height: 40, n_edges: 3});
var circle_id   = db.add({color: "blue", radius: 20});

//db.set will add/overwrite attributes and values on an entitiy
db.set(circle_id, {color: "red", n_edges: 0});// -> true (returns false on failure)

//db.get returns the entities data
db.get(circle_id);// -> {color: "red", radius: 20, n_edges: 0} (returns null if it's not found)

//At this point the db has 3 entities the same as in the example

//All entities that have a `height` attribute
db.q({a: ["height"]});// -> [ square_id, triangle_id ]

//All entities that have a `height` and a `width` attribute
db.q({a: ["height", "width"]});// -> [ square_id ]

//All entities with a value `20`
db.q({v: [20]});// -> [ square_id, circle_id ]

//All entities where `color == red`
db.q({av: [["color", "red"]]});// -> [ triangle_id, circle_id ]

//entities are easy to remove
db.remove(square_id);// -> true

//if an ID doesn't exist it returns false
db.remove(square_id);// -> false

Installing

There are 3 ways to include this library

With browserify

$ npm install --save entity-wharf

Then use it

var Wharf = require('entity-wharf');
...

With a script tag

Download this script then include it in your html

<script src="entity-wharf.min.js"></script>

Then use it

var Wharf = ENTITY_WHARF;
...

With RequireJS

require(['entity-wharf'], function(Wharf) {
	...
});

License

The MIT License (MIT)

Copyright (c) 2014 Small Helm LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 08 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc