October 5, 2012

New Visual Studio Code Snippets for the .NET Couchbase Client Library

I have a few Visual Studio code snippets that I use regularly when testing out new installations of Couchbase Server.  I've just made them available on GitHub and Nuget.  Right now the snippets are fairly basic, but over time I'll work on creating some more best-practice and common task snippets.  At this point, the snippets are most useful for someone just starting out with the Couchbase .NET Client.

The first snippet (cbc) will take care of setting up a client instance using the default configuration (in code, not app|web.config)

var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools/"));
config.Bucket = "default";

var client = new CouchbaseClient(config);

There are also simple get (cbget) and store (cbstore) snippets that will save you a little typing.

client.Store(StoreMode.Set, key, value);
var item = client.Get<string>(key);

There is also a snippet for iterating over a view (cbview).

var view = client.GetView("DesignDoc", "ViewName");
foreach (var row in view)
{
    var doc = client.Get(row.ItemId); //get original doc
}

You can install the snippets via Nuget:

Install-Package CouchbaseSnippets

Or you could clone the repo on GitHub:

http://github.com/jzablocki/CouchbaseSnippets

 

Comments