Golang语言开发的开源NoSQL数据库——TieDot简介

简介

项目开源地址:https://github.com/HouzuoGuo/tiedot

发起者留下了他的Twitter,貌似姓郭,是个美籍华人

项目简介中,有关于对性能的描述,有人用此数据库抓取了维基百科,保存5900万数据,共73G。

安装

配置好Go环境后,运行

go get github.com/HouzuoGuo/tiedot

入门

使用有2种方式,使用HTTP做接口,适用任何语言;使用嵌入式,使用Go语言,这里介绍使用Go语言,数据库的嵌入模式,足以应付百万请求/天了。

项目自带了演示代码,通过下面的命令执行

./tiedot -mode=example

性能评估命令

1./tiedot -mode=bench   # 对40万数据,进行增删改查 2./tiedot -mode=bench2  # 还没仔细看

项目中,example.go 文件是Go语言的使用示例

1// It is very important to initialize random number generator seed! 2 rand.Seed(time.Now().UTC().UnixNano()) 3 // Create and open database创建并打开数据库 4 dir := "/tmp/MyDatabase" 5 os.RemoveAll(dir) 6 defer os.RemoveAll(dir) 7 8 myDB, err := db.OpenDB(dir) 9 if err != nil { 10 panic(err) 11 } 12 13 // Create two collections Feeds and Votes创建2张表 14 // "2" means collection data and indexes are divided into two halves, allowing concurrent access from two threads 15 if err := myDB.Create("Feeds", 2); err != nil { 16 panic(err) 17 } 18 if err := myDB.Create("Votes", 2); err != nil { 19 panic(err) 20 } 21 22 // What collections do I now have?查询都有哪些表 23 for name := range myDB.StrCol { 24 fmt.Printf("I have a collection called %s\n", name) 25 } 26 27 // Rename collection "Votes" to "Points"把表"Votes"重命名为"Points" 28 if err := myDB.Rename("Votes", "Points"); err != nil { 29 panic(err) 30 } 31 32 // Drop (delete) collection "Points"删除表"Points" 33 if err := myDB.Drop("Points"); err != nil { 34 panic(err) 35 } 36 37 // Scrub (repair and compact) "Feeds"修复并压缩表"Feeds" 38 myDB.Scrub("Feeds") 39 40 // ****************** Document Management ****************** 41 // Start using a collection使用表"Feeds" 42 feeds := myDB.Use("Feeds") 43 44 // Insert document (document must be map[string]interface{})插入数据 45 docID, err := feeds.Insert(map[string]interface{}{ 46 "name": "Go 1.2 is released", 47 "url":  "golang.org"}) 48 if err != nil { 49 panic(err) 50 } 51 52 // Read document根据id查询数据 53 var readBack interface{} 54 feeds.Read(docID, &readBack) // pass in document's physical ID 55 fmt.Println(readBack) 56 57 // Update document (document must be map[string]interface{})改数据 58 err = feeds.Update(docID, map[string]interface{}{ 59 "name": "Go is very popular", 60 "url":  "google.com"}) 61 if err != nil { 62 panic(err) 63 } 64 65 // Delete document删除数据 66 feeds.Delete(docID) 67 68 // Delete document 69 feeds.Delete(123) // An ID which does not exist does no harm 70 71 // ****************** Index Management ******************索引管理 72 // Secondary indexes assist in many types of queries 73 // Create index (path leads to document JSON attribute)建索引 74 if err := feeds.Index([]string{"author", "name", "first_name"}); err != nil { 75 panic(err) 76 } 77 if err := feeds.Index([]string{"Title"}); err != nil { 78 panic(err) 79 } 80 if err := feeds.Index([]string{"Source"}); err != nil { 81 panic(err) 82 } 83 84 // What indexes do I have on collection A?查询有哪些索引 85 for path := range feeds.SecIndexes { 86 fmt.Printf("I have an index on path %s\n", path) 87 } 88 89 // Remove index删索引 90 if err := feeds.Unindex([]string{"author", "name", "first_name"}); err != nil { 91 panic(err) 92 } 93 94 // ****************** Queries ******************查询表 95 // Let's prepare a number of docments for a start 96 feeds.Insert(map[string]interface{}{"Title": "New Go release", "Source": "golang.org", "Age": 3}) 97 feeds.Insert(map[string]interface{}{"Title": "Kitkat is here", "Source": "google.com", "Age": 2}) 98 feeds.Insert(map[string]interface{}{"Title": "Good Slackware", "Source": "slackware.com", "Age": 1}) 99 100 queryStr := `[{"eq": "New Go release", "in": ["Title"]}, {"eq": "slackware.com", "in": ["Source"]}]` 101 var query interface{} 102 json.Unmarshal([]byte(queryStr), &query)查询条件 103 104 queryResult := make(map[uint64]struct{}) // query result (document IDs) goes into map keys保存查询结果的变量 105 106 if err := db.EvalQuery(query, feeds, &queryResult); err != nil {执行查询 107 panic(err) 108 } 109 110 // Query results are physical document IDs打印查询结果 111 for id := range queryResult { 112 fmt.Printf("Query returned document ID %d\n", id) 113 } 114 115 // To use the document itself, simply read it back 116 for id := range queryResult { 117 feeds.Read(id, &readBack) 118 fmt.Printf("Query returned document %v\n", readBack) 119 } 120 121 // Gracefully close database关闭数据库 122 myDB.Close()
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

swap空间的增减方法

(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap