
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
github.com/bushwood/couchdb
Minimalist CouchDB client
Make sure there is a couch instane running on default port (5984) for it to work. Have disabled the DeleteDB for now so the DB created would persist.
$ export GOPATH=$PWD
$ go get -a
$ go test -v
For any operation, there is a Database Object which represents a connection to a database in couchdb client.
client := NewClient("127.0.0.1", 5984) // Creates the client conenction.
dbObj := client.DB("testdb") //Db object which represents the connection to db.
Exists checks if the database exists. Create can create the database if it does not exist.
status, err := dbObj.Exists() // Status contains the status of the check
err := dbObj.Create() //Creates a new database with the dbName passed to the object
Creating a new document can be done as follows. Any json can be save and the example below shows how to Marshal an object.
doc := NewDocument("", "", &DBObject) //args - ID and Revison of the docuemnt to pickup
byteObj, err := json.Marshal(obj)
err := doc.Create(byteObj) //Creates a document Id and Rev would be updated by now.
// For updating,
obj.Update()
byteObj, err = json.Marshal(obj)
err = doc.Update((byteObj)
To get the object back, the way to go about it would be to wrap the object with CouchWrapper which can take care of the extra information that comes back.
doc := NewDocument(Id, Rev, &DBObject) //Rev can be empty and not used right now, have it there for if present case.
jsonObj, err := doc.GetDocument()
if err != nil {
t.Error("Error ", err)
}
type UpdateObj struct {
CouchWrapperUpdate
TestObj
}
obj := &UpdateObj{}
json.Unmarshal(jsonObj, obj)
View has two parts- DesignDoc and View DesignDoc is the representation of the design Document. Each design Document can have multiple Views assosciated with it. The example below shows how to come up with a designDocument contating multiple views.
view := NewView("test_view", "doc", "doc.age < 22", "doc.name, doc.age")
view2 := NewView("raw_view", "", "", "")
view2.RawStatus = true
view2.RawJson = "function(rawDoc) {console.log(1234)}"
fView := NewView("fred_view", "newVar", "newVar.age > 22", "newVar.name, newVar.age")
doc := NewDesignDoc("test_design", &DBObject) // Creating the doc
doc.AddView(view) // Adding the views into it.
doc.AddView(fView)
doc.AddView(view2)
err := doc.SaveDoc() //Saving the document which creates the permanent view.
if err != nil {
t.Error(err)
}
Requesting a view.
//arguments are @designDoc - followed by test_view
err, data := DBObject.GetView("test_design", "test_view", "")
if err != nil {
t.Error("Error :", err)
} else {
t.Log(string(data))
}
The views in designDocuments can be updated as well.
err, desDoc := RetreiveDocFromDb("test_design", &DBObject)
if err == nil {
desDoc.Views[0].Name = "test_view_updated" //Demo of an update. Assuming a view exists.
desDoc.RevStatus = true
err := desDoc.SaveDoc()
if err != nil {
t.Error(err)
}
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.