Skip to main content

Using @capgo/capacitor-fast-sql

Fast SQL Plugin for high-performance SQLite database access.

Install

bun add @capgo/capacitor-fast-sql
bunx cap sync

What This Plugin Exposes

  • connect - Initialize the database connection and start the HTTP server.
  • disconnect - Close database connection and stop the HTTP server.
  • getServerInfo - Get the HTTP server port and token for direct communication.
  • execute - Execute a SQL query via Capacitor bridge (for simple queries). For better performance with large datasets, use the HTTP protocol directly via SQLConnection class.

Example Usage

connect

Initialize the database connection and start the HTTP server.

import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';

const conn = await CapgoCapacitorFastSql.connect({ database: 'myapp' });
console.log('Connected on port:', conn.port);

disconnect

Close database connection and stop the HTTP server.

import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';

await CapgoCapacitorFastSql.disconnect({ database: 'myapp' });

getServerInfo

Get the HTTP server port and token for direct communication.

import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';

const info = await CapgoCapacitorFastSql.getServerInfo({ database: 'myapp' });
console.log('Server port:', info.port);

execute

Execute a SQL query via Capacitor bridge (for simple queries). For better performance with large datasets, use the HTTP protocol directly via SQLConnection class.

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

Full Reference