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.
- Host: GitHub
- URL: https://github.com/ije/postdb
- Owner: ije
- License: mit
- Created: 2020-07-05T12:35:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-11-13T11:25:55.000Z (over 2 years ago)
- Last Synced: 2025-05-07T20:08:20.183Z (about 1 year ago)
- Topics: boltdb, golang, postdb
- Language: Go
- Homepage:
- Size: 113 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PostDB
[](https://godoc.org/github.com/ije/postdb)
[](https://goreportcard.com/report/github.com/ije/postdb)
[](./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)
```