К основному содержанию
скилл CX Codex

sqlite-to-fast-sql — скилл для Claude Code: миграция SQLite на Fast

Переносит Capacitor-приложение с bridge-плагинов SQLite на @capgo/capacitor-fast-sql, сохраняя данные, транзакции и BLOB.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add Cap-go/capgo-skills --skill sqlite-to-fast-sql -a claude-code
Открыть на GitHub

Что делает sqlite-to-fast-sql

Скилл ведёт миграцию по шагам: сначала инвентаризация пакетов и слоя данных, потом таблица соответствия вызовов, затем установка и правка конфигов. Он знает про @capacitor-community/sqlite, cordova-sqlite-storage, драйверы TypeORM, Drizzle и Kysely — и подсказывает, чем заменить createConnection, open, query, run, executeSet.

Fast SQL ходит в нативный SQLite через HTTP-сервер на localhost с токеном, а не через мост Capacitor. Поэтому крупные SELECT и пакетные записи перестают упираться в сериализацию JSON. Плата за это — настройка iOS ATS (NSAllowsLocalNetworking) и Android cleartext для localhost и 127.0.0.1. Если в приложении уже есть network security config, скилл советует влить domain-config в существующий файл, а не перезаписывать его.

Пути к базам у старого плагина и у Fast SQL различаются, так что файлы сами не подхватятся — перенос данных придётся продумать отдельно. Шифрование SQLCipher включается по платформе и требует отдельной зависимости: net.zetetic:sqlcipher-android для Android или pod CapgoCapacitorFastSql/SQLCipher для iOS. Ключ держите вне JS.

Какие задачи решает

  • заменить вызовы createConnection, open и query на API Fast SQL
  • ускорить большие выборки, которые тормозят на мосте Capacitor
  • включить шифрование SQLCipher и вынести ключ из JS
  • перенести пары ключ-значение в KeyValueStore
  • починить ошибки настройки: ATS, cleartext localhost, OPFS-заголовки

Примеры запросов агенту

  • Проверь package.json и покажи, какие SQL-плагины у нас стоят, прежде чем что-то менять
  • Переведи наш слой данных с @capacitor-community/sqlite на @capgo/capacitor-fast-sql, транзакции и BLOB сохрани
  • Добавь шифрование SQLCipher для Android и iOS и объясни, откуда брать ключ

Как установить sqlite-to-fast-sql

1Через Skills CLI (Vercel)

npx skills add Cap-go/capgo-skills --skill sqlite-to-fast-sql -a claude-code

2Вручную: положить файлы

~/.claude/skills/sqlite-to-fast-sql/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/sqlite-to-fast-sql/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о sqlite-to-fast-sql

Как установить sqlite-to-fast-sql в Claude?

Выполните npx skills add Cap-go/capgo-skills --skill sqlite-to-fast-sql -a claude-code. Скилл окажется в ~/.claude/skills/sqlite-to-fast-sql/SKILL.md.

Что делает sqlite-to-fast-sql?

Проводит миграцию с bridge-плагинов SQLite на @capgo/capacitor-fast-sql: сопоставляет старые вызовы с новым API, ставит пакет, правит конфиги iOS и Android и подсказывает, как не потерять существующие файлы баз.

Для каких хранилищ скилл не подходит?

Для @capacitor/preferences и приложений только на IndexedDB есть capacitor-offline-first, для Ionic Secure Storage и Identity Vault — ionic-enterprise-sdk-migration. Код, который уже оборачивает Fast SQL, сюда тоже не относится.

Исходный текст

SKILL.md · MIT
---
name: sqlite-to-fast-sql
description: Migrates SQLite and SQL-style Capacitor storage (@capacitor-community/sqlite, cordova-sqlite-storage, @ionic/storage with a SQLite driver, TypeORM/Drizzle/Kysely capacitor drivers, and other bridge-based SQL plugins) to @capgo/capacitor-fast-sql. Use when replacing createConnection/open/query/run/executeSet calls, slow large result sets over the Capacitor bridge, adding SQLCipher encryption, keeping transactions and BLOBs, moving key-value data to KeyValueStore, preserving existing database files during the switch, or fixing Fast SQL setup errors (ATS NSAllowsLocalNetworking, Android cleartext localhost, "Encryption is not available in this build", web OPFS COOP/COEP headers). Do not use for non-SQL storage such as Preferences (capacitor-offline-first), Ionic Secure Storage or Identity Vault (ionic-enterprise-sdk-migration), generic app upgrades (capacitor-app-upgrades), or code that already wraps Fast SQL.
allowed-tools:
  - Bash(node -e *)
  - Bash(npm *)
  - Bash(npx cap *)
---

# SQLite to Fast SQL Migration

Swap a bridge-based SQL plugin for `@capgo/capacitor-fast-sql` without losing user data.

## When to Use

TRIGGER when:
- `package.json` has `@capacitor-community/sqlite`, `cordova-sqlite-storage`, `@capawesome-team/capacitor-sqlite`, an ORM capacitor driver, or another SQLite plugin, and the user wants Fast SQL.
- Large `SELECT`s or sync writes are slow because every row crosses the Capacitor bridge as JSON.
- The app needs encryption, transactions, batch writes, BLOBs, or an encrypted key-value store.

Do not use for:
- `@capacitor/preferences` or IndexedDB-only apps -> `capacitor-offline-first`.
- `@ionic-enterprise/secure-storage` / Identity Vault -> `ionic-enterprise-sdk-migration`.
- Apps already on Fast SQL needing schema design or sync logic -> `capacitor-offline-first`.

## Live Project Snapshot

Detected SQL-related packages:
!`node -e "const fs=require('fs');if(!fs.existsSync('package.json'))process.exit(0);const pkg=JSON.parse(fs.readFileSync('package.json','utf8'));const needles=['sqlite','sqlcipher','typeorm','watermelondb','pouchdb','@capacitor-community/sqlite','@capawesome-team/capacitor-sqlite','@capgo/capacitor-fast-sql'];const out=[];for(const section of ['dependencies','devDependencies']){for(const [name,version] of Object.entries(pkg[section]||{})){if(needles.some((needle)=>name.includes(needle)))out.push(section+'.'+name+'='+version)}}console.log(out.sort().join('\n'))"`

## How Fast SQL Differs

- Native SQLite is reached through a token-protected HTTP server on `localhost`, not the Capacitor bridge, so big result sets and batches avoid bridge serialization. This is why iOS ATS and Android cleartext config are required.
- Plugin major follows Capacitor major (v8 for Capacitor 8). Current: 8.2.x.
- Database files: iOS `Documents/<database>.db`, Android `<filesDir>/<database>.db`. Other plugins use different paths and names, so existing data is not picked up automatically.
- Web: official `@sqlite.org/sqlite-wasm` with OPFS persistence (bundled dependency, no `sql.js` install). Older versions used sql.js + IndexedDB; that data is not migrated automatically.
- Encryption: SQLCipher, opt-in per platform.

## Procedure

### Step 1: Inventory

Read `package.json` and grep the data layer. Record: plugin and version, database names, schema/migration mechanism (`user_version`, upgrade statements, ORM migrations), use of transactions, BLOBs, encryption (and where the key comes from), JSON import/export, web support, and approximate data size. Report this before changing code.

### Step 2: Map the API

```ts
import { FastSQL, KeyValueStore } from '@capgo/capacitor-fast-sql';

const db = await FastSQL.connect({ database: 'app' });            // { encrypted, encryptionKey, readOnly }
const rows = await db.query('SELECT * FROM todo WHERE done = ?', [0]);
const { rowsAffected, insertId } = await db.run('INSERT INTO todo (title) VALUES (?)', ['A']);
await db.execute('CREATE TABLE IF NOT EXISTS todo (id INTEGER PRIMARY KEY, title TEXT, done INTEGER DEFAULT 0)');
await db.executeBatch([{ statement: 'INSERT INTO log (m) VALUES (?)', params: ['x'] }]);
await db.transaction(async (tx) => { await tx.run('UPDATE a SET n = n - 1'); await tx.run('UPDATE b SET n = n + 1'); });
await FastSQL.disconnect('app');
```

| `@capacitor-community/sqlite` | Fast SQL |
|---|---|
| `new SQLiteConnection(CapacitorSQLite)`, `createConnection(name, encrypted, mode, version, readonly)`, `db.open()` | `FastSQL.connect({ database, encrypted, encryptionKey, readOnly })` |
| `db.query(sql, values)` -> `{ values }` | `db.query(sql, params)` -> rows array |
| `db.run(sql, values)` -> `{ changes: { changes, lastId } }` | `db.run(sql, params)` -> `{ rowsAffected, insertId }` |
| `db.execute(multiStatementSql)` | `db.execute(sql)` per statement, or `executeBatch` |
| `db.executeSet([{ statement, values }])` | `db.executeBatch([{ statement, params }])` |
| `beginTransaction/commitTransaction/rollbackTransaction`, `transaction` flag on calls | `db.transaction(cb)` or `beginTransaction()` / `commit()` / `rollback()` |
| `addUpgradeStatement` + version | Keep your own `PRAGMA user_version` migration runner |
| `closeConnection(name)` | `FastSQL.disconnect(name)` |
| `importFromJson` / `exportToJson` | Not provided; write rows with `executeBatch` |
| `cordova-sqlite-storage` `db.executeSql(sql, params, ok, err)` / `db.transaction(tx => tx.executeSql(...))` | `db.query`/`db.run` and `db.transaction(async tx => ...)` |

Key-value data (Ionic Storage, Preferences-like wrappers) -> `KeyValueStore.open({ database, encrypted, encryptionKey, store })` with `set/get/has/remove/clear/keys`.

### Step 3: Install and configure

```bash
npm install @capgo/capacitor-fast-sql
npx cap sync
```

iOS `ios/App/App/Info.plist` (loopback only; does not weaken ATS for other hosts):

```xml
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsLocalNetworking</key>
    <true/>
</dict>
```

Android `android/app/src/main/res/xml/network_security_config.xml`, referenced by `android:networkSecurityConfig="@xml/network_security_config"` on `<application>`:

```xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="false">localhost</domain>
        <domain includeSubdomains="false">127.0.0.1</domain>
    </domain-config>
</network-security-config>
```

If the app already has a network security config, merge the `domain-config` instead of replacing the file.

Encryption (only if `encrypted: true`):
- Android: `implementation 'net.zetetic:sqlcipher-android:4.13.0'` (or current) in `android/app/build.gradle` dependencies.
- iOS (CocoaPods): `pod 'CapgoCapacitorFastSql/SQLCipher', :path => '../../node_modules/@capgo/capacitor-fast-sql'` in `ios/App/Podfile`, then `pod install`. For SPM projects check the plugin README for the current SQLCipher option.
- Keep the key out of JS source: store it with `@capgo/capacitor-native-biometric` or fetch it from your backend.

Web (only if the app ships on web): serve `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`, and in Vite add `optimizeDeps.exclude: ['@sqlite.org/sqlite-wasm']`. `CapgoCapacitorFastSql.configureWeb({ ... })` before the first `connect()` is optional and a no-op on native.

### Step 4: Preserve existing data

Pick one with the user:
1. Dual-plugin release (safest): keep the old plugin installed for one release. On first launch, if a `migrated` flag is missing, read tables from the old plugin, `executeBatch` them into Fast SQL inside a transaction, verify counts, set the flag. Remove the old plugin in the next release.
2. File copy: copy the old `.db` file to Fast SQL's path before the first `connect()` (old community plugin files are typically named `<name>SQLite.db`; verify the real path on a device first). Encrypted files keep working only with the same key and a compatible SQLCipher version.
3. Re-sync from server: acceptable when local data is a cache; confirm with the user.

### Step 5: Swap code and remove the old plugin

Replace imports and calls behind the existing data-access layer; keep schema and migration steps. Then (after the carry-over release if option 1):

```bash
npm uninstall @capacitor-community/sqlite   # or the plugin in use
npx cap sync
```

## Verification

- `rg -n "@capacitor-community/sqlite|cordova-sqlite|CapacitorSQLite|SQLiteConnection" -g '!node_modules' src` returns nothing after cleanup.
- Upgrade test: install the current store build, create data, install the new build over it; row counts match.
- Smoke test on both platforms: create, read, update, delete, transaction rollback (throw inside `transaction` and confirm no partial writes), BLOB round-trip (`Uint8Array`).
- Encrypted DB: opening with a wrong key fails; file is unreadable with plain `sqlite3`.
- Measure a large query before/after to confirm the performance goal.

## Error Handling

| Error / symptom | Fix |
|---|---|
| iOS: requests to `http://localhost:<port>` fail, `The resource could not be loaded because the App Transport Security policy requires the use of a secure connection` | Add `NSAllowsLocalNetworking` |
| Android: `net::ERR_CLEARTEXT_NOT_PERMITTED` or `CLEARTEXT communication to localhost not permitted by network security policy` | Add the localhost `network_security_config.xml` and reference it in the manifest |
| iOS: `Encryption is not available in this build. Add SQLCipher to enable encryption.` | Install the SQLCipher subspec or use `encrypted: false` |
| Android: `Encryption is not available. ... to your app's build.gradle to enable encryption.` | Add `net.zetetic:sqlcipher-android` to the app module |
| `Encryption key is required when encrypted is true` | Pass `encryptionKey` with `encrypted: true` |
| App starts with an empty database after update | New file path; run the Step 4 carry-over |
| Web: OPFS / `SharedArrayBuffer` errors | Missing COOP/COEP headers or Vite pre-bundling sqlite-wasm |
| `query` returns objects where code expected `{ values }` | Old community-plugin result shape; update callers to use the rows array |

© Cap-go · MIT · Cap-go/capgo-skills

Похожие скиллы

Все скиллы по теме «Данные и базы» →
SQLite Database Expert JARVIS AI Assistant Скилл настраивает локальную базу SQLite для десктопных приложений на Rust и Tauri. Защищает от SQL-инъекций, настраивает полнотекстовый поиск FTS5 и управляет миграциями. CX Codex +1 3 100установок capacitor-plugins capawesome-team Скилл проводит агента по установке и настройке плагинов Capacitor из шести источников, включая официальные, Capawesome и Firebase. CX Codex +1 1 800установок capacitor-expert capawesome-team Скилл-справочник по Capacitor: архитектура, CLI, плагины, интеграция с фреймворками и Capawesome Cloud. Пригодится, когда агент собирает или чинит кросс-платформенное приложение. CX Codex +1 1 100установок bun-sqlite secondsky Скилл подсказывает агенту, как писать код для встроенного драйвера bun:sqlite: запросы, подготовленные выражения, транзакции. CX Codex +1 495установок appmigrationkit dpearson2699 Скилл помогает настроить перенос данных между iOS и другими платформами через AppMigrationKit во время первичной настройки устройства. CX Codex +1 3 000установок assess-react-native-migration callstackincubator Разбирает продуктовые репозитории и решает, стоит ли переносить мобильное приложение на React Native — до того, как начнётся код. CX Codex +1 2 100установок

Из того же набора29

konsta-ui Скилл помогает агенту собирать интерфейс Capacitor-приложения на Konsta UI v5 с Tailwind CSS v4 и разбираться, почему компоненты остались без стилей. CX Codex +1 836установок cocoapods-to-spm Переводит iOS-проект Capacitor с CocoaPods на Swift Package Manager и подсказывает, что делать с плагинами без Package.swift. CX Codex +1 796установок capacitor-app-upgrades Ведёт приложение на Capacitor через мажорные версии по одной, с обязательным шагом UIScene для iOS перед Capacitor 9. CX Codex +1 771установок capacitor-plugin-upgrades Ведёт плагин Capacitor через один или несколько мажорных апгрейдов, от 4 до 9, с аудитом iOS UIScene. Пригодится мейнтейнерам, у которых peerDependencies отстали от приложения. CX Codex +1 730установок capgo-release-management Скилл ведёт релизы Capgo из CLI: загрузка бандлов, каналы, постепенный выкат, откат и шифрование. Пригодится, когда релиз ломается на загрузке или нужно откатить бандл. CX Codex +1 705установок capacitor-app-upgrade-v7-to-v8 Ведёт приложение на Capacitor 7 к восьмой версии: сначала npx cap migrate, потом ручной чек-лист по iOS и Android. CX Codex +1 704установок webapp-to-capacitor Планирует и выполняет превращение веб-приложения, PWA или SPA в приложение под iOS и Android на Capacitor, которое проходит ревью магазинов. CX Codex +1 665установок ionic-appflow-migration Переводит Ionic или Capacitor проект с Ionic Appflow на Capgo: живые обновления, сборки и публикация в стор. CX Codex +1 653установок

Спонсоры проекта

Компании, которые помогают держать аналитику открытой