Code Monkey home page Code Monkey logo

cosmox's Introduction

Build

Project

The project aims at providing an Elixir client for the Cosmos DB SQL REST API. Although the library provides a map for every functionality of the SQL REST API, there are no optimisation available for handling the collection.

Special mention

This project took huge inspiration from this project.

Usage

The library acts as a client for the four different entities available in Cosmos DB, each of which has its own module:

  • Cosmox.Database: provides functions to create, modify and delete a database in an instance of Cosmos DB.
  • Cosmox.Container: provides functions to create, modify and delete containers in a database.
  • Cosmox.Document: provides functions to create, patch, modify, delete and query documents in a container, both in and among different partitions. There is currently no check available for queries that spans more than one partition.
  • Cosmox.StoredProcedure: provides a way to manage stored procedures in Cosmos DB.

The library has connection pooling baked in already, and it uses Nestru to generate structs from maps, but its usage is completely optional, and to activate it it will be necessary to pass the struct to deserialise the response to as the last parameters in the Cosmox.Document functions.

Configuration

Cosmox requires defining the Cosmos DB instance URL and the access key. These information can be found in the Azure Portal under the Keys tab.

Cosmox uses Finch to handle the connection pooling. It is automatically configured, but the configuration can be overridden by specifying the cosmos_db_pool_size configuration.

This is an example of the configuration:

config :cosmox,
  cosmos_db_host: "<substitute-cosmos-db-host-here>",
  cosmos_db_key: "<substitute-cosmos-db-key-here>",
  cosmos_db_pool_size: <substitute-with-connection-pool-size>

Note: the Cosmos DB key grants access to the database, so it's highly recommended to store the cosmos_db_key configuration in a safe way.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

cosmox's People

Contributors

maxdac avatar microsoft-github-operations[bot] avatar microsoftopensource avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

quency-ai

cosmox's Issues

Invalid Item...Configuration of Cosmos Container Prob?

Heyo, following the docs - created my own struct. And no matter what I do I get:

{:error, %Cosmox.Response.ErrorMessage{errors: "Invalid item"}}

Is this actually telling me there is something wrong with the struct? Or is this something coming back from Cosmos DB itseslf?

At first I thought it was my container, but this makes me believe that's fine:

iex(11)> Cosmox.Container.get_container("lei-reports", "lei-reports-container")
{:ok,
 %Cosmox.Structs.Collection{
   id: "lei-reports-container",
   indexing_policy: %Cosmox.Structs.Collections.IndexingPolicy{
     indexingMode: "consistent",
     automatic: true,
     includedPaths: [%Cosmox.Structs.Path{path: "/*"}],
     excludedPaths: [%Cosmox.Structs.Path{path: "/\"_etag\"/?"}]
   },
   partition_key: %Cosmox.Structs.PartitionKey{
     paths: ["/id"],
     kind: "Hash",
     version: 0
   },
   conflict_resolution_policy: %Cosmox.Structs.Collections.ConflictResolutionPolicy{
     mode: "LastWriterWins",
     conflict_resolution_path: "/_ts",
     conflict_resolution_procedure: ""
   },
   geospatial_config: %Cosmox.Structs.Collections.GeospatialConfig{
     type: "Geography"
   },
   _rid: "B9BnAIPTNCo=",
   _ts: 1671487712,
   _self: "dbs/B9BnAA==/colls/B9BnAIPTNCo=/",
   _etag: "\"00003606-0000-0700-0000-63a0e0e00000\"",
   _docs: "docs/",
   _sprocs: "sprocs/",
   _triggers: "triggers/",
   _udfs: "udfs/",
   _conflicts: "conflicts/"
 }}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.