메인 콘텐츠로 건너뛰기

Getting Started

설치

설치
터미널 창
bun add @capgo/capacitor-fast-sql
bunx cap sync

Import

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

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

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

데이터베이스 연결을 종료하고 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);

Capacitor를 통해 간단한 쿼리 실행하기. 대량 데이터를 다루기 위해 더 나은 성능을 원한다면, HTTP 프로토콜을 직접 사용하여 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

beginTransaction 섹션

데이터베이스 트랜잭션 시작.

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

commitTransaction

commitTransaction 섹션

현재 트랜잭션 커밋.

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

rollbackTransaction

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

__CAPGO_KEEP_0__을 위한 웹 특정 옵션을 구성합니다.

__CAPGO_KEEP_1__를 호출하세요. __CAPGO_KEEP_2__ __CAPGO_KEEP_3__에 대한 __CAPGO_KEEP_1__ 호출 전에 sql.js를 로컬로 패키징된 경로 대신 기본 CDN에서 로드하기 위해 sql.js WASM 모듈을 사용합니다. 이 메서드는 iOS 및 Android에서 비어 있습니다. connect() __CAPGO_KEEP_4__

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

__CAPGO_KEEP_6__

__CAPGO_KEEP_7__

SQLConnectionOptions

__CAPGO_KEEP_8__

__CAPGO_KEEP_9__

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

__CAPGO_KEEP_0__ 지원하는 SQL 값 유형.

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

SQLResult

SQLResult

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() __CAPGO_KEEP_0__를 사용하여 sql.js를 로컬로 패키징된 경로에서 CDN 대신 로드합니다.

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

SQL row 결과 - 열 이름에 색인된 값.

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

이 페이지는 플러그인의 src/definitions.ts. 업스트림에서 pubic API이 변경될 때 다시 싱크를 실행하세요.

Getting Started에서 계속

Getting Started에서 계속 섹션 제목

Capgo를 사용하는 경우 Getting Started to plan dashboard and API operations, connect it with @capgo/capacitor-fast-sql @capgo/capacitor-fast-sql API 개요 API 개요 구현 세부 사항 소개 소개 구현 세부 사항 API 키 API 키 구현 세부 사항 및 장치 장치 구현 세부 사항.