SuperAPI AI 工具集

instantdb

编程与开发

查看项目

更新于 10-16 01:15

技能介绍

用途:以 InstantDB 作为后端构建完整可用的应用,适用于 React、vanilla JS 及 Expo/React Native 项目。

主要能力:Instant 是客户端数据库,内置查询、事务、认证、权限、存储、实时与离线支持。SDK 包括 @instantdb/core(vanilla JS)、@instantdb/react(React)、@instantdb/react-native(React Native/Expo)、@instantdb/admin(后端脚本/服务器)。

使用方式:安装前先确认项目使用的包管理器(npm、pnpm、bun),再安装最新版 SDK。管理应用需查看 instant.schema.ts 与 instant.perms.ts,以及 .env 中的 app id 和 admin token。新建应用:npx instant-cli init-without-files --title <APP_NAME>;未登录时先在 https://instantdb.com 注册或登录,再运行 npx instant-cli login,然后重跑初始化命令。已有 app id/admin token 但无 schema/perm 文件时:npx instant-cli pull --yes。修改 schema 后推送:npx instant-cli push schema --yes;重命名字段:npx instant-cli push schema --rename 'posts.author:posts.creator stores.owner:stores.manager' --yes;修改权限后推送:npx instant-cli push perms --yes。CLI 临时查询:npx instant-cli query '{ posts: {} }' --admin,需上下文标志 --admin、--as-email <email> 或 --as-guest,也支持 --app <id>。

查询与权限要点:React 中须遵守 hooks 规则;过滤或排序的字段必须在 schema 中建立索引,排序不支持嵌套属性。where 支持相等、$ne、$isNull、$gt/$lt/$gte/$lte、$in、$like/$ilike、and/or 及嵌套字段,不支持 $exists、$nin、$regex。分页键仅用于顶层命名空间。权限中 data.ref 用于关联属性且返回列表,auth.ref 路径须以 $user 开头。$users 默认 view 为 auth.id == data.id,update/delete 默认 false,create 默认 true;$files 默认全部 false,且 data.ref 不适用于 $files。存储方面,图片或文件应使用 Instant Storage,上传自动创建 $files 实体,schema 中须包含 $files,且 $files 只能通过 db.storage.uploadFile 创建。

限制:资料未提供收费、价格与平台等具体信息;不确定的功能应查阅官方文档。