Démarrage
Copiez une invitation de configuration avec les étapes d'installation et la guide markdown complet pour ce plugin.
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.
Installer
Section intitulée « Installer »Vous pouvez utiliser notre configuration assistée par l'IA pour installer le plugin. Ajoutez les compétences Capgo à votre outil IA à l'aide de la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsEnsuite, utilisez la prompt suivante :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-fast-sql` plugin in my project.Si vous préférez la configuration manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à la plateforme ci-dessous :
bun add @capgo/capacitor-fast-sqlbunx cap syncImporter
Section intitulée « Importer »import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';API Aperçu
Section intitulée “API Aperçu”connect
Section intitulée “connect”Initialisez la connexion de base de données et démarrez le serveur HTTP.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const conn = await CapgoCapacitorFastSql.connect({ database: 'myapp' });console.log('Connected on port:', conn.port);disconnect
Section intitulée “se déconnecter”Fermer la connexion de base de données et arrêter le serveur HTTP.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.disconnect({ database: 'myapp' });getServerInfo
Section intitulée “getServerInfo”Obtenez le port et le jeton du serveur HTTP pour une communication directe.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const info = await CapgoCapacitorFastSql.getServerInfo({ database: 'myapp' });console.log('Server port:', info.port);execute
Section intitulée “exécuter”Exécutez une requête SQL via Capacitor pont (pour les requêtes simples). Pour une meilleure performance avec de grands ensembles de données, utilisez le protocole HTTP directement via la classe 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
Section intitulée “beginTransaction”Commencez une transaction de base de données.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.beginTransaction({ database: 'myapp' });// Execute multiple operationsawait CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });commitTransaction
Section intitulée “commitTransaction”Validez la transaction actuelle.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });rollbackTransaction
Section intitulée “rollbackTransaction”Annulez la transaction actuelle.
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
Section intitulée “configureWeb”Configure les options web spécifiques pour le module sql.js WASM.
Appeler cela avant le premier connect() appel à charger sql.js à partir d'un chemin de bundle local au lieu de la CDN par défaut. Cette méthode est un no-op sur iOS et 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' });Référence de type
Section intitulée “Référence de type”SQLConnectionOptions
Section intitulée “Options de connexion SQL”Options de connexion de base de données.
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
Section intitulée “Valeur SQL”Types de valeurs SQL pris en charge par le plugin.
export type SQLValue = string | number | boolean | null | Uint8Array;SQLResult
Section intitulée “Résultat SQL”Résultat de l'exécution d'une requête 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
Section intitulée “Niveau d'isolation”Niveaux d'isolation de transaction.
export enum IsolationLevel { ReadUncommitted = 'READ UNCOMMITTED', ReadCommitted = 'READ COMMITTED', RepeatableRead = 'REPEATABLE READ', Serializable = 'SERIALIZABLE',}Configuration de la plateforme Web pour le module sql.js WASM. Utilisez avec configureWeb() pour charger sql.js à partir d'un chemin de bureau local empaqueté au lieu du CDN par défaut.
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;}Résultat de ligne SQL - valeurs indexées par le nom de la colonne.
export interface SQLRow { [column: string]: SQLValue;}Source De Vérité
Section intitulée “Source De Vérité”Cette page est générée à partir du plugin’s src/definitions.tsRe-run la synchronisation lorsque les modifications publiques API sont détectées en amont.
Continuer depuis Getting Started
Section intitulée “Continuer depuis Getting Started”Si vous utilisez Getting Started pour planifier le tableau de bord et les opérations API, connectez-le avec Utiliser @capgo/capacitor-fast-sql pour la capacité native dans Utiliser @capgo/capacitor-fast-sql, Vue d'ensemble de API pour le détail d'implémentation dans Vue d'ensemble de API, Introduction pour le détail d'implémentation dans Introduction, Clés de API pour le détail d'implémentation dans Clés de API, et Appareils pour le détail d'implémentation dans Appareils.