Socket
Socket
Sign inDemoInstall

@zeit/cosmosdb-query

Package Overview
Dependencies
Maintainers
53
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zeit/cosmosdb-query

A SQL parser and executer for Cosmos DB


Version published
Weekly downloads
911K
increased by66.89%
Maintainers
53
Weekly downloads
 
Created
Source

cosmosdb-query

A SQL parser and executer for Cosmos DB.

const { default: query } = require("@zeit/cosmosdb-query");

const items = [
  { id: "foo" },
  { id: "bar" }
];

const { result } = query("SELECT * FROM c WHERE c.id = @id")
  .exec(items, {
    parameters: [{ name: "@id", value: "foo" }]
  });
console.log(result); // [ { id: "foo" } ]

query(sql)

  • sql <string>
  • Returns: <Query>
const q = query("SELECT * FROM c")

Class: Query

q.exec(items[, options])

  • items <Object[]> | <null>
  • options <Object>
    • parameters <Object[]> The parameters to pass to query
    • udf <Object>
    • maxItemCount <number> The number of items to return at a time
    • continuation <Object> Continuation token
  • Returns: <Object>
    • result <Object[]> Result documents
    • continuation <Object> Continuation token for subsequent calls

Executes a query for items.

query(`SELECT VALUE udf.REGEX_MATCH("foobar", ".*bar")`).exec([], {
  udf: {
    REGEX_MATCH(input, pattern) {
      return input.match(pattern) !== null
    }
  }
});

When the maxItemCount and/or continuation options are used, all itesms have to contain the _rid field with unique values.

const items = [
  { _rid: "a", value: 1 },
  { _rid: "b", value: 2 },
  { _rid: "c", value: 3 }
];
const q = query(`SELECT * FROM c`);
const { result, continuation } = q.exec(items, { maxItemCount: 2 });
console.log(result); // [ { _rid: "a", value: 1 }, { _rid: "b", value: 2 } ]

const { result: result2 } = q.exec(items, { maxItemCount: 2, continuation });
console.log(result2); // [ { _rid: "c", value: 3 } ]

q.containsPartitionKeys(keys)

  • keys <string[]>
  • Returns: <boolean>

Determines whether query may contain partition keys.

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.

Supported queries

All queries are supported except spatial functions

FAQs

Package last updated on 02 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc