JayData is cross-platform (runs on HTML5 desktop and mobile browsers, can be hosted in Cordova/PhoneGap environment on iPhone, iPad, Android or Windows Phone 8+) and cross-layer as it works on client-side and server-side (Node.JS).
Please read the release notes for current status of the providers.
Visit http://jaydata.org for detailed information and documentation.
Official builds are released on CodePlex (http://jaydata.codeplex.com) can be used to develop applications, to get the structured sourcecode to develop JayData itself, visit http://github.com/jaystack/jaydata
JayData comes with multiple licensing: you can use it under MIT license if ship software software under MIT, but it should be used under GPL if you distribute your software under GPLv2. JayData Pro is a closed-source commercial product recommended for enterprise projects and commercial development efforts. http://jaystack.com/licensing
$ npm install jaydata
How to build
$ git clone https://github.com/jaystack/jaydata.git$ cd jaydata$ npm install$ gulp
Use JayData as a standalone global library
Providers are lazy loaded from the same location as the core JayData script under the
If you want to use a JayData module, include it manually in a
Use Jaydata with System.js
Using JayData with System.js needs a little bit of a setup and you have to map all providers you want to use in your application.
var map ='jaydata/core': 'lib/jaydata/jaydata.min''jaydata/odata': 'lib/jaydata/jaydataproviders/oDataProvider.min';var meta ='jaydata/odata':format: 'cjs'deps: 'jaydata/core';var config =map: mapmeta: meta;System;
With this setup you can now import the
jaydata/odata module in your application code. See a full example in Angular2 here.
Use JayData with Require.js
If you want to use Require.js to import JayData into your application, you need to set the path configuration correctly:
See a working example using Require.js and Durandal here.
JayData basics in 7 simple steps
In most scenarios, the 7 simple steps of JayData basics are enough to handle data of your application. For more details, visit http://jaydata.org.
Step 1 - Define your data model
Simple model that works online and offline as well. Define your data model:
var Todo = $dataEntity;var TodoDatabase = $dataEntityContext;
Step 2 - Initialize the data storage
You can Initialize your context to handle an OData endpoint just by passing the OData service URL as a single string parameter.
var todoDB = "";
If you want to use a local database, pass the name of your database as a string. JayData automatically detects what type of local database solution is available on the client and creates a context to an IndexedDB, WebSQL, LocalStorage or InMemory database.
var todoDB = "MyTodoDatase";
You can even specify, what type of database you want to use by providing a storage provider configuration object.
var todoDB =provider: 'webSql' databaseName: 'MyTodoDatabase';
Step 3 - Create data
You can create new data by adding new entities to an entity set.
You can add a single entity to an entity set...
...or you can create multiple new entities by using the
addMany function. In the handler of the
saveChanges function you will get how many entities were saved.
Step 4 - Read data
To retrieve all database items as an array, use the
You can filter your data just like the native
forEach is equivalent to this:
You can pass a query parameters object as the second argument of the
filter function and access these query parameters on
this in the query function.
filter function. This is specially useful, when you want to create your query dynamically.
In some scenarios you want to just retrieve some fields of your entity and map these fields as different names.
As you store more and more entities in your database, it's practical to retrieve only a subset of your data by using paging functions.
If you want to sort your result by a selected field, use
orderByDescending. As you can still use a string instead of a function in the query function, you can dynamically construct your ordering query.
If you want more dynamic control over order direction, use the
order function. If you need descending ordering on the field, use the
- sign before the field name.
Step 5 - Update data
To update an entity, attach it to the context and JayData will track the changes on the entity. On calling the
saveChanges function, your attached and updated entities will be saved.
Step 6 - Delete data
Just like updating data, but instead of
attach you will use
removeAll function if you want to truncate all data in a single entity set.
Step 7 - Generate some UI with jQuery
JaySvcUtil - Code generator tool that builds JayData data model classes from $metadata service of OData endpoints.