<commit_before>## Caddyshack-couchdb

This is the couchdb adapter for caddyshack. The caddyshack code and idea can be found here. 

https://github.com/gospackler/caddyshack

### How it works?

It is basically a type which implements the Store interface of caddyshack. Within each of the functions the couchdb adapter is used to get the work done.

Reading elements works. Only the tags need to be played with. 
```go
type TestObj struct {
        Name  string
        Value string
        Id    string
}
```

```go
type RetTestObj struct {
        couchdb.CouchWrapperUpdate
        TestObj
}
```
The retrieve and save structs need to be separate as fields get added like _id and _rev while receiving.

The adapter requires a type to be registered with it while initializing. This type will be created while retrieving the object. *(json.Unmarshal)* uses it and is dynamically created using reflection.

```go
couchStore := NewCouchStore(res, &RetTestObj{})
```

Some working functions
For creating an object of type testObj in couch. tags could be used to get the right names.

```go
err = caddy.StoreIns.Create(testObj)
```

To get an object when a key is passed,
```go
err, obj := caddy.StoreIns.ReadOne(key)
actualObj := obj.(*RetTestObj)  // Assertion needed as golang is compiled
fmt.Println("Got the actual object back.", actualObj.TestObj)
```
Explicit assertion is needed because go being a statically compiled language requires the type to be bound to it. The interface object is received back which needs to be converted to the object type we need.

For more details, have a look at *couch_test.go* which contains the case of *registering, creating an object and retrieving* the object from a couch db.

## Queries

Couch Wrapper supports queries the way caddyshack expects it to. There are two types of Queries possible. 
### 1. Basic Couch Query
In this type of query raw javascript can be passed to populate the fields that the json unmarshal can use. 

``` go
    query := NewQuery("function(doc) {emit(doc.field1);}", "new_view", "new_design", CouchStoreIns)
    err, objects := Caddy.StoreIns.Read(query)
    if err != nil {
            t.Error("Error while reading query ", query, " ", err)
    } else {
            t.Log("Read", objects)
    }<commit_msg>Changes to Readme as the need for having couchwrapper update is removed<commit_after>## Caddyshack-couchdb

This is the couchdb adapter for caddyshack. The caddyshack code and idea can be found here. 

https://github.com/gospackler/caddyshack

### How it works?

It is basically a type which implements the Store interface of caddyshack. Within each of the functions the couchdb adapter is used to get the work done.

Reading elements works. Only the tags need to be played with. 
```go
type TestObj struct {
        Name  string
        Value string
        Id    string
}
```

The retrieve and save structs need to be separate as fields get added like _id and _rev while receiving.

The adapter requires a type to be registered with it while initializing. This type will be created while retrieving the object. *(json.Unmarshal)* uses it and is dynamically created using reflection.

```go
couchStore := NewCouchStore(res, &TestObj{})
```

Some working functions
For creating an object of type testObj in couch. tags could be used to get the right names.

```go
err = caddy.StoreIns.Create(testObj)
```

To get an object when a key is passed,
```go
err, obj := caddy.StoreIns.ReadOne(key)
actualObj := obj.(*TestObj)  // Assertion needed as golang is compiled
fmt.Println("Got the actual object back.", actualObj.TestObj)
```
Explicit assertion is needed because go being a statically compiled language requires the type to be bound to it. The interface object is received back which needs to be converted to the object type we need.

For more details, have a look at *couch_test.go* which contains the case of *registering, creating an object and retrieving* the object from a couch db.

## Queries

Couch Wrapper supports queries the way caddyshack expects it to. There are two types of Queries possible. 
### 1. Basic Couch Query
In this type of query raw javascript can be passed to populate the fields that the json unmarshal can use. 

``` go
    query := NewQuery("function(doc) {emit(doc.field1);}", "new_view", "new_design", CouchStoreIns)
    err, objects := Caddy.StoreIns.Read(query)
    if err != nil {
            t.Error("Error while reading query ", query, " ", err)
    } else {
            t.Log("Read", objects)
    }
{'fraction_non_alphanumeric': 0.0764627659574468, 'fraction_numerical': 0.0008865248226950354, 'mean_word_length': 3.740546218487395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6358023', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1240, 'n_words': 615}