Giter VIP home page Giter VIP logo

datastore's Introduction

Datastore

Brick reactive data layer

Build Status NPM Downloads pledge

Datastore is a bloat free interface for data store and database access.

  • Adaptive: There are hundreds of databases out there. Datastore intends to provide an agnostic but yet simple interface on top of them. Seamlessly swap between database adapters and never change your code.
  • Async: Never worry about when your data will be available. Datastore uses promises at its core and allows you to deal with asynchronous access elegantly.
  • Isomorphic: Datastore works server side and synchronizing data between your browser and your server has never been as easy.

Try it online!

Usage

var store = require('datastore')

// initialize datastore with mongodb adapter
var data = store({
  hello: 'world'
}, mongo('user'))

data.set('age', 30)
data.set('name', 'bredele').then(function() {
  // do something when name has been set in database
})

Datastore's goal is to help you focus on a single API without committing to one type of data storage. Thus you can easily switch in the middle of your projects from a in-memory store to any kind of database without changing a single line of code.

Check out examples and docs for more information.

Installation

npm install datastore --save

NPM

Question

For questions and feedback please use our twitter account. For support, bug reports and or feature requests please make sure to read our community guideline and use the issue list of this repo and make sure it's not present yet in our reporting checklist.

Contribution

Datastore is an open source project and would not exist without its community. If you want to participate please make sure to read our guideline before making a pull request. If you have any datastore-related project, adapter or other let everyone know in our wiki.

License

The MIT License (MIT)

Copyright (c) 2016 Olivier Wietrich

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.

datastore's People

Contributors

bredele avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

datastore's Issues

clone

Could we optimize the obj clone?

format component

var t = format(function(str) {
  return str + ''; 
});

should also chain formatters!

select

var store = new Store({
  title: 'hello',
  items: ['hello', 'world']
})

var items = store.select('items');
items.set(0, 'foo');

select return a datastore from a key.

init proxy handler

In the same way we can proxy setters and getters we should be able to proxy the construction of a store.

reset data

by default the store data is a type of Object but if you reset the data with an Array it should be an instanceof Array

set and update

we should be able to do something like:

store.set({
  key: val
});

it doesn't make a reset but update or add.

Localstore

  store.local('name'); // sync
  ...
  store.local('name', true); //save

array type

the dle function just set as the index as undefined, it doesn't really delete it.

use datastore / wall with duo

I'm guessing you already peeked at the successor of component: duo. They are directly fetching the project via git-tags. The Problem is that they are prefixed with a "v" and postfixed it with "-alpha". This breaks the whole semver resolution and the installation fails.

node_modules\duo-package\node_modules\semver\semver.js:273
    throw new TypeError('Invalid Version: ' + version);
          ^
TypeError: Invalid Version: v1.2-alpha

Is there a way to work around that or do we need to release versions without any post or prefix?

Thanks

Get all data

I may be missing the obvious, but how do I get all the data stored in a datastore object as an array? I would like to iterate over the items with forEach, map and so on.

change and on

store.change('weight', ...);
store.change('bredele.weight', ...);

Change could accept callback or pipes.

explanation: what is a store?

List the differences between a store and a model (more flexilble, etc) and say the reason why it doesn't make sense to use object descriptors with store (because it's not a fixed subset of peroperties).

Get path

store.get('prop.attr');

Listen prop or create new store from it or make diff

store.on('changed prop.attr', ...);

set/update and array

store.set(0,{
  name : 'amy'
});

Would it be nice to update a store array as following:

store.set(0,'name', 'olivier');

reset array

we emit deleted events with index on previous store data.
ex:
old data: 7
new data: 4

deleted events: 5 6 7

Should we emit the actual index?

Updated event and strict mode

I added an event 'updated' which is trigerred on set, del and reset. You can choose to trigger or not this event by setting the strict mode to true:

//trigger updated
store.set('name','bredele');

//doesn't trigger updated
store.set('name','bredele', true);

It is used internally (by pipe) and is useful for some plugins. For example, the plugin mirror emit an event to the server on changes, and set its data when some data are received from the server.

store.on('updated', function(name, val) {
  socket.emit('change', name, val);
});

socket.on('change', function(name, val){
  store.set(name, val, true);
});

Without the strict node, we will send date in loop to the server (data from server - set local store and trigger change - send data to server on change).

My question is: is there a better way to prevent to send data in loop to the server?

Pipe

Pipe with an other store (listen change on one store and set a property in the other)

Emitter proto

We could gain about 40% performance.

function Store() {
  Emitter.call(this);
}

Store.prototype = Emitter.prototype;

factory?

store({})
  .set(...)
  .local(...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.