alternatex/store 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alternatex/store

Composer 安装命令:

composer require alternatex/store

包简介

Lightweight storage wrapper

README 文档

README

Build Status

A lightweight datastore wrapper providing CRUD operations for arbitrary objects.

Index

Quickstart

Embedding

Require.js

require(["store"], function(Store) {
  // ...
});

HTML

<script src="src/client/store.js"></script>

Client API

Store

Configure

Defaults are configured as follows:

Store.configure({ 
  url: "http://localhost/datastore.php", 
  ttl: 3600
});

Note

configure() alters the prototype object, hence modifications are propagated to instances on property level given that the respective instance properties have not been modified previously.

Create

var objectStore = new Store({ namespace: 'object' });

Object

Create

Preset
var object = objectStore.create({ 
  country: 'USA', 
  firstname: 'Stephen', 
  lastname: 'Colbert' 
}); 
Barebone
var object = objectStore.create(); 
object.set('country', 'USA');
object.set('firstname', 'Jon'); 
object.set('lastname', 'Stewart'); 

Read

List
objectStore.list();
Single
objectStore.get('8c0c1ff0-d0fe-38b7-376a-b0b1d53bd557');

Update

Instance
object.update();
Datastore
objectStore.update(object);

Delete

Instance
object.remove();
Datastore
objectStore.remove(object);

Summary

<script src="src/client/store.js"></script>
<script>
(function(){

  // local variables
  var object, objectId, objectStore, objects;

  // configure store defaults 
  Store.configure({ 
    url: "http://localhost/store/examples/server.php", 
    ttl: 3600
  });

  // create new store
  objectStore = new Store({ namespace: 'object' });

  // create new store bound object
  object = objectStore.create({ 
    country: 'US', 
    firstname: 'Stephen', 
    lastname: 'Colbert' 
  });
  
  // update on insert 
  objectStore.update(object).done(function(object){
    
    // wrap json object
    object = objectStore.create(object);

    // update properties
    object.set('firstname', 'Jon');
    object.set('lastname', 'Stewart');

    // extract
    objectId = object.get('id');

    // update object
    objectStore.update(object).done(function(object){        

        // fetch object w/previously retrieved objectId
        objectStore.get(objectId).done(function(object){

           // wrap json object
           object = objectStore.create(object);

           // say hi
           console.log(object.get('firstname') + " " + object.get('lastname'));
        });
    });
  });

  // collect update promises
  objects = [];

  // create some objects
  Store.times(10, function(count){

    // store update promises
    objects.push(objectStore.create({ 
      title: 'No.' + count,       
      abstract: 'Lorem Ipsum [...]',       
      text: 'Lorem Ipsum Si Amet They Say',             
      author: 'me', 
      lastmod: new Date().getTime()
    }).update());
  });

  // when all objects have been updated
  Store.when(objects).done(function(objects){
  
    // fetch all objects 
    objects = objectStore.list();
    
    // print when object have been retrieved
    Store.when(objects).done(function(objects){

      // log each
      objects.forEach(function(object, index){
        console.log(index, object);
      });
    });    
  });

  // fetch object 
  object = objectStore.get(objectId);

  // process fetched object
  Store.when(object).done(function(object){  

    // execute on success  
    console.info("done", object);  

  }).fail(function(objects){    

    // execute on fail
    console.error("fail", objects);    

  }).always(function(objects){    

    // always execute this block
    console.log("always", objects);

  });

})();
</script>

<!-- example html input -->
<form method="POST" action="//localhost/store/examples/server.php/resources/update" enctype="multipart/form-data">      
  <input type="hidden" name="namespace" value="resources"/>
  <input type="hidden" name="action" value="update"/>
  <input type="hidden" name="instance[type]" value="type"/>
  <input type="hidden" name="instance[name]" value="name"/>
  <input type="hidden" name="instance[option][key]" value="key"/>
  <input type="hidden" name="instance[option][value]" value="value"/>
  <input type="hidden" name="instance[option][lists][whitelist][]" value="good.host.com"/>
  <input type="hidden" name="instance[option][lists][blacklist][]" value="evil.host.com"/>
  <input type="file" name="instance[file]"/>
  <button>Update</button>
</form>

Routes

...

Server API

Latest Stable Version Dependency Status

Repositories

File Stores

Collections stored on a file basis.

Limitations

Built with prototyping in mind. Won't scale.

CSV

...

JSON

Supports embedding binary data base64 encoded.

Serialized

Stores data using PHPs serialize() function. Supports embedding binary data base64 encoded.

Documentation

Roadmap

  • Access Control
  • Synchronization
  • JSON Schema
    • Generators

License

Released under two licenses: new BSD, and MIT. You may pick the license that best suits your development needs.

https://raw.github.com/alternatex/store/master/LICENSE

统计信息

  • 总下载量: 42
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-10-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固