tidev / appcelerator.encrypteddatabase

An encrypted version of the Ti.Database namespace
https://titaniumsdk.com/api/modules/encrypteddatabase.html
Other
5 stars 2 forks source link

feat(all): update libraries #280

Open m1ga opened 2 years ago

m1ga commented 2 years ago

Android

This new API release provides major benefits including optimized support for concurrent database access, drastic performance improvements, API simplification, and codebase modernization.

iOS


Binary: appcelerator.encrypteddatabase-android-5.0.1.zip

appcelerator.encrypteddatabase-iphone-4.0.1.zip


according to SQLCipher: 59.59 sec vs 3.01 sec (Pixel 6): Screenshot_20220814_005040

source: SQLCipher

My tests:

normal: 10.05 sec
4.1.0: 54.5 sec
5.0.0: 39.5 sec
var DB = require('appcelerator.encrypteddatabase');
var instance = null;
var dataTofetch = null;
var win = Ti.UI.createWindow();
var lbl = Ti.UI.createLabel();
var timeStart = 0;
win.addEventListener('open', function() {
    timeStart = new Date();
    init();
    setup();
    insert();
    fetch();
    closeDB();
    lbl.text = ((new Date()) - timeStart) / 1000 + " sec";
});

function init() {
    DB.password = 'secret';
    Ti.API.info('Opening DB ...');
    // instance = Ti.Database.open('myDatabase');   // use normal database
    instance = DB.open('test.db');
}

function setup() {
    console.log("setup");
    instance.execute('CREATE TABLE IF NOT EXISTS testtable(id integer PRIMARY KEY);');
    for (var i = 0; i < 10000; ++i) {
        console.log("adding row " + i);
        instance.execute('INSERT OR IGNORE INTO testtable(id) VALUES (' + i + ');');
    }
}

function insert() {
    console.log("insert");
    var dataToInsertHandle = instance.execute('SELECT id FROM testtable ORDER BY id DESC LIMIT 1;');
    var dataToInsert = null;
    if (dataToInsertHandle.isValidRow()) {
        dataToInsert = (dataToInsertHandle.fieldByName('id') + 1);
        dataTofetch = dataToInsert;
    }
    instance.execute('INSERT OR IGNORE INTO testtable(id) VALUES (' + dataToInsert + ');');

    for (var i = dataToInsert; i < dataToInsert + 10000; ++i) {
        console.log("adding row " + i);
        instance.execute('INSERT OR IGNORE INTO testtable(id) VALUES (' + i + ');');
    }
}

function fetch() {
    console.log("read");
    var rowValue = null;
    for (var i = 0; i < 10000; ++i) {
        var dataTofetch = Math.round(Math.random() * 10000);
        var rowHandle = instance.execute('SELECT * FROM testtable WHERE id=' + dataTofetch + ';');
        if (rowHandle.isValidRow()) {
            rowValue = rowHandle.fieldByName('id');
            console.log("got value: " + rowValue);
        }
    }
}

function closeDB() {
    instance.close();
}
win.add(lbl);
win.open();