Getting Started
复制一个包含安装步骤和此插件的完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-fast-sql`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/fast-sql/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
标题为“安装”您可以使用我们的 AI 助手设置来安装插件。将 Capgo 技能添加到您的 AI 工具中,使用以下命令:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-fast-sql` plugin in my project.如果您更喜欢手动设置,请运行以下命令安装插件并按照以下平台特定的说明进行操作:
bun add @capgo/capacitor-fast-sqlbunx cap sync导入
导入部分import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';API概述
导入部分:API概述connect
连接部分初始化数据库连接并启动HTTP服务器
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const conn = await CapgoCapacitorFastSql.connect({ database: 'myapp' });console.log('Connected on port:', conn.port);disconnect
Section titled “断开连接”关闭数据库连接并停止 HTTP 服务器。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.disconnect({ database: 'myapp' });getServerInfo
Section titled “获取服务器信息”获取 HTTP 服务器端口和令牌以进行直接通信。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const info = await CapgoCapacitorFastSql.getServerInfo({ database: 'myapp' });console.log('Server port:', info.port);execute
Section titled “执行”通过 Capacitor 桥执行 SQL 查询(适用于简单查询)。 对于大型数据集的更好性能,使用 HTTP 协议直接通过 SQLConnection 类。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const result = await CapgoCapacitorFastSql.execute({ database: 'myapp', statement: 'SELECT * FROM users WHERE age > ?', params: [18]});console.log('Rows:', result.rows);beginTransaction
Section titled “开始事务”开始数据库事务。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.beginTransaction({ database: 'myapp' });// Execute multiple operationsawait CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });commitTransaction
Section titled “commitTransaction”确认当前事务。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });rollbackTransaction
Section titled “rollbackTransaction”回滚当前事务。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
try { await CapgoCapacitorFastSql.beginTransaction({ database: 'myapp' }); // Operations... await CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });} catch (error) { await CapgoCapacitorFastSql.rollbackTransaction({ database: 'myapp' });}configureWeb
Section titled “configureWeb”配置 sql.js WASM 模块的 web 特定选项。
在 iOS 和 Android 上无效 在 connect() iOS 和 Android 上无效
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
// Configure once at app startup (web only)await CapgoCapacitorFastSql.configureWeb({ sqlJsUrl: '/assets/sql-wasm.js', wasmUrl: '/assets/sql-wasm.wasm',});const db = await FastSQL.connect({ database: 'myapp' });类型参考
类型参考部分SQLConnectionOptions
数据库连接选项数据库连接选项。
export interface SQLConnectionOptions { /** * Database name (file will be created in app data directory) */ database: string;
/** * Enable encryption (iOS/Android only) */ encrypted?: boolean;
/** * Encryption key (required if encrypted is true) */ encryptionKey?: string;
/** * Read-only mode */ readOnly?: boolean;}SQLValue
部分标题“SQLValue”插件支持的SQL值类型。
export type SQLValue = string | number | boolean | null | Uint8Array;SQLResult
部分标题“SQLResult”SQL查询执行结果。
export interface SQLResult { /** * Rows returned by the query (for SELECT statements) */ rows: SQLRow[];
/** * Number of rows affected by the query (for INSERT/UPDATE/DELETE) */ rowsAffected: number;
/** * ID of the last inserted row (for INSERT statements with auto-increment) */ insertId?: number;}IsolationLevel
Section titled “隔离级别”事务隔离级别。
export enum IsolationLevel { ReadUncommitted = 'READ UNCOMMITTED', ReadCommitted = 'READ COMMITTED', RepeatableRead = 'REPEATABLE READ', Serializable = 'SERIALIZABLE',}WebConfig
Section titled “WebConfig”用于sql.js WASM模块的Web平台配置。使用 configureWeb() 来从本地打包路径加载sql.js而不是默认的CDN。
export interface WebConfig { /** * URL to the sql.js JavaScript file (`sql-wasm.js`). * When omitted, the plugin loads from the cdnjs CDN. * @example '/assets/sql-wasm.js' */ sqlJsUrl?: string;
/** * URL to the sql.js WebAssembly binary (`sql-wasm.wasm`). * When omitted, the plugin loads from the cdnjs CDN. * @example '/assets/sql-wasm.wasm' */ wasmUrl?: string;}SQLRow
Section titled “SQLRow”SQL行结果 - 值按列名索引。
export interface SQLRow { [column: string]: SQLValue;}真实数据来源
Section titled “真实数据来源”本页面由插件生成 src/definitions.ts当公共API上游发生变化时,请重新同步。
从开始
标题:从开始如果您正在使用 开始 来规划仪表板和API操作,请将其连接到 使用@capgo/capacitor-fast-sql for the native capability in Using @capgo/capacitor-fast-sql, 使用@API/__CAPGO_KEEP_1__-fast-sql for the implementation detail in API Overview, 概述 为Introduction中的实现细节 API Keys 为API Keys中的实现细节,和 Devices 为Devices中的实现细节。