Search code examples
teleriknativescriptnativescript-telerik-ui

How can i use internal database from scratch


How can i using internal database for example (sqlite) for offline app in nativescript without using any plugin.

i'm searched every were how i can installed or used sqlite or other internal database for nativescript but i didn't have any answer.


Solution

  • Just like you would do with any code that you need to access the native APIs

    e.g. (JavaScript) Android example

    var query = "select sqlite_version() AS sqlite_version";
    var db = android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(":memory:", null);
    var cursor = db.rawQuery(query, null);
    var sqliteVersion = "";
    if (cursor.moveToNext()) {
        sqliteVersion = cursor.getString(0);
        console.log(sqliteVersion);
    }
    

    The API references for SQLite in Android here and that said you can now follow a basic Android database tutorial and implement it step by step in your NativeScript application using JavaScript or TypeScript

    Still, the plugin could provide all that wrapped in a ready-to-go functionality so unless you are lacking something it will be easier to use the nativescript-sqlite and avoid writing native code for Android and then for iOS.