coco

package module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 15 Imported by: 0

README

coco

Built-in document database, Large-scale data warehouse

Use
  • insert
type demo struct {
    Name        string `json:"name"`
	Age         int    `json:"age"`
	Description string `json:"description"`
}

client := NewClient(NewDefaultConfig("./out"))
collection, err := client.Database("test1").Collection("test1")
if err != nil {
    log.Fatalln(err)
}

rs := make([]interface{}, 0)
for i := 0; i < 60030; i++ {
    r := demo{
        Name:        fmt.Sprintf("scp-%d", i),
        Age:         rand.Intn(600),
        Description: fmt.Sprintf("scp-NB-%d", i),
    }
    rs = append(rs, r)
}
err = collection.InsertMany(context.TODO(), rs)
if err != nil {
    log.Fatalln(err)
}
  • search
    client := NewClient(NewDefaultConfig("./out"))
	collection, err := client.Database("test1").Collection("test1")
	if err != nil {
		log.Fatalln(err)
	}

	find, err := collection.Find(context.TODO(), M{
        "name": "scp",        
		"age": M{
			"$<": 300,
		},
	})
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(find)
	defer find.Close()

	rs := make([]demo, 0)
	all, err := find.All(context.TODO(), &rs)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(all)

	marshal, err := json.Marshal(rs)
	if err == nil {
		log.Println(string(marshal))
	}
BateV1 Performance
  • Insert (7500 HHD) 68W/s
  • Search (7500 HHD No Index ) 500W data full table scan time 2s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(conf *Conf) *Client

func (*Client) Database

func (c *Client) Database(database string) *Database

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

func (*Collection) Find

func (c *Collection) Find(ctx context.Context, filter M) (*Cursor, error)

func (*Collection) InsertMany

func (c *Collection) InsertMany(ctx context.Context, documents []interface{}) error

type Conf

type Conf struct {
	Path         string // 文档存储路径
	MaxSize      uint64 // 单文件最大存储个数  (文件越小在并行查询下越快)
	MaxReadPool  uint64 // 最大读取线程数
	MaxWritePool uint64 // 写大写入编码线程  ( 采用顺序写入 理论能跑满当前磁盘性能)
}

func NewDefaultConfig

func NewDefaultConfig(path string) *Conf

type Cursor

type Cursor struct {
	// contains filtered or unexported fields
}

func (*Cursor) All

func (c *Cursor) All(ctx context.Context, results interface{}) (count int, err error)

func (*Cursor) Close

func (c *Cursor) Close() error

type Database

type Database struct {
	// contains filtered or unexported fields
}

func (*Database) Collection

func (d *Database) Collection(collection string) (*Collection, error)

type M

type M map[string]interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL