|
|
|
|
@@ -4,6 +4,130 @@ An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Db/api](https:
|
|
|
|
|
|
|
|
|
|
Endpoints:
|
|
|
|
|
|
|
|
|
|
## RenameTable
|
|
|
|
|
|
|
|
|
|
Rename a table
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://m3o.com/db/api#RenameTable](https://m3o.com/db/api#RenameTable)
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package example
|
|
|
|
|
|
|
|
|
|
import(
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"go.m3o.com/db"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Rename a table
|
|
|
|
|
func RenameTable() {
|
|
|
|
|
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
|
|
|
rsp, err := dbService.RenameTable(&db.RenameTableRequest{
|
|
|
|
|
From: "events",
|
|
|
|
|
To: "events_backup",
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
fmt.Println(rsp, err)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
## Create
|
|
|
|
|
|
|
|
|
|
Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://m3o.com/db/api#Create](https://m3o.com/db/api#Create)
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package example
|
|
|
|
|
|
|
|
|
|
import(
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"go.m3o.com/db"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
|
|
|
|
func CreateArecord() {
|
|
|
|
|
dbService := db.NewDbService(os.Getenv("M3O_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)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
## Update
|
|
|
|
|
|
|
|
|
|
Update a record in the database. Include an "id" in the record to update.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://m3o.com/db/api#Update](https://m3o.com/db/api#Update)
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package example
|
|
|
|
|
|
|
|
|
|
import(
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"go.m3o.com/db"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Update a record in the database. Include an "id" in the record to update.
|
|
|
|
|
func UpdateArecord() {
|
|
|
|
|
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
|
|
|
rsp, err := dbService.Update(&db.UpdateRequest{
|
|
|
|
|
Record: map[string]interface{}{
|
|
|
|
|
"id": "1",
|
|
|
|
|
"age": 43,
|
|
|
|
|
},
|
|
|
|
|
Table: "users",
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
fmt.Println(rsp, err)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
## Read
|
|
|
|
|
|
|
|
|
|
Read data from a table. Lookup can be by ID or via querying any field in the record.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://m3o.com/db/api#Read](https://m3o.com/db/api#Read)
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package example
|
|
|
|
|
|
|
|
|
|
import(
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"go.m3o.com/db"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 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("M3O_API_TOKEN"))
|
|
|
|
|
rsp, err := dbService.Read(&db.ReadRequest{
|
|
|
|
|
Query: "age == 43",
|
|
|
|
|
Table: "users",
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
fmt.Println(rsp, err)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
## Delete
|
|
|
|
|
|
|
|
|
|
Delete a record in the database by id.
|
|
|
|
|
@@ -91,7 +215,7 @@ func CountEntriesInAtable() {
|
|
|
|
|
```
|
|
|
|
|
## ListTables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List tables in the DB
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://m3o.com/db/api#ListTables](https://m3o.com/db/api#ListTables)
|
|
|
|
|
@@ -106,7 +230,7 @@ import(
|
|
|
|
|
"go.m3o.com/db"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// List tables in the DB
|
|
|
|
|
func ListTables() {
|
|
|
|
|
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
|
|
|
rsp, err := dbService.ListTables(&db.ListTablesRequest{
|
|
|
|
|
@@ -116,127 +240,3 @@ func ListTables() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
## RenameTable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://m3o.com/db/api#RenameTable](https://m3o.com/db/api#RenameTable)
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package example
|
|
|
|
|
|
|
|
|
|
import(
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"go.m3o.com/db"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
func RenameTable() {
|
|
|
|
|
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
|
|
|
rsp, err := dbService.RenameTable(&db.RenameTableRequest{
|
|
|
|
|
From: "events",
|
|
|
|
|
To: "events_backup",
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
fmt.Println(rsp, err)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
## Create
|
|
|
|
|
|
|
|
|
|
Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://m3o.com/db/api#Create](https://m3o.com/db/api#Create)
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package example
|
|
|
|
|
|
|
|
|
|
import(
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"go.m3o.com/db"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Create a record in the database. Optionally include an "id" field otherwise it's set automatically.
|
|
|
|
|
func CreateArecord() {
|
|
|
|
|
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
|
|
|
rsp, err := dbService.Create(&db.CreateRequest{
|
|
|
|
|
Record: map[string]interface{}{
|
|
|
|
|
"id": "1",
|
|
|
|
|
"name": "Jane",
|
|
|
|
|
"age": 42,
|
|
|
|
|
"isActive": true,
|
|
|
|
|
},
|
|
|
|
|
Table: "users",
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
fmt.Println(rsp, err)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
## Update
|
|
|
|
|
|
|
|
|
|
Update a record in the database. Include an "id" in the record to update.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://m3o.com/db/api#Update](https://m3o.com/db/api#Update)
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package example
|
|
|
|
|
|
|
|
|
|
import(
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"go.m3o.com/db"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Update a record in the database. Include an "id" in the record to update.
|
|
|
|
|
func UpdateArecord() {
|
|
|
|
|
dbService := db.NewDbService(os.Getenv("M3O_API_TOKEN"))
|
|
|
|
|
rsp, err := dbService.Update(&db.UpdateRequest{
|
|
|
|
|
Record: map[string]interface{}{
|
|
|
|
|
"id": "1",
|
|
|
|
|
"age": 43,
|
|
|
|
|
},
|
|
|
|
|
Table: "users",
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
fmt.Println(rsp, err)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
## Read
|
|
|
|
|
|
|
|
|
|
Read data from a table. Lookup can be by ID or via querying any field in the record.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://m3o.com/db/api#Read](https://m3o.com/db/api#Read)
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
package example
|
|
|
|
|
|
|
|
|
|
import(
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"go.m3o.com/db"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 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("M3O_API_TOKEN"))
|
|
|
|
|
rsp, err := dbService.Read(&db.ReadRequest{
|
|
|
|
|
Query: "age == 43",
|
|
|
|
|
Table: "users",
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
fmt.Println(rsp, err)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|