@zeit/cosmosdb-query
Advanced tools
Comparing version 0.0.9 to 0.1.0
@@ -10,4 +10,9 @@ // | ||
code, | ||
parameters | ||
} | ||
parameters, | ||
udf | ||
} | ||
) => { | ||
@@ -28,4 +33,5 @@ // eslint-disable-next-line no-new-func | ||
helpers, | ||
udf, | ||
params | ||
); | ||
}; |
@@ -32,3 +32,12 @@ // | ||
exec(coll , parameters ) { | ||
exec( | ||
coll , | ||
{ | ||
parameters, | ||
udf | ||
} | ||
= {} | ||
) { | ||
const { code } = this; | ||
@@ -39,3 +48,3 @@ if (!code) { | ||
return execute(coll, { code, parameters }); | ||
return execute(coll, { code, parameters, udf }); | ||
} | ||
@@ -42,0 +51,0 @@ |
@@ -636,2 +636,7 @@ // | ||
}, | ||
// udf | ||
{ | ||
type: "Identifier", | ||
name: "udf" | ||
}, | ||
// parameters | ||
@@ -638,0 +643,0 @@ { |
{ | ||
"name": "@zeit/cosmosdb-query", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"license": "UNLICENSED", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -6,22 +6,72 @@ # cosmosdb-query | ||
```js | ||
const query = require('@zeit/cosmosdb-query') | ||
const query = require("@zeit/cosmosdb-query") | ||
const collection = [ | ||
{ id: 'foo' }, | ||
{ id: 'bar' } | ||
{ id: "foo" }, | ||
{ id: "bar" } | ||
] | ||
const docs = query('SELECT * FROM c WHERE c.id = @id') | ||
.exec(collection, [{ name: '@id', value: 'foo' }]) | ||
console.log(docs) // [ { id: 'foo' } ] | ||
const docs = query("SELECT * FROM c WHERE c.id = @id") | ||
.exec(collection, { | ||
parameters: [{ name: "@id", value: "foo" }] | ||
}) | ||
console.log(docs) // [ { id: "foo" } ] | ||
``` | ||
q = query('SELECT * FROM c WHERE c.id = 1') | ||
if (!q.containsPartitionKeys(['/key'])) { | ||
throw new Error('query doesn\'t contain partition keys') | ||
### query(sql) | ||
- `sql` <string> | ||
- Returns: <Query> | ||
```js | ||
const q = query("SELECT * FROM c") | ||
``` | ||
## Class: Query | ||
### q.exec(collection[, options]) | ||
- `collection` <Object[]> | <null> | ||
- `options` <Object> | ||
- `parameters` <Object[]> The parameters to pass to query | ||
- `udf` <Object> | ||
- Returns: <Object[]> | ||
Executes query for `collection`. | ||
```js | ||
query(`SELECT VALUE udf.REGEX_MATCH("foobar", ".*bar")`).exec(null, { | ||
udf: { | ||
REGEX_MATCH(input, pattern) { | ||
return input.match(pattern) !== null | ||
} | ||
} | ||
}) | ||
``` | ||
### q.containsPartitionKeys(keys) | ||
- `keys` <string[]> | ||
- Returns: <boolean> | ||
Determines whether query may contain partition keys. | ||
```js | ||
const q = query("SELECT * FROM c WHERE c.id = 1") | ||
if (!q.containsPartitionKeys(["/key"])) { | ||
throw new Error("query doesn't contain partition keys") | ||
} | ||
``` | ||
### q.ast | ||
- <Object> | ||
The AST object of query. | ||
## TODO | ||
- Spatial functions | ||
- User-defined functions | ||
- Support spatial functions |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
200882
7034
77