https://github.com/tbdsux/minidb
a simple flat-files json database
https://github.com/tbdsux/minidb
flat-file flat-file-db flat-json go go-json json jsondb mini-json minidb simpledb
Last synced: about 2 months ago
JSON representation
a simple flat-files json database
- Host: GitHub
- URL: https://github.com/tbdsux/minidb
- Owner: tbdsux
- License: unlicense
- Created: 2021-05-18T12:04:04.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-11T14:56:12.000Z (almost 5 years ago)
- Last Synced: 2026-01-12T01:36:21.703Z (5 months ago)
- Topics: flat-file, flat-file-db, flat-json, go, go-json, json, jsondb, mini-json, minidb, simpledb
- Language: Go
- Homepage:
- Size: 89.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# minidb
[](https://github.com/TheBoringDude/minidb/actions)
a simple multi-flat-files json database
This has a really weird structure and api and **I know it :happy:**
## Install
```bash
go get -u github.com/TheBoringDude/minidb
```
## Usage
```go
package main
import (
"fmt"
"github.com/TheBoringDude/minidb"
)
func main() {
db := mindb.New('db')
fmt.Println(db)
}
```
All operations are just appending and setting in a `map[string]interface{}` or `append([]interface{}, interface{})`.
In all operations, it writes to the json file. I think it is not a good idea?
#### Full Doc: https://pkg.go.dev/github.com/TheBoringDude/minidb
### MiniDB
It takes a directory and manages all files within it. It is better only to use this when trying to manage multiple json files.
New files are created with a **`random uuid`** using [**`ksuid`**](https://github.com/segmentio/ksuid) so each file created by the library is unique.
#### NOTE: this creates many json files in a specified directory
```go
db := minidb.New("dirfolder")
// db.Keys("key"), nested minidbs
// db.Collections("key"), a json collections, []
// db.Store("key"), a simple json key-value store (not meant with nested maps)
cols := db.Collections("posts")
cols.Push(map[string]string{
"title": "Hello World",
"content": "This is just something, maybe a content or not. I don't know how it works though.",
})
// multiple elements is possible
cols.Push(100, 20, "sample", false, []int{1,2,3,4,5})
fmt.Println(cols)
```
### MiniCollections
A simple collections json db file.
```go
db := minidb.NewCollections("cols.json")
db.Push(1)
fmt.Println(1)
```
### MiniStore
A simple key-value store json db file.
```go
db := minidb.NewStore("store.json")
db.Set("key", "value")
fmt.Println(db.GetString("key"))
```
## TODO
- Improve concurrency support.
- fixes, improvements
- more changes..
- ...future development
##
#### © 2021 | [License](./LICENSE)