@ragestudio/scylla-odm 0.22.2 → 0.22.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/batch/index.d.ts +3 -3
  2. package/batch/index.d.ts.map +1 -1
  3. package/client.d.ts +6 -5
  4. package/client.d.ts.map +1 -1
  5. package/client.js +11 -12
  6. package/client.js.map +1 -1
  7. package/cql_gen/create_table.d.ts +1 -1
  8. package/cql_gen/create_table.d.ts.map +1 -1
  9. package/document/index.d.ts +3 -3
  10. package/document/index.d.ts.map +1 -1
  11. package/driver/LICENSE.txt +177 -0
  12. package/driver/NOTICE.txt +67 -0
  13. package/driver/auth/index.d.ts +37 -0
  14. package/driver/auth/index.js +37 -0
  15. package/driver/auth/no-auth-provider.js +73 -0
  16. package/driver/auth/plain-text-auth-provider.js +81 -0
  17. package/driver/auth/provider.js +77 -0
  18. package/driver/client-options.js +442 -0
  19. package/driver/client.js +1267 -0
  20. package/driver/concurrent/index.d.ts +49 -0
  21. package/driver/concurrent/index.js +366 -0
  22. package/driver/connection.js +1034 -0
  23. package/driver/control-connection.js +1282 -0
  24. package/driver/encoder.js +2316 -0
  25. package/driver/errors.js +223 -0
  26. package/driver/execution-options.js +612 -0
  27. package/driver/execution-profile.js +274 -0
  28. package/driver/host-connection-pool.js +587 -0
  29. package/driver/host.js +699 -0
  30. package/driver/index.d.ts +387 -0
  31. package/driver/index.js +81 -0
  32. package/driver/mapping/cache.js +214 -0
  33. package/driver/mapping/doc-info-adapter.js +171 -0
  34. package/driver/mapping/index.d.ts +219 -0
  35. package/driver/mapping/index.js +57 -0
  36. package/driver/mapping/mapper.js +225 -0
  37. package/driver/mapping/mapping-handler.js +641 -0
  38. package/driver/mapping/model-batch-item.js +215 -0
  39. package/driver/mapping/model-batch-mapper.js +141 -0
  40. package/driver/mapping/model-mapper.js +315 -0
  41. package/driver/mapping/model-mapping-info.js +225 -0
  42. package/driver/mapping/object-selector.js +417 -0
  43. package/driver/mapping/q.js +156 -0
  44. package/driver/mapping/query-generator.js +556 -0
  45. package/driver/mapping/result-mapper.js +123 -0
  46. package/driver/mapping/result.js +139 -0
  47. package/driver/mapping/table-mappings.js +133 -0
  48. package/driver/mapping/tree.js +160 -0
  49. package/driver/metadata/aggregate.js +79 -0
  50. package/driver/metadata/client-state.js +119 -0
  51. package/driver/metadata/data-collection.js +182 -0
  52. package/driver/metadata/event-debouncer.js +174 -0
  53. package/driver/metadata/index.d.ts +276 -0
  54. package/driver/metadata/index.js +1156 -0
  55. package/driver/metadata/materialized-view.js +49 -0
  56. package/driver/metadata/schema-function.js +98 -0
  57. package/driver/metadata/schema-index.js +166 -0
  58. package/driver/metadata/schema-parser.js +1399 -0
  59. package/driver/metadata/table-metadata.js +77 -0
  60. package/driver/operation-state.js +206 -0
  61. package/driver/policies/address-resolution.js +145 -0
  62. package/driver/policies/index.d.ts +241 -0
  63. package/driver/policies/index.js +110 -0
  64. package/driver/policies/load-balancing.js +970 -0
  65. package/driver/policies/reconnection.js +166 -0
  66. package/driver/policies/retry.js +326 -0
  67. package/driver/policies/speculative-execution.js +150 -0
  68. package/driver/policies/timestamp-generation.js +176 -0
  69. package/driver/prepare-handler.js +347 -0
  70. package/driver/promise-utils.js +191 -0
  71. package/driver/readers.js +624 -0
  72. package/driver/request-execution.js +644 -0
  73. package/driver/request-handler.js +332 -0
  74. package/driver/requests.js +618 -0
  75. package/driver/stream-id-stack.js +209 -0
  76. package/driver/streams.js +745 -0
  77. package/driver/token.js +325 -0
  78. package/driver/tokenizer.js +631 -0
  79. package/driver/types/big-decimal.js +282 -0
  80. package/driver/types/duration.js +576 -0
  81. package/driver/types/index.d.ts +486 -0
  82. package/driver/types/index.js +733 -0
  83. package/driver/types/inet-address.js +262 -0
  84. package/driver/types/integer.js +818 -0
  85. package/driver/types/local-date.js +280 -0
  86. package/driver/types/local-time.js +299 -0
  87. package/driver/types/mutable-long.js +385 -0
  88. package/driver/types/protocol-version.js +391 -0
  89. package/driver/types/result-set.js +287 -0
  90. package/driver/types/result-stream.js +164 -0
  91. package/driver/types/row.js +85 -0
  92. package/driver/types/time-uuid.js +414 -0
  93. package/driver/types/tuple.js +103 -0
  94. package/driver/types/uuid.js +160 -0
  95. package/driver/types/vector.js +130 -0
  96. package/driver/types/version-number.js +153 -0
  97. package/driver/utils.js +1485 -0
  98. package/driver/writers.js +350 -0
  99. package/global.d.ts +1 -1
  100. package/global.d.ts.map +1 -1
  101. package/index.d.ts +6 -6
  102. package/index.d.ts.map +1 -1
  103. package/index.js +6 -6
  104. package/index.js.map +1 -1
  105. package/migrate/index.d.ts +1 -1
  106. package/migrate/index.d.ts.map +1 -1
  107. package/migrate/index.js +1 -1
  108. package/migrate/index.js.map +1 -1
  109. package/model/index.d.ts +6 -6
  110. package/model/index.d.ts.map +1 -1
  111. package/model/index.js +10 -10
  112. package/model/index.js.map +1 -1
  113. package/operations/countAll.d.ts +1 -1
  114. package/operations/countAll.d.ts.map +1 -1
  115. package/operations/delete.d.ts +3 -4
  116. package/operations/delete.d.ts.map +1 -1
  117. package/operations/delete.js +1 -1
  118. package/operations/delete.js.map +1 -1
  119. package/operations/find.d.ts +2 -2
  120. package/operations/find.d.ts.map +1 -1
  121. package/operations/find.js +1 -1
  122. package/operations/find.js.map +1 -1
  123. package/operations/findOne.d.ts +2 -2
  124. package/operations/findOne.d.ts.map +1 -1
  125. package/operations/findOne.js +1 -1
  126. package/operations/findOne.js.map +1 -1
  127. package/operations/insert.d.ts +3 -3
  128. package/operations/insert.d.ts.map +1 -1
  129. package/operations/insert.js +2 -2
  130. package/operations/insert.js.map +1 -1
  131. package/operations/sync.d.ts +1 -1
  132. package/operations/sync.d.ts.map +1 -1
  133. package/operations/sync.js +1 -1
  134. package/operations/sync.js.map +1 -1
  135. package/operations/tableExists.d.ts +1 -1
  136. package/operations/tableExists.d.ts.map +1 -1
  137. package/operations/update.d.ts +3 -3
  138. package/operations/update.d.ts.map +1 -1
  139. package/operations/update.js +2 -2
  140. package/operations/update.js.map +1 -1
  141. package/package.json +4 -12
  142. package/schema/index.d.ts +1 -1
  143. package/schema/index.d.ts.map +1 -1
  144. package/types.d.ts +4 -4
  145. package/types.d.ts.map +1 -1
  146. package/utils/queryParser.d.ts +1 -1
  147. package/utils/queryParser.d.ts.map +1 -1
  148. package/utils/queryParser.js +1 -1
  149. package/utils/queryParser.js.map +1 -1
  150. package/utils/typeChecker.d.ts +1 -1
  151. package/utils/typeChecker.d.ts.map +1 -1
  152. package/utils/typeChecker.js +1 -1
  153. package/utils/typeChecker.js.map +1 -1
@@ -0,0 +1,215 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import Cache from "./cache.js"
20
+
21
+ /**
22
+ * Represents a query or a set of queries used to perform a mutation in a batch.
23
+ * @alias module:mapping~ModelBatchItem
24
+ */
25
+ class ModelBatchItem {
26
+ /**
27
+ * @param {Object} doc
28
+ * @param {Object} docInfo
29
+ * @param {MappingHandler} handler
30
+ * @param {Tree} cache
31
+ */
32
+ constructor(doc, docInfo, handler, cache) {
33
+ this.doc = doc
34
+ this.docInfo = docInfo
35
+ this.handler = handler
36
+ this.cache = cache
37
+ }
38
+
39
+ /**
40
+ * @ignore
41
+ * @returns <Promise<Array>>
42
+ */
43
+ getQueries() {
44
+ const docKeys = Object.keys(this.doc)
45
+ const cacheItem = this.cache.getOrCreate(
46
+ this.getCacheKey(docKeys),
47
+ () => ({
48
+ queries: null,
49
+ }),
50
+ )
51
+
52
+ if (cacheItem.queries === null) {
53
+ cacheItem.queries = this.createQueries(docKeys)
54
+ }
55
+
56
+ return cacheItem.queries
57
+ }
58
+
59
+ /**
60
+ * Gets the cache key for this item.
61
+ * @abstract
62
+ * @param {Array} docKeys
63
+ * @returns {Iterator}
64
+ */
65
+ getCacheKey(docKeys) {
66
+ throw new Error("getCacheKey must be implemented")
67
+ }
68
+
69
+ /**
70
+ * Gets the Promise to create the queries.
71
+ * @abstract
72
+ * @param {Array} docKeys
73
+ * @returns {Promise<Array>}
74
+ */
75
+ createQueries(docKeys) {
76
+ throw new Error("getCacheKey must be implemented")
77
+ }
78
+
79
+ /**
80
+ * Pushes the queries and parameters represented by this instance to the provided array.
81
+ * @internal
82
+ * @ignore
83
+ * @param {Array} arr
84
+ * @return {Promise<{isIdempotent, isCounter}>}
85
+ */
86
+ pushQueries(arr) {
87
+ let isIdempotent = true
88
+ let isCounter
89
+
90
+ return this.getQueries().then((queries) => {
91
+ queries.forEach((q) => {
92
+ // It's idempotent if all the queries contained are idempotent
93
+ isIdempotent = isIdempotent && q.isIdempotent
94
+
95
+ // Either all queries are counter mutation or we let it fail at server level
96
+ isCounter = q.isCounter
97
+
98
+ arr.push({
99
+ query: q.query,
100
+ params: q.paramsGetter(
101
+ this.doc,
102
+ this.docInfo,
103
+ this.getMappingInfo(),
104
+ ),
105
+ })
106
+ })
107
+
108
+ return { isIdempotent, isCounter }
109
+ })
110
+ }
111
+
112
+ /**
113
+ * Gets the mapping information for this batch item.
114
+ * @internal
115
+ * @ignore
116
+ */
117
+ getMappingInfo() {
118
+ return this.handler.info
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Represents a single or a set of INSERT queries in a batch.
124
+ * @ignore
125
+ * @internal
126
+ */
127
+ class InsertModelBatchItem extends ModelBatchItem {
128
+ /**
129
+ * @param {Object} doc
130
+ * @param {Object} docInfo
131
+ * @param {MappingHandler} handler
132
+ * @param {Tree} cache
133
+ */
134
+ constructor(doc, docInfo, handler, cache) {
135
+ super(doc, docInfo, handler, cache)
136
+ }
137
+
138
+ /** @override */
139
+ getCacheKey(docKeys) {
140
+ return Cache.getInsertKey(docKeys, this.docInfo)
141
+ }
142
+
143
+ /** @override */
144
+ createQueries(docKeys) {
145
+ return this.handler.createInsertQueries(docKeys, this.doc, this.docInfo)
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Represents a single or a set of UPDATE queries in a batch.
151
+ * @ignore
152
+ * @internal
153
+ */
154
+ class UpdateModelBatchItem extends ModelBatchItem {
155
+ /**
156
+ * @param {Object} doc
157
+ * @param {Object} docInfo
158
+ * @param {MappingHandler} handler
159
+ * @param {Tree} cache
160
+ */
161
+ constructor(doc, docInfo, handler, cache) {
162
+ super(doc, docInfo, handler, cache)
163
+ }
164
+
165
+ /** @override */
166
+ getCacheKey(docKeys) {
167
+ return Cache.getUpdateKey(docKeys, this.doc, this.docInfo)
168
+ }
169
+
170
+ /** @override */
171
+ createQueries(docKeys) {
172
+ return this.handler.createUpdateQueries(docKeys, this.doc, this.docInfo)
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Represents a single or a set of DELETE queries in a batch.
178
+ * @ignore
179
+ * @internal
180
+ */
181
+ class RemoveModelBatchItem extends ModelBatchItem {
182
+ /**
183
+ * @param {Object} doc
184
+ * @param {Object} docInfo
185
+ * @param {MappingHandler} handler
186
+ * @param {Tree} cache
187
+ */
188
+ constructor(doc, docInfo, handler, cache) {
189
+ super(doc, docInfo, handler, cache)
190
+ }
191
+
192
+ /** @override */
193
+ getCacheKey(docKeys) {
194
+ return Cache.getRemoveKey(docKeys, this.doc, this.docInfo)
195
+ }
196
+
197
+ /** @override */
198
+ createQueries(docKeys) {
199
+ return this.handler.createDeleteQueries(docKeys, this.doc, this.docInfo)
200
+ }
201
+ }
202
+
203
+ export {
204
+ ModelBatchItem,
205
+ InsertModelBatchItem,
206
+ UpdateModelBatchItem,
207
+ RemoveModelBatchItem,
208
+ }
209
+
210
+ export default {
211
+ ModelBatchItem,
212
+ InsertModelBatchItem,
213
+ UpdateModelBatchItem,
214
+ RemoveModelBatchItem,
215
+ }
@@ -0,0 +1,141 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import Tree from "./tree.js"
20
+ import {
21
+ InsertModelBatchItem,
22
+ UpdateModelBatchItem,
23
+ RemoveModelBatchItem,
24
+ } from "./model-batch-item.js"
25
+
26
+ /**
27
+ * Provides utility methods to group multiple mutations on a single batch.
28
+ * @alias module:mapping~ModelBatchMapper
29
+ */
30
+ class ModelBatchMapper {
31
+ /**
32
+ * Creates a new instance of model batch mapper.
33
+ * <p>
34
+ * An instance of this class is exposed as a singleton in the <code>batching</code> field of the
35
+ * [ModelMapper]{@link module:mapping~ModelMapper}. Note that new instances should not be create with this
36
+ * constructor.
37
+ * </p>
38
+ * @param {MappingHandler} handler
39
+ * @ignore
40
+ */
41
+ constructor(handler) {
42
+ this._handler = handler
43
+ this._cache = {
44
+ insert: new Tree(),
45
+ update: new Tree(),
46
+ remove: new Tree(),
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Gets a [ModelBatchItem]{@link module:mapping~ModelBatchItem} containing the queries for the INSERT mutation to be
52
+ * used in a batch execution.
53
+ * @param {Object} doc An object containing the properties to insert.
54
+ * @param {Object} [docInfo] An object containing the additional document information.
55
+ * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the
56
+ * INSERT cql statements generated. If specified, it must include the columns to insert and the primary keys.
57
+ * @param {Number} [docInfo.ttl] Specifies an optional Time To Live (in seconds) for the inserted values.
58
+ * @param {Boolean} [docInfo.ifNotExists] When set, it only inserts if the row does not exist prior to the insertion.
59
+ * <p>Please note that using IF NOT EXISTS will incur a non negligible performance cost so this should be used
60
+ * sparingly.</p>
61
+ * @returns {ModelBatchItem} A [ModelBatchItem]{@link module:mapping~ModelBatchItem} instance representing a query
62
+ * or a set of queries to be included in a batch.
63
+ */
64
+ insert(doc, docInfo) {
65
+ return new InsertModelBatchItem(
66
+ doc,
67
+ docInfo,
68
+ this._handler,
69
+ this._cache.insert,
70
+ )
71
+ }
72
+
73
+ /**
74
+ * Gets a [ModelBatchItem]{@link module:mapping~ModelBatchItem} containing the queries for the UPDATE mutation to be
75
+ * used in a batch execution.
76
+ * @param {Object} doc An object containing the properties to update.
77
+ * @param {Object} [docInfo] An object containing the additional document information.
78
+ * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the
79
+ * UPDATE cql statements generated. If specified, it must include the columns to update and the primary keys.
80
+ * @param {Number} [docInfo.ttl] Specifies an optional Time To Live (in seconds) for the inserted values.
81
+ * @param {Boolean} [docInfo.ifExists] When set, it only updates if the row already exists on the server.
82
+ * <p>
83
+ * Please note that using IF conditions will incur a non negligible performance cost on the server-side so this
84
+ * should be used sparingly.
85
+ * </p>
86
+ * @param {Object} [docInfo.when] A document that act as the condition that has to be met for the UPDATE to occur.
87
+ * Use this property only in the case you want to specify a conditional clause for lightweight transactions (CAS).
88
+ * <p>
89
+ * Please note that using IF conditions will incur a non negligible performance cost on the server-side so this
90
+ * should be used sparingly.
91
+ * </p>
92
+ * @returns {ModelBatchItem} A [ModelBatchItem]{@link module:mapping~ModelBatchItem} instance representing a query
93
+ * or a set of queries to be included in a batch.
94
+ */
95
+ update(doc, docInfo) {
96
+ return new UpdateModelBatchItem(
97
+ doc,
98
+ docInfo,
99
+ this._handler,
100
+ this._cache.update,
101
+ )
102
+ }
103
+
104
+ /**
105
+ * Gets a [ModelBatchItem]{@link module:mapping~ModelBatchItem} containing the queries for the DELETE mutation to be
106
+ * used in a batch execution.
107
+ * @param {Object} doc A document containing the primary keys values of the document to delete.
108
+ * @param {Object} [docInfo] An object containing the additional doc information.
109
+ * @param {Object} [docInfo.when] A document that act as the condition that has to be met for the DELETE to occur.
110
+ * Use this property only in the case you want to specify a conditional clause for lightweight transactions (CAS).
111
+ * When the CQL query is generated, this would be used to generate the `IF` clause.
112
+ * <p>
113
+ * Please note that using IF conditions will incur a non negligible performance cost on the server-side so this
114
+ * should be used sparingly.
115
+ * </p>
116
+ * @param {Boolean} [docInfo.ifExists] When set, it only issues the DELETE command if the row already exists on the
117
+ * server.
118
+ * <p>
119
+ * Please note that using IF conditions will incur a non negligible performance cost on the server-side so this
120
+ * should be used sparingly.
121
+ * </p>
122
+ * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the
123
+ * DELETE cql statement generated. If specified, it must include the columns to delete and the primary keys.
124
+ * @param {Boolean} [docInfo.deleteOnlyColumns] Determines that, when more document properties are specified
125
+ * besides the primary keys, the generated DELETE statement should be used to delete some column values but leave
126
+ * the row. When this is enabled and more properties are specified, a DELETE statement will have the following form:
127
+ * "DELETE col1, col2 FROM table1 WHERE pk1 = ? AND pk2 = ?"
128
+ * @returns {ModelBatchItem} A [ModelBatchItem]{@link module:mapping~ModelBatchItem} instance representing a query
129
+ * or a set of queries to be included in a batch.
130
+ */
131
+ remove(doc, docInfo) {
132
+ return new RemoveModelBatchItem(
133
+ doc,
134
+ docInfo,
135
+ this._handler,
136
+ this._cache.update,
137
+ )
138
+ }
139
+ }
140
+
141
+ export default ModelBatchMapper
@@ -0,0 +1,315 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import ModelBatchMapper from "./model-batch-mapper.js"
20
+
21
+ /**
22
+ * Represents an object mapper for a specific model.
23
+ * @alias module:mapping~ModelMapper
24
+ */
25
+ class ModelMapper {
26
+ constructor(name, handler) {
27
+ /**
28
+ * Gets the name identifier of the model.
29
+ * @type {String}
30
+ */
31
+ this.name = name
32
+ this._handler = handler
33
+ /**
34
+ * Gets a [ModelBatchMapper]{@link module:mapping~ModelBatchMapper} instance containing utility methods to group
35
+ * multiple doc mutations in a single batch.
36
+ * @type {ModelBatchMapper}
37
+ */
38
+ this.batching = new ModelBatchMapper(this._handler)
39
+ }
40
+
41
+ /**
42
+ * Gets the first document matching the provided filter or null when not found.
43
+ * <p>
44
+ * Note that all partition and clustering keys must be defined in order to use this method.
45
+ * </p>
46
+ * @param {Object} doc The object containing the properties that map to the primary keys.
47
+ * @param {Object} [docInfo] An object containing the additional document information.
48
+ * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the
49
+ * SELECT cql statement generated, in order to restrict the amount of columns retrieved.
50
+ * @param {Object|String} [executionOptions] An object containing the options to be used for the requests
51
+ * execution or a string representing the name of the execution profile.
52
+ * @param {String} [executionOptions.executionProfile] The name of the execution profile.
53
+ * @return {Promise<Object>}
54
+ * @example <caption>Get a video by id</caption>
55
+ * videoMapper.get({ id })
56
+ * @example <caption>Get a video by id, selecting specific columns</caption>
57
+ * videoMapper.get({ id }, fields: ['name', 'description'])
58
+ */
59
+ get(doc, docInfo, executionOptions) {
60
+ if (executionOptions === undefined && typeof docInfo === "string") {
61
+ executionOptions = docInfo
62
+ docInfo = null
63
+ }
64
+
65
+ return this._handler
66
+ .getSelectExecutor(doc, docInfo, true)
67
+ .then((executor) => executor(doc, docInfo, executionOptions))
68
+ .then((result) => result.first())
69
+ }
70
+
71
+ /**
72
+ * Executes a SELECT query based on the filter and returns the result as an iterable of documents.
73
+ * @param {Object} doc An object containing the properties that map to the primary keys to filter.
74
+ * @param {Object} [docInfo] An object containing the additional document information.
75
+ * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the
76
+ * SELECT cql statement generated, in order to restrict the amount of columns retrieved.
77
+ * @param {Object<String, String>} [docInfo.orderBy] An associative array containing the column names as key and
78
+ * the order string (asc or desc) as value used to set the order of the results server-side.
79
+ * @param {Number} [docInfo.limit] Restricts the result of the query to a maximum number of rows on the
80
+ * server.
81
+ * @param {Object|String} [executionOptions] An object containing the options to be used for the requests
82
+ * execution or a string representing the name of the execution profile.
83
+ * @param {String} [executionOptions.executionProfile] The name of the execution profile.
84
+ * @param {Number} [executionOptions.fetchSize] The amount of rows to retrieve per page.
85
+ * @param {Number} [executionOptions.pageState] A Buffer instance or a string token representing the paging state.
86
+ * <p>When provided, the query will be executed starting from a given paging state.</p>
87
+ * @return {Promise<Result>} A Promise that resolves to a [Result]{@link module:mapping~Result} instance.
88
+ * @example <caption>Get user's videos</caption>
89
+ * const result = await videoMapper.find({ userId });
90
+ * for (let video of result) {
91
+ * console.log(video.name);
92
+ * }
93
+ * @example <caption>Get user's videos from a certain date</caption>
94
+ * videoMapper.find({ userId, addedDate: q.gte(date)});
95
+ * @example <caption>Get user's videos in reverse order</caption>
96
+ * videoMapper.find({ userId }, { orderBy: { addedDate: 'desc' }});
97
+ */
98
+ find(doc, docInfo, executionOptions) {
99
+ if (executionOptions === undefined && typeof docInfo === "string") {
100
+ executionOptions = docInfo
101
+ docInfo = null
102
+ }
103
+
104
+ return this._handler
105
+ .getSelectExecutor(doc, docInfo, false)
106
+ .then((executor) => executor(doc, docInfo, executionOptions))
107
+ }
108
+
109
+ /**
110
+ * Executes a SELECT query without a filter and returns the result as an iterable of documents.
111
+ * <p>
112
+ * This is only recommended to be used for tables with a limited amount of results. Otherwise, breaking up the
113
+ * token ranges on the client side should be used.
114
+ * </p>
115
+ * @param {Object} [docInfo] An object containing the additional document information.
116
+ * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the
117
+ * SELECT cql statement generated, in order to restrict the amount of columns retrieved.
118
+ * @param {Object<String, String>} [docInfo.orderBy] An associative array containing the column names as key and
119
+ * the order string (asc or desc) as value used to set the order of the results server-side.
120
+ * @param {Number} [docInfo.limit] Restricts the result of the query to a maximum number of rows on the
121
+ * server.
122
+ * @param {Object|String} [executionOptions] An object containing the options to be used for the requests
123
+ * execution or a string representing the name of the execution profile.
124
+ * @param {String} [executionOptions.executionProfile] The name of the execution profile.
125
+ * @param {Number} [executionOptions.fetchSize] The mount of rows to retrieve per page.
126
+ * @param {Number} [executionOptions.pageState] A Buffer instance or a string token representing the paging state.
127
+ * <p>When provided, the query will be executed starting from a given paging state.</p>
128
+ * @return {Promise<Result>} A Promise that resolves to a [Result]{@link module:mapping~Result} instance.
129
+ */
130
+ findAll(docInfo, executionOptions) {
131
+ if (executionOptions === undefined && typeof docInfo === "string") {
132
+ executionOptions = docInfo
133
+ docInfo = null
134
+ }
135
+
136
+ const executor = this._handler.getSelectAllExecutor(docInfo)
137
+ return executor(docInfo, executionOptions)
138
+ }
139
+
140
+ /**
141
+ * Inserts a document.
142
+ * <p>
143
+ * When the model is mapped to multiple tables, it will insert a row in each table when all the primary keys
144
+ * are specified.
145
+ * </p>
146
+ * @param {Object} doc An object containing the properties to insert.
147
+ * @param {Object} [docInfo] An object containing the additional document information.
148
+ * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the
149
+ * INSERT cql statements generated. If specified, it must include the columns to insert and the primary keys.
150
+ * @param {Number} [docInfo.ttl] Specifies an optional Time To Live (in seconds) for the inserted values.
151
+ * @param {Boolean} [docInfo.ifNotExists] When set, it only inserts if the row does not exist prior to the insertion.
152
+ * <p>Please note that using IF NOT EXISTS will incur a non negligible performance cost so this should be used
153
+ * sparingly.</p>
154
+ * @param {Object|String} [executionOptions] An object containing the options to be used for the requests
155
+ * execution or a string representing the name of the execution profile.
156
+ * @param {String} [executionOptions.executionProfile] The name of the execution profile.
157
+ * @param {Boolean} [executionOptions.isIdempotent] Defines whether the query can be applied multiple times without
158
+ * changing the result beyond the initial application.
159
+ * <p>
160
+ * By default all generated INSERT statements are considered idempotent, except in the case of lightweight
161
+ * transactions. Lightweight transactions at client level with transparent retries can
162
+ * break linearizability. If that is not an issue for your application, you can manually set this field to true.
163
+ * </p>
164
+ * @param {Number|Long} [executionOptions.timestamp] The default timestamp for the query in microseconds from the
165
+ * unix epoch (00:00:00, January 1st, 1970).
166
+ * <p>When provided, this will replace the client generated and the server side assigned timestamp.</p>
167
+ * @return {Promise<Result>} A Promise that resolves to a [Result]{@link module:mapping~Result} instance.
168
+ * @example <caption>Insert a video</caption>
169
+ * videoMapper.insert({ id, name });
170
+ */
171
+ insert(doc, docInfo, executionOptions) {
172
+ if (executionOptions === undefined && typeof docInfo === "string") {
173
+ executionOptions = docInfo
174
+ docInfo = null
175
+ }
176
+
177
+ return this._handler
178
+ .getInsertExecutor(doc, docInfo)
179
+ .then((executor) => executor(doc, docInfo, executionOptions))
180
+ }
181
+
182
+ /**
183
+ * Updates a document.
184
+ * <p>
185
+ * When the model is mapped to multiple tables, it will update a row in each table when all the primary keys
186
+ * are specified.
187
+ * </p>
188
+ * @param {Object} doc An object containing the properties to update.
189
+ * @param {Object} [docInfo] An object containing the additional document information.
190
+ * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the
191
+ * UPDATE cql statements generated. If specified, it must include the columns to update and the primary keys.
192
+ * @param {Number} [docInfo.ttl] Specifies an optional Time To Live (in seconds) for the inserted values.
193
+ * @param {Boolean} [docInfo.ifExists] When set, it only updates if the row already exists on the server.
194
+ * <p>
195
+ * Please note that using IF conditions will incur a non negligible performance cost on the server-side so this
196
+ * should be used sparingly.
197
+ * </p>
198
+ * @param {Object} [docInfo.when] A document that act as the condition that has to be met for the UPDATE to occur.
199
+ * Use this property only in the case you want to specify a conditional clause for lightweight transactions (CAS).
200
+ * <p>
201
+ * Please note that using IF conditions will incur a non negligible performance cost on the server-side so this
202
+ * should be used sparingly.
203
+ * </p>
204
+ * @param {Object|String} [executionOptions] An object containing the options to be used for the requests
205
+ * execution or a string representing the name of the execution profile.
206
+ * @param {String} [executionOptions.executionProfile] The name of the execution profile.
207
+ * @param {Boolean} [executionOptions.isIdempotent] Defines whether the query can be applied multiple times without
208
+ * changing the result beyond the initial application.
209
+ * <p>
210
+ * The mapper uses the generated queries to determine the default value. When an UPDATE is generated with a
211
+ * counter column or appending/prepending to a list column, the execution is marked as not idempotent.
212
+ * </p>
213
+ * <p>
214
+ * Additionally, the mapper uses the safest approach for queries with lightweight transactions (Compare and
215
+ * Set) by considering them as non-idempotent. Lightweight transactions at client level with transparent retries can
216
+ * break linearizability. If that is not an issue for your application, you can manually set this field to true.
217
+ * </p>
218
+ * @param {Number|Long} [executionOptions.timestamp] The default timestamp for the query in microseconds from the
219
+ * unix epoch (00:00:00, January 1st, 1970).
220
+ * <p>When provided, this will replace the client generated and the server side assigned timestamp.</p>
221
+ * @return {Promise<Result>} A Promise that resolves to a [Result]{@link module:mapping~Result} instance.
222
+ * @example <caption>Update the name of a video</caption>
223
+ * videoMapper.update({ id, name });
224
+ */
225
+ update(doc, docInfo, executionOptions) {
226
+ if (executionOptions === undefined && typeof docInfo === "string") {
227
+ executionOptions = docInfo
228
+ docInfo = null
229
+ }
230
+
231
+ return this._handler
232
+ .getUpdateExecutor(doc, docInfo)
233
+ .then((executor) => executor(doc, docInfo, executionOptions))
234
+ }
235
+
236
+ /**
237
+ * Deletes a document.
238
+ * @param {Object} doc A document containing the primary keys values of the document to delete.
239
+ * @param {Object} [docInfo] An object containing the additional doc information.
240
+ * @param {Object} [docInfo.when] A document that act as the condition that has to be met for the DELETE to occur.
241
+ * Use this property only in the case you want to specify a conditional clause for lightweight transactions (CAS).
242
+ * When the CQL query is generated, this would be used to generate the `IF` clause.
243
+ * <p>
244
+ * Please note that using IF conditions will incur a non negligible performance cost on the server-side so this
245
+ * should be used sparingly.
246
+ * </p>
247
+ * @param {Boolean} [docInfo.ifExists] When set, it only issues the DELETE command if the row already exists on the
248
+ * server.
249
+ * <p>
250
+ * Please note that using IF conditions will incur a non negligible performance cost on the server-side so this
251
+ * should be used sparingly.
252
+ * </p>
253
+ * @param {Array<String>} [docInfo.fields] An Array containing the name of the properties that will be used in the
254
+ * DELETE cql statement generated. If specified, it must include the columns to delete and the primary keys.
255
+ * @param {Boolean} [docInfo.deleteOnlyColumns] Determines that, when more document properties are specified
256
+ * besides the primary keys, the generated DELETE statement should be used to delete some column values but leave
257
+ * the row. When this is enabled and more properties are specified, a DELETE statement will have the following form:
258
+ * "DELETE col1, col2 FROM table1 WHERE pk1 = ? AND pk2 = ?"
259
+ * @param {Object|String} [executionOptions] An object containing the options to be used for the requests
260
+ * execution or a string representing the name of the execution profile.
261
+ * @param {String} [executionOptions.executionProfile] The name of the execution profile.
262
+ * @param {Boolean} [executionOptions.isIdempotent] Defines whether the query can be applied multiple times without
263
+ * changing the result beyond the initial application.
264
+ * <p>
265
+ * By default all generated DELETE statements are considered idempotent, except in the case of lightweight
266
+ * transactions. Lightweight transactions at client level with transparent retries can
267
+ * break linearizability. If that is not an issue for your application, you can manually set this field to true.
268
+ * </p>
269
+ * @param {Number|Long} [executionOptions.timestamp] The default timestamp for the query in microseconds from the
270
+ * unix epoch (00:00:00, January 1st, 1970).
271
+ * <p>When provided, this will replace the client generated and the server side assigned timestamp.</p>
272
+ * @return {Promise<Result>} A Promise that resolves to a [Result]{@link module:mapping~Result} instance.
273
+ * @example <caption>Delete a video</caption>
274
+ * videoMapper.remove({ id });
275
+ */
276
+ remove(doc, docInfo, executionOptions) {
277
+ if (executionOptions === undefined && typeof docInfo === "string") {
278
+ executionOptions = docInfo
279
+ docInfo = null
280
+ }
281
+
282
+ return this._handler
283
+ .getDeleteExecutor(doc, docInfo)
284
+ .then((executor) => executor(doc, docInfo, executionOptions))
285
+ }
286
+
287
+ /**
288
+ * Uses the provided query and param getter function to execute a query and map the results.
289
+ * Gets a function that takes the document, executes the query and returns the mapped results.
290
+ * @param {String} query The query to execute.
291
+ * @param {Function} paramsHandler The function to execute to extract the parameters of a document.
292
+ * @param {Object|String} [executionOptions] When provided, the options for all executions generated with this
293
+ * method will use the provided options and it will not consider the executionOptions per call.
294
+ * @param {String} [executionOptions.executionProfile] The name of the execution profile.
295
+ * @param {Number} [executionOptions.fetchSize] Amount of rows to retrieve per page.
296
+ * @param {Boolean} [executionOptions.isIdempotent] Defines whether the query can be applied multiple times
297
+ * without changing the result beyond the initial application.
298
+ * @param {Number} [executionOptions.pageState] Buffer or string token representing the paging state.
299
+ * <p>When provided, the query will be executed starting from a given paging state.</p>
300
+ * @param {Number|Long} [executionOptions.timestamp] The default timestamp for the query in microseconds from the
301
+ * unix epoch (00:00:00, January 1st, 1970).
302
+ * <p>When provided, this will replace the client generated and the server side assigned timestamp.</p>
303
+ * @return {Function} Returns a function that takes the document and execution options as parameters and returns a
304
+ * Promise the resolves to a [Result]{@link module:mapping~Result} instance.
305
+ */
306
+ mapWithQuery(query, paramsHandler, executionOptions) {
307
+ return this._handler.getExecutorFromQuery(
308
+ query,
309
+ paramsHandler,
310
+ executionOptions,
311
+ )
312
+ }
313
+ }
314
+
315
+ export default ModelMapper