/api/query
sql
- 🔥 SQL 查询
/api/query/sql
请求
ts
/**
* query the database using SQL
*/
export interface IPayload {
/**
* SQL query statements
*/
readonly stmt: string;
}
json5
/**
* schemas/kernel/api/query/sql/payload.schema.json5
* 使用 SQL 查询数据库
* REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#execute-sql-query
* REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/sql.go#L29-L47
* @pathname: /api/query/sql
* @version: 2.9.3
*/
{
$schema: 'https://json-schema.org/draft/2020-12/schema',
$id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/query/sql/payload.schema.json5',
$comment: 'v2.9.3',
$ref: '#/$defs/root',
$defs: {
root: {
title: 'payload body',
description: 'query the database using SQL',
type: 'object',
additionalProperties: false,
required: [
'stmt',
],
properties: {
stmt: {
// SQL 查询语句
type: 'string',
description: 'SQL query statements',
},
},
},
},
}
json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/query/sql/payload.schema.json",
"$comment": "v2.9.3",
"$ref": "#/$defs/root",
"$defs": {
"root": {
"title": "payload body",
"description": "query the database using SQL",
"type": "object",
"additionalProperties": false,
"required": [
"stmt"
],
"properties": {
"stmt": {
"type": "string",
"description": "SQL query statements"
}
}
}
}
}
响应
ts
/**
* render template file
*/
export interface IResponse {
/**
* status code
*/
readonly code: number;
readonly data: { [key: string]: any }[];
/**
* status message
*/
readonly msg: string;
}
json5
/**
* schemas/kernel/api/query/sql/response.schema.json5
* 使用 SQL 查询数据库
* REF: https://github.com/siyuan-note/siyuan/blob/master/API.md#execute-sql-query
* REF: https://github.com/siyuan-note/siyuan/blob/v2.9.3/kernel/api/sql.go#L29-L47
* @pathname: /api/query/sql
* @version: 2.9.3
*/
{
$schema: 'https://json-schema.org/draft/2020-12/schema',
$id: 'https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/query/sql/response.schema.json5',
$comment: 'v2.9.3',
$ref: '#/$defs/root',
$defs: {
root: {
title: 'response body',
description: 'render template file',
type: 'object',
additionalProperties: false,
required: [
'code',
'msg',
'data',
],
properties: {
code: {
type: 'integer',
description: 'status code',
},
msg: {
type: 'string',
description: 'status message',
},
data: {
$ref: '#/$defs/data',
},
},
},
data: {
title: 'IData',
description: 'response data',
type: 'array',
items: {
$ref: '#/$defs/datum',
},
},
datum: {
title: 'IDatum',
description: 'query results',
type: 'object',
additionalProperties: true,
required: [],
properties: {},
},
},
}
json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/siyuan-community/siyuan-sdk/raw/main/schemas/kernel/api/query/sql/response.schema.json",
"$comment": "v2.9.3",
"$ref": "#/$defs/root",
"$defs": {
"root": {
"title": "response body",
"description": "render template file",
"type": "object",
"additionalProperties": false,
"required": [
"code",
"msg",
"data"
],
"properties": {
"code": {
"type": "integer",
"description": "status code"
},
"msg": {
"type": "string",
"description": "status message"
},
"data": {
"$ref": "#/$defs/data"
}
}
},
"data": {
"title": "IData",
"description": "response data",
"type": "array",
"items": {
"$ref": "#/$defs/datum"
}
},
"datum": {
"title": "IDatum",
"description": "query results",
"type": "object",
"additionalProperties": true,
"required": [],
"properties": {}
}
}
}