{"id":18820368,"url":"https://github.com/drylikov/cosmosdb-query","last_synced_at":"2026-03-16T22:31:58.847Z","repository":{"id":244591327,"uuid":"815690131","full_name":"drylikov/Cosmosdb-Query","owner":"drylikov","description":"A SQL parser and executer for Cosmos DB.","archived":false,"fork":false,"pushed_at":"2024-06-15T21:08:23.000Z","size":81,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"drylikov","last_synced_at":"2025-03-27T14:07:17.497Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drylikov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-15T21:05:45.000Z","updated_at":"2025-03-19T16:10:21.000Z","dependencies_parsed_at":"2024-06-15T22:23:27.075Z","dependency_job_id":"501871f0-e424-4b85-8728-fa518a0f12ce","html_url":"https://github.com/drylikov/Cosmosdb-Query","commit_stats":null,"previous_names":["drylikov/cosmosdb-query"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drylikov%2FCosmosdb-Query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drylikov%2FCosmosdb-Query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drylikov%2FCosmosdb-Query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drylikov%2FCosmosdb-Query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drylikov","download_url":"https://codeload.github.com/drylikov/Cosmosdb-Query/tar.gz/refs/heads/drylikov","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248797890,"owners_count":21163209,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T00:28:13.973Z","updated_at":"2026-03-16T22:31:58.796Z","avatar_url":"https://github.com/drylikov.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cosmosdb-Query\n\nA SQL parser and executer for Cosmos DB.\n\n```js\nconst { default: query } = require(\"@zeit/cosmosdb-query\");\n\nconst items = [\n  { id: \"foo\" },\n  { id: \"bar\" }\n];\n\nconst { result } = query(\"SELECT * FROM c WHERE c.id = @id\")\n  .exec(items, {\n    parameters: [{ name: \"@id\", value: \"foo\" }]\n  });\nconsole.log(result); // [ { id: \"foo\" } ]\n```\n\n### query(sql)\n\n- `sql` \u0026lt;string\u003e\n- Returns: \u0026lt;Query\u003e\n\n```js\nconst q = query(\"SELECT * FROM c\")\n```\n\n## Class: Query\n\n### q.exec(items[, options])\n\n- `items` \u0026lt;Object[]\u003e | \u0026lt;null\u003e\n- `options` \u0026lt;Object\u003e\n  - `parameters` \u0026lt;Object[]\u003e The parameters to pass to query\n  - `udf` \u0026lt;Object\u003e\n  - `maxItemCount` \u0026lt;number\u003e The number of items to return at a time\n  - `continuation` \u0026lt;Object\u003e Continuation token\n  - `compositeIndexes `\u0026lt;Object[][]\u003e Optional composite index definitions for validating multiple `ORDER BY` properties. By default, no definition is required and this value is used only for validation.\n- Returns: \u0026lt;Object\u003e\n  - `result` \u0026lt;Object[]\u003e Result documents\n  - `continuation` \u0026lt;Object\u003e Continuation token for subsequent calls\n\n\nExecutes a query for `items`.\n\n```js\nquery(`SELECT VALUE udf.REGEX_MATCH(\"foobar\", \".*bar\")`).exec([], {\n  udf: {\n    REGEX_MATCH(input, pattern) {\n      return input.match(pattern) !== null\n    }\n  }\n});\n```\n\nWhen the `maxItemCount` and/or `continuation` options are used,\nall itesms have to contain the `_rid` field with unique values.\n\n```js\nconst items = [\n  { _rid: \"a\", value: 1 },\n  { _rid: \"b\", value: 2 },\n  { _rid: \"c\", value: 3 }\n];\nconst q = query(`SELECT * FROM c`);\nconst { result, continuation } = q.exec(items, { maxItemCount: 2 });\nconsole.log(result); // [ { _rid: \"a\", value: 1 }, { _rid: \"b\", value: 2 } ]\n\nconst { result: result2 } = q.exec(items, { maxItemCount: 2, continuation });\nconsole.log(result2); // [ { _rid: \"c\", value: 3 } ]\n```\n\n### q.containsPartitionKeys(keys)\n\n- `keys` \u0026lt;string[]\u003e\n- Returns: \u0026lt;boolean\u003e\n\n\nDetermines whether query may contain partition keys.\n\n```js\nconst q = query(\"SELECT * FROM c WHERE c.id = 1\");\nif (!q.containsPartitionKeys([\"/key\"])) {\n  throw new Error(\"query doesn't contain partition keys\");\n}\n```\n\n### q.ast\n\n- \u0026lt;Object\u003e\n\nThe AST object of query.\n\n## Class: SyntaxError\n\n```js\nconst { default: query, SyntaxError } = require(\"@zeit/cosmosdb-query\");\n\ntry {\n  query(\"INVALID SELECT\").exec(items);\n} catch (err) {\n  if (err instanceof SyntaxError) {\n    console.error(err);\n  }\n  throw err;\n}\n```\n\n## Supported queries\n\nAll queries are supported except spatial functions `ST_ISVALID` and `ST_ISVALIDDETAILED`.\n\nThe spatial functions `ST_INTERSECTS`, `ST_WITHIN`, and `ST_DISTANCE` are supported; use parameters to pass in GeoJSON as strings. Items in collections that are GeoJSON are expected to be of type string.\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrylikov%2Fcosmosdb-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrylikov%2Fcosmosdb-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrylikov%2Fcosmosdb-query/lists"}