Webの設定
このプラグインのインストール手順と全体のマークダウン ガイドを含むセットアップ コマンドをコピーする。
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.
インストール
「インストール」のセクション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
「切断」のセクションデータベース接続を閉じ、HTTP サーバーを停止します。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.disconnect({ database: 'myapp' });getServerInfo
「getServerInfo」セクション直接通信のためにHTTPサーバーポートとトークンを取得します。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const info = await CapgoCapacitorFastSql.getServerInfo({ database: 'myapp' });console.log('Server port:', info.port);execute
「execute」セクションCapacitor ブリッジを使用してシンプルなクエリを実行します (シンプルなクエリの場合)。 大規模なデータセットの場合、パフォーマンスを向上させるには、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
「beginTransaction」セクショントランザクションを開始します。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.beginTransaction({ database: 'myapp' });// Execute multiple operationsawait CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });commitTransaction
「commitTransaction」セクション現在のトランザクションをコミットします。
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });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
セクション「sql.js WASM モジュールの web スペシフィック オプションの設定」sql.js WASM モジュールの web スペシフィック オプションを設定します。
呼び出す 最初の ローカルにバンドルされたパスからデフォルトの CDN の代わりに sql.js を読み込む最初の呼び出しより前に呼び出してください。このメソッドは iOS と Android で何も実行しません。 connect() クリップボードにコピー
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
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
IsolationLevelのセクショントランザクションの隔離レベル。
export enum IsolationLevel { ReadUncommitted = 'READ UNCOMMITTED', ReadCommitted = 'READ COMMITTED', RepeatableRead = 'REPEATABLE READ', Serializable = 'SERIALIZABLE',}WebConfig
WebConfigsql.js WASMモジュールのWebプラットフォーム設定。デフォルトのCDNではなく、ローカルにバンドルされたパスからsql.jsを読み込むには configureWeb() ローカルにバンドルされたパスからsql.jsを読み込むには
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
SQLRowSQL結果 - 列名でインデックスされた値。
export interface SQLRow { [column: string]: SQLValue;}真実の源
真実の源このページはプラグインの src/definitions.tspublic APIがアップストリームで変更された場合に再度同期を実行してください。