{"id":19471582,"url":"https://github.com/aaronpowell/fsharp.cosmosdb","last_synced_at":"2025-07-14T21:34:37.977Z","repository":{"id":38440395,"uuid":"246171358","full_name":"aaronpowell/FSharp.CosmosDb","owner":"aaronpowell","description":"An F# wrapper around Cosmos DB's .NET SDK to make it more friendly for F# developers","archived":false,"fork":false,"pushed_at":"2024-09-03T22:15:52.000Z","size":1782,"stargazers_count":80,"open_issues_count":7,"forks_count":12,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-02-27T15:33:12.018Z","etag":null,"topics":["azure","cosmosdb","fsharp"],"latest_commit_sha":null,"homepage":null,"language":"F#","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/aaronpowell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"License.md","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":"2020-03-10T00:28:19.000Z","updated_at":"2025-01-11T20:24:49.000Z","dependencies_parsed_at":"2024-01-16T02:45:16.249Z","dependency_job_id":"692d139a-3e53-436b-ab5f-5fba4bebdd59","html_url":"https://github.com/aaronpowell/FSharp.CosmosDb","commit_stats":{"total_commits":217,"total_committers":7,"mean_commits":31.0,"dds":"0.13364055299539168","last_synced_commit":"8d1cb92d294d56686ffa50eca56f123cf209eb96"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpowell%2FFSharp.CosmosDb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpowell%2FFSharp.CosmosDb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpowell%2FFSharp.CosmosDb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpowell%2FFSharp.CosmosDb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronpowell","download_url":"https://codeload.github.com/aaronpowell/FSharp.CosmosDb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242214934,"owners_count":20090721,"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":["azure","cosmosdb","fsharp"],"created_at":"2024-11-10T19:02:25.338Z","updated_at":"2025-03-06T13:14:20.801Z","avatar_url":"https://github.com/aaronpowell.png","language":"F#","funding_links":[],"categories":["General Purpose Libraries"],"sub_categories":["Performance Analysis"],"readme":"# FSharp.CosmosDb 🌍\n\n![Latest Build](https://github.com/aaronpowell/FSharp.CosmosDb/workflows/Build%20release%20candidate/badge.svg) ![Latest Release](https://github.com/aaronpowell/FSharp.CosmosDb/workflows/Publish%20Release/badge.svg) [![NuGet Badge - FSharp.CosmosDb](https://buildstats.info/nuget/FSharp.CosmosDb)](https://www.nuget.org/packages/FSharp.CosmosDb) [![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg?color=blue\u0026style=flat-square)](http://opensource.org/licenses/MIT)\n\nThis project is a wrapper around the [Cosmos DB](https://docs.microsoft.com/azure/cosmos-db/introduction?WT.mc_id=javascript-0000-aapowell) [v4 .NET SDK](https://docs.microsoft.com/azure/cosmos-db/create-sql-api-dotnet-v4?WT.mc_id=javascript-0000-aapowell) to make it a bit more friendly to the F# language.\n\n## Install\n\nInstall via NuGet:\n\n```bash\ndotnet add package FSharp.CosmosDb\n```\n\nOr using Paket:\n\n```bash\ndotnet paket add FSharp.CosmosDb\n```\n\n## Usage\n\nAll operations will return an `AsyncSeq` via [FSharp.Control.AsyncSeq](http://fsprojects.github.io/FSharp.Control.AsyncSeq/index.html) that contains the data fetched, data inserted or data updated.\n\n### Insert\n\n```fsharp\nopen FSharp.CosmosDb\n\nlet connStr = \"...\"\n\nlet insertUsers data =\n    connStr\n    |\u003e Cosmos.fromConnectionString\n    |\u003e Cosmos.database \"UserDb\"\n    |\u003e Cosmos.container \"UserContainer\"\n    |\u003e Cosmos.insertMany\u003cUser\u003e data\n    |\u003e Cosmos.execAsync\n```\n\n### Upsert\n\n```fsharp\nopen FSharp.CosmosDb\n\nlet connStr = \"...\"\n\nlet insertUsers data =\n    connStr\n    |\u003e Cosmos.fromConnectionString\n    |\u003e Cosmos.database \"UserDb\"\n    |\u003e Cosmos.container \"UserContainer\"\n    |\u003e Cosmos.upsertMany\u003cUser\u003e data\n    |\u003e Cosmos.execAsync\n```\n\n### Update\n\n```fsharp\nopen FSharp.CosmosDb\n\nlet connStr = \"...\"\n\nlet updateUser id partitionKey =\n    connStr\n    |\u003e Cosmos.fromConnectionString\n    |\u003e Cosmos.database \"UserDb\"\n    |\u003e Cosmos.container \"UserContainer\"\n    |\u003e Cosmos.update\u003cUser\u003e id partitionKey (fun user -\u003e { user with IsRegistered = true })\n    |\u003e Cosmos.execAsync\n```\n\n### Query\n\n```f#\nopen FSharp.CosmosDb\n\nlet host = \"https://...\"\nlet key = \"...\"\nlet findUsers() =\n    host\n    |\u003e Cosmos.host\n    |\u003e Cosmos.connect key\n    |\u003e Cosmos.database \"UserDb\"\n    |\u003e Cosmos.container \"UserContainer\"\n    |\u003e Cosmos.query \"SELECT u.FirstName, u.LastName FROM u WHERE u.LastName = @name\"\n    |\u003e Cosmos.parameters [ \"@name\", box \"Powell\" ]\n    |\u003e Cosmos.execAsync\u003cUser\u003e\n```\n\n```f#\n[\u003cEntryPoint\u003e]\nlet main argv =\n    async {\n        let users = findUsers()\n        do! users\n        |\u003e AsyncSeq.iter (fun u -\u003e printfn \"%s %s\" u.FirstName u.LastName)\n\n        return 0\n    } |\u003e Async.RunSynchronously\n```\n\n### DeleteItem\n\n```f#\nopen FSharp.CosmosDb\n\nlet connStr = \"...\"\n\nlet updateUser id partitionKey =\n    connStr\n    |\u003e Cosmos.fromConnectionString\n    |\u003e Cosmos.database \"UserDb\"\n    |\u003e Cosmos.container \"UserContainer\"\n    |\u003e Cosmos.deleteItem id partitionKey\n    |\u003e Cosmos.execAsync\n```\n\n### DeleteContainer\n```f#\nopen FSharp.CosmosDb\n\nlet connStr = \"...\"\n\nconnStr\n|\u003e Cosmos.container \"ContainerName\"\n|\u003e Cosmos.deleteContainer\n|\u003e Cosmos.execAsync\n|\u003e Async.Ignore\n```\n    \n# FSharp.CosmosDb.Analyzer 💡\n\n[![NuGet Badge - FSharp.CosmosDb](https://buildstats.info/nuget/FSharp.CosmosDb)](https://www.nuget.org/packages/FSharp.CosmosDb)\n\nAlso part of this repo is a [F# Analyzer](https://github.com/ionide/FSharp.Analyzers.SDK) for use from the CLI or in Ionide.\n\n![Analyzer in action](/docs/images/cosmos-analyzer-usage.gif)\n\n## Features\n\n- Validation of database name against databases in Cosmos\n  - Quick fix provided with list of possible db names\n- Validation of container name against containers in the database\n  - Quick fix provided with list of possible container names\n- Detection of unused parameters in the query\n  - Quick fix provided with list of defined parameters (if any)\n- Detection of supplied but unused parameters\n  - Quick fix provided with list of declared parameters\n- Detection of missing `@` for parameter name\n  - Quick fix provided to add it in\n\n## Analyzer Usage\n\n### 1. Provide connection information\n\nConnection information can be provided as either environment variables or using an `appsettings.json`/`appsettings.Development.json` file.\n\n#### Environment Variables\n\nThe analyzer will look for the following environment variables:\n\n- `FSHARP_COSMOS_CONNSTR` -\u003e A full connection string to Cosmos DB\n- `FSHARP_COSMOS_HOST` \u0026 `FSHARP_COSMOS_KEY` -\u003e The URI endpoint and access key\n\nThe `FSHARP_COSMOS_CONNSTR` will take precedence if both sets of environment variables are provided\n\n#### App Settings\n\nThe 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:\n\n```json\n{\n  \"CosmosConnection\": {\n    \"ConnectionString\": \"\",\n    \"Host\": \"\",\n    \"Key\": \"\"\n  }\n}\n```\n\nIf `CosmosConnection.ConnectionString` exists, it will be used, otherwise it will use the `CosmosConnection.Host` and `CosmosConnection.Key` to connect.\n\n### 2. Install the Analyzer from paket\n\n`paket add FSharp.CosmosDb.Analyzer --group Analyzers`\n\n### 3. Enable Analyzers in Ionide\n\nAdd the following settings (globally or in the workspace):\n\n```json\n{\n  \"FSharp.enableAnalyzers\": true,\n  \"FSharp.analyzersPath\": [\"./packages/analyzers\"]\n}\n```\n\n# License\n\n[MIT](./License.md)\n\n# Thank You\n\n- Zaid Ajaj for the [Npgsql Analyzer](https://github.com/Zaid-Ajaj/Npgsql.FSharp.Analyzer). Without this I wouldn't have been able to work out how to do it (and there's some code lifted from there)\n- [Krzysztof Cieślak](https://twitter.com/k_cieslak) for the amazing Ionide plugin\n- [Isaac Abraham](https://twitter.com/isaac_abraham) for helping fix the parser\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronpowell%2Ffsharp.cosmosdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronpowell%2Ffsharp.cosmosdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronpowell%2Ffsharp.cosmosdb/lists"}