/** * TestUpdateDocumentAll */ func TestUpdateDocumentAll() { data, err := Database.UpdateDocumentAll([]interface{}{ 0: map[string]interface{}{"name": "kerem 2", "type": "tmp", "_id": "7ee9cdd673b109e030cec8c6f10020f7", "_rev": "1-3c92d3e67136c8b206d90ea37a3ee76d"}, 1: map[string]interface{}{"name": "murat 2", "type": "tmp", "_id": "7ee9cdd673b109e030cec8c6f1002cc1", "_rev": "1-09e886345b525e53892815baff169f03"}, }) if err != nil { panic(err) } util.Dumpf("Database Update Document All >> %+v", data) util.Dumpf("Database Update Document All >> doc.0.ok: %v", util.Dig("0.ok", data)) util.Dumpf("Database Update Document All >> doc.0.id: %s", util.Dig("0.id", data)) util.Dumpf("Database Update Document All >> doc.0.rev: %s", util.Dig("0.rev", data)) // or for i, doc := range data { // check ok's if doc["ok"] == nil { util.Dumpf("Halt! error: doc.%d > %s reason: %s", i, doc["error"], doc["reason"]) } for key, value := range doc { util.Dumpf("Database Update Document All >> doc.%d.%s: %v", i, key, value) } } }
// Get changes. // // @param query map[string]interface{} // @return []map[string]interface{}, error func (this *Database) GetChanges( query map[string]interface{}, docIds []string) (map[string]interface{}, error) { query = util.Param(query) if docIds != nil { query["filter"] = "_doc_ids" } body := util.ParamList("doc_ids", docIds) data, err := this.Client.Post(this.Name+"/_changes", query, body, nil). GetBodyData(nil) if err != nil { return nil, err } ret := util.Map() ret["last_seq"] = util.Dig("last_seq", data) ret["results"] = util.MapList(0) // set empty as default if results := data.(map[string]interface{})["results"].([]interface{}); results != nil { ret["results"] = util.MapList(results) // @overwrite for i, result := range results { ret["results"].([]map[string]interface{})[i] = map[string]interface{}{ "id": util.Dig("id", result), "seq": util.Dig("seq", result), "deleted": util.Dig("deleted", result), "changes": util.Dig("changes", result), } } } return ret, nil }
/** * TestReplicate */ func TestReplicate() { data, err := Database.Replicate("foo_replicate", true) if err != nil { panic(err) } util.Dumpf("Database Replicate >> %+v", data) util.Dumpf("Database Replicate >> ok: %v", data["ok"]) util.Dumpf("Database Replicate >> history.0: %v", util.Dig("0", data["history"])) util.Dumpf("Database Replicate >> history.0.start_time: %s", util.Dig("0.start_time", data["history"])) }
/** * TestGetSecurity */ func TestGetSecurity() { data, err := Database.GetSecurity() if err != nil { panic(err) } util.Dumpf("Database Get Security >> %+v", data) util.Dumpf("Database Get Security >> admins %+v", data["admins"]) util.Dumpf("Database Get Security >> admins.names.0 %s", util.Dig("admins.names.0", data)) util.Dumpf("Database Get Security >> admins.roles.0 %s", util.Dig("admins.roles.0", data)) }
/** * TestReplicate */ func TestReplicate() { data, err := Server.Replicate(map[string]interface{}{ "source": "foo", "target": "foo_replicate", "create_target": true, }) if err != nil { panic(err) } util.Dumpf("Server Database Replicate >> %+v", data) util.Dumpf("Server Database Replicate >> ok: %v", data["ok"]) util.Dumpf("Server Database Replicate >> history.0: %v", util.Dig("0", data["history"])) util.Dumpf("Server Database Replicate >> history.0.start_time: %s", util.Dig("0.start_time", data["history"])) }
/** * TestGetMissingRevisions */ func TestGetMissingRevisions() { data, err := Database.GetMissingRevisions(map[string]interface{}{ "667b0208441066a0954717b50c0008a9": []string{ "5-dd1a3738fcbd759ed744f7971fe94332", }, }) if err != nil { panic(err) } util.Dumpf("Database Missing Revisions >> %v", data) util.Dumpf("Database Missing Revisions >> missing_revs: %v", data["missing_revs"]) util.Dumpf("Database Missing Revisions >> missing_revs.667b0208441066a0954717b50c0008a9: %s", util.Dig("missing_revs.667b0208441066a0954717b50c0008a9", data)) util.Dumpf("Database Missing Revisions >> missing_revs.0: %s", util.Dig("missing_revs.667b0208441066a0954717b50c0008a9.0", data)) }
/** * TestGetDocumentAll */ func TestGetDocumentAll() { data, err := Database.GetDocumentAll(nil, nil) // data, err := Database.GetDocumentAll(nil, []string{"5db345a5f26484352ea5d813180031fb"}) if err != nil { panic(err) } // util.Dumpf("Database Document All >> %+v", data) util.Dumpf("Database Document All >> offset: %d", data["offset"]) util.Dumpf("Database Document All >> total_rows: %d", data["total_rows"]) // // util.Dumpf("Database Document All >> rows: %+v", data["rows"]) util.Dumpf("Database Document All >> rows.0: %+v", util.Dig("rows.0", data)) util.Dumpf("Database Document All >> rows.0.id: %s", util.Dig("rows.0.id", data)) util.Dumpf("Database Document All >> rows.0.key: %s", util.Dig("rows.0.key", data)) util.Dumpf("Database Document All >> rows.0.value.rev: %s", util.Dig("rows.0.value.rev", data)) util.Dumpf("Database Document All >> rows.0.doc.name: %s", util.Dig("rows.0.doc.name", data)) }
/** * TestInfo */ func TestInfo() { data, err := Server.Info() if err != nil { panic(err) } util.Dumpf("Server Info >> %+v", data) util.Dumpf("Server Info >> couchdb: %s", data["couchdb"]) // or util.Dumpf("Server Info >> couchdb: %s", util.Dig("couchdb", data)) util.Dumpf("Server Info >> uuid: %s", util.Dig("uuid", data)) util.Dumpf("Server Info >> version: %s", util.Dig("version", data)) // or util.Dumpf("Server Info >> vendor.name: %s", util.Dig("vendor.name", data)) util.Dumpf("Server Info >> vendor.version: %s", util.Dig("vendor.version", data)) util.Dumpf("Server Info >> vendor.name: %s", data["vendor"].(map[string]string)["name"]) util.Dumpf("Server Info >> vendor.version: %s", data["vendor"].(map[string]string)["version"]) }
/** * TestCreateDocumentAll */ func TestCreateDocumentAll() { data, err := Database.CreateDocumentAll([]interface{}{ 0: map[string]interface{}{"name": "kerem", "type": "tmp"}, 1: map[string]interface{}{"name": "murat", "type": "tmp"}, }) if err != nil { panic(err) } util.Dumpf("Database Create Document All >> %+v", data) util.Dumpf("Database Create Document All >> doc.0.ok: %v", util.Dig("0.ok", data)) util.Dumpf("Database Create Document All >> doc.0.id: %s", util.Dig("0.id", data)) util.Dumpf("Database Create Document All >> doc.0.rev: %s", util.Dig("0.rev", data)) // or for i, doc := range data { for key, value := range doc { util.Dumpf("Database Create Document All >> doc.%d.%s: %v", i, key, value) } } }
/** * TestFindRevisions */ func TestFindRevisions() { var doc = _document( "_id", "83b5e0a0b3bd41d9a21cee7ae8000615", ) data, err := doc.FindRevisions() if err != nil { panic(err) } util.Dumpf("Document Find Revisions >> %v", data) util.Dumpf("Document Find Revisions >> start: %d", data["start"]) util.Dumpf("Document Find Revisions >> ids: %v", data["ids"]) util.Dumpf("Document Find Revisions >> ids.0: %v", util.Dig("ids.0", data)) }
// Get missing revisions diff. // // @param object map[string]interface{} // @return map[string]interface{}, error func (this *Database) GetMissingRevisionsDiff( object map[string]interface{}) (map[string]interface{}, error) { data, err := this.Client.Post(this.Name+"/_revs_diff", nil, object, nil).GetBodyData(nil) if err != nil { return nil, err } ret := util.Map() for id, _ := range data.(map[string]interface{}) { ret[id] = map[string]interface{}{ "missing": util.Dig(id+".missing", data), } } return ret, nil }
/** * TestGetDocument */ func TestGetDocument() { data, err := Database.GetDocument("5db345a5f26484352ea5d813180031fb") if err != nil { panic(err) } util.Dumpf("Database Document >> %+v", data) util.Dumpf("Database Document >> id: %s", data["id"]) util.Dumpf("Database Document >> key: %s", data["key"]) util.Dumpf("Database Document >> value.rev: %s", util.Dig("value.rev", data)) util.Dumpf("Database Document >> doc: %+v", data["doc"]) // util.Dumpf("Database Document >> doc._id: %s", util.Dig("doc._id", data)) // util.Dumpf("Database Document >> doc._rev: %s", util.Dig("doc._rev", data)) // or for key, value := range util.DigMap("doc", data) { util.Dumpf("Database Document >> doc.%s: %v", key, value) } }
/** * TestViewTemp */ func TestViewTemp() { var map_ = "function(doc){if(doc.type=='tmp') emit(null,doc)}" data, err := Database.ViewTemp(map_, "") if err != nil { panic(err) } // util.Dumpf("Database View Temp >> %+v", data) util.Dumpf("Database View Temp >> offset: %d", data["offset"]) util.Dumpf("Database View Temp >> total_rows: %d", data["total_rows"]) // // util.Dumpf("Database View Temp >> rows: %+v", data["rows"]) util.Dumpf("Database View Temp >> rows.0: %+v", util.Dig("rows.0", data)) util.Dumpf("Database View Temp >> rows.0.id: %s", util.Dig("rows.0.id", data)) util.Dumpf("Database View Temp >> rows.0.key: %s", util.Dig("rows.0.key", data)) util.Dumpf("Database View Temp >> rows.0.value: %+v", util.Dig("rows.0.value", data)) util.Dumpf("Database View Temp >> rows.0.value._id: %s", util.Dig("rows.0.value._id", data)) util.Dumpf("Database View Temp >> rows.0.value._rev: %s", util.Dig("rows.0.value._rev", data)) util.Dumpf("Database View Temp >> rows.0.value.type: %s", util.Dig("rows.0.value.type", data)) util.Dumpf("Database View Temp >> rows.0.value.name: %s", util.Dig("rows.0.value.name", data)) }