コンテンツに進む

はじめに

GitHub

CapgoのAI-Assistedセットアップを使用してプラグインをインストールできます。次のコマンドを使用して、CapgoスキルをAIツールに追加してください。

コピーする
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

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

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-sql
bunx cap sync

インポート

インポート
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';

APIの概要

APIガイド

切断

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

ターミナル画面

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 ブリッジを使用してシンプルなクエリを実行します (シンプルなクエリの場合)。 大規模なデータセットの場合、SQLConnectionクラスを使用してHTTPプロトコルを直接使用することでパフォーマンスが向上します。

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

configureWeb

Web特有の設定

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

呼び出し 最初の first 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;
}

プラグインがサポートする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;
}

IsolationLevel

「IsolationLevel」

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

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.ts公開 API がアップストリームで変更されたときに再度同期してください。

「Getting Started」を使用している場合 はじめに 「Getting Started」を使用してダッシュボードとAPIの操作を計画するには、APIを接続します。 「@capgo/capacitor-fast-sql」を使用 「@capgo/capacitor-fast-sql」のネイティブ機能 「API Overview」の実装詳細 「API Overview」 Introduction 「Introduction」 「API Keys」 APIの実装詳細については Devices __CAPGO_KEEP_0__