All Projects → Crokus → cosmosdb-repo

Crokus / cosmosdb-repo

Licence: MIT license
Repository pattern for Cosmos DB

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to cosmosdb-repo

Cosmos.Identity
A Cosmos storage provider for ASP.NET Core Identity.
Stars: ✭ 26 (-58.06%)
Mutual labels:  documentdb, cosmosdb
spring-data-cosmosdb
Access data with Azure Cosmos DB
Stars: ✭ 94 (+51.61%)
Mutual labels:  documentdb, 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 (+67.74%)
Mutual labels:  documentdb, cosmosdb
Orleans.CosmosDB
Orleans providers for Azure Cosmos DB
Stars: ✭ 36 (-41.94%)
Mutual labels:  documentdb, cosmosdb
documentdb-typescript
[DEPRECATED] TypeScript interface for Microsoft Azure Cosmos DB
Stars: ✭ 18 (-70.97%)
Mutual labels:  documentdb, 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 (-67.74%)
Mutual labels:  cosmosdb
backend-csharp
A C# / Azure Functions implementation of the API for https://www.theurlist.com
Stars: ✭ 35 (-43.55%)
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 (-70.97%)
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 (+82.26%)
Mutual labels:  cosmosdb
terraform-aws-documentdb-cluster
Terraform module to provision a DocumentDB cluster on AWS
Stars: ✭ 32 (-48.39%)
Mutual labels:  documentdb
FSharp.CosmosDb
An F# wrapper around Cosmos DB's .NET SDK to make it more friendly for F# developers
Stars: ✭ 64 (+3.23%)
Mutual labels:  cosmosdb
smart-store
No description or website provided.
Stars: ✭ 73 (+17.74%)
Mutual labels:  cosmosdb
git-documentdb
Offline-first Database that Syncs with Git
Stars: ✭ 20 (-67.74%)
Mutual labels:  documentdb
Marten
.NET Transactional Document DB and Event Store on PostgreSQL
Stars: ✭ 1,654 (+2567.74%)
Mutual labels:  documentdb
huskydb
HuskyDB - Windows Native C++ NoSQL Database
Stars: ✭ 27 (-56.45%)
Mutual labels:  documentdb
Liquid-Application-Framework
Liquid Application Framework documentation, useful links and sample project
Stars: ✭ 467 (+653.23%)
Mutual labels:  cosmosdb
jlik.me
URL Shortener project.
Stars: ✭ 31 (-50%)
Mutual labels:  cosmosdb
vue-cosmosdb
Cosmos DB, Express.js, Vue, and Node.js app
Stars: ✭ 58 (-6.45%)
Mutual labels:  cosmosdb
MCW-OSS-PaaS-and-DevOps
MCW OSS PaaS and DevOps
Stars: ✭ 49 (-20.97%)
Mutual labels:  cosmosdb
Tinydb
TinyDB is a lightweight document oriented database optimized for your happiness :)
Stars: ✭ 4,713 (+7501.61%)
Mutual labels:  documentdb

Simple repository pattern for Cosmos DB

Nuget

Installation

Use NuGet to install the package.

PM> Install-Package DocumentDB.Repository

Getting started

Step 1: Get DocumentDB client

Before you can play with your DocumentDB database you need to get the DocumentDB Client by passing your endopointUrl and authorizationKey (primary).

internal class Program
{
    public static IReliableReadWriteDocumentClient Client { get; set; }

	private static void Main(string[] args)
	{
		IDocumentDbInitializer init = new DocumentDbInitializer();

		string endpointUrl = ConfigurationManager.AppSettings["azure.documentdb.endpointUrl"];
		string authorizationKey = ConfigurationManager.AppSettings["azure.documentdb.authorizationKey"];

		// get the Azure DocumentDB client
		Client = init.GetClient(endpointUrl, authorizationKey);

		// Run demo
		Task t = MainAsync(args);
		t.Wait();
	}
}    

Step 2: Create Repository and use it with your POCO objects

With the client in place create a repository providing database id (will be created if it doesn't exist). Now it's really easy to do the CRUD operations:

private static async Task MainAsync(string[] args)
{
	string databaseId = ConfigurationManager.AppSettings["azure.documentdb.databaseId"];

	// create repository for persons
	DocumentDbRepository<Person> repo = new DocumentDbRepository<Person>(Client, databaseId);

	// create a new person
	Person matt = new Person
	{
		FirstName = "m4tt",
		LastName = "TBA",
		BirthDayDateTime = new DateTime(1990, 10, 10),
		PhoneNumbers =
			new Collection<PhoneNumber>
			{
				new PhoneNumber {Number = "555", Type = "Mobile"},
				new PhoneNumber {Number = "777", Type = "Landline"}
			}
	};

	// add person to database's collection (if collection doesn't exist it will be created and named as class name -it's a convenction, that can be configured during initialization of the repository)
	matt = await repo.AddOrUpdateAsync(matt);

	// create another person
	Person jack = new Person
	{
		FirstName = "Jack",
		LastName = "Smith",
		BirthDayDateTime = new DateTime(1990, 10, 10),
		PhoneNumbers = new Collection<PhoneNumber>()
	};

	// add jack to collection
	jack = await repo.AddOrUpdateAsync(jack);

	// update first name
	matt.FirstName = "Matt";

	// add last name
	matt.LastName = "Smith";

	// remove landline phone number
	matt.PhoneNumbers.RemoveAt(1);

	// should update person
	await repo.AddOrUpdateAsync(matt);

	// get Matt by his Id
	Person justMatt = await repo.GetByIdAsync(matt.Id);

	// ... or by his first name
	Person firstMatt = await repo.FirstOrDefaultAsync(p => p.FirstName.Equals("matt", StringComparison.OrdinalIgnoreCase));

	// query all the smiths
	var smiths = (await repo.WhereAsync(p => p.LastName.Equals("Smith", StringComparison.OrdinalIgnoreCase))).ToList();
	
	// count all persons
        var personsCount = await repo.CountAsync();

        // count all jacks
        var jacksCount = await repo.CountAsync(p => p.FirstName == "Jack");
	
	// remove matt from collection
	await repo.RemoveAsync(matt.Id);

	// remove jack from collection
	await repo.RemoveAsync(jack.Id);
}

Full example can be found here.

License

cosmosdb-repo is provided under the MIT license.

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].