Coder Social home page Coder Social logo

sandeepc24 / fsharp.cosmosdb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aaronpowell/fsharp.cosmosdb

0.0 1.0 0.0 1.65 MB

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

License: MIT License

F# 89.55% Batchfile 0.08% Shell 0.17% TypeScript 10.19%

fsharp.cosmosdb's Introduction

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

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>

The result from a query is an AsyncSeq via FSharp.Control.AsyncSeq.

[<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

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

Usage

1. Set two environment variables:

  • FSHARP_COSMOS_HOST -> The host address of your Cosmos DB
  • FSHARP_COSMOS_KEY -> The access key of your Cosmos DB

2. Install the Analyzer from paket

paket add FSharp.Cosmos.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 Yous

  • 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

fsharp.cosmosdb's People

Contributors

aaronpowell avatar

Watchers

James Cloos avatar

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.