An open API service indexing awesome lists of open source software.

https://github.com/ije/postdb

A database to store your posts in golang with bbolt, noSQL.
https://github.com/ije/postdb

boltdb golang postdb

Last synced: about 1 year ago
JSON representation

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

Awesome Lists containing this project

README

          

# PostDB

[![GoDoc](https://godoc.org/github.com/ije/postdb?status.svg)](https://godoc.org/github.com/ije/postdb)
[![GoReport](https://goreportcard.com/badge/github.com/ije/postdb)](https://goreportcard.com/report/github.com/ije/postdb)
[![MIT](https://img.shields.io/badge/license-MIT-green)](./LICENSE)

A database to store posts in [Go](https://golang.org) with [BoltDB](https://github.com/etcd-io/bbolt), noSQL.

## Installation
```bash
go get github.com/ije/postdb
```

## Usage

```go
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)
```