Giter Club home page Giter Club logo

couchbase-model-views's Introduction

couchbase-model-views

Sample project demonstrating how to generate basic Couchbase Views with the CouchbaseClient and custom attributes on data objects

NOTE: Not supported under Couchbase Enterprise Support Subscriptions!

Usage (Models)

Reference Couchbase.ModelViews.Framework in your models project. Decorate the class with the name of the design doc.
Decorate properties with the name of the views to which they should be keys. Optionally, include the order in which the properties should be emitted.

[CouchbaseDesignDoc("beers")]
[CouchbaseAllView]
public class Beer
  {
	public string Id { get; set; }

	[CouchbaseViewKey("by_abv_and_name", "name", 1)]
	[CouchbaseViewKey("by_name", "name")]
	public string Name { get; set; }

	public string Description { get; set; }

	[CouchbaseViewKey("by_abv_and_name", "abv", 0)]
	public float ABV { get; set; }

	[CouchbaseViewKey("by_brewery", "breweryId")]
	public string Brewery { get; set; }
  }

[CouchbaseDesignDoc("beers")]
[CouchbaseAllView]
public class Brewery
  {
	[CouchbaseCollatedViewKey("all_with_beers", "beer", "name", "brewery_id")]
	public string Id { get; set; }

	[CouchbaseViewKey("by_name", "name")]
	public string Name { get; set; }

	public string Description { get; set; }
	
	[CouchbaseViewKeyCount("by_state", "state", 1)]
	public string State { get; set; }

	[CouchbaseSpatialView("by_location", "geo.lng", 0)]
	public float Longitude { get; set; }
	
	[CouchbaseSpatialView("by_location", "geo.lat", 1)]
	public float Latitude { get; set; }  		
  }

Usage (Console App)

In app.config, list the assemblies from which to build views (along with the CouchbaseCluster configuration).

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>    
    <sectionGroup name="modelViews">
      <section name="assemblies" type="System.Configuration.DictionarySectionHandler"/>      
    </sectionGroup>
    <section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
  </configSections>

  <modelViews>
    <assemblies>
      <add key="DemoModels" value="CouchbaseModelViews.DemoModels" />
    </assemblies>
  </modelViews>

  <couchbase>
    <servers bucket="beer-sample" bucketPassword="">
      <add uri="http://localhost:8091/pools"/>      
    </servers>
  </couchbase>
</configuration>

Run the console application. The sample Beer class above will produce the following views:

{
  "views": {
    "all": {
      "map": "function(doc, meta) { \r\n\t if (doc.type == \"beer\") { \r\n\t\t emit(null, null); \r\n\t } \r\n }"        
    },
    "by_name_and_abv": {
      "map": "function(doc, meta) { \r\n\t if (doc.type == \"beer\" && doc.name && doc.abv) { \r\n\t\t emit([doc.name, doc.abv], null); \r\n\t } \r\n }"
    },
    "by_name": {
      "map": "function(doc, meta) { \r\n\t if (doc.type == \"beer\" && doc.name) { \r\n\t\t emit(doc.name, null); \r\n\t } \r\n }"
    },
    "by_brewery": {
      "map": "function(doc, meta) { \r\n\t if (doc.type == \"beer\" && doc.breweryId) { \r\n\t\t emit(doc.breweryId, null); \r\n\t } \r\n }"
    }
  }
}

couchbase-model-views's People

Contributors

jzablocki avatar jeffrymorris avatar jamesantrobus avatar

Stargazers

Karl Solgård avatar  avatar  avatar Jake Scott avatar Jasdeep Jaitla avatar

Watchers

Thuan Nguyen avatar Richard Smedley avatar Denis Rosa avatar Venkat avatar Leo Schuman avatar  avatar  avatar Charles Dixon avatar Priya Rajagopal avatar Chris Harris avatar Jake Rawsthorne avatar Dmitrii Chechetkin avatar Pavel Paulau avatar James Cloos avatar Donald Scott avatar  avatar  avatar Hod Greeley avatar Subhashni Balakrishnan avatar  avatar Artem Stemkovski avatar  avatar Clarence J M Tauro avatar Sandip Nandi avatar  avatar  avatar James Nocentini avatar Tai  avatar Rohinton Kazak avatar  avatar Jaekwon Park avatar  avatar  avatar Ali Alsuliman avatar Jack Harper avatar Rob Hedgpeth avatar Sarath Kumar Sivan avatar Fabrice Leray avatar Elliot Scribner avatar Fujio Turner avatar  avatar Cyrus Hanlon avatar Matt Hall avatar Gilda avatar Arun Vijayraghavan avatar  avatar Richard Ponton avatar  avatar Daniel James avatar Adam S Levy avatar Daniel Nicholson avatar Parag Agarwal avatar  avatar James H avatar  avatar  avatar  avatar James Powenski avatar Phil Stott avatar Naitik Shah avatar  avatar Anji avatar  avatar David Maier avatar Arunkumar Senthilnathan avatar  avatar Jesse Roberson avatar  avatar Balakumaran G avatar Austin Gonyou avatar Hussain Towaileb avatar  avatar Isaac Lowe avatar Ashwin avatar Murtadha Hubail avatar Roi Katz avatar  avatar Karim Meliani avatar Daniel Ma avatar  avatar  avatar Vijay Girish avatar Korrigan Clark avatar  avatar Keshav Murthy avatar Pascal Gasp avatar  avatar Rob Ashcom avatar Raphaël CHIR avatar David Saadeh avatar Seth Lowie avatar Ryan Kehoe avatar Wael avatar  avatar Raymundo Flores Medina avatar Ludovic DUFRENOY avatar Jared Casey avatar Abhishek Bose avatar Bharath G P avatar Nirvair Singh avatar

couchbase-model-views's Issues

Null reference when DesignDocManager is using CouchbaseClientConfiguration

I created a new DesignDocManager and passed in an instance of CouchbaseClientConfiguration on the constructor.

When calling the create method on the DesignDocManager instance a null reference exception is thrown.

System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=CouchbaseModelViews.Framework
StackTrace:
   at CouchbaseModelViews.Framework.DesignDocManager.Create(String designDocName, String designDoc, Action`1 callback) in c:\code\couchbase-model-views\src\CouchbaseModelViews.Framework\DesignDocManager.cs:line 61
   at CouchbaseModelViews.Framework.DesignDocManager.Create(IDictionary`2 designDocs, Action`1 callback) in c:\code\couchbase-model-views\src\CouchbaseModelViews.Framework\DesignDocManager.cs:line 83
   at CouchbaseModelViewsGenerator.Program.Main(String[] args) in c:\code\couchbase-model-views\src\CouchbaseModelViewsGenerator\Program.cs:line 48

When using this constructor the _config field is never set, probably because we've passed in a CouchbaseClientConfiguration rather than a CouchbaseClientSection. Whatever the reason, the exception is thrown later on when we try and get the Bucket from the configuration.

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.