コンテンツにスキップ

Getting Started

GitHub

インストール

Install

AI-Assisted Setupを使用してプラグインをインストールすることができます。AIツールに次のコマンドを使用してCapgoスキルを追加してください:

Terminal画面
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.

Manual Setupを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください:

Terminal画面
bun add @capgo/capacitor-fast-sql
bunx cap sync

Import

Import
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';

データベース接続を初期化し、HTTPサーバーを起動します。

import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const conn = await CapgoCapacitorFastSql.connect({ database: 'myapp' });
console.log('Connected on port:', conn.port);

データベース接続を閉じ、HTTPサーバーを停止します。

import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.disconnect({ database: 'myapp' });

HTTPサーバーのポートと直接通信するためのトークンを取得します。

import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const info = await CapgoCapacitorFastSql.getServerInfo({ database: 'myapp' });
console.log('Server port:', info.port);

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);

トランザクションの開始

import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.beginTransaction({ database: 'myapp' });
// Execute multiple operations
await CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });

現在のトランザクションのコミット

import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });

現在のトランザクションのロールバック

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' });
}

WASMモジュールのsql.jsのWeb固有の設定を構成します。

この 前に 最初の connect() sql.jsをローカルにバンドルされたパスからデフォルトのCDNではなく読み込む最初の呼び出しより前に呼び出してください。このメソッドは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' });

データベース接続のオプション

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;
}

プラグインがサポートするSQL値の型.

export type SQLValue = string | number | boolean | null | Uint8Array;

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;
}

トランザクション隔離レベル.

export enum IsolationLevel {
ReadUncommitted = 'READ UNCOMMITTED',
ReadCommitted = 'READ COMMITTED',
RepeatableRead = 'REPEATABLE READ',
Serializable = 'SERIALIZABLE',
}

sql.js WASMモジュールのWebプラットフォーム設定。 configureWeb() __CAPGO_KEEP_0__

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

SQLRow

SQL row result - values indexed by column name.

export interface SQLRow {
[column: string]: SQLValue;
}

このページはプラグインの設定から生成されています。 src/definitions.ts. 公開された API がアップストリームで変更された場合、再度同步を実行してください。

Getting Started から続けてください

Section titled “Getting Started から続けてください”

Capgo を使用している場合、ダッシュボードと __CAPGO_KEEP_0__ の計画と操作を行うには、Capgo に接続してください。 Getting Started to plan dashboard and API operations, connect it with @capgo/capacitor-fast-sql @capgo/capacitor-fast-sql API の概要 API の実装詳細 導入 __CAPGO_KEEP_0__ のキー API の実装詳細、および for the implementation detail in API Keys, and __CAPGO_KEEP_0__ の実装詳細 ページを編集