GithubHelp home page GithubHelp logo

hhy5277 / jio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nexedi/jio

0.0 2.0 0.0 4.67 MB

Javascript Input/Output (Mirror of https://lab.nexedi.com/nexedi/jio ; Please submit patches and issues there)

Home Page: http://jio.readthedocs.org/

License: GNU Lesser General Public License v3.0

ApacheConf 0.01% JavaScript 99.41% Makefile 0.02% HTML 0.56%

jio's Introduction

Javascript Input/Output

jIO is a client-side JavaScript library to manage documents across multiple storages.

Getting Started

To set up jIO you should include jio.js, dependencies and the connectors for the storages you want to use in the HTML page header (note that more dependencies may be required depending on type of storages being used):

<script src="RSVP.js"></script>
<script src="jio-latest.js"></script>

Then create your jIO instance like this:

// create a new jio
var jio_instance = jIO.createJIO({
  type: "query",
  sub_storage: {
    type: "uuid",
    sub_storage: {
      "type": "indexeddb",
      "database": "test"
    }
  }
});

Documents and Methods

Documents are JSON strings that contain metadata (properties, like a filename) and attachments (optional content, for example image.jpg).

jIO exposes the following methods to create, read, update and delete documents (for more information, including revision management and available options for each method, please refer to the documentation):

// create and store new document
jio_instance.post({"title": "some title"})
  .then(function (new_id) {
    ...
  });

// create or update an existing document
jio_instance.put(new_id, {"title": "New Title"})
  .then(function () 
    // console.log("Document stored");
  });

// add an attachement to a document
jio_instance.putAttachment(document_id, attachment_id, new Blob())
  .then(function () {
    // console.log("Blob stored");
  });

// read a document
jio_instance.get(document_id)
  .then(function (document) {
    // console.log(document);
    // {
    //   "title": "New Title",
    // }
  });

// read an attachement
jio_instance.getAttachment(document_id, attachment_id)
  .then(function (blob) {
    // console.log(blob);
  });

// delete a document and its attachment(s)
jio_instance.remove(document_id)
  .then(function () {
    // console.log("Document deleted");
  });

// delete an attachement
jio_instance.removeAttachment(document_id, attachment_id)
  .then(function () {
    // console.log("Attachment deleted");
  });

// get all documents
jio_instance.allDocs().then(function (response) {
  // console.log(response);
  // {
  //   "data": {
  //     "total_rows": 1,
  //     "rows": [{
  //       "id": "my_document",
  //       "value": {}
  //     }]
  //   }
  // }
});

Example

This is an example of how to store a video file with one attachment in local storage. Note that attachments should be added after document creation.

// create a new localStorage
var jio_instance = jIO.createJIO({
  "type": "local",
});

var my_video_blob = new Blob([my_video_binary_string], {
  "type": "video/ogg"
});

// post the document
jio_instance.put("myVideo", {
  "title"       : "My Video",
  "format"      : ["video/ogg", "vorbis", "HD"],
  "language"    : "en",
  "description" : "Images Compilation"
}).then(function (response) {

  // add video attachment
  return jio_instance.putAttachment(
    "myVideo",
    "video.ogv",
    my_video_blob
  });

}).then(function (response) {

  alert('Video Stored');

}, function (err) {

  alert('Error when attaching the video');

}, function (progression) {

  console.log(progression);

});

Storage Locations

jIO allows to build "storage trees" consisting of connectors to multiple storages (webDav, xWiki, S3, localStorage) and use type-storages to add features like revision management or indices to a child storage (sub_storage).

The following storages are currently supported:

  • LocalStorage (browser local storage)
  • IndexedDB
  • ERP5Storage
  • DAVStorage (connect to webDAV, more information on the documentation)

For more information on the specific storages including guidelines on how to create your own connector, please also refer to the documentation.

jIO Query

jIO can use queries, which can be run in the allDocs() method to query document lists. A sample query would look like this (note that not all storages support allDocs and jio queries, and that pre-querying of documents on distant storages should best be done server-side):

// run allDocs with query option on an existing jIO
jio_instance.allDocs({
  "query": '(fieldX: >= "string" AND fieldY: < "string")',
  // records to display ("from to")
  "limit": [0, 5],
  // sort by
  "sort_on": [[<string A>, 'descending']],
  // fields to return in response
  "select_list": [<string A>, <string B>]
}).then(function (response) {
  // console.log(response);
  // {
  //   "total_rows": 1,
  //   "rows": [{
  //     "id": <string>,
  //     "value": {
  //       <string A>: <string>,
  //       <string B>: <string>
  //     }
  //   }, { .. }]
  // }
});

To find out more about queries, please refer to the documentation.

Authors

  • Francois Billioud
  • Tristan Cavelier
  • Sven Franck
  • Romain Courteaud

Copyright and license

jIO is an open-source library and is licensed under the LGPL license. More information on LGPL can be found here.

Contribute

Get development environment:

git clone https://lab.nexedi.com/nexedi/jio.git jio.git
cd jio.git
npm install
alias grunt="./node_modules/grunt-cli/bin/grunt"
grunt

Run tests:

grunt server

and open http://127.0.0.1:9000/test/tests.html

Submit merge requests on lab.nexedi.com.

jio's People

Contributors

aureliencalonne avatar ecrinde avatar gidzit avatar jonriv avatar klawlf82 avatar sebatyne avatar sebrobin avatar slaimu avatar

Watchers

 avatar  avatar

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.