@lovrabet/sdk 1.1.17 → 1.1.19-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/src/api/index.d.ts +51 -0
- package/dist/src/api/types.d.ts +18 -0
- package/dist/src/client/client.d.ts +5 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ const client = createClient({
|
|
|
34
34
|
models: {
|
|
35
35
|
users: {
|
|
36
36
|
tableName: "users",
|
|
37
|
-
|
|
37
|
+
datasetCode: "your-dataset-code",
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
});
|
|
@@ -82,7 +82,7 @@ const client = createClient({
|
|
|
82
82
|
models: {
|
|
83
83
|
users: {
|
|
84
84
|
tableName: "users",
|
|
85
|
-
|
|
85
|
+
datasetCode: "your-dataset-code",
|
|
86
86
|
},
|
|
87
87
|
},
|
|
88
88
|
});
|
|
@@ -102,7 +102,7 @@ const client = createClient({
|
|
|
102
102
|
models: {
|
|
103
103
|
users: {
|
|
104
104
|
tableName: "users",
|
|
105
|
-
|
|
105
|
+
datasetCode: "your-dataset-code",
|
|
106
106
|
},
|
|
107
107
|
},
|
|
108
108
|
});
|
|
@@ -177,8 +177,8 @@ import { registerModels, createClient } from "@lovrabet/sdk";
|
|
|
177
177
|
registerModels({
|
|
178
178
|
appCode: "your-app-code",
|
|
179
179
|
models: {
|
|
180
|
-
users: { tableName: "users",
|
|
181
|
-
posts: { tableName: "posts",
|
|
180
|
+
users: { tableName: "users", datasetCode: "ds-001" },
|
|
181
|
+
posts: { tableName: "posts", datasetCode: "ds-002" },
|
|
182
182
|
},
|
|
183
183
|
});
|
|
184
184
|
|
|
@@ -238,6 +238,83 @@ client.setToken(newToken, newTimestamp);
|
|
|
238
238
|
client.switchEnv("daily");
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
+
### 执行自定义 SQL
|
|
242
|
+
|
|
243
|
+
SDK 提供了 `client.api` 命名空间,用于执行自定义 SQL 查询和其他通用 API 调用。
|
|
244
|
+
|
|
245
|
+
#### 基础查询
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
// 执行 SQL 查询,返回结果数组
|
|
249
|
+
const results = await client.api.executeSql('fc8e7777-06e3847d');
|
|
250
|
+
console.log(results);
|
|
251
|
+
// [
|
|
252
|
+
// { creation_date: '2025-08-13', page_count: 2 },
|
|
253
|
+
// { creation_date: '2025-08-19', page_count: 3 },
|
|
254
|
+
// ...
|
|
255
|
+
// ]
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
#### 参数化查询
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
// 传递参数到 SQL
|
|
262
|
+
const results = await client.api.executeSql('fc8e7777-xxxxx', {
|
|
263
|
+
userId: '123',
|
|
264
|
+
startDate: '2025-01-01'
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
#### 带类型提示
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
// 定义结果类型
|
|
272
|
+
interface PageStat {
|
|
273
|
+
creation_date: string;
|
|
274
|
+
page_count: number;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// 使用泛型获得类型安全
|
|
278
|
+
const stats = await client.api.executeSql<PageStat>('fc8e7777-06e3847d');
|
|
279
|
+
stats.forEach(stat => {
|
|
280
|
+
console.log(stat.creation_date); // TypeScript 自动补全
|
|
281
|
+
console.log(stat.page_count);
|
|
282
|
+
});
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
#### 处理查询结果
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
// 获取第一条结果
|
|
289
|
+
const results = await client.api.executeSql<PageStat>('fc8e7777-xxxxx');
|
|
290
|
+
const firstResult = results[0];
|
|
291
|
+
|
|
292
|
+
if (firstResult) {
|
|
293
|
+
console.log(`日期: ${firstResult.creation_date}, 数量: ${firstResult.page_count}`);
|
|
294
|
+
} else {
|
|
295
|
+
console.log('无结果');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// 过滤结果
|
|
299
|
+
const activeItems = results.filter(item => item.status === 'active');
|
|
300
|
+
|
|
301
|
+
// 查找特定结果
|
|
302
|
+
const targetItem = results.find(item => item.id === '123');
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
#### 错误处理
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
try {
|
|
309
|
+
const results = await client.api.executeSql('fc8e7777-xxxxx');
|
|
310
|
+
} catch (error) {
|
|
311
|
+
if (error instanceof LovrabetError) {
|
|
312
|
+
console.error('SQL执行失败:', error.message);
|
|
313
|
+
console.error('错误代码:', error.code);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
241
318
|
## 📖 API 文档
|
|
242
319
|
|
|
243
320
|
### 主要导出
|
|
@@ -267,6 +344,9 @@ import {
|
|
|
267
344
|
// 错误处理
|
|
268
345
|
LovrabetError,
|
|
269
346
|
|
|
347
|
+
// API 命名空间
|
|
348
|
+
ApiNamespace,
|
|
349
|
+
|
|
270
350
|
// TypeScript 类型
|
|
271
351
|
type ClientConfig,
|
|
272
352
|
type TokenResult,
|
|
@@ -275,6 +355,8 @@ import {
|
|
|
275
355
|
type SortList,
|
|
276
356
|
type SelectOption,
|
|
277
357
|
type SelectOptionsParams,
|
|
358
|
+
type SqlExecuteRequest,
|
|
359
|
+
type SqlExecuteResult,
|
|
278
360
|
|
|
279
361
|
// 枚举
|
|
280
362
|
SortOrder,
|
|
@@ -298,12 +380,13 @@ interface ClientConfig {
|
|
|
298
380
|
### CRUD 操作
|
|
299
381
|
|
|
300
382
|
```typescript
|
|
301
|
-
//
|
|
383
|
+
// 查询列表(返回 paging/tableData/tableColumns)
|
|
302
384
|
const response = await client.models.users.getList({
|
|
303
385
|
currentPage: 1,
|
|
304
386
|
pageSize: 20,
|
|
305
|
-
// 其他查询参数
|
|
306
387
|
});
|
|
388
|
+
console.log(response.paging.totalCount);
|
|
389
|
+
console.log(response.tableColumns);
|
|
307
390
|
|
|
308
391
|
// 查询列表(带排序)
|
|
309
392
|
import { SortOrder } from "@lovrabet/sdk";
|
|
@@ -416,7 +499,7 @@ const client = createClient({ token });
|
|
|
416
499
|
|
|
417
500
|
## 📝 What's New
|
|
418
501
|
|
|
419
|
-
### v1.1.
|
|
502
|
+
### v1.1.18 (2025-10-18)
|
|
420
503
|
|
|
421
504
|
**新增功能 (New Features):**
|
|
422
505
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ export { getApiEndpoint, getAvailableEnvironments, } from "./src/config/endpoint
|
|
|
4
4
|
export { CONFIG_NAMES, ENVIRONMENTS, DEFAULTS, HTTP_STATUS, ERROR_MESSAGES, API_PATHS, } from "./src/config/constants";
|
|
5
5
|
export { LovrabetError } from "./src/utils/errors";
|
|
6
6
|
export { AbstractBaseModel, OpenApiModel, WebApiModel, ModelFactory, } from "./src/models/index";
|
|
7
|
+
export { ApiNamespace } from "./src/api/index";
|
|
7
8
|
export { AuthManager, } from "./src/auth/index";
|
|
8
9
|
export { generateOpenApiToken, TokenGenerator, isTokenExpiring, getTokenRemainingTime, type GenerateTokenParams, type TokenResult } from "./src/auth/index";
|
|
9
10
|
export type { ClientConfig, LovrabetClient, ModelConfig, ModelsConfig, } from "./src/types/index";
|
|
10
11
|
export type { ListParams, ListResponse, Environment, BaseModelMethods, SortList, SelectOption, SelectOptionsParams, } from "./src/types/index";
|
|
12
|
+
export type { SqlExecuteRequest, SqlExecuteResult, } from "./src/api/types";
|
|
11
13
|
export { SortOrder, } from "./src/types/index";
|