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AE,IAAI;YAC9B,IAAI;gBACA,IAAM,oBAAkB,GAAG,KAAI,CAAC,MAAM,CAAC,YAAY,CAAC,KAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC3E;;;kBAGE;gBACF,oBAAkB,CAAC,WAAW,CAAC,UAAC,GAAQ;oBACpC,GAAG,CAAC,UAAU,CAAC,2BAA2B,EAAE,EAAE,EAAE,UAAC,CAAM,EAAE,MAAW;wBAChE,EAAE,CAAC,oBAAkB,CAAC,CAAC;oBAC3B,CAAC,EAAE,UAAC,CAAM,EAAE,GAAQ;wBAChB,IAAI,CAAC,EAAC,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAC,CAAC,CAAC;oBACvC,CAAC,CAAC,CAAC;gBACP,CAAC,EAAE,UAAC,GAAQ;oBACR,IAAI,CAAC,GAAG,CAAC,CAAC;gBACd,CAAC,CAAC,CAAC;aACN;YAAC,OAAO,KAAK,EAAE;gBACZ,IAAI,CAAC,KAAK,CAAC,CAAC;aACf;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACO,qCAAgB,GAA1B;QACI,IAAI;YACA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACpC;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,+DAA8B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SAC5D;IACL,CAAC;IACL,iBAAC;AAAD,CA1FA,AA0FC,CA1F+B,2CAAoB,GA0FnD;AA1FY,gCAAU","file":"ExpoDriver.js","sourcesContent":["import {AbstractSqliteDriver} from \"../sqlite-abstract/AbstractSqliteDriver\";\nimport {ExpoConnectionOptions} from \"./ExpoConnectionOptions\";\nimport {ExpoQueryRunner} from \"./ExpoQueryRunner\";\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 Expo: any;\n}\ndeclare const window: Window;\n\nexport class ExpoDriver extends AbstractSqliteDriver {\n options: ExpoConnectionOptions;\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 // 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 try {\n this.queryRunner = undefined;\n this.databaseConnection = undefined;\n ok();\n } catch (error) {\n fail(error);\n }\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 ExpoQueryRunner(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 try {\n const databaseConnection = this.sqlite.openDatabase(this.options.database);\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 */\n databaseConnection.transaction((tsx: any) => {\n tsx.executeSql(`PRAGMA foreign_keys = ON;`, [], (t: any, result: any) => {\n ok(databaseConnection);\n }, (t: any, err: any) => {\n fail({transaction: t, error: err});\n });\n }, (err: any) => {\n fail(err);\n });\n } catch (error) {\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.Expo.SQLite;\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"Expo\", \"expo\");\n }\n }\n}\n"],"sourceRoot":"../.."}
|