<commit_before># ChesterSharp

Copyright (C) 2012 <NAME> <<EMAIL>>

Licensed under Apache v2 (see COPYING.txt for details)

Asynchronous CouchDB access library in C#, for .net 4.5 and using the
new HttpClient library.

Has no external dependencies except for James Newton-King's json.net
library.

I've written it on Mono 2.11.4 on Linux (and have not yet tested it on
Microsoft), although I don't see much likelihood of trouble.

# Usage

Please note that all of the API is async, in that it returns Tasks
that can be either `await`ed (C#'s continuations) or passed a lambda
with `ContinueWith` to invoke when ready.

Open a database:

```csharp
Couch couchdb = new ChesterSharp.Couch("localhost", 5984);
CouchDatabase myDatabase = await couchdb.OpenDatabase("mydatabase");
```

Fetch a document from CouchDB, as a string:

```csharp
String myDocument = await myDatabase.GetRawDocument("documentid");
```

Fetch a document from CouchDB, with a POCO type:

```csharp
public class Person : ChesterSharp.Documents.CouchDocument {
    public String Name { get; set; }
}

Person person = await myDatabase.GetDocument<Person>("personid");
```

Create a document in CouchDB, with a POCO type (reusing type above):

```csharp
var person = new Person { Name = "<NAME>", Id = "vonmises" };

// It will update the POCO object with the newly acquired CouchDB
// generated rev (and ID if none was specified), and return it

await myDatabase.CreateDocument<Person>(person);
```

Update an existing document:

```csharp
var person = await myDatabase.GetDocument<Person>("vonmises");
person.Name = "<NAME>, economist";

await myDatabase.UpdateDocument<Person>(person);
```

Create (or replace) a design document:

```csharp
// in addition to the POCO above, make a seprate
// design document class:

public class PersonDesign : ChesterSharp.Documents.DesignDocument {
    // Views on the design document are defined by special nested
    // classes.
    public class All : View {
        public override string Map { get {
                return @"function(doc) {
                    if(doc[""type""] === ""person"") {
                        emit(doc[""_id""], doc.title);
                    }
                }";
            }
        }
    }
}

await myDatabase.UpdateDesignDocument<PersonDesign>();
```

Fetch a view:

```csharp
// note that, for now, the system always uses include_docs, and
// deserializes the result into the provided CouchDocument type (the
// third type argument).  Anything directly emit()ted is currently
// ignored.

IEnumerable<List<Person>> persons = await myDatabase.GetDocsFromView<PersonDesign, PersonDesign.Living, Person>();
```

And more.  See the tests in `ChesterSharp/CouchTest.cs` for
further details.

# Building

1. Initialize and fetch the dependency git submodules:

    git submodule init
    git submodule update

2. Open the included MonoDevelop/MSBuild solution file.  If that gives
   trouble, try making a new solution including the
   `ChesterSharp/ChesterSharp.csproj` project and the JSON.net
   project.
   
3. You may have to adjust the target .net framework on the
   NewtonSoft.Json project to be ".NET 4.0", if you're using
   MonoDevelop.<commit_msg>Fix hilarious mistake in README.<commit_after># ChesterSharp

Copyright (C) 2012 <NAME> <<EMAIL>>

Licensed under Apache v2 (see COPYING.txt for details)

Asynchronous CouchDB access library in C#, for .net 4.5 and using the
new HttpClient library.

Has no external dependencies except for James Newton-King's json.net
library.

I've written it on Mono 2.11.4 on Linux (and have not yet tested it on
Microsoft), although I don't see much likelihood of trouble.

# Usage

Please note that all of the API is async, in that it returns Tasks
that can be either `await`ed (C#'s continuations) or passed a lambda
with `ContinueWith` to invoke when ready.

Open a database:

```csharp
Couch couchdb = new ChesterSharp.Couch("localhost", 5984);
CouchDatabase myDatabase = await couchdb.OpenDatabase("mydatabase");
```

Fetch a document from CouchDB, as a string:

```csharp
String myDocument = await myDatabase.GetRawDocument("documentid");
```

Fetch a document from CouchDB, with a POCO type:

```csharp
public class Person : ChesterSharp.Documents.CouchDocument {
    public String Name { get; set; }
}

Person person = await myDatabase.GetDocument<Person>("personid");
```

Create a document in CouchDB, with a POCO type (reusing type above):

```csharp
var person = new Person { Name = "<NAME>", Id = "vonmises" };

// It will update the POCO object with the newly acquired CouchDB
// generated rev (and ID if none was specified), and return it

await myDatabase.CreateDocument<Person>(person);
```

Update an existing document:

```csharp
var person = await myDatabase.GetDocument<Person>("vonmises");
person.Name = "<NAME>, economist";

await myDatabase.UpdateDocument<Person>(person);
```

Create (or replace) a design document:

```csharp
// in addition to the POCO above, make a seprate
// design document class:

public class PersonDesign : ChesterSharp.Documents.DesignDocument {
    // Views on the design document are defined by special nested
    // classes.
    public class All : View {
        public override string Map { get {
                return @"function(doc) {
                    if(doc[""type""] === ""person"") {
                        emit(doc[""_id""], doc.title);
                    }
                }";
            }
        }
    }
}

await myDatabase.UpdateDesignDocument<PersonDesign>();
```

Fetch a view:

```csharp
// note that, for now, the system always uses include_docs, and
// deserializes the result into the provided CouchDocument type (the
// third type argument).  Anything directly emit()ted is currently
// ignored.

IEnumerable<Person> persons = await myDatabase.GetDocsFromView<PersonDesign, PersonDesign.Living, Person>();
```

And more.  See the tests in `ChesterSharp/CouchTest.cs` for
further details.

# Building

1. Initialize and fetch the dependency git submodules:

    git submodule init
    git submodule update

2. Open the included MonoDevelop/MSBuild solution file.  If that gives
   trouble, try making a new solution including the
   `ChesterSharp/ChesterSharp.csproj` project and the JSON.net
   project.
   
3. You may have to adjust the target .net framework on the
   NewtonSoft.Json project to be ".NET 4.0", if you're using
   MonoDevelop.
{'fraction_non_alphanumeric': 0.0975800156128025, 'fraction_numerical': 0.00624512099921936, 'mean_word_length': 3.628612716763006, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2575433', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1790, 'n_words': 731}