Getting Started
Ein Setup-Vorschlag mit den Installationsanweisungen und der vollständigen Markdown-Guideline für diesen Plugin kopieren.
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.
Installieren
Abschnitt mit dem Titel „Installieren“Sie können unsere AI-gestützte Einrichtung verwenden, um das Plugin zu installieren. Fügen Sie die Capgo-Fähigkeiten zu Ihrem KI-Tool hinzu, indem Sie die folgende Befehlszeile verwenden:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsVerwenden Sie dann die folgende Anfrage:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-fast-sql` plugin in my project.Wenn Sie die manuelle Einrichtung bevorzugen, installieren Sie das Plugin, indem Sie die folgenden Befehle ausführen und folgen Sie den unten angegebenen Plattform-spezifischen Anweisungen:
bun add @capgo/capacitor-fast-sqlbunx cap syncImportieren
Abschnitt mit dem Titel „Importieren“import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';API Übersicht
Abschnitt mit dem Titel „API Übersicht“Die Datenbankverbindung initialisieren und den HTTP-Server starten.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const conn = await CapgoCapacitorFastSql.connect({ database: 'myapp' });console.log('Connected on port:', conn.port);disconnect
Abschnitt mit dem Titel „disconnect“Verbindung zur Datenbank schließen und den HTTP-Server stoppen.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.disconnect({ database: 'myapp' });getServerInfo
Abschnitt mit dem Titel „getServerInfo“Holen Sie sich den HTTP-Server-Port und den Token für direkte Kommunikation.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const info = await CapgoCapacitorFastSql.getServerInfo({ database: 'myapp' });console.log('Server port:', info.port);Ausführen Sie eine SQL-Anfrage über die Capacitor-Brücke (für einfache Abfragen). Für bessere Leistung bei großen Datensätzen verwenden Sie das HTTP-Protokoll direkt über die SQLConnection-Klasse.
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
Abschnitt mit dem Titel „beginTransaction“Beginnen Sie eine Datenbanktransaktion.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.beginTransaction({ database: 'myapp' });// Execute multiple operationsawait CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });commitTransaction
Abschnitt mit dem Titel „commitTransaction“Transaktion speichern.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });rollbackTransaction
Abschnitt: "rollbackTransaction"Aktuelle Transaktion rückgängig machen.
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
Abschnitt: "configureWeb"Konfigurieren Sie die web-spezifischen Optionen für das sql.js-WASM-Modul.
Aufrufen Sie dies vor dem ersten connect() Aufruf von sql.js aus einem lokal verpackten Pfad anstatt des Standard-CDN. Diese Methode ist auf iOS und Android ein No-Op.
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' });Typenverweis
Abschnitt mit dem Titel „Typenverweis“SQLConnectionOptions
Abschnitt mit dem Titel „SQLConnectionOptions“Datenbankverbindungsoptionen.
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;}Durch den Plugin unterstützte SQL-Werttypen.
export type SQLValue = string | number | boolean | null | Uint8Array;SQLResult
Abschnitt mit dem Titel „SQLResult“Ergebnis der Ausführung einer SQL-Anfrage.
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
Abschnitt mit dem Titel „IsolationLevel“Transaktionsisolationsebenen.
export enum IsolationLevel { ReadUncommitted = 'READ UNCOMMITTED', ReadCommitted = 'READ COMMITTED', RepeatableRead = 'REPEATABLE READ', Serializable = 'SERIALIZABLE',}WebConfig
Abschnitt mit dem Titel “WebConfig”Webplattform-Konfiguration für das sql.js-WASM-Modul. Verwenden Sie dies, um configureWeb() um sql.js aus einem lokal verpackten Pfad zu laden, anstatt den Standard-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-Rohdatenwert - Werte indexiert nach Spaltenname.
export interface SQLRow { [column: string]: SQLValue;}Quelle der Wahrheit
Abschnitt mit dem Titel “Quelle der Wahrheit”Diese Seite wird aus der Plugin-Konfiguration generiert. src/definitions.ts. Re-run die Synchronisierung, wenn die öffentliche API sich upstream ändert.
Weiter von Getting Started
Abschnitt mit dem Titel “Weiter von Getting Started”Wenn Sie Getting Started zur Planung von Dashboard und API-Operationen verwenden, verbinden Sie es mit Mit @capgo/capacitor-fast-sql für die native Fähigkeit in Mit @capgo/capacitor-fast-sql, API-Übersicht für die Implementierungsdetails in API-Übersicht, Einführung für die Implementierungsdetails in Einführung, API Schlüssel für die Implementierungsdetails in API Schlüssel, und Geräte für die Implementierungsdetails in Geräte.