Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public openDB(){
let instance= this;
//CHECK IF IT EXISTS AND IF ITS OPEN
if(Sqlite.exists("MyDB")){
if(instance.db.isOpen()){
console.log("DB is already open!");
instance.info = "DB is already open!";
} else {
var db_promise = new Sqlite("MyDB", false, (err, db)=>{
if (err) {
console.error("We failed to open database", err);
instance.info = "We failed to open database " + err;
} else {
console.log("Are we open yet (Inside Callback)? ", db.isOpen() ? "Yes" : "No"); // Yes
instance.info = "DB opened";
instance.db = db;
}
});
}
exports.pageLoaded = function(args) {
page = args.object;
page.bindingContext = {names: data};
if (!sqlite.exists(dbname)) {
sqlite.copyDatabase(dbname);
}
new sqlite(dbname, {key: 'testing', multithreading: !!sqlite.HAS_COMMERCIAL, migrate: true}, function(err, dbConnection) {
if (err) {
console.log(err, err.stack);
}
db = dbConnection;
db.resultType(sqlite.RESULTSASOBJECT);
db.version().then(function (results) {
console.log("User Version: ", results, typeof results, Number.isNumber(results)); //, String.isString(results));
});
if (sqlite.HAS_ENCRYPTION) {
db.get("PRAGMA cipher_version;").then(function(results) {
console.log("Cipher version", results['cipher_version']);
public closeDB(){
let instance = this;
//CHECK IF IT EXISTS AND IF ITS OPEN
if(Sqlite.exists("MyDB")){
if(this.db.isOpen()){
this.db.close((err)=>{
if(err){
console.log("We failed to close database");
} else {
console.log("DB closed");
instance.info = "DB closed";
}
})
} else {
console.log("DB is already closed!");
instance.info = "DB is already closed!";
}
} else {
console.log("DB doesn't exist");
function onCreateConnection(fn, scope) {
consoleLogMsg("db.service", "createConnection");
if (!Sqlite.exists(dbFile)) {
Sqlite.copyDatabase(dbFile);
}
dbPromise = new Sqlite(dbName, function (err, dbConnection) {
if (err) {
console.error(err);
} else {
dbConnection.resultType(Sqlite.RESULTSASOBJECT);
if (typeof fn === "function") {
if (scope) {
fn.apply(scope, [dbConnection]);
} else {
fn(dbConnection);
}
}
dbConnection.close();
}
function AppComponent() {
if (!Sqlite.exists("highscore.db")) {
Sqlite.copyDatabase("highscore.db");
}
}
return AppComponent;
public constructor() {
if (!Sqlite.exists("highscore.db")) {
Sqlite.copyDatabase("highscore.db");
}
}