Quick Start
The Lovrabet SDK is a lightweight JavaScript/TypeScript SDK that gets you connected to Lovrabet platform data services in no time.
💡 Recommended Lovrabet CLI generates your configuration in one step, saving you the manual setup. See the CLI 5-minute quick start.
Installation
Install the SDK with npm or yarn:
npm install @lovrabet/sdk
# 或
yarn add @lovrabet/sdk⚡ Get Started in 5 Minutes
1. Automatic CLI Configuration (recommended)
Generate your configuration with the CLI, then use it right away:
import { createClient } from "@lovrabet/sdk";
import "./api/api"; // 导入 CLI 生成的配置
const client = createClient();
// 标准方式访问(推荐)- 使用 dataset_ 前缀 + datasetCode
const users = await client.models.dataset_71494bcba13f4ec7858abe90794183ad.filter({
currentPage: 1,
pageSize: 20,
});
// 别名方式访问(语法糖)- 使用配置的 alias
const users = await client.models.users.filter({
currentPage: 1,
pageSize: 20,
});💡 Standard vs alias: both are functionally identical. The standard style uses the datasetCode — globally unique and AI-friendly; the alias style is more readable and is pure syntax sugar.
2. Manual Configuration
import { registerModels, createClient } from "@lovrabet/sdk";
// 注册配置
registerModels({
appCode: "your-app-code",
models: [
{
datasetCode: "8d2dcbae08b54bdd84c00be558ed48df",
tableName: "users",
alias: "users", // 可选:模型别名
name: "用户表", // 可选:UI 显示名称
},
{
datasetCode: "a1b2c3d4e5f6789012345678abcdef12",
tableName: "posts",
alias: "posts",
},
],
});
const client = createClient();
// 标准方式访问(推荐)
const users = await client.models.dataset_8d2dcbae08b54bdd84c00be558ed48df.filter();
// 别名方式访问(语法糖)
const users = await client.models.users.filter();📊 Response Structure
List query response
const response = await client.models.dataset_8d2dcbae08b54bdd84c00be558ed48df.filter();
console.log(response.tableData); // 数据列表
console.log(response.total); // 总数
console.log(response.currentPage); // 当前页
console.log(response.pageSize); // 页大小Single record response
const user = await client.models.dataset_8d2dcbae08b54bdd84c00be558ed48df.getOne("user-id");
console.log(user); // 用户详情对象🎯 CLI-Generated Configuration
If you use the Lovrabet CLI, the configuration files are generated automatically:
src/api/api.ts (generated by the CLI)
import { registerModels, type ModelsConfig } from "@lovrabet/sdk";
export const LOVRABET_MODELS_CONFIG: ModelsConfig = {
appCode: "app-c4c89304",
models: [
{
datasetCode: "71494bcba13f4ec7858abe90794183ad",
tableName: "users",
alias: "users",
name: "用户管理",
},
{
datasetCode: "d26ed512e878461ca97d287a47606fd3",
tableName: "posts",
alias: "posts",
name: "文章管理",
},
],
} as const;
// 自动注册默认配置
registerModels(LOVRABET_MODELS_CONFIG);src/api/client.ts (your code)
import { createClient } from "@lovrabet/sdk";
import "./api"; // 导入配置文件,执行注册
// 创建客户端实例
export const lovrabetClient = createClient();
// 在组件中使用
// import { lovrabetClient } from '@/api/client';
// 标准方式:lovrabetClient.models.dataset_71494bcba13f4ec7858abe90794183ad.filter()
// 别名方式:lovrabetClient.models.users.filter()🛠️ Basic CRUD Operations
// 查询列表(带分页和条件过滤)
const users = await client.models.dataset_8d2dcbae08b54bdd84c00be558ed48df.filter({
where: { status: { $eq: "active" } },
currentPage: 1,
pageSize: 10,
});
// 获取单条记录
const user = await client.models.dataset_8d2dcbae08b54bdd84c00be558ed48df.getOne("user-id");
// 创建新记录
const newUser = await client.models.dataset_8d2dcbae08b54bdd84c00be558ed48df.create({
name: "Jane Doe",
email: "jane@example.com",
status: "active",
});
// 更新记录
const updatedUser = await client.models.dataset_8d2dcbae08b54bdd84c00be558ed48df.update("user-id", {
name: "Jane Smith",
email: "jane.smith@example.com",
});
// 删除记录
await client.models.dataset_8d2dcbae08b54bdd84c00be558ed48df.delete("user-id");💡 The examples above use the standard
dataset_xxxstyle; the alias style works too, e.g.client.models.users.xxx().
🆕 What's New in v1.2.0
Model Access
v1.2.0 supports both standard and alias model access:
// 标准方式(推荐)- 使用 dataset_ 前缀 + datasetCode
// 全局唯一,便于 AI 工具生成代码
const users = await client.models.dataset_8d2dcbae08b54bdd84c00be558ed48df.filter();
// 别名方式(语法糖)- 使用配置的 alias
// 方便人类阅读,功能与标准方式完全一致
const users = await client.models.users.filter();💡 An alias is just a pointer — the SDK still uses the datasetCode internally, and everything behaves exactly as with the standard style.
Model Manager Enhancements
// 获取所有模型详细信息
const details = client.getModelListDetails();
// 返回: [{ datasetCode: '8d2dcbae08b54bdd84c00be558ed48df', alias: 'users', name: '用户表' }, ...]
// 动态添加模型
client.addModel({
datasetCode: 'f7e6d5c4b3a2901234567890fedcba98',
tableName: 'products',
alias: 'products'
});📖 Next Steps
Congratulations — you now know the basics of the Lovrabet SDK. Where to go next:
- 📋 Configuration - explore the configuration options
- 🔐 Authentication - set up user authentication
- 📊 API guide - dive deeper into API operations
- 🎯 TypeScript support - a type-safe development experience
❓ Running into Problems?
If anything goes wrong along the way, check out:
- 🛠️ Troubleshooting - answers to common questions
- 📞 Technical support - contact the Lovrabet technical team