메뉴로 이동

시작하기

설치

설치
터미널 창
bun add @capgo/capacitor-fast-sql
bunx cap sync
import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';

connect

연결

데이터베이스 연결을 초기화하고 HTTP 서버를 시작합니다.

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

disconnect

연결 해제

데이터베이스 연결을 닫고 HTTP 서버를 중지합니다.

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

직접 통신을 위해 HTTP 서버 포트와 토큰을 가져옵니다.

import { CapgoCapacitorFastSql } from '@capgo/capacitor-fast-sql';
const info = await CapgoCapacitorFastSql.getServerInfo({ database: 'myapp' });
console.log('Server port:', info.port);

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

beginTransaction

Copy to clipboard

beginTransaction 섹션

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

commitTransaction

Copy to clipboard

commitTransaction 섹션

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

rollbackTransaction

롤백 트랜잭션

현재 트랜잭션을 롤백합니다.

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

이 메소드는 iOS와 Android에서 무시됩니다.

클립보드에 복사 타입 참조 SQL.js WASM 모듈의 웹 관련 옵션을 구성합니다. connect() 이 메소드는 iOS와 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' });

SQLConnectionOptions

SQLConnectionOptions 섹션

데이터베이스 연결 옵션입니다.

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

플러그인이 지원하는 SQL 값 유형입니다.

export type SQLValue = string | number | boolean | null | Uint8Array;

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

IsolationLevel 섹션

트랜잭션 격리 수준입니다.

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

WebConfig

WebConfig

sql.js WASM 모듈의 웹 플랫폼 설정입니다. configureWeb() 로컬로 패키징된 경로 대신 기본 CDN을 사용하여 sql.js를 로드합니다.

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

SQLRow

SQLRow

SQL 결과 행 - 열 이름에 따라 인덱싱된 값.

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

이 페이지는 플러그인의 src/definitions.ts에서 생성됩니다. upstream의 API가 변경될 때마다 다시 동기화하세요.