Prise en main
Copiez un prompt de configuration avec les étapes d'installation et la guide markdown complète 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.
Installation
Section intitulée “Installation”Vous pouvez utiliser notre configuration assistée par l'IA pour installer le plugin. Ajoutez les Capgo compétences à votre outil IA en utilisant 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 au 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”Initialiser la connexion de base de données et démarrer 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”Obtenir 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);Exécutez une requête SQL via le pont Capacitor (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 « débuterTransaction »Démarrez 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 »Confirmez la transaction en cours.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });rollbackTransaction
Section intitulée « rollbackTransaction »Annulez la transaction en cours.
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 »Configurez les options spécifiques au web 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 “SQLValue”Les types de valeurs SQL pris en charge par le plugin.
export type SQLValue = string | number | boolean | null | Uint8Array;SQLResult
Section intitulée “SQLResult”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 “IsolationLevel”Niveaux d'isolation de transaction.
export enum IsolationLevel { ReadUncommitted = 'READ UNCOMMITTED', ReadCommitted = 'READ COMMITTED', RepeatableRead = 'REPEATABLE READ', Serializable = 'SERIALIZABLE',}WebConfig
Section intitulée “WebConfig”Configuration de la plateforme Web pour le module sql.js WASM. Utilisez configureWeb() pour charger sql.js à partir d'un chemin de bureau localisé 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.ts. Re-run la synchronisation lorsque le public API change en amont.
Continuez de Getting Started
Section intitulée “Continuez de Getting Started”Si vous utilisez Getting Started planifier le tableau de bord et les opérations API, connecter-le avec En utilisant @capgo/capacitor-fast-sql pour la capacité native dans En utilisant @capgo/capacitor-fast-sql, API Vue d'ensemble pour le détail d'implémentation dans API Vue d'ensemble, Introduction pour le détail d'implémentation dans Introduction, API Clés pour le détail d'implémentation dans API Clés, et Appareils pour le détail d'implémentation dans Appareils.