https://github.com/x-color/docdb-in-go
document db in golang
https://github.com/x-color/docdb-in-go
documentdb golang
Last synced: 5 months ago
JSON representation
document db in golang
- Host: GitHub
- URL: https://github.com/x-color/docdb-in-go
- Owner: x-color
- License: mit
- Created: 2022-06-19T05:33:28.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-24T08:18:09.000Z (almost 4 years ago)
- Last Synced: 2024-06-21T06:28:57.634Z (almost 2 years ago)
- Topics: documentdb, golang
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Document DB in Go
I created the document DB referring to [the blog](https://notes.eatonphil.com/documentdb.html).
## Usage
```sh
$ go run main.go
$ curl -X POST \
-H 'Content-Type: application/json' \
-d '{"id": "1", "name": "bookA", "detail": {"price": 100,"description": "this is sample book"}}' \
http://localhost:8080/docs
{"id":"c759b15f-131e-41d6-af3c-5680c8f1ea11"}
$ curl -X POST \
-H 'Content-Type: application/json' \
-d '{"id": "2", "name": "bookB", "detail": {"price": 200,"description": "this is sample book"}}' \
http://localhost:8080/docs
{"id":"23a96578-e900-424f-a73f-808ff15d0823"}
$ curl -s http://localhost:8080/docs/23a96578-e900-424f-a73f-808ff15d0823 | jq
{
"detail": {
"description": "this is sample book",
"price": 200
},
"id": "2",
"name": "bookB"
}
$ curl --get -s http://localhost:8080/docs --data-urlencode 'q=name:"bookA"' | jq
{
"count": 1,
"documents": [
{
"document": {
"detail": {
"description": "this is sample book",
"price": 100
},
"id": "1",
"name": "bookA"
},
"id": "c759b15f-131e-41d6-af3c-5680c8f1ea11"
}
]
}
$ curl --get -s http://localhost:8080/docs --data-urlencode 'q=detail.price:>150' | jq
{
"count": 1,
"documents": [
{
"document": {
"detail": {
"description": "this is sample book",
"price": 200
},
"id": "2",
"name": "bookB"
},
"id": "23a96578-e900-424f-a73f-808ff15d0823"
}
]
}
$ curl --get -s http://localhost:8080/docs --data-urlencode 'q=detail.description:"this is sample book"' | jq
{
"count": 2,
"documents": [
{
"document": {
"detail": {
"description": "this is sample book",
"price": 100
},
"id": "1",
"name": "bookA"
},
"id": "c759b15f-131e-41d6-af3c-5680c8f1ea11"
},
{
"document": {
"detail": {
"description": "this is sample book",
"price": 200
},
"id": "2",
"name": "bookB"
},
"id": "23a96578-e900-424f-a73f-808ff15d0823"
}
]
}
```