Skip to content

Commit 4a26a8c

Browse files
authored
feat: support to query next page in elastic (#663)
* feat: support to query next page in elastic * fix the typescript syntax error --------- Co-authored-by: rick <[email protected]>
1 parent 6c9ab38 commit 4a26a8c

File tree

10 files changed

+458
-399
lines changed

10 files changed

+458
-399
lines changed

console/atest-ui/src/views/DataManager.vue

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { ref, watch } from 'vue'
33
import { API } from './net'
4+
import type { QueryObject } from './net'
45
import type { Store } from './store'
56
import type { Pair } from './types'
67
import { ElMessage } from 'element-plus'
@@ -12,6 +13,10 @@ import { Refresh, Document } from '@element-plus/icons-vue'
1213
const stores: Ref<Store[]> = ref([])
1314
const kind = ref('')
1415
const store = ref('')
16+
const query = ref({
17+
offset: 0,
18+
limit: 10
19+
} as QueryObject)
1520
const sqlQuery = ref('')
1621
const queryResult = ref([] as any[])
1722
const queryResultAsJSON = ref('')
@@ -175,8 +180,12 @@ const executeQuery = async () => {
175180
}
176181
const executeWithQuery = async (sql: string) => {
177182
let success = false
183+
query.value.store = store.value
184+
query.value.key = queryDataMeta.value.currentDatabase
185+
query.value.sql = sql
186+
178187
try {
179-
const data = await API.DataQueryAsync(store.value, kind.value, queryDataMeta.value.currentDatabase, sql);
188+
const data = await API.DataQueryAsync(query.value);
180189
switch (kind.value) {
181190
case 'atest-store-orm':
182191
case 'atest-store-cassandra':
@@ -207,6 +216,10 @@ const executeWithQuery = async (sql: string) => {
207216
}
208217
return success
209218
}
219+
const nextPage = () => {
220+
query.value.offset += query.value.limit
221+
executeQuery()
222+
}
210223
</script>
211224

212225
<template>
@@ -234,7 +247,7 @@ const executeWithQuery = async (sql: string) => {
234247
</el-scrollbar>
235248
</el-aside>
236249
<el-container>
237-
<el-header>
250+
<el-header style="height: auto">
238251
<el-form @submit.prevent="executeQuery">
239252
<el-row :gutter="10">
240253
<el-col :span="4">
@@ -264,6 +277,21 @@ const executeWithQuery = async (sql: string) => {
264277
</el-select>
265278
</el-col>
266279
</el-row>
280+
<el-row :gutter="10" v-if="kind === 'atest-store-elasticsearch'">
281+
<el-col :span="10">
282+
<el-input type="number" v-model="query.offset">
283+
<template #prepend>Offset</template>
284+
</el-input>
285+
</el-col>
286+
<el-col :span="10">
287+
<el-input type="number" v-model="query.limit">
288+
<template #prepend>Limit</template>
289+
</el-input>
290+
</el-col>
291+
<el-col :span="2">
292+
<el-button type="primary" @click="nextPage">Next</el-button>
293+
</el-col>
294+
</el-row>
267295
</el-form>
268296
</el-header>
269297
<el-main>

console/atest-ui/src/views/net.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023-2024 API Testing Authors.
2+
Copyright 2023-2025 API Testing Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import { ca } from 'element-plus/es/locales.mjs'
1716
import { Cache } from './cache'
1817

1918
async function DefaultResponseProcess(response: any) {
@@ -780,22 +779,23 @@ var SBOM = (callback: (d: any) => void) => {
780779
.then(callback)
781780
}
782781

783-
interface QueryObject {
782+
export interface QueryObject {
783+
store: string
784784
sql: string
785785
key: string
786+
offset: number
787+
limit: number
786788
}
787-
var DataQueryAsync = (store: string, kind: string, currentDatabase: string, query: string) => {
788-
const queryObj = {
789-
'key': currentDatabase,
790-
'sql': query,
791-
} as QueryObject;
789+
const DataQueryAsync = (query: QueryObject) => {
792790
const requestOptions = {
793791
method: 'POST',
794792
headers: {
795-
'X-Store-Name': store,
796-
'X-Database': currentDatabase
793+
'X-Store-Name': query.store,
794+
'X-Database': query.key,
795+
'X-Offset': `${query.offset}`,
796+
'X-Limit': `${query.limit}`
797797
},
798-
body: JSON.stringify(queryObj)
798+
body: JSON.stringify(query)
799799
}
800800
return fetch(`/api/v1/data/query`, requestOptions)
801801
.then(DefaultResponseProcess)

pkg/server/gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616
package server
1717

1818
import (
19-
context "context"
19+
"context"
2020
"net/http"
2121

2222
"google.golang.org/grpc/metadata"

pkg/server/remote_server.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,8 +1249,10 @@ func (s *server) Query(ctx context.Context, query *DataQuery) (result *DataQuery
12491249
defer loader.Close()
12501250
var dataResult testing.DataResult
12511251
if dataResult, err = loader.Query(map[string]string{
1252-
"sql": query.Sql,
1253-
"key": query.Key,
1252+
"sql": query.Sql,
1253+
"key": query.Key,
1254+
"offset": fmt.Sprintf("%d", query.Offset),
1255+
"limit": fmt.Sprintf("%d", query.Limit),
12541256
}); err == nil {
12551257
result = &DataQueryResult{
12561258
Data: mapToPair(dataResult.Pairs),

0 commit comments

Comments
 (0)