处理数据
文档操作是集合 action。数据库访问使用 Api-Key 和 Api-Secret,当数据库 owner 被允许时也可以使用 Glue owner token。
插入文档
curl -X POST "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:insert" \
-H "Content-Type: application/jsonl" \
-H "Api-Key: your-api-key" \
-H "Api-Secret: your-api-secret" \
-d '{"id":"1","name":"Alice"}
{"id":"2","name":"Bob"}'POST /v1/databases/%7BdatabaseId%7D/collections/%7Bcollection%7D:insert HTTP/1.1
Host: api.hola.cloud
Content-Type: application/jsonl
Api-Key: your-api-key
Api-Secret: your-api-secret
{"id":"1","name":"Alice"}
{"id":"2","name":"Bob"}package main
import (
"fmt"
"io"
"net/http"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"id": "1", "name": "Alice"}
bodyBytes, err := json.Marshal(payload)
if err != nil {
panic(err)
}
body := string(bodyBytes)
req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:insert", strings.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/jsonl")
req.Header.Set("Api-Key", "your-api-key")
req.Header.Set("Api-Secret", "your-api-secret")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(responseBody))
}
<?php
$payload = ['id' => '1', 'name' => 'Alice'];
$body = json_encode($payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:insert',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [
'Content-Type: application/jsonl',
'Api-Key: your-api-key',
'Api-Secret: your-api-secret',
],
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch));
}
curl_close($ch);
echo $response;
import requests
import json
headers = {
"Content-Type": "application/jsonl",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret",
}
payload = {"id": "1", "name": "Alice"}
body = json.dumps(payload)
response = requests.request(
"POST",
"https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:insert",
headers=headers,
data=body
)
print(response.text)
const payload = {"id": "1", "name": "Alice"};
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:insert", {
method: "POST",
headers: {
"Content-Type": "application/jsonl",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
},
body: JSON.stringify(payload)
});
console.log(await response.text());
const payload = {"id": "1", "name": "Alice"};
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:insert", {
method: "POST",
headers: {
"Content-Type": "application/jsonl",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
},
body: JSON.stringify(payload)
});
const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
var payload = Map.of("id", "1", "name", "Alice");
var body = new ObjectMapper().writeValueAsString(payload);
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:insert"))
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.header("Content-Type", "application/jsonl")
.header("Api-Key", "your-api-key")
.header("Api-Secret", "your-api-secret")
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}响应为插入后的 JSONL 文档。
1{"id":"1","name":"Alice"}
2{"id":"2","name":"Bob"}
查询文档
curl -X POST "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:find" \
-H "Content-Type: application/json" \
-H "Api-Key: your-api-key" \
-H "Api-Secret: your-api-secret" \
-d '{
"filter": {
"name": "Alice"
}
}'POST /v1/databases/%7BdatabaseId%7D/collections/%7Bcollection%7D:find HTTP/1.1
Host: api.hola.cloud
Content-Type: application/json
Api-Key: your-api-key
Api-Secret: your-api-secret
{
"filter": {
"name": "Alice"
}
}package main
import (
"fmt"
"io"
"net/http"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"filter": map[string]any{"name": "Alice"}}
bodyBytes, err := json.Marshal(payload)
if err != nil {
panic(err)
}
body := string(bodyBytes)
req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:find", strings.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Api-Key", "your-api-key")
req.Header.Set("Api-Secret", "your-api-secret")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(responseBody))
}
<?php
$payload = ['filter' => ['name' => 'Alice']];
$body = json_encode($payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:find',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Api-Key: your-api-key',
'Api-Secret: your-api-secret',
],
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch));
}
curl_close($ch);
echo $response;
import requests
import json
headers = {
"Content-Type": "application/json",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret",
}
payload = {"filter": {"name": "Alice"}}
body = json.dumps(payload)
response = requests.request(
"POST",
"https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:find",
headers=headers,
data=body
)
print(response.text)
const payload = {"filter": {"name": "Alice"}};
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:find", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
},
body: JSON.stringify(payload)
});
console.log(await response.text());
const payload = {"filter": {"name": "Alice"}};
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:find", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
},
body: JSON.stringify(payload)
});
const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
var payload = Map.of("filter", Map.of("name", "Alice"));
var body = new ObjectMapper().writeValueAsString(payload);
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:find"))
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.header("Content-Type", "application/json")
.header("Api-Key", "your-api-key")
.header("Api-Secret", "your-api-secret")
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}响应为匹配的 JSONL 文档。
1{"id":"1","name":"Alice"}
根据 ID 获取文档
curl -X GET "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}/documents/{documentId}" \
-H "Api-Key: your-api-key" \
-H "Api-Secret: your-api-secret"GET /v1/databases/%7BdatabaseId%7D/collections/%7Bcollection%7D/documents/%7BdocumentId%7D HTTP/1.1
Host: api.hola.cloud
Api-Key: your-api-key
Api-Secret: your-api-secret
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, err := http.NewRequest("GET", "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}/documents/{documentId}", nil)
if err != nil {
panic(err)
}
req.Header.Set("Api-Key", "your-api-key")
req.Header.Set("Api-Secret", "your-api-secret")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(responseBody))
}
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}/documents/{documentId}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => [
'Api-Key: your-api-key',
'Api-Secret: your-api-secret',
],
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch));
}
curl_close($ch);
echo $response;
import requests
headers = {
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret",
}
response = requests.request(
"GET",
"https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}/documents/{documentId}",
headers=headers
)
print(response.text)
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}/documents/{documentId}", {
method: "GET",
headers: {
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
}
});
console.log(await response.text());
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}/documents/{documentId}", {
method: "GET",
headers: {
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
}
});
const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}/documents/{documentId}"))
.method("GET", HttpRequest.BodyPublishers.noBody())
.header("Api-Key", "your-api-key")
.header("Api-Secret", "your-api-secret")
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}响应为文档 JSON。
1{
2 "id": "1",
3 "name": "Alice"
4}
修改文档
curl -X POST "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:patch" \
-H "Content-Type: application/json" \
-H "Api-Key: your-api-key" \
-H "Api-Secret: your-api-secret" \
-d '{
"filter": {
"id": "1"
},
"patch": {
"name": "Alice Updated"
}
}'POST /v1/databases/%7BdatabaseId%7D/collections/%7Bcollection%7D:patch HTTP/1.1
Host: api.hola.cloud
Content-Type: application/json
Api-Key: your-api-key
Api-Secret: your-api-secret
{
"filter": {
"id": "1"
},
"patch": {
"name": "Alice Updated"
}
}package main
import (
"fmt"
"io"
"net/http"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"filter": map[string]any{"id": "1"}, "patch": map[string]any{"name": "Alice Updated"}}
bodyBytes, err := json.Marshal(payload)
if err != nil {
panic(err)
}
body := string(bodyBytes)
req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:patch", strings.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Api-Key", "your-api-key")
req.Header.Set("Api-Secret", "your-api-secret")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(responseBody))
}
<?php
$payload = ['filter' => ['id' => '1'], 'patch' => ['name' => 'Alice Updated']];
$body = json_encode($payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:patch',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Api-Key: your-api-key',
'Api-Secret: your-api-secret',
],
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch));
}
curl_close($ch);
echo $response;
import requests
import json
headers = {
"Content-Type": "application/json",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret",
}
payload = {"filter": {"id": "1"}, "patch": {"name": "Alice Updated"}}
body = json.dumps(payload)
response = requests.request(
"POST",
"https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:patch",
headers=headers,
data=body
)
print(response.text)
const payload = {"filter": {"id": "1"}, "patch": {"name": "Alice Updated"}};
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:patch", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
},
body: JSON.stringify(payload)
});
console.log(await response.text());
const payload = {"filter": {"id": "1"}, "patch": {"name": "Alice Updated"}};
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:patch", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
},
body: JSON.stringify(payload)
});
const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
var payload = Map.of("filter", Map.of("id", "1"), "patch", Map.of("name", "Alice Updated"));
var body = new ObjectMapper().writeValueAsString(payload);
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:patch"))
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.header("Content-Type", "application/json")
.header("Api-Key", "your-api-key")
.header("Api-Secret", "your-api-secret")
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}响应为修改后的 JSONL 文档。
1{"id":"1","name":"Alice Updated"}
删除文档
curl -X POST "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:remove" \
-H "Content-Type: application/json" \
-H "Api-Key: your-api-key" \
-H "Api-Secret: your-api-secret" \
-d '{
"filter": {
"id": "1"
}
}'POST /v1/databases/%7BdatabaseId%7D/collections/%7Bcollection%7D:remove HTTP/1.1
Host: api.hola.cloud
Content-Type: application/json
Api-Key: your-api-key
Api-Secret: your-api-secret
{
"filter": {
"id": "1"
}
}package main
import (
"fmt"
"io"
"net/http"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"filter": map[string]any{"id": "1"}}
bodyBytes, err := json.Marshal(payload)
if err != nil {
panic(err)
}
body := string(bodyBytes)
req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:remove", strings.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Api-Key", "your-api-key")
req.Header.Set("Api-Secret", "your-api-secret")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(responseBody))
}
<?php
$payload = ['filter' => ['id' => '1']];
$body = json_encode($payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:remove',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Api-Key: your-api-key',
'Api-Secret: your-api-secret',
],
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch));
}
curl_close($ch);
echo $response;
import requests
import json
headers = {
"Content-Type": "application/json",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret",
}
payload = {"filter": {"id": "1"}}
body = json.dumps(payload)
response = requests.request(
"POST",
"https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:remove",
headers=headers,
data=body
)
print(response.text)
const payload = {"filter": {"id": "1"}};
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:remove", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
},
body: JSON.stringify(payload)
});
console.log(await response.text());
const payload = {"filter": {"id": "1"}};
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:remove", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Api-Key": "your-api-key",
"Api-Secret": "your-api-secret"
},
body: JSON.stringify(payload)
});
const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
var payload = Map.of("filter", Map.of("id", "1"));
var body = new ObjectMapper().writeValueAsString(payload);
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.hola.cloud/v1/databases/{databaseId}/collections/{collection}:remove"))
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.header("Content-Type", "application/json")
.header("Api-Key", "your-api-key")
.header("Api-Secret", "your-api-secret")
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}响应为删除的 JSONL 文档。
1{"id":"1","name":"Alice Updated"}
评论