src/sqlite.ios.js
function Database(dbname, options, callback) {
    if (!this instanceof Database) { // jshint ignore:line
        //noinspection JSValidateTypes
        return new Database(dbname, options, callback);
    }
    this._isOpen = false;
    this._resultType = Database.RESULTSASARRAY;
    this._valuesType = Database.VALUESARENATIVE;

    if (typeof options === 'function') {
        callback = options;
        options = {};
    } else {
        options = options || {};
    }

    if (options && options.multithreading && typeof global.Worker === 'function') {
        delete options.multithreading;
        if (!Database.HAS_COMMERCIAL) {
            throw new Error("Commercial only feature; see http://nativescript.tools/product/10");
        }
        return new Database._multiSQL(dbname, options, callback);
    }

    // Check to see if it has a path, or if it is a relative dbname
    // DBNAME = "" - is a Temporary Database
    // DBNAME = ":memory:" - is a Memory only database
    if (dbname !== "" && dbname !== ":memory:") {
        let path;
        if (dbname.indexOf('/') === -1) {
            // noinspection JSUnresolvedVariable, JSUnresolvedFunction
            path = fs.knownFolders.documents().path;
            dbname = path + '/' + dbname;
        } else {
            path = dbname.substr(0, dbname.lastIndexOf('/') + 1);
        }

        // Create "databases" folder if it is missing.  This causes issues on Emulators if it is missing
        // So we create it if it is missing

        try {
            // noinspection JSUnresolvedVariable
            if (!fs.File.exists(path)) {
                //noinspection JSUnresolvedFunction
                const fileManager = iosProperty(NSFileManager, NSFileManager.defaultManager);
                //noinspection JSUnresolvedFunction
                if (!fileManager.createDirectoryAtPathWithIntermediateDirectoriesAttributesError(path, true, null, null)) {
                    console.warn("SQLITE.CONSTRUCTOR - Creating DB Folder Error");
                }
            }
        }
        catch (err) {
            console.warn("SQLITE.CONSTRUCTOR - Creating DB Folder Error", err);
        }
    }
    this._dbnamePtr = toCharPtr(dbname);
    const self = this;
    //noinspection JSUnresolvedFunction
    return new Promise(function (resolve, reject) {
        let error;
        try {
        	let flags = 0;
        	if (typeof options.iosFlags !== 'undefined') {
        		flags = options.iosFlags;
			}

            self._db = new interop.Reference();
            if (options && options.readOnly) {
                // SQLITE_OPEN_FULLMUTEX = 65536, SQLITE_OPEN_READONLY = 1 ---- 1 | 65536 = 65537
                error = sqlite3_open_v2(self._dbnamePtr, self._db, 65537 | flags, null);
            } else {
                // SQLITE_OPEN_FULLMUTEX = 65536, SQLITE_OPEN_CREATE = 4, SQLITE_OPEN_READWRITE = 2 --- 4 | 2 | 65536 = 65542
                error = sqlite3_open_v2(self._dbnamePtr, self._db, 65542 | flags, null);
            }
            self._db = self._db.value;
        } catch (err) {
            if (callback) { callback(err, null); }
            reject(err);
            return;
        }
        if (error) {
            if (callback) { callback(error, null); }
            reject(error);
            return;
        }

        self._isOpen = true;

        let doneCnt = _DatabasePluginInits.length, doneHandled = 0;
        const done = function(err) {
        	if (err) {
        		doneHandled = doneCnt;  // We don't want any more triggers after this
				if (callback) { callback(err, null); }
				reject(err);
        		return;
			}
			doneHandled++;
        	if (doneHandled === doneCnt) {
				if (callback) { callback(null, self); }
				resolve(self);
			}
		};

        if (doneCnt) {
        	try {
				for (let i = 0; i < doneCnt; i++) {
					_DatabasePluginInits[i].call(self, options, done);
				}
			} catch (err) {
        		done(err);
			}
		} else {
			if (callback) { callback(null, self); }
			resolve(self);
		}

    });
}
function Database(dbname, options, callback) {
    if (!this instanceof Database) { // jshint ignore:line
        //noinspection JSValidateTypes
        return new Database(dbname, options, callback);
    }
    this._isOpen = false;
    this._resultType = Database.RESULTSASARRAY;
    this._valuesType = Database.VALUESARENATIVE;

    if (typeof options === 'function') {
        callback = options;
        options = {};
    } else {
        options = options || {};
    }

    if (options && options.multithreading && typeof global.Worker === 'function') {
        delete options.multithreading;
        if (!Database.HAS_COMMERCIAL) {
            throw new Error("Commercial only feature; see http://nativescript.tools/product/10");
        }
        return new Database._multiSQL(dbname, options, callback);
    }

    // Check to see if it has a path, or if it is a relative dbname
    // DBNAME = "" - is a Temporary Database
    // DBNAME = ":memory:" - is a Memory only database
    if (dbname !== "" && dbname !== ":memory:") {
        let path;
        if (dbname.indexOf('/') === -1) {
            // noinspection JSUnresolvedVariable, JSUnresolvedFunction
            path = fs.knownFolders.documents().path;
            dbname = path + '/' + dbname;
        } else {
            path = dbname.substr(0, dbname.lastIndexOf('/') + 1);
        }

        // Create "databases" folder if it is missing.  This causes issues on Emulators if it is missing
        // So we create it if it is missing

        try {
            // noinspection JSUnresolvedVariable
            if (!fs.File.exists(path)) {
                //noinspection JSUnresolvedFunction
                const fileManager = iosProperty(NSFileManager, NSFileManager.defaultManager);
                //noinspection JSUnresolvedFunction
                if (!fileManager.createDirectoryAtPathWithIntermediateDirectoriesAttributesError(path, true, null, null)) {
                    console.warn("SQLITE.CONSTRUCTOR - Creating DB Folder Error");
                }
            }
        }
        catch (err) {
            console.warn("SQLITE.CONSTRUCTOR - Creating DB Folder Error", err);
        }
    }
    this._dbnamePtr = toCharPtr(dbname);
    const self = this;
    //noinspection JSUnresolvedFunction
    return new Promise(function (resolve, reject) {
        let error;
        try {
        	let flags = 0;
        	if (typeof options.iosFlags !== 'undefined') {
        		flags = options.iosFlags;
			}

            self._db = new interop.Reference();
            if (options && options.readOnly) {
                // SQLITE_OPEN_FULLMUTEX = 65536, SQLITE_OPEN_READONLY = 1 ---- 1 | 65536 = 65537
                error = sqlite3_open_v2(self._dbnamePtr, self._db, 65537 | flags, null);
            } else {
                // SQLITE_OPEN_FULLMUTEX = 65536, SQLITE_OPEN_CREATE = 4, SQLITE_OPEN_READWRITE = 2 --- 4 | 2 | 65536 = 65542
                error = sqlite3_open_v2(self._dbnamePtr, self._db, 65542 | flags, null);
            }
            self._db = self._db.value;
        } catch (err) {
            if (callback) { callback(err, null); }
            reject(err);
            return;
        }
        if (error) {
            if (callback) { callback(error, null); }
            reject(error);
            return;
        }

        self._isOpen = true;

        let doneCnt = _DatabasePluginInits.length, doneHandled = 0;
        const done = function(err) {
        	if (err) {
        		doneHandled = doneCnt;  // We don't want any more triggers after this
				if (callback) { callback(err, null); }
				reject(err);
        		return;
			}
			doneHandled++;
        	if (doneHandled === doneCnt) {
				if (callback) { callback(null, self); }
				resolve(self);
			}
		};

        if (doneCnt) {
        	try {
				for (let i = 0; i < doneCnt; i++) {
					_DatabasePluginInits[i].call(self, options, done);
				}
			} catch (err) {
        		done(err);
			}
		} else {
			if (callback) { callback(null, self); }
			resolve(self);
		}

    });
}
noinspection JSValidateJSDoc *
Database Constructor
@param dbname - Database Name
@param options - options
@param callback - Callback when Done
@returns {Promise} object
@constructor