All Projects → aaronpowell → FSharp.CosmosDb

aaronpowell / FSharp.CosmosDb

Licence: MIT license
An F# wrapper around Cosmos DB's .NET SDK to make it more friendly for F# developers

Programming Languages

F#
602 projects
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to FSharp.CosmosDb

kafka-connect-cosmosdb
Kafka Connect connectors for Azure Cosmos DB
Stars: ✭ 28 (-56.25%)
Mutual labels:  cosmosdb
entref-spring-boot
A RESTful DAL (Database Abstraction Layer) reference implementation written using Spring.
Stars: ✭ 19 (-70.31%)
Mutual labels:  cosmosdb
cosmosdb-repo
Repository pattern for Cosmos DB
Stars: ✭ 62 (-3.12%)
Mutual labels:  cosmosdb
vue-cosmosdb
Cosmos DB, Express.js, Vue, and Node.js app
Stars: ✭ 58 (-9.37%)
Mutual labels:  cosmosdb
documentdb-typescript
[DEPRECATED] TypeScript interface for Microsoft Azure Cosmos DB
Stars: ✭ 18 (-71.87%)
Mutual labels:  cosmosdb
MCW-OSS-PaaS-and-DevOps
MCW OSS PaaS and DevOps
Stars: ✭ 49 (-23.44%)
Mutual labels:  cosmosdb
Orleans.CosmosDB
Orleans providers for Azure Cosmos DB
Stars: ✭ 36 (-43.75%)
Mutual labels:  cosmosdb
CosmicClone
Cosmic Clone is a utility that can backup\clone\restore a azure Cosmos database Collection. It can also anonymize cosmos documents and helps hide personally identifiable data.
Stars: ✭ 113 (+76.56%)
Mutual labels:  cosmosdb
CosmosDB
PowerShell Module for working with Azure Cosmos DB databases, collections, documents, attachments, offers, users, permissions, triggers, stored procedures and user defined functions.
Stars: ✭ 104 (+62.5%)
Mutual labels:  cosmosdb
jlik.me
URL Shortener project.
Stars: ✭ 31 (-51.56%)
Mutual labels:  cosmosdb
AzureServicesForUnity
Accessing Azure services (App Service, Table Storage, CosmosDB with Table API, Event Hubs) from a Unity game
Stars: ✭ 52 (-18.75%)
Mutual labels:  cosmosdb
Cosmos.Identity
A Cosmos storage provider for ASP.NET Core Identity.
Stars: ✭ 26 (-59.37%)
Mutual labels:  cosmosdb
smart-store
No description or website provided.
Stars: ✭ 73 (+14.06%)
Mutual labels:  cosmosdb
cosmosdb-materialized-views
A full sample that shows how to implement real-time updated Materalized Views with CosmosDB, Change Feed and Azure Functions
Stars: ✭ 20 (-68.75%)
Mutual labels:  cosmosdb
backend-csharp
A C# / Azure Functions implementation of the API for https://www.theurlist.com
Stars: ✭ 35 (-45.31%)
Mutual labels:  cosmosdb
inventory-hub-java-on-azure
Sample Inventory Hub App using Serverless and Event-driven Java - on Azure with Spring Boot, Tomcat, Functions, Event Hub and Cosmos DB
Stars: ✭ 18 (-71.87%)
Mutual labels:  cosmosdb
spring-data-cosmosdb
Access data with Azure Cosmos DB
Stars: ✭ 94 (+46.88%)
Mutual labels:  cosmosdb
Liquid-Application-Framework
Liquid Application Framework documentation, useful links and sample project
Stars: ✭ 467 (+629.69%)
Mutual labels:  cosmosdb

FSharp.CosmosDb 🌍

Latest Build Latest Release NuGet Badge - FSharp.CosmosDb The MIT License

This project is a wrapper around the Cosmos DB v4 .NET SDK to make it a bit more friendly to the F# language.

Install

Install via NuGet:

dotnet add package FSharp.CosmosDb

Or using Paket:

dotnet paket add FSharp.CosmosDb

Usage

All operations will return an AsyncSeq via FSharp.Control.AsyncSeq that contains the data fetched, data inserted or data updated.

Insert

open FSharp.CosmosDb

let connStr = "..."

let insertUsers data =
    connStr
    |> Cosmos.fromConnectionString
    |> Cosmos.database "UserDb"
    |> Cosmos.container "UserContainer"
    |> Cosmos.insertMany<User> data
    |> Cosmos.execAsync

Upsert

open FSharp.CosmosDb

let connStr = "..."

let insertUsers data =
    connStr
    |> Cosmos.fromConnectionString
    |> Cosmos.database "UserDb"
    |> Cosmos.container "UserContainer"
    |> Cosmos.upsertMany<User> data
    |> Cosmos.execAsync

Update

open FSharp.CosmosDb

let connStr = "..."

let updateUser id partitionKey =
    connStr
    |> Cosmos.fromConnectionString
    |> Cosmos.database "UserDb"
    |> Cosmos.container "UserContainer"
    |> Cosmos.update<User> id partitionKey (fun user -> { user with IsRegistered = true })
    |> Cosmos.execAsync

Query

open FSharp.CosmosDb

let host = "https://..."
let key = "..."
let findUsers() =
    host
    |> Cosmos.host
    |> Cosmos.connect key
    |> Cosmos.database "UserDb"
    |> Cosmos.container "UserContainer"
    |> Cosmos.query "SELECT u.FirstName, u.LastName FROM u WHERE u.LastName = @name"
    |> Cosmos.parameters [ "@name", box "Powell" ]
    |> Cosmos.execAsync<User>
[<EntryPoint>]
let main argv =
    async {
        let users = findUsers()
        do! users
        |> AsyncSeq.iter (fun u -> printfn "%s %s" u.FirstName u.LastName)

        return 0
    } |> Async.RunSynchronously

DeleteItem

open FSharp.CosmosDb

let connStr = "..."

let updateUser id partitionKey =
    connStr
    |> Cosmos.fromConnectionString
    |> Cosmos.database "UserDb"
    |> Cosmos.container "UserContainer"
    |> Cosmos.deleteItem id partitionKey
    |> Cosmos.execAsync

DeleteContainer

open FSharp.CosmosDb

let connStr = "..."

connStr
|> Cosmos.container "ContainerName"
|> Cosmos.deleteContainer
|> Cosmos.execAsync
|> Async.Ignore

FSharp.CosmosDb.Analyzer 💡

NuGet Badge - FSharp.CosmosDb

Also part of this repo is a F# Analyzer for use from the CLI or in Ionide.

Analyzer in action

Features

  • Validation of database name against databases in Cosmos
    • Quick fix provided with list of possible db names
  • Validation of container name against containers in the database
    • Quick fix provided with list of possible container names
  • Detection of unused parameters in the query
    • Quick fix provided with list of defined parameters (if any)
  • Detection of supplied but unused parameters
    • Quick fix provided with list of declared parameters
  • Detection of missing @ for parameter name
    • Quick fix provided to add it in

Analyzer Usage

1. Provide connection information

Connection information can be provided as either environment variables or using an appsettings.json/appsettings.Development.json file.

Environment Variables

The analyzer will look for the following environment variables:

  • FSHARP_COSMOS_CONNSTR -> A full connection string to Cosmos DB
  • FSHARP_COSMOS_HOST & FSHARP_COSMOS_KEY -> The URI endpoint and access key

The FSHARP_COSMOS_CONNSTR will take precedence if both sets of environment variables are provided

App Settings

The analyzer will look for a file matching appsettings.json or appsettings.Development.json in either the workspace root of the VS Code instance or relative to the file being parsed. The file is expected to have the following JSON structure in it:

{
  "CosmosConnection": {
    "ConnectionString": "",
    "Host": "",
    "Key": ""
  }
}

If CosmosConnection.ConnectionString exists, it will be used, otherwise it will use the CosmosConnection.Host and CosmosConnection.Key to connect.

2. Install the Analyzer from paket

paket add FSharp.CosmosDb.Analyzer --group Analyzers

3. Enable Analyzers in Ionide

Add the following settings (globally or in the workspace):

{
  "FSharp.enableAnalyzers": true,
  "FSharp.analyzersPath": ["./packages/analyzers"]
}

License

MIT

Thank You

  • Zaid Ajaj for the Npgsql Analyzer. Without this I wouldn't have been able to work out how to do it (and there's some code lifted from there)
  • Krzysztof Cieślak for the amazing Ionide plugin
  • Isaac Abraham for helping fix the parser
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].