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Driver.js","sourcesContent":["import {AbstractSqliteDriver} from \"../sqlite-abstract/AbstractSqliteDriver\";\nimport {ReactNativeConnectionOptions} from \"./ReactNativeConnectionOptions\";\nimport {ReactNativeQueryRunner} from \"./ReactNativeQueryRunner\";\nimport {QueryRunner} from \"../../query-runner/QueryRunner\";\nimport {Connection} from \"../../connection/Connection\";\nimport {DriverOptionNotSetError} from \"../../error/DriverOptionNotSetError\";\nimport {DriverPackageNotInstalledError} from \"../../error/DriverPackageNotInstalledError\";\n\nexport class ReactNativeDriver extends AbstractSqliteDriver {\n    options: ReactNativeConnectionOptions;\n    \n    // -------------------------------------------------------------------------\n    // Constructor\n    // -------------------------------------------------------------------------\n\n    constructor(connection: Connection) {\n        super(connection);\n\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 ReactNativeQueryRunner(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 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 = require(\"react-native-sqlite-storage\");\n\n        } catch (e) {\n            throw new DriverPackageNotInstalledError(\"React-Native\", \"react-native-sqlite-storage\");\n        }\n    }\n}"],"sourceRoot":"../.."}