Zum Inhalt springen

Getting Started

GitHub

Sie können unsere AI-gestützte Einrichtung verwenden, um das Plugin zu installieren. Fügen Sie die Capgo-Fähigkeiten zu Ihrem AI-Tool hinzu, indem Sie die folgende Befehlszeile verwenden:

Terminal-Fenster
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Verwenden Sie dann die folgende Anweisung:

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 die Plattform-spezifischen Anweisungen unten befolgen:

Terminal-Fenster
bun add @capgo/capacitor-fast-sql
bunx cap sync
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';

Initialisieren Sie die Datenbankverbindung und starten Sie den HTTP-Server.

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

Schließen Sie die Datenbankverbindung und beenden Sie den HTTP-Server.

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

Ermitteln Sie die HTTP-Server-Portnummer 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);

Führen Sie über die Capacitor-Brücke (für einfache Abfragen) eine SQL-Anfrage aus. Für eine 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);

Beginnen Sie eine Datenbanktransaktion.

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

Bestätigen Sie die aktuelle Transaktion.

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

Rückgängigmachen der aktuellen Transaktion.

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

Konfigurieren Sie die web-spezifischen Optionen für das sql.js-WASM-Modul.

Aufrufen Sie dies vorher vorher connect() die erste

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

Zwischenablage kopieren

Typenverweis

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;

Erfolg einer SQL-Anfrageausführung.

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

Transaktionsisolationsebenen.

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

Web-Plattform-Konfiguration für das sql.js-WASM-Modul. Verwenden Sie mit configureWeb() um sql.js von einem lokal verbundenen Pfad zu laden, anstatt der 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-Datenzeilenresultat - Werte indexiert nach Spaltenname.

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

Diese Seite wurde aus dem Plugin generiert. Wenn die öffentliche __CAPGO_KEEP_0__ upstream geändert wird, führen Sie die Synchronisation erneut durch. src/definitions.ts. Re-run the sync when the public API changes upstream.

Abschnitt mit dem Titel „Fortsetzen von Getting Started“

Abschnitt mit dem Titel „Fortsetzen von Getting Started“

Wenn Sie diese verwenden Einstieg um einen Dashboard und API-Bereich zu planen und zu konfigurieren, verbinden Sie ihn mit Verwendung von @capgo/capacitor-fast-sql für die native Fähigkeit in Verwendung von @capgo/capacitor-fast-sql Übersicht über API für die Implementierungsdetails in Übersicht über API 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äten.