简介
项目开源地址:https://github.com/HouzuoGuo/tiedot
发起者留下了他的Twitter,貌似姓郭,是个美籍华人
项目简介中,有关于对性能的描述,有人用此数据库抓取了维基百科,保存5900万数据,共73G。
安装
配置好Go环境后,运行
gogetgithub.com/HouzuoGuo/tiedot
入门
使用有2种方式,使用HTTP做接口,适用任何语言;使用嵌入式,使用Go语言,这里介绍使用Go语言,数据库的嵌入模式,足以应付百万请求/天了。
./tiedot-mode=example
性能评估命令
./tiedot-mode=bench#对40万数据,进行增删改查 ./tiedot-mode=bench2#还没仔细看
项目中,example.go文件是Go语言的使用示例
//Itisveryimportanttoinitializerandomnumbergeneratorseed! rand.Seed(time.Now().UTC().UnixNano()) //Createandopendatabase创建并打开数据库 dir:="/tmp/MyDatabase" os.RemoveAll(dir) deferos.RemoveAll(dir) myDB,err:=db.OpenDB(dir) iferr!=nil{ panic(err) } //CreatetwocollectionsFeedsandVotes创建2张表 //"2"meanscollectiondataandindexesaredividedintotwohalves,allowingconcurrentaccessfromtwothreads iferr:=myDB.Create("Feeds",2);err!=nil{ panic(err) } iferr:=myDB.Create("Votes",2);err!=nil{ panic(err) } //WhatcollectionsdoInowhave?查询都有哪些表 forname:=rangemyDB.StrCol{ fmt.Printf("Ihaveacollectioncalled%s\n",name) } //Renamecollection"Votes"to"Points"把表"Votes"重命名为"Points" iferr:=myDB.Rename("Votes","Points");err!=nil{ panic(err) } //Drop(delete)collection"Points"删除表"Points" iferr:=myDB.Drop("Points");err!=nil{ panic(err) } //Scrub(repairandcompact)"Feeds"修复并压缩表"Feeds" myDB.Scrub("Feeds") //******************DocumentManagement****************** //Startusingacollection使用表"Feeds" Feeds:=myDB.Use("Feeds") //Insertdocument(documentmustbemap[string]interface{})插入数据 docID,err:=Feeds.Insert(map[string]interface{}{ "name":"Go1.2isreleased","url":"golang.org"}) iferr!=nil{ panic(err) } //Readdocument根据id查询数据 varreadBackinterface{} Feeds.Read(docID,&readBack)//passindocument'sphysicalID fmt.Println(readBack) //Updatedocument(documentmustbemap[string]interface{})改数据 err=Feeds.Update(docID,map[string]interface{}{ "name":"Goisverypopular","url":"google.com"}) iferr!=nil{ panic(err) } //Deletedocument删除数据 Feeds.Delete(docID) //Deletedocument Feeds.Delete(123)//AnIDwhichdoesnotexistdoesnoharm //******************IndexManagement******************索引管理 //Secondaryindexesassistinmanytypesofqueries //Createindex(pathleadstodocumentJSONattribute)建索引 iferr:=Feeds.Index([]string{"author","name","first_name"});err!=nil{ panic(err) } iferr:=Feeds.Index([]string{"Title"});err!=nil{ panic(err) } iferr:=Feeds.Index([]string{"Source"});err!=nil{ panic(err) } //WhatindexesdoIhaveoncollectionA?查询有哪些索引 forpath:=rangeFeeds.SecIndexes{ fmt.Printf("Ihaveanindexonpath%s\n",path) } //Removeindex删索引 iferr:=Feeds.Unindex([]string{"author","first_name"});err!=nil{ panic(err) } //******************Queries******************查询表 //Let'sprepareanumberofdocmentsforastart Feeds.Insert(map[string]interface{}{"Title":"NewGorelease","Source":"golang.org","Age":3}) Feeds.Insert(map[string]interface{}{"Title":"Kitkatishere","Source":"google.com","Age":2}) Feeds.Insert(map[string]interface{}{"Title":"GoodSlackware","Source":"slackware.com","Age":1}) queryStr:=`[{"eq":"NewGorelease","in":["Title"]},{"eq":"slackware.com","in":["Source"]}]` varqueryinterface{} json.Unmarshal([]byte(queryStr),&query)查询条件 queryResult:=make(map[uint64]struct{})//queryresult(documentIDs)goesintomapkeys保存查询结果的变量 iferr:=db.EvalQuery(query,Feeds,&queryResult);err!=nil{执行查询 panic(err) } //QueryresultsarephysicaldocumentIDs打印查询结果 forid:=rangequeryResult{ fmt.Printf("QueryreturneddocumentID%d\n",id) } //Tousethedocumentitself,simplyreaditback forid:=rangequeryResult{ Feeds.Read(id,&readBack) fmt.Printf("Queryreturneddocument%v\n",readBack) } //Gracefullyclosedatabase关闭数据库 myDB.Close()