Démarrage
Copier 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.
Installer
Section intitulée « Installer »bun add @capgo/capacitor-fast-sqlbunx cap syncImporter
Section intitulée « Import »import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';API Vue d'ensemble
Section intitulée « API Vue d'ensemble »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 « disconnect »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 du serveur HTTP et le jeton 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 des 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 »Validez la transaction actuelle.
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
await CapgoCapacitorFastSql.commitTransaction({ database: 'myapp' });rollbackTransaction
Section intitulée « rollbackTransaction »Annuler 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”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 local empaqueté au lieu du 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 à la 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 »Types de valeurs SQL pris en charge par l'extension.
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 avec configureWeb() pour charger sql.js à partir d'un chemin de bundle local 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 changent en amont.