mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-20 06:25:07 +00:00
Generate clients (#206)
This commit is contained in:
12
examples/db/create/curl/createARecord.sh
Executable file
12
examples/db/create/curl/createARecord.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
curl "https://api.m3o.com/v1/db/Create" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"record": {
|
||||
"age": 42,
|
||||
"id": "1",
|
||||
"isActive": true,
|
||||
"name": "Jane"
|
||||
},
|
||||
"table": "users"
|
||||
}'
|
||||
22
examples/db/create/go/createARecord.go
Executable file
22
examples/db/create/go/createARecord.go
Executable file
@@ -0,0 +1,22 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/db"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
||||
func CreateArecord() {
|
||||
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := dbService.Create(&db.CreateRequest{
|
||||
Record: map[string]interface{}{
|
||||
"age": 42,
|
||||
"isActive": true,
|
||||
"id": "1",
|
||||
"name": "Jane",
|
||||
},
|
||||
Table: "users",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
18
examples/db/create/node/createARecord.js
Executable file
18
examples/db/create/node/createARecord.js
Executable file
@@ -0,0 +1,18 @@
|
||||
import * as db from "m3o/db";
|
||||
|
||||
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
||||
async function CreateArecord() {
|
||||
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await dbService.create({
|
||||
record: {
|
||||
age: 42,
|
||||
id: "1",
|
||||
isActive: true,
|
||||
name: "Jane",
|
||||
},
|
||||
table: "users",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await CreateArecord();
|
||||
7
examples/db/delete/curl/deleteARecord.sh
Executable file
7
examples/db/delete/curl/deleteARecord.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
curl "https://api.m3o.com/v1/db/Delete" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"id": "1",
|
||||
"table": "users"
|
||||
}'
|
||||
17
examples/db/delete/go/deleteARecord.go
Executable file
17
examples/db/delete/go/deleteARecord.go
Executable file
@@ -0,0 +1,17 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/db"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Delete a record in the database by id.
|
||||
func DeleteArecord() {
|
||||
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := dbService.Delete(&db.DeleteRequest{
|
||||
Id: "1",
|
||||
Table: "users",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
13
examples/db/delete/node/deleteARecord.js
Executable file
13
examples/db/delete/node/deleteARecord.js
Executable file
@@ -0,0 +1,13 @@
|
||||
import * as db from "m3o/db";
|
||||
|
||||
// Delete a record in the database by id.
|
||||
async function DeleteArecord() {
|
||||
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await dbService.delete({
|
||||
id: "1",
|
||||
table: "users",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await DeleteArecord();
|
||||
7
examples/db/read/curl/readRecords.sh
Executable file
7
examples/db/read/curl/readRecords.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
curl "https://api.m3o.com/v1/db/Read" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"query": "age == 43",
|
||||
"table": "users"
|
||||
}'
|
||||
17
examples/db/read/go/readRecords.go
Executable file
17
examples/db/read/go/readRecords.go
Executable file
@@ -0,0 +1,17 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/db"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Read data from a table. Lookup can be by ID or via querying any field in the record.
|
||||
func ReadRecords() {
|
||||
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := dbService.Read(&db.ReadRequest{
|
||||
Query: "age == 43",
|
||||
Table: "users",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
13
examples/db/read/node/readRecords.js
Executable file
13
examples/db/read/node/readRecords.js
Executable file
@@ -0,0 +1,13 @@
|
||||
import * as db from "m3o/db";
|
||||
|
||||
// Read data from a table. Lookup can be by ID or via querying any field in the record.
|
||||
async function ReadRecords() {
|
||||
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await dbService.read({
|
||||
query: "age == 43",
|
||||
table: "users",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await ReadRecords();
|
||||
6
examples/db/truncate/curl/truncateTable.sh
Executable file
6
examples/db/truncate/curl/truncateTable.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/db/Truncate" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"table": "users"
|
||||
}'
|
||||
16
examples/db/truncate/go/truncateTable.go
Executable file
16
examples/db/truncate/go/truncateTable.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/db"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Truncate the records in a table
|
||||
func TruncateTable() {
|
||||
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := dbService.Truncate(&db.TruncateRequest{
|
||||
Table: "users",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/db/truncate/node/truncateTable.js
Executable file
12
examples/db/truncate/node/truncateTable.js
Executable file
@@ -0,0 +1,12 @@
|
||||
import * as db from "m3o/db";
|
||||
|
||||
// Truncate the records in a table
|
||||
async function TruncateTable() {
|
||||
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await dbService.truncate({
|
||||
table: "users",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await TruncateTable();
|
||||
10
examples/db/update/curl/updateARecord.sh
Executable file
10
examples/db/update/curl/updateARecord.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
curl "https://api.m3o.com/v1/db/Update" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"record": {
|
||||
"age": 43,
|
||||
"id": "1"
|
||||
},
|
||||
"table": "users"
|
||||
}'
|
||||
20
examples/db/update/go/updateARecord.go
Executable file
20
examples/db/update/go/updateARecord.go
Executable file
@@ -0,0 +1,20 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/micro/services/clients/go/db"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Update a record in the database. Include an "id" in the record to update.
|
||||
func UpdateArecord() {
|
||||
dbService := db.NewDbService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := dbService.Update(&db.UpdateRequest{
|
||||
Record: map[string]interface{}{
|
||||
"age": 43,
|
||||
"id": "1",
|
||||
},
|
||||
Table: "users",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
16
examples/db/update/node/updateARecord.js
Executable file
16
examples/db/update/node/updateARecord.js
Executable file
@@ -0,0 +1,16 @@
|
||||
import * as db from "m3o/db";
|
||||
|
||||
// Update a record in the database. Include an "id" in the record to update.
|
||||
async function UpdateArecord() {
|
||||
let dbService = new db.DbService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await dbService.update({
|
||||
record: {
|
||||
age: 43,
|
||||
id: "1",
|
||||
},
|
||||
table: "users",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
await UpdateArecord();
|
||||
Reference in New Issue
Block a user