db service: Count endpoint (#236)

This commit is contained in:
Janos Dobronszki
2021-10-21 09:35:51 +01:00
committed by GitHub
parent 36b705930f
commit 2b6a219b0e
13 changed files with 384 additions and 118 deletions

View File

@@ -0,0 +1,6 @@
curl "https://api.m3o.com/v1/db/Count" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MICRO_API_TOKEN" \
-d '{
"table": "users"
}'

View File

@@ -0,0 +1,16 @@
package example
import (
"fmt"
"github.com/micro/services/clients/go/db"
"os"
)
// Count records in a table
func CountEntriesInAtable() {
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
rsp, err := dbService.Count(&db.CountRequest{
Table: "users",
})
fmt.Println(rsp, err)
}

View File

@@ -0,0 +1,12 @@
import * as db from "m3o/db";
// Count records in a table
async function CountEntriesInAtable() {
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
let rsp = await dbService.count({
table: "users",
});
console.log(rsp);
}
await CountEntriesInAtable();

View File

@@ -11,10 +11,10 @@ func CreateArecord() {
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
rsp, err := dbService.Create(&db.CreateRequest{
Record: map[string]interface{}{
"id": "1",
"name": "Jane",
"age": 42,
"isActive": true,
"id": "1",
},
Table: "users",
})

View File

@@ -11,9 +11,9 @@ func PublishAmessage() {
streamService := stream.NewStreamService(os.Getenv("MICRO_API_TOKEN"))
rsp, err := streamService.Publish(&stream.PublishRequest{
Message: map[string]interface{}{
"user": "john",
"id": "1",
"type": "signup",
"user": "john",
},
Topic: "events",
})