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2FtD","file":"CordovaDriver.js","sourcesContent":["import {AbstractSqliteDriver} from \"../sqlite-abstract/AbstractSqliteDriver\";\nimport {CordovaConnectionOptions} from \"./CordovaConnectionOptions\";\nimport {CordovaQueryRunner} from \"./CordovaQueryRunner\";\nimport {QueryRunner} from \"../../query-runner/QueryRunner\";\nimport {Connection} from \"../../connection/Connection\";\nimport {DriverOptionNotSetError} from \"../../error/DriverOptionNotSetError\";\nimport {DriverPackageNotInstalledError} from \"../../error/DriverPackageNotInstalledError\";\n\n// needed for typescript compiler\ninterface Window {\n    sqlitePlugin: any;\n}\n\ndeclare var window: Window;\n\nexport class CordovaDriver extends AbstractSqliteDriver {\n    options: CordovaConnectionOptions;\n    \n    // -------------------------------------------------------------------------\n    // Constructor\n    // -------------------------------------------------------------------------\n\n    constructor(connection: Connection) {\n        super(connection);\n\n        // this.connection = connection;\n        // this.options = connection.options as CordovaConnectionOptions;\n        this.database = this.options.database;\n\n        // validate options to make sure everything is set\n        if (!this.options.database)\n            throw new DriverOptionNotSetError(\"database\");\n\n        if (!this.options.location)\n            throw new DriverOptionNotSetError(\"location\");\n\n        // load sqlite package\n        this.loadDependencies();\n    }\n    \n\n    // -------------------------------------------------------------------------\n    // Public Methods\n    // -------------------------------------------------------------------------\n\n    /**\n     * Closes connection with database.\n     */\n    async disconnect(): Promise<void> {\n        return new Promise<void>((ok, fail) => {\n            this.queryRunner = undefined;\n            this.databaseConnection.close(ok, fail);\n        });\n    }\n    \n    /**\n     * Creates a query runner used to execute database queries.\n     */\n    createQueryRunner(mode: \"master\"|\"slave\" = \"master\"): QueryRunner {\n        if (!this.queryRunner)\n            this.queryRunner = new CordovaQueryRunner(this);\n\n        return this.queryRunner;\n    }\n    \n    // -------------------------------------------------------------------------\n    // Protected Methods\n    // -------------------------------------------------------------------------\n\n    /**\n     * Creates connection with the database.\n     */\n    protected createDatabaseConnection() {\n        return new Promise<void>((ok, fail) => {\n            const options = Object.assign({}, {\n                name: this.options.database,\n                location: this.options.location,\n            }, this.options.extra || {});\n\n            this.sqlite.openDatabase(options, (db: any) => {\n                const databaseConnection = db;\n\n                // we need to enable foreign keys in sqlite to make sure all foreign key related features\n                // working properly. this also makes onDelete to work with sqlite.\n                databaseConnection.executeSql(`PRAGMA foreign_keys = ON;`, [], (result: any) => {\n                    ok(databaseConnection);\n                }, (error: any) => {\n                    fail(error);\n                });\n            }, (error: any) => {\n                fail(error);\n            });\n        });\n    }\n\n    /**\n     * If driver dependency is not given explicitly, then try to load it via \"require\".\n     */\n    protected loadDependencies(): void {\n        try {\n            this.sqlite = window.sqlitePlugin;\n\n        } catch (e) {\n            throw new DriverPackageNotInstalledError(\"Cordova-SQLite\", \"cordova-sqlite-storage\");\n        }\n    }\n}"],"sourceRoot":"../.."}