メインコンテンツにジャンプ

Getting Started

GitHub

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

ターミナル画面
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を使用する場合は、以下のコマンドを実行してください。プラットフォーム固有の指示は下記を参照してください。

ターミナル画面
bun add @capgo/capacitor-fast-sql
bunx cap sync
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);

SQLクエリを 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

__CAPGO_KEEP_1__

__CAPGO_KEEP_2__

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

commitTransaction

__CAPGO_KEEP_1__

__CAPGO_KEEP_3__

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

rollbackTransaction

__CAPGO_KEEP_1__

__CAPGO_KEEP_4__

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

__CAPGO_KEEP_1__

__CAPGO_KEEP_5__

このメソッドを呼び出す前に __CAPGO_KEEP_0__ 最初の呼び出し前に connect() __CAPGO_KEEP_0__

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」

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() を使用して、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;
}

SQL 行結果 - 値は列名で索引されている。

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

このページはプラグインの「 src/definitions.tspublic API がアップストリームで変更された場合に再度同步を実行してください。

あなたが「 Getting Started から ダッシュボードと API の作業を計画する場合、 「@capgo/capacitor-fast-sql」を使用します native機能の使用に@capgo/capacitor-fast-sqlを使用します。 APIの概要 APIの実装詳細について 導入 導入の実装詳細について APIのキー 実装詳細についてAPIのキー デバイス 実装詳細についてデバイス