Skip to content

ije/postdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostDB

GoDoc GoReport MIT

A database to store posts in Go with BoltDB, noSQL.

Installation

go get github.com/ije/postdb

Usage

import (
	"github.com/ije/postdb"
	"github.com/ije/postdb/q"
)

// opening a database
db, err := postdb.Open("post.db", 0666, false)
if err != nil {
    return err
}
defer db.Close()

// get all posts in the database
db.List()

// get posts with query
db.List(q.Tags("foo", "bar"), q.Range(1, 100), q.Order(q.DESC), q.Select("title", "date", "content"))

// get post without kv
db.Get(q.ID(id))

// get post with specified kv
db.Get(q.ID(id), q.Select("title", "date"))

// get post with prefixed kv
db.Get(q.ID(id), q.Select("title_*")) // match key in title_en,title_zh...

// get post with full kv
db.Get(q.ID(id), q.Select("*"))

// add a new post
db.Put(q.Alias(name), q.Status(1), q.Tags("foo", "bar"), q.KV{"foo": []byte("bar")})

// update the existing post
db.Update(q.ID(id), q.KV{"foo": []byte("cool")})

// delete the existing kv of the post
db.DeleteKV(q.ID(id), q.Select("foo"))

// delete the existing posts
db.Delete(q.ID(id))

// using namespace
ns := db.Namespace("name")
ns.List()
ns.Get(q.ID(id))
...

// backup the entire database
db.WriteTo(w)

About

A database to store your posts in golang with bbolt, noSQL.

Topics

Resources

License

Stars

Watchers

Forks

Languages