How to use the @feathersjs/adapter-commons.select function in @feathersjs/adapter-commons

To help you get started, we’ve selected a few @feathersjs/adapter-commons 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 feathersjs-ecosystem / feathers-sequelize / lib / index.js View on Github external
where: Object.assign({
        [this.Op.and]: { [this.id]: id }
      }, where)
    }, params.sequelize);

    const Model = this.applyScope(params);

    // findById calls findAll under the hood. We use findAll so that
    // eager loading can be used without a separate code path.
    return Model.findAll(q).then(result => {
      if (result.length === 0) {
        throw new errors.NotFound(`No record found for id '${id}'`);
      }

      return result[0];
    }).then(select(params, this.id)).catch(utils.errorHandler);
  }
github feathersjs-ecosystem / feathers-nedb / lib / index.js View on Github external
let runQuery = total => nfcall(q, 'exec').then(data => {
      return {
        total,
        limit: filters.$limit,
        skip: filters.$skip || 0,
        data: data.map(select(params, this.id))
      };
    });
github feathersjs-ecosystem / feathers-sequelize / lib / index.js View on Github external
where[this.Op.and] = { [this.id]: id };
    }

    const options = Object.assign({}, { where }, params.sequelize);

    const Model = this.applyScope(params);

    if (params.$returning !== false) {
      return this._getOrFind(id, opts).then(data => {
        return Model.destroy(options).then(() => data);
      })
        .then(select(params, this.id))
        .catch(utils.errorHandler);
    } else {
      return Model.destroy(options).then(() => Promise.resolve([]))
        .then(select(params, this.id))
        .catch(utils.errorHandler);
    }
  }
}
github feathersjs-ecosystem / feathers-mongoose / lib / service.js View on Github external
const isMulti = Array.isArray(_data);
    const data = isMulti ? _data : [_data];

    return model.create(data, params.mongoose).then(results => {
      if ($populate) {
        return Promise.all(results.map(result => this.Model.populate(result, $populate)));
      }

      return results;
    }).then(results => {
      if (this.lean) {
        results = results.map(item => (item.toObject ? item.toObject() : item));
      }

      return isMulti ? results : results[0];
    }).then(select(params, this.id)).catch(errorHandler);
  }
github feathersjs-ecosystem / feathers-nedb / lib / index.js View on Github external
_remove (id, params = {}) {
    const { query, options } = this.multiOptions(id, params);

    return this._findOrGet(id, params).then(items =>
      nfcall(this.getModel(params), 'remove', query, options)
        .then(() => items)
    ).then(select(params, this.id));
  }
}
github feathersjs-ecosystem / feathers-mongodb / lib / index.js View on Github external
_get (id, params = {}) {
    const { query } = this.filterQuery(params);

    query.$and = (query.$and || []).concat({ [this.id]: this._objectifyId(id) });

    return this.Model.findOne(query).then(data => {
      if (!data) {
        throw new errors.NotFound(`No record found for id '${id}'`);
      }

      return data;
    }).then(select(params, this.id)).catch(errorHandler);
  }
github feathersjs-ecosystem / feathers-nedb / lib / index.js View on Github external
async _get (id, params = {}) {
    const { query } = this.filterQuery(params);
    const findOptions = Object.assign({ $and: [{ [this.id]: id }, query] });

    return nfcall(this.getModel(params), 'findOne', findOptions)
      .then(doc => {
        if (!doc) {
          throw new errors.NotFound(`No record found for id '${id}'`);
        }

        return doc;
      })
      .then(select(params, this.id));
  }
github feathersjs-ecosystem / feathers-mongoose / lib / service.js View on Github external
.then((result) => {
          if (result === null) {
            throw new errors.NotFound(`No record found for id '${id}'`, query);
          }
          return this.Model.deleteOne(query, params.mongoose).lean(this.lean)
            .exec()
            .then(() => result)
            .then(select(params, this.id));
        })
        .catch(errorHandler);
github feathersjs-ecosystem / feathers-nedb / lib / index.js View on Github external
_create (raw, params = {}) {
    const addId = item => {
      if (this.id !== '_id' && item[this.id] === undefined) {
        return Object.assign({
          [this.id]: crypto.randomBytes(8).toString('hex')
        }, item);
      }

      return item;
    };
    const data = Array.isArray(raw) ? raw.map(addId) : addId(raw);

    return nfcall(this.getModel(params), 'insert', data)
      .then(select(params, this.id));
  }
github feathersjs-ecosystem / feathers-sequelize / lib / index.js View on Github external
return this._get(id, { sequelize: seqOptions, query: where }).then(instance => {
      const copy = Object.keys(instance.toJSON()).reduce((result, key) => {
        result[key] = typeof data[key] === 'undefined' ? null : data[key];

        return result;
      }, {});

      return instance.update(copy, seqOptions)
        .then(() => this._get(id, {
          sequelize: Object.assign({}, seqOptions, {
            raw: this.raw
          })
        }));
    })
      .then(select(params, this.id))
      .catch(utils.errorHandler);
  }

@feathersjs/adapter-commons

Shared database adapter utility functions

MIT
Latest version published 8 days ago

Package Health Score

92 / 100
Full package analysis