How to use js-data - 10 common examples

To help you get started, we’ve selected a few js-data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / js-data-http / js-data-http-tests.ts View on Github external
import * as JSData from 'js-data';
import DSHttpAdapter = require("js-data-http");

declare var axios: any;

const adapter = new DSHttpAdapter();
const store = new JSData.DS();
store.registerAdapter('http', adapter, { default: true });

adapter.defaults.basePath = '/api';
adapter.http = axios;

const ADocument: JSData.DSResourceDefinition = store.defineResource('document');

ADocument.inject({ id: 5, author: 'John' });

// bypass the data store
adapter.update(ADocument, 5, { author: 'Johnny' }).then((document: any) => {
    document; // { id: 5, author: 'Johnny' }

    // The updated document has NOT been injected into the data store because we bypassed the data store
    ADocument.get(document.id); // { id: 5, author: 'John' }
});
github Wikodit / js-data-jsonapi-light / test / ds.ts View on Github external
import { DataStore } from 'js-data'

declare var JSData:any;
declare var JSDataJsonApiLight:any;

export const store = new DataStore({
  // addToCache: JSDataJsonApiLight.JSDataOverride.addToCache,
  // mapperWrap: JSDataJsonApiLight.JSDataOverride.mapperWrap
});

const jsonApiAdapter = new JSDataJsonApiLight.JsonApiAdapter({
  suffix: '.json',
  basePath: 'api',
  store: store
});

store.registerAdapter('jsonApi', jsonApiAdapter, { default: true })

// afterEach(function(){
//   DS.clear()
// })
github js-data / js-data-sql / src / index.js View on Github external
if (utils.isObject(query.where) && Object.keys(query.where).length !== 0) {
      // Apply filter for each field
      sqlBuilder = this.applyWhereFromObject(sqlBuilder, query.where, opts)
    } else if (utils.isArray(query.where)) {
      sqlBuilder = this.applyWhereFromArray(sqlBuilder, query.where, opts)
    }

    // Sort
    if (query.orderBy) {
      if (utils.isString(query.orderBy)) {
        query.orderBy = [
          [query.orderBy, 'asc']
        ]
      }
      for (var i = 0; i < query.orderBy.length; i++) {
        if (utils.isString(query.orderBy[i])) {
          query.orderBy[i] = [query.orderBy[i], 'asc']
        }
        sqlBuilder = sqlBuilder.orderBy(query.orderBy[i][0], (query.orderBy[i][1] || '').toUpperCase() === 'DESC' ? 'desc' : 'asc')
      }
    }

    // Offset
    if (query.skip) {
      sqlBuilder = sqlBuilder.offset(+query.skip)
    }

    // Limit
    if (query.limit) {
      sqlBuilder = sqlBuilder.limit(+query.limit)
    }
github js-data / js-data-http / build_examples / webpack_es6 / app.js View on Github external
import {DataStore} from 'js-data'
// normally this would be "import DSHttpAdatper from 'js-data-http'"
import HttpAdapter from '../../';

document.getElementById('main').innerHTML = HttpAdapter.version.full;

var adapter = new HttpAdapter()
var store = new DataStore()
store.registerAdapter('http', adapter, { default: true })
store.defineMapper('user')

store.find('user', 1).catch(function (err) {
  console.log(err)
})
github js-data / js-data-http / build_examples / webpack / app.js View on Github external
var JSData = require('js-data')
// normally this would be "var HttpAdapter = require('js-data-http')"
var HttpAdapter = require('../../')

document.getElementById('main').innerHTML = HttpAdapter.version.full

var adapter = new HttpAdapter()
var store = new JSData.DataStore()
store.registerAdapter('http', adapter, { default: true })
store.defineMapper('user')

store.find('user', 1).catch(function (err) {
  console.log(err)
})
github js-data / js-data-http / build_examples / node / app.js View on Github external
var JSData = require('js-data')
// normally this would be "var HttpAdapter = require('js-data-http-node')"
var HttpAdapter = require('../../')

var adapter = new HttpAdapter()
var store = new JSData.Container()
store.registerAdapter('http', adapter, { default: true })
store.defineMapper('user')

store.find('user', 1).catch(function (err) {
  console.log(err)
})
github js-data / js-data-http / src / index.js View on Github external
export function HttpAdapter (opts) {
  utils.classCallCheck(this, HttpAdapter)

  opts || (opts = {})
  // Fill in any missing options with the defaults
  utils.fillIn(opts, DEFAULTS)
  Adapter.call(this, opts)
}
github js-data / js-data-mongodb / src / index.js View on Github external
export function MongoDBAdapter (opts) {
  utils.classCallCheck(this, MongoDBAdapter)
  opts || (opts = {})
  if (utils.isString(opts)) {
    opts = { uri: opts }
  }
  utils.fillIn(opts, DEFAULTS)

  // Setup non-enumerable properties
  Object.defineProperties(this, {
    /**
     * A Promise that resolves to a reference to the MongoDB client being used by
     * this adapter.
     *
     * @name MongoDBAdapter#client
     * @type {Promise}
     */
    client: {
      writable: true,
      value: undefined
github js-data / js-data-rethinkdb / src / index.js View on Github external
// Filter
    let groups

    if (utils.isObject(query.where) && Object.keys(query.where).length !== 0) {
      groups = this._applyWhereFromArray([query.where])
    } else if (utils.isArray(query.where)) {
      groups = this._applyWhereFromArray(query.where)
    }

    if (groups) {
      rql = rql.filter((row) => this._testArrayGroup(null, groups, row, opts) || true)
    }

    // Sort
    if (query.orderBy) {
      if (utils.isString(query.orderBy)) {
        query.orderBy = [
          [query.orderBy, 'asc']
        ]
      }
      for (var i = 0; i < query.orderBy.length; i++) {
        if (utils.isString(query.orderBy[i])) {
          query.orderBy[i] = [query.orderBy[i], 'asc']
        }
        rql = (query.orderBy[i][1] || '').toUpperCase() === 'DESC' ? rql.orderBy(r.desc(query.orderBy[i][0])) : rql.orderBy(query.orderBy[i][0])
      }
    }

    // Offset
    if (query.skip) {
      rql = rql.skip(+query.skip)
    }
github js-data / js-data-sql / src / index.js View on Github external
}
        delete query[keyword]
      }
    })

    // Filter
    if (utils.isObject(query.where) && Object.keys(query.where).length !== 0) {
      // Apply filter for each field
      sqlBuilder = this.applyWhereFromObject(sqlBuilder, query.where, opts)
    } else if (utils.isArray(query.where)) {
      sqlBuilder = this.applyWhereFromArray(sqlBuilder, query.where, opts)
    }

    // Sort
    if (query.orderBy) {
      if (utils.isString(query.orderBy)) {
        query.orderBy = [
          [query.orderBy, 'asc']
        ]
      }
      for (var i = 0; i < query.orderBy.length; i++) {
        if (utils.isString(query.orderBy[i])) {
          query.orderBy[i] = [query.orderBy[i], 'asc']
        }
        sqlBuilder = sqlBuilder.orderBy(query.orderBy[i][0], (query.orderBy[i][1] || '').toUpperCase() === 'DESC' ? 'desc' : 'asc')
      }
    }

    // Offset
    if (query.skip) {
      sqlBuilder = sqlBuilder.offset(+query.skip)
    }