https://github.com/valerianomacuri/lowdb
Simple to use local JSON database. Powered by Go. Inspired in lowdb for Javascript
https://github.com/valerianomacuri/lowdb
database embedded-database fake-api go golang javascript json json-api json-server localstorage lowdb lowdb-adapter nodejs storage toml typecode yaml
Last synced: 9 days ago
JSON representation
Simple to use local JSON database. Powered by Go. Inspired in lowdb for Javascript
- Host: GitHub
- URL: https://github.com/valerianomacuri/lowdb
- Owner: valerianomacuri
- License: mit
- Created: 2022-06-12T22:19:19.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-14T17:45:02.000Z (almost 3 years ago)
- Last Synced: 2024-06-19T06:54:05.046Z (10 months ago)
- Topics: database, embedded-database, fake-api, go, golang, javascript, json, json-api, json-server, localstorage, lowdb, lowdb-adapter, nodejs, storage, toml, typecode, yaml
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 15
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lowdb [](https://pkg.go.dev/github.com/valerianomacuri/lowdb)
> Simple to use local JSON database. Powered by Go. Inspired in lowdb for
> Javascript```go
db.Data.Posts = append(
db.Data.Posts,
Data.Posts{ ID: 1, Title: "lowdb is awesome"},
)
``````json
// db.json
{
"posts": [
{ "id": 1, "title": "lowdb is awesome" }
]
}
```## Install
```console
go get github.com/valerianomacuri/lowdb
```## Usage
```console
touch db.json && echo "{}" > db.json
``````json
// db.json
{}
``````go
package mainimport (
"github.com/valerianomacuri/lowdb/adapters"
"github.com/valerianomacuri/lowdb/low"
)// Define the data structure for database
type Data struct {
Posts []Post `json:"posts"`
}
type Post struct {
ID uint64 `json:"id"`
Title string `json:"title"`
}func main() {
adapter := adapters.NewJSONFile[Data]("db.json")
db := low.New[Data](adapter)
// Read data from JSON file, this will set db.Data content
db.Read()// Finally write db.Data content to file
defer db.Write()// Append a post into posts array
db.Data.Posts = append(
db.Data.Posts,
Post{ID: 1, Title: "lowdb is awesome"},
)
}
```## Help us