### Install with pnpm
Source: https://github.com/capacitor-community/sqlite/blob/master/README.md
Install the plugin and its dependencies with pnpm, then sync with Capacitor.
```bash
pnpm install --save @capacitor-community/sqlite
pnpm install --save jeep-sqlite
pnpm install --save sql.js
npx cap sync
```
--------------------------------
### Install with yarn
Source: https://github.com/capacitor-community/sqlite/blob/master/README.md
Install the plugin using yarn and sync with Capacitor.
```bash
yarn add @capacitor-community/sqlite
npx cap sync
```
--------------------------------
### Install with npm
Source: https://github.com/capacitor-community/sqlite/blob/master/README.md
Install the plugin using npm and sync with Capacitor.
```bash
npm install --save @capacitor-community/sqlite
npx cap sync
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/capacitor-community/sqlite/blob/master/CONTRIBUTING.md
Run this command after cloning the repository to install all necessary project dependencies.
```shell
npm install
```
--------------------------------
### Install @capacitor-community/sqlite
Source: https://github.com/capacitor-community/sqlite/blob/master/docs/Biometric-Authentication.md
Install the latest version of the @capacitor-community/sqlite package using npm.
```bash
npm i --save @capacitor-community/sqlite@latest
```
--------------------------------
### Capacitor Configuration Example
Source: https://github.com/capacitor-community/sqlite/blob/master/README.md
Example configuration for the CapacitorSQLite plugin in capacitor.config.ts, including settings for iOS, Android, and Electron encryption and biometrics.
```typescript
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.jeep.app.ionic7.angular.sqlite',
appName: 'ionic7-angular-sqlite-starter',
webDir: 'www',
server: {
androidScheme: 'https'
},
plugins: {
CapacitorSQLite: {
iosDatabaseLocation: 'Library/CapacitorDatabase',
iosIsEncryption: true,
iosKeychainPrefix: 'angular-sqlite-app-starter',
iosBiometric: {
biometricAuth: false,
biometricTitle : "Biometric login for capacitor sqlite"
},
androidIsEncryption: true,
androidBiometric: {
biometricAuth : false,
biometricTitle : "Biometric login for capacitor sqlite",
biometricSubTitle : "Log in using your biometric"
},
electronIsEncryption: true,
electronWindowsLocation: "C:\\ProgramData\\CapacitorDatabases",
electronMacLocation: "/Volumes/Development_Lacie/Development/Databases",
electronLinuxLocation: "Databases"
}
}
};
export default config;
```
--------------------------------
### Install @capacitor-community/sqlite and react-sqlite-hook
Source: https://github.com/capacitor-community/sqlite/blob/master/docs/Ionic-React-Usage.md
Install the necessary packages for native applications. Use `jeep-sqlite` for web browser compatibility.
```bash
npm i --save-dev @capacitor-community/sqlite@latest
npm i --save-dev react-sqlite-hook@latest
```
```bash
npm i --save-dev jeep-sqlite@latest
```
--------------------------------
### Partial Mode Import Example
Source: https://github.com/capacitor-community/sqlite/blob/master/docs/ImportExportJson.md
This example demonstrates a partial import, allowing for updates to existing tables, addition of new tables, and modification of indexes. It's useful for incremental data loading.
```javascript
const partialImport1: any = {
database : "db-from-json",
version: 1,
encrypted : false,
mode : "partial",
tables :[
{
name: "users",
values: [
[5,"Addington.com","Addington",22,0,1601972413],
[6,"Bannister.com","Bannister",59,0,1601983245],
[2,"Jones@example.com","Jones",45,0,1601995473],
[1, 'Whiteley.com', 'Whiteley', 30, 1, 1601995520],
]
},
{
name: "messages",
indexes: [
{name: "index_messages_on_title", value: "title"}
],
values: [
[4,2,"test post 4","content test post 4",0,1601983742],
[5,6,"test post 5","content test post 5",0,1601992872]
[1,1,'test post 1', 'content test post 1',1,1601995520],
[3,1,'test post 3', 'content test post 3',1,1601995520],
]
},
{
name: 'fruits',
schema: [
{ column: 'id', value: 'INTEGER PRIMARY KEY NOT NULL' },
{ column: 'name', value: 'TEXT UNIQUE NOT NULL' },
{ column: 'weight', value: 'REAL' },
{column:"sql_deleted", value:"BOOLEAN DEFAULT 0 CHECK (sql_deleted IN (0, 1))"},
{column:"last_modified", value:"INTEGER DEFAULT (strftime('%s', 'now'))"}
],
indexes: [
{ name: 'index_fruits_on_name', value: 'name' },
{ name: "index_fruits_on_last_modified",value: "last_modified DESC"},
],
values: [
[1, 'orange', 200.3,0,1601995573],
[2, 'apple', 450.0,0,1601995573],
[2, 'banana', 120.5,0,1601995573],
],
},
{
name: 'company',
schema: [
{ column: 'id', value: 'INTEGER NOT NULL' },
{ column: 'name', value: 'TEXT NOT NULL' },
{ column: 'age', value: 'INTEGER NOT NULL' },
{ column: 'address', value: 'TEXT' },
{ column: 'salary', value: 'REAL'},
{column:"sql_deleted", value:"BOOLEAN DEFAULT 0 CHECK (sql_deleted IN (0, 1))"},
{column:"last_modified", value:"INTEGER DEFAULT (strftime('%s', 'now'))"},
{ constraint: 'PK_id_name', value: 'PRIMARY KEY (id,name)'},
],
},
],
};
```
--------------------------------
### App.vue Setup with SQLite Hook
Source: https://github.com/capacitor-community/sqlite/blob/master/docs/Ionic-Vue-Usage.md
This snippet shows the App.vue file setup, demonstrating how to integrate the useSQLite hook and access global properties for managing modal states and messages.
```vue