Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@capacitor-community/sqlite
Advanced tools
@capacitor-community/sqlite
Capacitor community plugin for Native and Electron SQLite Databases. In Native databases could be encrypted with SQLCipher
The 2.4.x
is now accessible using the tag @initial
The 2.4.x
is NOT ANYMORE MAINTAINED
The refactor release has been upgraded to @capacitor/core@3.0.0-beta.1
.
!!! ONLY iOS and Android plugins have been upgraded !!!
To install it
npm i --save @capacitor-community/sqlite@next
This release provide a better Error handling through try...catch.
The test has been achieved on:
A refactoring has been started more than a month ago to reach the following objectives:
db.open(), db.close, ...
androidx.sqlite.db.xxx
@journeyapps/sqlcipher
. !!! NOT WORKING for Electron Windows platform !!!typeorm
or spatialite
drivers.This was discussed lengthly in issue#1 and issue#52
It is now available in a stable release 2.9.x
for all platforms (Android, iOS & Electron).
Developers are encouraged to start converting their applications. The interface to the plugin is now achieved through the use of connection wrappers
As you will see it is a Major
change and the release is now the basis of 3.0.0-beta
based on capacitor@3.0.0
.
So the 2.4.x
is now not anymore maintened.
The test has been achieved on:
Other frameworks will be tested later
When you will find issues, please report them with the REFACTOR
word at the start of the issue title.
To install it
npm i --save @capacitor-community/sqlite@latest
Hope you will enjoy it.
Maintainer | GitHub | Social |
---|---|---|
QuΓ©au Jean Pierre | jepiqueau |
The plugin follows the guidelines from the Capacitor Team
,
meaning that it will not work in IE11 without additional JavaScript transformations, e.g. with Babel.
The 2.4.x
stable release is accessible through the tag initial
npm install @capacitor-community/sqlite@initial
npx cap sync
npx cap add ios
npx cap add android
npx cap add @capacitor-community/electron
import com.getcapacitor.community.database.sqlite.CapacitorSQLite;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {
{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(CapacitorSQLite.class);
}
}
);
}
}
npm install --save sqlite3
npm install --save-dev @types/sqlite3
npm install --save-dev electron-rebuild
Modify the Electron package.json file by adding a script "postinstall"
"scripts": {
"electron:start": "electron ./",
"postinstall": "electron-rebuild -f -w sqlite3"
},
Execute the postinstall script
npm run postinstall
User/Databases/APP_NAME/
Then build YOUR_APPLICATION
npm run build
npx cap copy
npx cap copy @capacitor-community/electron
npx cap copy web
npx cap open android
npx cap open ios
npx cap open @capacitor-community/electron
Do not report anymore issues for 2.4.x
as this release is not anymore maintained.
No configuration required for this plugin
Name | Android | iOS | Electron | Web |
---|---|---|---|---|
open (non-encrypted DB) | β | β | β | β |
open (encrypted DB) | β | β | β | β |
close | β | β | β | β |
execute | β | β | β | β |
executeSet | β | β | β | β |
run | β | β | β | β |
query | β | β | β | β |
deleteDatabase | β | β | β | β |
importFromJson | β | β | β | β |
exportToJson | β | β | β | β |
createSyncTable | β | β | β | β |
setSyncDate | β | β | β | β |
isJsonValid | β | β | β | β |
isDBExists | β | β | β | β |
addUpgradeStatement | β | β | β | β |
ImportExportJson_Documentation
UpgradeDatabaseVersion_Documentation
In your code
import { Plugins, Capacitor } from '@capacitor/core';
import '@capacitor-community/sqlite';
const { CapacitorSQLite } = Plugins;
@Component( ... )
export class MyPage {
_sqlite: any;
_platform: string;
...
ngAfterViewInit()() {
this._platform = Capacitor.platform;
this._sqlite = CapacitorSQLite;
...
}
async testSQLitePlugin(): Promise<void> {
let result:any = await this._sqlite.open({database:"testsqlite"});
retOpenDB = result.result;
if(retOpenDB) {
// Create Tables if not exist
let sqlcmd: string = `
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY NOT NULL,
email TEXT UNIQUE NOT NULL,
name TEXT,
FirstName TEXT,
age INTEGER,
MobileNumber TEXT
);
PRAGMA user_version = 1;
COMMIT TRANSACTION;
`;
var retExe: any = await this._sqlite.execute({statements:sqlcmd});
console.log('retExe ',retExe.changes.changes);
// Insert some Users
sqlcmd = `
BEGIN TRANSACTION;
DELETE FROM users;
INSERT INTO users (name,email,age) VALUES ("Whiteley","Whiteley.com",30);
INSERT INTO users (name,email,age) VALUES ("Jones","Jones.com",44);
COMMIT TRANSACTION;
`;
retExe = await this._sqlite.execute({statements:sqlcmd});
// will print the changes 2 in that case
console.log('retExe ',retExe.changes.changes);
// Select all Users
sqlcmd = "SELECT * FROM users";
const retSelect: any = await this._sqlite.query({statement:sqlcmd,values:[]});
console.log('retSelect.values.length ',retSelect.values.length);
const row1: any = retSelect.values[0];
console.log("row1 users ",JSON.stringify(row1))
const row2: any = retSelect.values[1];
console.log("row2 users ",JSON.stringify(row2))
// Insert a new User with SQL and Values
sqlcmd = "INSERT INTO users (name,email,age) VALUES (?,?,?)";
let values: Array<any> = ["Simpson","Simpson@example.com",69];
var retRun: any = await this._sqlite.run({statement:sqlcmd,values:values});
console.log('retRun ',retRun.changes.changes,retRun.changes.lastId);
// Select Users with age > 35
sqlcmd = "SELECT name,email,age FROM users WHERE age > ?";
retSelect = await this._sqlite.query({statement:sqlcmd,values:["35"]});
console.log('retSelect ',retSelect.values.length);
// Execute a Set of raw SQL Statements
let set: Array<any> = [
{ statement:"INSERT INTO users (name,FirstName,email,age,MobileNumber) VALUES (?,?,?,?,?);",
values:["Blackberry","Peter","Blackberry@example.com",69,"4405060708"]
},
{ statement:"INSERT INTO users (name,FirstName,email,age,MobileNumber) VALUES (?,?,?,?,?);",
values:["Jones","Helen","HelenJones@example.com",42,"4404030201"]
},
{ statement:"INSERT INTO users (name,FirstName,email,age,MobileNumber) VALUES (?,?,?,?,?);",
values:["Davison","Bill","Davison@example.com",45,"4405162732"]
},
{ statement:"INSERT INTO users (name,FirstName,email,age,MobileNumber) VALUES (?,?,?,?,?);",
values:["Brown","John","Brown@example.com",35,"4405243853"]
},
{ statement:"UPDATE users SET age = ? , MobileNumber = ? WHERE id = ?;",
values:[51,"4404030237",2]
}
];
result = await this._sqlite.executeSet({set:set});
console.log("result.changes.changes ",result.changes.changes);
if(result.changes.changes != 5) return;
...
} else {
console.log("Error: Open database failed");
return;
}
}
...
}
The IOS and Android codes are using SQLCipher allowing for database encryption The Electron code use sqlite3
Thanks goes to these wonderful people (emoji key):
Jean Pierre QuΓ©au π» | Paul Antoine π» | Karyfars π» |
This project follows the all-contributors specification. Contributions of any kind welcome!
2.4.6 (2021-01-24)
update to @capacitor/core@2.4.6
move it from tag latest to tag initial
FAQs
Community plugin for native & electron SQLite databases
The npm package @capacitor-community/sqlite receives a total of 11,205 weekly downloads. As such, @capacitor-community/sqlite popularity was classified as popular.
We found that @capacitor-community/sqlite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 43 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.