Framework to simplify the use of Cloudant Database. It provides a friendly interface to communicate to Cloudant's API.
Divan is a nuget package and you must only install through nuget where will provide the stable version.
It supports only .netcore projects.
PM> Install-Package Divan.Cloudant
> dotnet add package Divan.Cloudant
The first step to use Divan.Cloudant, you need to create an instance of CloudantClient
, this class makes possible database handling, such as Create, Get and Delete.
var cloudantClient = new CloudantClient(new CloudantConnection("CLOUDANT_URL","CLOUDANT_USER","CLOUDANT_PWD"));
Cloudant API allows for easy development creation of databases. Inside the CloudantClient
, exists the method CreateDbAsync
or GetDbAsync
to get the work done.
CreateDbAsync
only creates the database in Cloudant.
var task = await cloudantClient.CreateDbAsync("myDatabase");
GetDbAsync
different of CreateDbAsync
, if there's no database of the same name it creates a new one and returns an instance of 'Database'.
var database = await cloudantClient.GetDatabaseAsync("myDatabase");
Divan.Cloudant serializes your model to json internally and send to Cloudant. By default Cloundant's documents has two required properties, _id and _rev, their values is generated automatically. Divan.Cloudant requires those properties in your models to be serialized to Json format and vice versa.
Model
public class ZipCodeModel {
public string _id { get; set; }
public string _rev { get; set; }
public string ZipCode { get; set; }
public string Address { get; set; }
public string Neighborhood { get; set; }
}
CreateDocAsync
var db = await cloudantClient.GetDatabaseAsync("myDatabase");
var doc = new ZipCodeModel
{
_id = null,
_rev = null,
ZipCode = "18103610",
Neighborhood = "Jardim Primavera",
Address = "Rua AngeloZanardo"
};
ResultObject resultObject = await db.CreateAsync<ZipCodeModel>(doc);
Console.WriteLine($"Document id is: {resultObject.id}");
- Renan Silveira - Initial work - Divan.Cloudant
See also the list of contributors who participated in this project.
This project is licensed under the GNU License - see the LICENSE.md file for details