Introduction to open Source NoSQL database--tiedot Golang language development

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Brief introduction

Project Open Source Address: Https://github.com/HouzuoGuo/tiedot

The initiator left his Twitter, apparently surnamed Guo, a Chinese-American.

In the project introduction, there is a description of the performance, someone used this database to crawl Wikipedia, save 59 million data, a total of 73G.

Installation

After configuring the Go environment, run

Go get Github.com/houzuoguo/tiedot

Entry

There are 2 ways to use HTTP as an interface, for any language, and to use the go language, the Go language is used, and the embedded mode of the database is sufficient to cope with millions of requests/days.

The project comes with a demo code that executes with the following command

./tiedot-mode=example

Performance evaluation Commands

./tiedot-mode=bench # for 400,000 data, make a search for additional deletions./TIEDOT-MODE=BENCH2 's not looking carefully.

Project, example.go files are examples of use of the Go language

 it is very important to initialize random number generator  seed!rand. Seed (time. Now (). UTC (). Unixnano ())// create and open database Create and open the database dir :=  "/tmp/mydatabase" OS. RemoveAll (dir) defer os. RemoveAll (dir) mydb, err := db. Opendb (dir) if err != nil {panic (err)}// create two collections feeds  and votes Create 2 sheets//  "2"  means collection data and indexes are  divided into two halves, allowing concurrent access from two  Threadsif err := mydb.create ("Feeds",  2);  err != nil {panic (err)}if  err := mydb.create ("votes",  2);  err != nil {panic (err)}// What  collections do i now have. What tables are available for queries For name := range mydb.strcol  {fmt. Printf ("I have&nbSp;a collection called %s\n ",  name)}// rename collection " Votes " to   "Points" renamed the table "votes" to "Points" If err := mydb.rename ("votes",  "Points");  err  != nil {panic (Err)}// drop  (delete)  collection  "Points" Delete table "Points" if  Err := mydb.drop ("Points");  err != nil {panic (err)}// scrub  (repair  and compact)   "Feeds" repair and compress the table "Feeds" Mydb.scrub ("Feeds")// ****************** document  management ******************// start using a collection using the table "Feeds" feeds :=  mydb.use ("Feeds")// insert document  (document must be map[string]interface {}) Insert data docid, err := feeds. Insert (map[string]interface{}{"name":  "go 1.2 is released", "url":   "golang.org"} ) If err != nil {panic (ERR)}// read document query data based on ID Var rEadback interface{}feeds. Read (docid, &readback)  // pass in document ' S physical idfmt.println ( Readback)// update document  (document must be map[string]interface{}) Change data err  = feeds. Update (docid, map[string]interface{}{"name":  "Go is very popular", "url":   " Google.com "}) if err != nil {panic (err)}// delete document Delete data feeds. Delete (DocID)// delete documentfeeds. Delete (123)  // an id which does not exist does no harm//  ****************** index management ****************** Index management// secondary indexes  assist in many types of queries// Create index  (path leads  to document json attribute) build index if err := feeds. Index ([]string{"author",  "name",  "First_Name"});  err !=&nbsP;nil {panic (Err)}if err := feeds. Index ([]string{"Title"});  err != nil {panic (err)}if err := feeds. Index ([]string{"Source"});  err != nil {panic (err)}// what indexes do i  have on collection a? What index for path := range feeds is queried. Secindexes {fmt. Printf ("i have an index on path %s\n",  path)}// remove index Delete Index if  err := feeds. Unindex ([]string{"author",  "name",  "First_Name"});  err != nil {panic (err)}//  ****************** queries ****************** query Table// let ' S prepare a number  of docments for a startfeeds. Insert (map[string]interface{}{"Title":  "New go release",  "Source":  "golang.org",   "Age":  3}) feeds. Insert (map[string]interface{}{"Title":  "Kitkat is here",  "SouRce ": " google.com ", " "Age":  2}) feeds. Insert (map[string]interface{}{"Title":  "Good slackware",  "Source":  "slackware.com",  " Age ":  1}) querystr :=  ' [{" eq ": " new go release ", " in ":  [" Title "]},  {"eq":  "slackware.com",  "in":  ["Source"]}] ' Var query interface{}json. Unmarshal ([]byte (QUERYSTR),  &query) query conditions Queryresult := make (map[uint64]struct{})  //  query result  (document ids)  goes into map keys the variable that holds the query result If err  := db. Evalquery (Query, feeds, &queryresult);  err != nil {Execute Query Panic (ERR)}//  Query results are physical document ids Print Query Results for id := range  Queryresult {fmt. Printf ("query returned document id %d\n",  id)}// to use the  Document itself, simply read it backfoR id := range queryresult {feeds. Read (Id, &readback) fmt. Printf ("query returned document %v\n",  readback)}// gracefully close  Database close Databases Mydb.close ()




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.