简体中文
Appearance
简体中文
Appearance
Datalayers 支持通过 HTTP/HTTPS 进行交互,SQL STATEMENT
通过 HTTP BODY
的方式进行传递。SQL 相关语法请参考:SQL Reference
curl -u"<username>:<password>" -X POST \
http://127.0.0.1:8361/api/v1/sql?db=<database_name> \
-H 'Content-Type: application/binary' \
-d '<SQL STATEMENT>'
curl -u"admin:public" -X POST \
http://127.0.0.1:8361/api/v1/sql \
-H 'Content-Type: application/binary' \
-d 'create database demo'
curl -u"admin:public" -X POST \
http://127.0.0.1:8361/api/v1/sql?db=demo \
-H 'Content-Type: application/binary' \
-d 'CREATE TABLE sensor_info (
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
sn INT32 NOT NULL,
speed int,
longitude float,
latitude float,
timestamp KEY (ts)) PARTITION BY HASH(sn) PARTITIONS 2 ENGINE=TimeSeries;'
返回值
{"affected_rows":1}
插入命令:
curl -u"admin:public" -X POST \
http://127.0.0.1:8361/api/v1/sql?db=demo \
-H 'Content-Type: application/binary' \
-d 'INSERT INTO sensor_info(sn, speed, longitude, latitude) VALUES(1, 120, 104.07, 30.59),(2, 120, 104.07, 30.59)'
返回值:
{"affected_rows":2}
package main
import (
"bytes"
"encoding/base64"
"fmt"
"io"
"net/http"
)
func main() {
username := "admin"
password := "public"
auth := username + ":" + password
authHeader := "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))
sql := "select * from sensor_info limit 10"
url := "http://127.0.0.1:8361/api/v1/sql?db=demo"
req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(sql)))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/binary")
req.Header.Set("Authorization", authHeader)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("Response Status:", resp.Status)
fmt.Println("Response Body:", string(body))
}
import type { UserConfig } from 'vitepress'
const config: UserConfig = {
// ...
}
export default config
import type { UserConfig } from 'vitepress'
const config: UserConfig = {
// ...
}
export default config