メインコンテンツへスキップ

はじめに

GitHub

AIアシストセットアップを使ってプラグインをインストールできます。以下のコマンドで、お使いのAIツールに Capgo スキルを追加してください:

ターミナルウィンドウ
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のプロンプトを使用します:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-data-storage-sqlite` plugin in my project.

手動セットアップを希望する場合は、以下のコマンドでプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:

ターミナルウィンドウ
bun add @capgo/capacitor-data-storage-sqlite
bunx cap sync
import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';

クイックスタート

「Quick start」セクション
import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
await CapgoCapacitorDataStorageSqlite.openStore({ database: 'app', encrypted: true });
await CapgoCapacitorDataStorageSqlite.set({ key: 'session', value: JSON.stringify(session) });
const { value } = await CapgoCapacitorDataStorageSqlite.get({ key: 'session' });
await CapgoCapacitorDataStorageSqlite.setTable({ table: 'drafts' });
await CapgoCapacitorDataStorageSqlite.set({ key: 'invoice-42', value: draftJson });

よくある落とし穴

「Common pitfalls」セクション
  • 使用前に開く: すべての読み書きには、開かれたストアのハンドルが必要です。
  • 暗号化の範囲: 暗号化は iOS および Android のネイティブストアに適用され、Web の IndexedDB パスには適用されません。
  • ログアウト時に閉じる: clear() および closeStore() 共有デバイスでのデータの不整合を防ぎます。

ストアを開く

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
await CapgoCapacitorDataStorageSqlite.openStore({
database: 'database',
table: 'table',
encrypted: false,
mode: 'encryption',
autoVacuum: 'none',
});

Storeを閉じる

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
await CapgoCapacitorDataStorageSqlite.closeStore({ database: 'database' });

Storeが開いているか確認する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.isStoreOpen({ database: 'database' });
console.log(result);

Storeが存在するか確認する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.isStoreExists({ database: 'database' });
console.log(result);

Storeを削除する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
await CapgoCapacitorDataStorageSqlite.deleteStore({
database: 'database',
table: 'table',
encrypted: false,
mode: 'encryption',
autoVacuum: 'none',
});

既存のストアにテーブルを設定または追加する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
await CapgoCapacitorDataStorageSqlite.setTable({ table: 'table' });

指定したキーと値でデータを保存する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
await CapgoCapacitorDataStorageSqlite.set({ key: 'key-123' });

指定したデータキーに対応する値を取得する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.get({ key: 'key-123' });
console.log(result);

指定したキーのデータを削除する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
await CapgoCapacitorDataStorageSqlite.remove({ key: 'key-123' });

データストアのクリア(全キーの削除)

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
await CapgoCapacitorDataStorageSqlite.clear();

データキーの存在確認

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.iskey({ key: 'key-123' });
console.log(result);

データキー一覧の取得

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.keys();
console.log(result);

データ値一覧の取得

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.values();
console.log(result);

フィルターキーのデータ値リストを取得する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.filtervalues({ filter: 'filter' });
console.log(result);

データのキー/値ペアのリストを取得する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.keysvalues();
console.log(result);

テーブルが存在するか確認する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.isTable({ table: 'table' });
console.log(result);

現在のストアのテーブル一覧を取得する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.tables();
console.log(result);

テーブルを削除する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
await CapgoCapacitorDataStorageSqlite.deleteTable({ table: 'table' });

JSONからデータベースをインポートする

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.importFromJson({ jsonstring: 'jsonstring' });
console.log(result);

JSONオブジェクトの妥当性を確認する

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.isJsonValid({ jsonstring: 'jsonstring' });
console.log(result);

データベースをJSONオブジェクトにエクスポートする

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';
const result = await CapgoCapacitorDataStorageSqlite.exportToJson();
console.log(result);
export interface capOpenStorageOptions {
/**
* The storage database name
*/
database?: string; // default:
// ios, android: storageSQLite
// web : storageIDB
/**
* The storage table name
*/
table?: string; // default:
// ios, android: storage_table
// web: storage_store
/**
* Set to true for database encryption
*/
encrypted?: boolean; // only for ios and android
/***
* Set the mode for database encryption
* ["encryption", "secret","newsecret"]
*/
mode?: string; // only for ios and android
}
export interface capStorageOptions {
/**
* The storage name
*/
database: string;
}
export interface capDataStorageResult {
/**
* result set to true when successful else false
*/
result?: boolean;
/**
* a returned message
*/
message?: string;
}
export interface capTableStorageOptions {
/**
* The storage table name
*/
table: string;
}
export interface capDataStorageOptions {
/**
* The data name
*/
key: string;
/**
* The data value when required
*/
value?: string;
}
export interface capValueResult {
/**
* the data value for a given data key
*/
value: string;
}
export interface capKeysResult {
/**
* the data key list as an Array
*/
keys: string[];
}
export interface capValuesResult {
/**
* the data values list as an Array
*/
values: string[];
}
export interface capFilterStorageOptions {
/**
* The filter data for filtering keys
*
* ['%filter', 'filter', 'filter%'] for
* [starts with filter, contains filter, ends with filter]
*/
filter: string;
}
export interface capKeysValuesResult {
/**
* the data keys/values list as an Array of {key:string,value:string}
*/
keysvalues: any[];
}
export interface capTablesResult {
/**
* the tables list as an Array
*/
tables: string[];
}
export interface capStoreImportOptions {
/**
* Set the JSON object to import
*
*/
jsonstring?: string;
}

このページはプラグインの src/definitions.tsから生成されています。上流で公開 API が変更されたら、sync を再実行してください。

以下を使用している場合: はじめに ストレージとファイル処理を計画するには、次と連携させます @capgo/capacitor-data-storage-sqlite の使い方 @capgo/capacitor-data-storage-sqlite を使用したネイティブ機能について @capgo/capacitor-data-storage-sqlite @capgo/capacitor-data-storage-sqlite の実装の詳細については、 @capgo/capacitor-file @capgo/capacitor-file の実装詳細について @capgo/capacitor-file の使用 @capgo/capacitor-file を使用したネイティブ機能、および @capgo/capacitor-uploader @capgo/capacitor-uploader. の実装詳細