This commit is contained in:
Janos Dobronszki
2021-10-21 14:28:25 +01:00
11 changed files with 382 additions and 116 deletions

View File

@@ -16,6 +16,12 @@ type DbService struct {
client *client.Client
}
// Count records in a table
func (t *DbService) Count(request *CountRequest) (*CountResponse, error) {
rsp := &CountResponse{}
return rsp, t.client.Call("db", "Count", request, rsp)
}
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
func (t *DbService) Create(request *CreateRequest) (*CreateResponse, error) {
rsp := &CreateResponse{}
@@ -46,6 +52,14 @@ func (t *DbService) Update(request *UpdateRequest) (*UpdateResponse, error) {
return rsp, t.client.Call("db", "Update", request, rsp)
}
type CountRequest struct {
Table string `json:"table"`
}
type CountResponse struct {
Count int32 `json:"count"`
}
type CreateRequest struct {
// JSON encoded record or records (can be array or object)
Record map[string]interface{} `json:"record"`

View File

@@ -6,6 +6,10 @@ export class DbService {
constructor(token: string) {
this.client = new m3o.Client({ token: token });
}
// Count records in a table
count(request: CountRequest): Promise<CountResponse> {
return this.client.call("db", "Count", request) as Promise<CountResponse>;
}
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
create(request: CreateRequest): Promise<CreateResponse> {
return this.client.call("db", "Create", request) as Promise<CreateResponse>;
@@ -32,6 +36,14 @@ export class DbService {
}
}
export interface CountRequest {
table?: string;
}
export interface CountResponse {
count?: number;
}
export interface CreateRequest {
// JSON encoded record or records (can be array or object)
record?: { [key: string]: any };