mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-16 13:04:34 +00:00
db service: Count endpoint (#236)
This commit is contained in:
6
examples/db/count/curl/countEntriesInATable.sh
Executable file
6
examples/db/count/curl/countEntriesInATable.sh
Executable 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"
|
||||
}'
|
||||
16
examples/db/count/go/countEntriesInATable.go
Executable file
16
examples/db/count/go/countEntriesInATable.go
Executable 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)
|
||||
}
|
||||
12
examples/db/count/node/countEntriesInATable.js
Executable file
12
examples/db/count/node/countEntriesInATable.js
Executable 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();
|
||||
@@ -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",
|
||||
})
|
||||
|
||||
@@ -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",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user