How to use the js-data.utils.plainCopy function in js-data

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 GoogleCloudPlatform / js-data-cloud-datastore / src / index.js View on Github external
_createHelper (mapper, records) {
    const singular = !utils.isArray(records);
    if (singular) {
      records = [records];
    }
    records = utils.plainCopy(records);
    return new utils.Promise((resolve, reject) => {
      let apiResponse;
      const idAttribute = mapper.idAttribute;
      const incompleteKey = this.datastore.key([mapper.name]);

      const transaction = this.datastore.transaction();
      transaction.run((err) => {
        if (err) {
          return reject(err);
        }
        // Allocate ids
        transaction.allocateIds(incompleteKey, records.length, (err, keys) => {
          if (err) {
            return reject(err);
          }
          const entities = records.map((_record, i) => {
github js-data / js-data-sql / src / index.js View on Github external
filterQuery (sqlBuilder, query, opts) {
    query = utils.plainCopy(query || {})
    opts || (opts = {})
    opts.operators || (opts.operators = {})
    query.where || (query.where = {})
    query.orderBy || (query.orderBy = query.sort)
    query.orderBy || (query.orderBy = [])
    query.skip || (query.skip = query.offset)

    // Transform non-keyword properties to "where" clause configuration
    utils.forOwn(query, (config, keyword) => {
      if (reserved.indexOf(keyword) === -1) {
        if (utils.isObject(config)) {
          query.where[keyword] = config
        } else {
          query.where[keyword] = {
            '==': config
          }
github GoogleCloudPlatform / js-data-cloud-datastore / src / index.js View on Github external
filterQuery (dsQuery, query, opts) {
    query = utils.plainCopy(query || {});
    opts || (opts = {});
    opts.operators || (opts.operators = {});
    query.where || (query.where = {});
    query.orderBy || (query.orderBy = query.sort);
    query.orderBy || (query.orderBy = []);
    query.skip || (query.skip = query.offset);

    // Transform non-keyword properties to "where" clause configuration
    utils.forOwn(query, (config, keyword) => {
      if (reserved.indexOf(keyword) === -1) {
        if (utils.isObject(config)) {
          query.where[keyword] = config;
        } else {
          query.where[keyword] = {
            '==': config
          };
github js-data / js-data-mongodb / src / index.js View on Github external
return this._run((client, success, failure) => {
      const collectionId = this._getCollectionId(mapper, opts)
      const insertManyOpts = this.getOpt('insertManyOpts', opts)
      props = utils.plainCopy(props)

      client.collection(collectionId)
        .insertMany(props, insertManyOpts, (err, cursor) => err ? failure(err) : success(cursor))
    }).then((cursor) => {
      let records = []
github js-data / js-data-mongodb / src / index.js View on Github external
getQueryOptions (mapper, query) {
    query = utils.plainCopy(query || {})
    query.orderBy = query.orderBy || query.sort
    query.skip = query.skip || query.offset

    let queryOptions = {}

    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']
        }
      }
github js-data / js-data-mongodb / src / index.js View on Github external
return this._run((client, success, failure) => {
      const collectionId = this._getCollectionId(mapper, opts)
      const insertOpts = this.getOpt('insertOpts', opts)

      const collection = client.collection(collectionId)
      const handler = (err, cursor) => err ? failure(err) : success(cursor)

      props = utils.plainCopy(props)

      if (collection.insertOne) {
        collection
          .insertOne(props, insertOpts, handler)
      } else {
        collection
          .insert(props, insertOpts, handler)
      }
    }).then((cursor) => {
      let record
github js-data / js-data-firebase / src / index.js View on Github external
_upsert (mapper, props, opts) {
    const _props = utils.plainCopy(props)
    opts || (opts = {})

    const id = utils.get(_props, mapper.idAttribute)
    const collectionRef = this.getRef(mapper, opts)

    let itemRef

    if (utils.isSorN(id)) {
      itemRef = collectionRef.child(id)
    } else {
      itemRef = collectionRef.push()
      utils.set(_props, mapper.idAttribute, itemRef.key)
    }

    return itemRef.set(_props)
      .then(() => this._once(itemRef))
github js-data / js-data-mongodb / src / index.js View on Github external
getQuery (mapper, query) {
    query = utils.plainCopy(query || {})
    query.where || (query.where = {})

    utils.forOwn(query, function (config, keyword) {
      if (reserved.indexOf(keyword) === -1) {
        if (utils.isObject(config)) {
          query.where[keyword] = config
        } else {
          query.where[keyword] = {
            '==': config
          }
        }
        delete query[keyword]
      }
    })

    let mongoQuery = {}
github GoogleCloudPlatform / js-data-cloud-datastore / src / index.js View on Github external
return this._findAll(mapper, query, opts).then((result) => {
      let [records] = result;
      records = records.filter((record) => record);
      if (records.length) {
        props = utils.plainCopy(props);
        return this._updateHelper(mapper, records, records.map(() => props), opts);
      }
      return [[], {}];
    });
  },
github GoogleCloudPlatform / js-data-cloud-datastore / src / index.js View on Github external
return this._find(mapper, id, opts).then((result) => {
      if (result[0]) {
        props = utils.plainCopy(props);
        return this._updateHelper(mapper, result[0], props, opts);
      }
      throw new Error('Not Found');
    });
  },