* Represents an object mapper for a specific model. * @alias module:mapping~ModelMapper
| 25 | * @alias module:mapping~ModelMapper |
| 26 | */ |
| 27 | class ModelMapper { |
| 28 | constructor(name, handler) { |
| 29 | /** |
| 30 | * Gets the name identifier of the model. |
| 31 | * @type {String} |
| 32 | */ |
| 33 | this.name = name; |
| 34 | this._handler = handler; |
| 35 | /** |
| 36 | * Gets a [ModelBatchMapper]{@link module:mapping~ModelBatchMapper} instance containing utility methods to group |
| 37 | * multiple doc mutations in a single batch. |
| 38 | * @type {ModelBatchMapper} |
| 39 | */ |
| 40 | this.batching = new ModelBatchMapper(this._handler); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Gets the first document matching the provided filter or null when not found. |
| 45 | * <p> |
| 46 | * Note that all partition and clustering keys must be defined in order to use this method. |
| 47 | * </p> |
| 48 | * @param {Object} doc The object containing the properties that map to the primary keys. |
| 49 | * @param {Object} [docInfo] An object containing the additional document information. |
| 50 | * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the |
| 51 | * SELECT cql statement generated, in order to restrict the amount of columns retrieved. |
| 52 | * @param {Object|String} [executionOptions] An object containing the options to be used for the requests |
| 53 | * execution or a string representing the name of the execution profile. |
| 54 | * @param {String} [executionOptions.executionProfile] The name of the execution profile. |
| 55 | * @return {Promise<Object>} |
| 56 | * @example <caption>Get a video by id</caption> |
| 57 | * videoMapper.get({ id }) |
| 58 | * @example <caption>Get a video by id, selecting specific columns</caption> |
| 59 | * videoMapper.get({ id }, fields: ['name', 'description']) |
| 60 | */ |
| 61 | get(doc, docInfo, executionOptions) { |
| 62 | if (executionOptions === undefined && typeof docInfo === 'string') { |
| 63 | executionOptions = docInfo; |
| 64 | docInfo = null; |
| 65 | } |
| 66 | |
| 67 | return this._handler.getSelectExecutor(doc, docInfo, true) |
| 68 | .then(executor => executor(doc, docInfo, executionOptions)) |
| 69 | .then(result => result.first()); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Executes a SELECT query based on the filter and returns the result as an iterable of documents. |
| 74 | * @param {Object} doc An object containing the properties that map to the primary keys to filter. |
| 75 | * @param {Object} [docInfo] An object containing the additional document information. |
| 76 | * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the |
| 77 | * SELECT cql statement generated, in order to restrict the amount of columns retrieved. |
| 78 | * @param {Object<String, String>} [docInfo.orderBy] An associative array containing the column names as key and |
| 79 | * the order string (asc or desc) as value used to set the order of the results server-side. |
| 80 | * @param {Number} [docInfo.limit] Restricts the result of the query to a maximum number of rows on the |
| 81 | * server. |
| 82 | * @param {Object|String} [executionOptions] An object containing the options to be used for the requests |
| 83 | * execution or a string representing the name of the execution profile. |
| 84 | * @param {String} [executionOptions.executionProfile] The name of the execution profile. |
nothing calls this directly
no outgoing calls
no test coverage detected