Module: js-data

Registered as js-data in NPM and Bower.

Also available from CDN.JS and JSDelivr.

Details
Source
index.js, line 1
Examples

Install from NPM

npm i --save js-data@beta

Install from Bower

bower i --save js-data@3.0.0-beta.1

Install from CDN.JS

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-data/3.0.0-beta.1/js-data.min.js"></script>

Install from JSDelivr

<script src="https://cdn.jsdelivr.net/js-data/3.0.0-beta.1/js-data.min.js"></script>

Load into your app via script tag

<script src="/path/to/js-data.min.js"></script>
<script>
  console.log(JSData.version.full); // "3.0.0-beta.1"
</script>

Load into your app via CommonJS

var JSData = require('js-data');

Load into your app via ES2015 Modules

import * as JSData from 'js-data';

Load into your app via AMD

define('myApp', ['js-data'], function (JSData) { ... })

Members


<static> Collection

JSData's Collection class.

Details
Type Since Source Tutorials See
Constructor 3.0.0 index.js, line 65
Example
import {Collection} from 'js-data'
const collection = new Collection()

<static> Component

JSData's Component class. Most components in JSData extend this class.

Details
Type Since Source See
Constructor 3.0.0 index.js, line 80
Example
import {Component} from 'js-data'
// Make a custom component.
const MyComponent = Component.extend({
  myMethod (someArg) { ... }
})

<static> Container

JSData's Container class. Defines and manages Mappers. Used in Node.js and in the browser, though in the browser you may want to use DataStore instead.

Details
Type Since Source Tutorials See
Constructor 3.0.0 index.js, line 98
Example
import {Container} from 'js-data'
const store = new Container()

<static> DataStore

JSData's DataStore class. Primarily for use in the browser. In Node.js you probably want to use Container instead.

Details
Type Since Source Tutorials See
Constructor 3.0.0 index.js, line 115
Example
import {DataStore} from 'js-data'
const store = new DataStore()

<static> Index

JSData's Index class, based on mindex.

Details
Type Since Source See
Constructor 3.0.0 index.js, line 131
  • Index

<static> LinkedCollection

JSData's LinkedCollection class. Used by the DataStore component. If you need to create a collection manually, you should probably use the Collection class.

Details
Type Since Source See
Constructor 3.0.0 index.js, line 141

<static> Mapper

JSData's Mapper class. The core of the ORM.

Examples

Recommended use

import {Container} from 'js-data'
const store = new Container()
store.defineMapper('user')

Create Mapper manually

import {Mapper} from 'js-data'
const UserMapper = new Mapper({ name: 'user' })

<static> Query

JSData's Query class. Used by the Collection component.

Details
Type Since Source See
Constructor 3.0.0 index.js, line 176

<static> Record

JSData's Record class.

Details
Type Since Source Tutorials See
Constructor 3.0.0 index.js, line 186
Example
import {Container} from 'js-data'
const store = new Container()
store.defineMapper('user')
const user = store.createRecord('user')

<static> Schema

JSData's Schema class. Implements http://json-schema.org/draft-04.

Example
import {Container, Schema} from 'js-data'
const userSchema = new Schema({
  properties: {
    id: { type: 'string' },
    name: { type: 'string' }
  }
})
const store = new Container()
store.defineMapper('user', {
  schema: userSchema
})

<static> utils

JSData's utility methods.

Details
Type Since Source See
Object 3.0.0 index.js, line 50
Properties:
Name Type Description
Promise Function

See utils.Promise.

Example
import {utils} from 'js-data'
console.log(utils.isString('foo')) // true

<static> version

Describes the version of this JSData object.

Details
Type Since Source
Object 2.0.0 index.js, line 29
Properties:
Name Type Description
full String

The full semver value.

major Number

The major version number.

minor Number

The minor version number.

patch Number

The patch version number.

alpha String | Boolean

The alpha version value, otherwise false if the current version is not alpha.

beta String | Boolean

The beta version value, otherwise false if the current version is not beta.

Example
console.log(JSData.version.full) // "3.0.0-beta.1"

Methods


<static> belongsTo(related, opts)

TODO

Method parameters:
Name Type Description
related Mapper

The relation the target belongs to.

opts Object

Configuration options.

Properties
Name Type Description
foreignKey String

The field that holds the primary key of the related record.

localField String

The field that holds a reference to the related record object.

Return value:
Type Description
Function

Invocation function, which accepts the target as the only parameter.

Details
Source
decorators.js, line 114

<static> hasMany(related, opts)

TODO

Method parameters:
Name Type Description
related Mapper

The relation of which the target has many.

opts Object

Configuration options.

Properties
Name Type Argument Description
foreignKey String <optional>

The field that holds the primary key of the related record.

localField String

The field that holds a reference to the related record object.

Return value:
Type Description
Function

Invocation function, which accepts the target as the only parameter.

Details
Source
decorators.js, line 136

<static> hasOne(related, opts)

TODO

Method parameters:
Name Type Description
related Mapper

The relation of which the target has one.

opts Object

Configuration options.

Properties
Name Type Argument Description
foreignKey String <optional>

The field that holds the primary key of the related record.

localField String

The field that holds a reference to the related record object.

Return value:
Type Description
Function

Invocation function, which accepts the target as the only parameter.

Details
Source
decorators.js, line 158