typeorm 0.3.5-dev.ec27803 → 0.3.6-dev.1197d1d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/browser/common/DeepPartial.d.ts +2 -2
- package/browser/common/DeepPartial.js.map +1 -1
- package/browser/data-source/BaseDataSourceOptions.d.ts +1 -2
- package/browser/data-source/BaseDataSourceOptions.js.map +1 -1
- package/browser/decorator/options/ColumnOptions.d.ts +1 -0
- package/browser/decorator/options/ColumnOptions.js.map +1 -1
- package/browser/driver/cordova/CordovaDriver.js +1 -1
- package/browser/driver/cordova/CordovaDriver.js.map +1 -1
- package/browser/driver/cordova/CordovaQueryRunner.js +2 -2
- package/browser/driver/cordova/CordovaQueryRunner.js.map +1 -1
- package/browser/driver/expo/ExpoDriver.js +1 -1
- package/browser/driver/expo/ExpoDriver.js.map +1 -1
- package/browser/driver/expo/ExpoQueryRunner.js +2 -2
- package/browser/driver/expo/ExpoQueryRunner.js.map +1 -1
- package/browser/driver/nativescript/NativescriptDriver.js +1 -1
- package/browser/driver/nativescript/NativescriptDriver.js.map +1 -1
- package/browser/driver/react-native/ReactNativeDriver.js +1 -1
- package/browser/driver/react-native/ReactNativeDriver.js.map +1 -1
- package/browser/driver/sqlite/SqliteDriver.js +3 -3
- package/browser/driver/sqlite/SqliteDriver.js.map +1 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +2 -2
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/browser/driver/sqljs/SqljsDriver.js +1 -1
- package/browser/driver/sqljs/SqljsDriver.js.map +1 -1
- package/browser/index.d.ts +4 -0
- package/browser/index.js +3 -0
- package/browser/index.js.map +1 -1
- package/commands/CommandUtils.js +1 -1
- package/commands/CommandUtils.js.map +1 -1
- package/commands/InitCommand.js +1 -1
- package/commands/InitCommand.js.map +1 -1
- package/common/DeepPartial.d.ts +2 -2
- package/common/DeepPartial.js.map +1 -1
- package/data-source/BaseDataSourceOptions.d.ts +1 -2
- package/data-source/BaseDataSourceOptions.js.map +1 -1
- package/decorator/options/ColumnOptions.d.ts +1 -0
- package/decorator/options/ColumnOptions.js.map +1 -1
- package/driver/cordova/CordovaDriver.js +1 -1
- package/driver/cordova/CordovaDriver.js.map +1 -1
- package/driver/cordova/CordovaQueryRunner.js +2 -2
- package/driver/cordova/CordovaQueryRunner.js.map +1 -1
- package/driver/expo/ExpoDriver.js +1 -1
- package/driver/expo/ExpoDriver.js.map +1 -1
- package/driver/expo/ExpoQueryRunner.js +2 -2
- package/driver/expo/ExpoQueryRunner.js.map +1 -1
- package/driver/nativescript/NativescriptDriver.js +1 -1
- package/driver/nativescript/NativescriptDriver.js.map +1 -1
- package/driver/react-native/ReactNativeDriver.js +1 -1
- package/driver/react-native/ReactNativeDriver.js.map +1 -1
- package/driver/sqlite/SqliteDriver.js +3 -3
- package/driver/sqlite/SqliteDriver.js.map +1 -1
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +2 -2
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/driver/sqljs/SqljsDriver.js +1 -1
- package/driver/sqljs/SqljsDriver.js.map +1 -1
- package/index.d.ts +4 -0
- package/index.js +3 -0
- package/index.js.map +1 -1
- package/index.mjs +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1277,6 +1277,7 @@ There are several extensions that simplify working with TypeORM and integrating
|
|
|
1277
1277
|
- ER Diagram generator - [typeorm-uml](https://github.com/eugene-manuilov/typeorm-uml/)
|
|
1278
1278
|
- another ER Diagram generator - [erdia](https://www.npmjs.com/package/erdia/)
|
|
1279
1279
|
- Create/Drop database - [typeorm-extension](https://github.com/Tada5hi/typeorm-extension)
|
|
1280
|
+
- Automatically update `data-source.ts` after generating migrations/entities - [typeorm-codebase-sync](https://www.npmjs.com/package/typeorm-codebase-sync)
|
|
1280
1281
|
|
|
1281
1282
|
## Contributing
|
|
1282
1283
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Same as Partial<T> but goes deeper and makes Partial<T> all its properties and sub-properties.
|
|
3
3
|
*/
|
|
4
|
-
export declare type DeepPartial<T> = T extends Array<infer U> ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? {
|
|
4
|
+
export declare type DeepPartial<T> = T | (T extends Array<infer U> ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? {
|
|
5
5
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
6
|
-
} : T;
|
|
6
|
+
} : T);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/common/DeepPartial.ts"],"names":[],"mappings":"","file":"DeepPartial.js","sourcesContent":["/**\n * Same as Partial<T> but goes deeper and makes Partial<T> all its properties and sub-properties.\n */\nexport type DeepPartial<T>
|
|
1
|
+
{"version":3,"sources":["../browser/src/common/DeepPartial.ts"],"names":[],"mappings":"","file":"DeepPartial.js","sourcesContent":["/**\n * Same as Partial<T> but goes deeper and makes Partial<T> all its properties and sub-properties.\n */\nexport type DeepPartial<T> =\n | T\n | (T extends Array<infer U>\n ? DeepPartial<U>[]\n : T extends Map<infer K, infer V>\n ? Map<DeepPartial<K>, DeepPartial<V>>\n : T extends Set<infer M>\n ? Set<DeepPartial<M>>\n : T extends object\n ? { [K in keyof T]?: DeepPartial<T[K]> }\n : T)\n"],"sourceRoot":".."}
|
|
@@ -35,8 +35,7 @@ export interface BaseDataSourceOptions {
|
|
|
35
35
|
readonly subscribers?: MixedList<Function | string>;
|
|
36
36
|
/**
|
|
37
37
|
* Migrations to be loaded for this connection.
|
|
38
|
-
* Accepts both migration classes and
|
|
39
|
-
* Directories support glob patterns.
|
|
38
|
+
* Accepts both migration classes and glob patterns representing migration files.
|
|
40
39
|
*/
|
|
41
40
|
readonly migrations?: MixedList<Function | string>;
|
|
42
41
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/data-source/BaseDataSourceOptions.ts"],"names":[],"mappings":"","file":"BaseDataSourceOptions.js","sourcesContent":["import { EntitySchema } from \"../entity-schema/EntitySchema\"\nimport { LoggerOptions } from \"../logger/LoggerOptions\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { DatabaseType } from \"../driver/types/DatabaseType\"\nimport { Logger } from \"../logger/Logger\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { MixedList } from \"../common/MixedList\"\n\n/**\n * BaseDataSourceOptions is set of DataSourceOptions shared by all database types.\n */\nexport interface BaseDataSourceOptions {\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n *\n * @deprecated\n */\n readonly name?: string\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: MixedList<Function | string | EntitySchema>\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: MixedList<Function | string>\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and
|
|
1
|
+
{"version":3,"sources":["../browser/src/data-source/BaseDataSourceOptions.ts"],"names":[],"mappings":"","file":"BaseDataSourceOptions.js","sourcesContent":["import { EntitySchema } from \"../entity-schema/EntitySchema\"\nimport { LoggerOptions } from \"../logger/LoggerOptions\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { DatabaseType } from \"../driver/types/DatabaseType\"\nimport { Logger } from \"../logger/Logger\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { MixedList } from \"../common/MixedList\"\n\n/**\n * BaseDataSourceOptions is set of DataSourceOptions shared by all database types.\n */\nexport interface BaseDataSourceOptions {\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n *\n * @deprecated\n */\n readonly name?: string\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: MixedList<Function | string | EntitySchema>\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: MixedList<Function | string>\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and glob patterns representing migration files.\n */\n readonly migrations?: MixedList<Function | string>\n\n /**\n * Migrations table name, in case of different name from \"migrations\".\n * Accepts single string name.\n */\n readonly migrationsTableName?: string\n\n /**\n * Transaction mode for migrations to run in\n */\n readonly migrationsTransactionMode?: \"all\" | \"none\" | \"each\"\n\n /**\n * Typeorm metadata table name, in case of different name from \"typeorm_metadata\".\n * Accepts single string name.\n */\n readonly metadataTableName?: string\n\n /**\n * Naming strategy to be used to name tables and columns in the database.\n */\n readonly namingStrategy?: NamingStrategyInterface\n\n /**\n * Logging options.\n */\n readonly logging?: LoggerOptions\n\n /**\n * Logger instance used to log queries and events in the ORM.\n */\n readonly logger?:\n | \"advanced-console\"\n | \"simple-console\"\n | \"file\"\n | \"debug\"\n | Logger\n\n /**\n * Maximum number of milliseconds query should be executed before logger log a warning.\n */\n readonly maxQueryExecutionTime?: number\n\n /**\n * Indicates if database schema should be auto created on every application launch.\n * Be careful with this option and don't use this in production - otherwise you can lose production data.\n * This option is useful during debug and development.\n * Alternative to it, you can use CLI and run schema:sync command.\n *\n * Note that for MongoDB database it does not create schema, because MongoDB is schemaless.\n * Instead, it syncs just by creating indices.\n */\n readonly synchronize?: boolean\n\n /**\n * Indicates if migrations should be auto run on every application launch.\n * Alternative to it, you can use CLI and run migrations:run command.\n */\n readonly migrationsRun?: boolean\n\n /**\n * Drops the schema each time connection is being established.\n * Be careful with this option and don't use this in production - otherwise you'll lose all production data.\n * This option is useful during debug and development.\n */\n readonly dropSchema?: boolean\n\n /**\n * Prefix to use on all tables (collections) of this connection in the database.\n */\n readonly entityPrefix?: string\n\n /**\n * When creating new Entity instances, skip all constructors when true.\n */\n readonly entitySkipConstructor?: boolean\n\n /**\n * Extra connection options to be passed to the underlying driver.\n *\n * todo: deprecate this and move all database-specific types into hts own connection options object.\n */\n readonly extra?: any\n\n /**\n * Specifies how relations must be loaded - using \"joins\" or separate queries.\n * If you are loading too much data with nested joins it's better to load relations\n * using separate queries.\n *\n * Default strategy is \"join\", but this default can be changed here.\n * Also, strategy can be set per-query in FindOptions and QueryBuilder.\n */\n readonly relationLoadStrategy?: \"join\" | \"query\"\n\n /**\n * Optionally applied \"typename\" to the model.\n * If set, then each hydrated model will have this property with the target model / entity name inside.\n *\n * (works like a discriminator property).\n */\n readonly typename?: string\n\n /**\n * Holds reference to the baseDirectory where configuration file are expected.\n *\n * @internal\n */\n baseDirectory?: string\n\n /**\n * Allows to setup cache options.\n */\n readonly cache?:\n | boolean\n | {\n /**\n * Type of caching.\n *\n * - \"database\" means cached values will be stored in the separate table in database. This is default value.\n * - \"redis\" means cached values will be stored inside redis. You must provide redis connection options.\n */\n readonly type?:\n | \"database\"\n | \"redis\"\n | \"ioredis\"\n | \"ioredis/cluster\" // todo: add mongodb and other cache providers as well in the future\n\n /**\n * Factory function for custom cache providers that implement QueryResultCache.\n */\n readonly provider?: (connection: DataSource) => QueryResultCache\n\n /**\n * Configurable table name for \"database\" type cache.\n * Default value is \"query-result-cache\"\n */\n readonly tableName?: string\n\n /**\n * Used to provide redis connection options.\n */\n readonly options?: any\n\n /**\n * If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.\n */\n readonly alwaysEnabled?: boolean\n\n /**\n * Time in milliseconds in which cache will expire.\n * This can be setup per-query.\n * Default value is 1000 which is equivalent to 1 second.\n */\n readonly duration?: number\n\n /**\n * Used to specify if cache errors should be ignored, and pass through the call to the Database.\n */\n readonly ignoreErrors?: boolean\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/decorator/options/ColumnOptions.ts"],"names":[],"mappings":"","file":"ColumnOptions.js","sourcesContent":["import { ColumnType } from \"../../driver/types/ColumnTypes\"\nimport { ValueTransformer } from \"./ValueTransformer\"\nimport { ColumnCommonOptions } from \"./ColumnCommonOptions\"\n\n/**\n * Describes all column's options.\n */\nexport interface ColumnOptions extends ColumnCommonOptions {\n /**\n * Column type. Must be one of the value from the ColumnTypes class.\n */\n type?: ColumnType\n\n /**\n * Column name in the database.\n */\n name?: string\n\n /**\n * Column type's length. Used only on some column types.\n * For example type = \"string\" and length = \"100\" means that ORM will create a column with type varchar(100).\n */\n length?: string | number\n\n /**\n * Column type's display width. Used only on some column types in MySQL.\n * For example, INT(4) specifies an INT with a display width of four digits.\n */\n width?: number\n\n /**\n * Indicates if column's value can be set to NULL.\n */\n nullable?: boolean\n\n /**\n * Indicates if column value is not updated by \"save\" operation.\n * It means you'll be able to write this value only when you first time insert the object.\n * Default value is \"false\".\n *\n * @deprecated Please use the `update` option instead. Careful, it takes\n * the opposite value to readonly.\n *\n */\n readonly?: boolean\n\n /**\n * Indicates if column value is updated by \"save\" operation.\n * If false, you'll be able to write this value only when you first time insert the object.\n * Default value is \"true\".\n */\n update?: boolean\n\n /**\n * Indicates if column is always selected by QueryBuilder and find operations.\n * Default value is \"true\".\n */\n select?: boolean\n\n /**\n * Indicates if column is inserted by default.\n * Default value is \"true\".\n */\n insert?: boolean\n\n /**\n * Default database value.\n */\n default?: any\n\n /**\n * ON UPDATE trigger. Works only for MySQL.\n */\n onUpdate?: string\n\n /**\n * Indicates if this column is a primary key.\n * Same can be achieved when @PrimaryColumn decorator is used.\n */\n primary?: boolean\n\n /**\n * Specifies if column's value must be unique or not.\n */\n unique?: boolean\n\n /**\n * Column comment. Not supported by all database types.\n */\n comment?: string\n\n /**\n * The precision for a decimal (exact numeric) column (applies only for decimal column), which is the maximum\n * number of digits that are stored for the values.\n */\n precision?: number | null\n\n /**\n * The scale for a decimal (exact numeric) column (applies only for decimal column), which represents the number\n * of digits to the right of the decimal point and must not be greater than precision.\n */\n scale?: number\n\n /**\n * Puts ZEROFILL attribute on to numeric column. Works only for MySQL.\n * If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to this column\n */\n zerofill?: boolean\n\n /**\n * Puts UNSIGNED attribute on to numeric column. Works only for MySQL.\n */\n unsigned?: boolean\n\n /**\n * Defines a column character set.\n * Not supported by all database types.\n */\n charset?: string\n\n /**\n * Defines a column collation.\n */\n collation?: string\n\n /**\n * Array of possible enumerated values.\n */\n enum?: (string | number)[] | Object\n /**\n * Exact name of enum\n */\n enumName?: string\n\n /**\n * Generated column expression. Supports only in MySQL.\n */\n asExpression?: string\n\n /**\n * Generated column type. Supports only in MySQL.\n */\n generatedType?: \"VIRTUAL\" | \"STORED\"\n\n /**\n * Identity column type. Supports only in Postgres 10+.\n */\n generatedIdentity?: \"ALWAYS\" | \"BY DEFAULT\"\n\n /**\n * Return type of HSTORE column.\n * Returns value as string or as object.\n */\n hstoreType?: \"object\" | \"string\"\n\n /**\n * Indicates if this column is an array.\n * Can be simply set to true or array length can be specified.\n * Supported only by postgres.\n */\n array?: boolean\n\n /**\n * Specifies a value transformer that is to be used to (un)marshal\n * this column when reading or writing to the database.\n */\n transformer?: ValueTransformer | ValueTransformer[]\n\n /**\n * Spatial Feature Type (Geometry, Point, Polygon, etc.)\n */\n spatialFeatureType?: string\n\n /**\n * SRID (Spatial Reference ID (EPSG code))\n */\n srid?: number\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/decorator/options/ColumnOptions.ts"],"names":[],"mappings":"","file":"ColumnOptions.js","sourcesContent":["import { ColumnType } from \"../../driver/types/ColumnTypes\"\nimport { ValueTransformer } from \"./ValueTransformer\"\nimport { ColumnCommonOptions } from \"./ColumnCommonOptions\"\n\n/**\n * Describes all column's options.\n */\nexport interface ColumnOptions extends ColumnCommonOptions {\n /**\n * Column type. Must be one of the value from the ColumnTypes class.\n */\n type?: ColumnType\n\n /**\n * Column name in the database.\n */\n name?: string\n\n /**\n * Column type's length. Used only on some column types.\n * For example type = \"string\" and length = \"100\" means that ORM will create a column with type varchar(100).\n */\n length?: string | number\n\n /**\n * Column type's display width. Used only on some column types in MySQL.\n * For example, INT(4) specifies an INT with a display width of four digits.\n */\n width?: number\n\n /**\n * Indicates if column's value can be set to NULL.\n * Default value is \"false\".\n */\n nullable?: boolean\n\n /**\n * Indicates if column value is not updated by \"save\" operation.\n * It means you'll be able to write this value only when you first time insert the object.\n * Default value is \"false\".\n *\n * @deprecated Please use the `update` option instead. Careful, it takes\n * the opposite value to readonly.\n *\n */\n readonly?: boolean\n\n /**\n * Indicates if column value is updated by \"save\" operation.\n * If false, you'll be able to write this value only when you first time insert the object.\n * Default value is \"true\".\n */\n update?: boolean\n\n /**\n * Indicates if column is always selected by QueryBuilder and find operations.\n * Default value is \"true\".\n */\n select?: boolean\n\n /**\n * Indicates if column is inserted by default.\n * Default value is \"true\".\n */\n insert?: boolean\n\n /**\n * Default database value.\n */\n default?: any\n\n /**\n * ON UPDATE trigger. Works only for MySQL.\n */\n onUpdate?: string\n\n /**\n * Indicates if this column is a primary key.\n * Same can be achieved when @PrimaryColumn decorator is used.\n */\n primary?: boolean\n\n /**\n * Specifies if column's value must be unique or not.\n */\n unique?: boolean\n\n /**\n * Column comment. Not supported by all database types.\n */\n comment?: string\n\n /**\n * The precision for a decimal (exact numeric) column (applies only for decimal column), which is the maximum\n * number of digits that are stored for the values.\n */\n precision?: number | null\n\n /**\n * The scale for a decimal (exact numeric) column (applies only for decimal column), which represents the number\n * of digits to the right of the decimal point and must not be greater than precision.\n */\n scale?: number\n\n /**\n * Puts ZEROFILL attribute on to numeric column. Works only for MySQL.\n * If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to this column\n */\n zerofill?: boolean\n\n /**\n * Puts UNSIGNED attribute on to numeric column. Works only for MySQL.\n */\n unsigned?: boolean\n\n /**\n * Defines a column character set.\n * Not supported by all database types.\n */\n charset?: string\n\n /**\n * Defines a column collation.\n */\n collation?: string\n\n /**\n * Array of possible enumerated values.\n */\n enum?: (string | number)[] | Object\n /**\n * Exact name of enum\n */\n enumName?: string\n\n /**\n * Generated column expression. Supports only in MySQL.\n */\n asExpression?: string\n\n /**\n * Generated column type. Supports only in MySQL.\n */\n generatedType?: \"VIRTUAL\" | \"STORED\"\n\n /**\n * Identity column type. Supports only in Postgres 10+.\n */\n generatedIdentity?: \"ALWAYS\" | \"BY DEFAULT\"\n\n /**\n * Return type of HSTORE column.\n * Returns value as string or as object.\n */\n hstoreType?: \"object\" | \"string\"\n\n /**\n * Indicates if this column is an array.\n * Can be simply set to true or array length can be specified.\n * Supported only by postgres.\n */\n array?: boolean\n\n /**\n * Specifies a value transformer that is to be used to (un)marshal\n * this column when reading or writing to the database.\n */\n transformer?: ValueTransformer | ValueTransformer[]\n\n /**\n * Spatial Feature Type (Geometry, Point, Polygon, etc.)\n */\n spatialFeatureType?: string\n\n /**\n * SRID (Spatial Reference ID (EPSG code))\n */\n srid?: number\n}\n"],"sourceRoot":"../.."}
|
|
@@ -56,7 +56,7 @@ export class CordovaDriver extends AbstractSqliteDriver {
|
|
|
56
56
|
await new Promise((ok, fail) => {
|
|
57
57
|
// we need to enable foreign keys in sqlite to make sure all foreign key related features
|
|
58
58
|
// working properly. this also makes onDelete to work with sqlite.
|
|
59
|
-
connection.executeSql(`PRAGMA foreign_keys = ON
|
|
59
|
+
connection.executeSql(`PRAGMA foreign_keys = ON`, [], () => ok(), (err) => fail(err));
|
|
60
60
|
});
|
|
61
61
|
return connection;
|
|
62
62
|
}
|
|
@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AAE,CAAC,EAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;QAC/D,CAAC,CAAC,CAAA;QAEF,MAAM,IAAI,OAAO,CAAO,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE;YACjC,yFAAyF;YACzF,kEAAkE;YAClE,UAAU,CAAC,UAAU,CACjB,0BAA0B,EAC1B,EAAE,EACF,GAAG,EAAE,CAAC,EAAE,EAAE,EACV,CAAC,GAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAC1B,CAAA;QACL,CAAC,CAAC,CAAA;QAEF,OAAO,UAAU,CAAA;IACrB,CAAC;IAED;;OAEG;IACO,gBAAgB;QACtB,IAAI;YACA,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,YAAY,CAAA;YACzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;SACvB;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,8BAA8B,CACpC,gBAAgB,EAChB,wBAAwB,CAC3B,CAAA;SACJ;IACL,CAAC;CACJ","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 { DataSource } from \"../../data-source/DataSource\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\n\n// needed for typescript compiler\ninterface Window {\n sqlitePlugin: any\n}\n\ndeclare let window: Window\n\nexport class CordovaDriver extends AbstractSqliteDriver {\n options: CordovaConnectionOptions\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\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 // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Closes connection with database.\n */\n async disconnect(): Promise<void> {\n this.queryRunner = undefined\n\n return new Promise<void>((ok, fail) => {\n this.databaseConnection.close(ok, fail)\n })\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner {\n if (!this.queryRunner) 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 async createDatabaseConnection() {\n const options = Object.assign(\n {},\n {\n name: this.options.database,\n location: this.options.location,\n },\n this.options.extra || {},\n )\n\n const connection = await new Promise<any>((resolve) => {\n this.sqlite.openDatabase(options, (db: any) => resolve(db))\n })\n\n await new Promise<void>((ok, fail) => {\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 connection.executeSql(\n `PRAGMA foreign_keys = ON`,\n [],\n () => ok(),\n (err: any) => fail(err),\n )\n })\n\n return connection\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 const sqlite = this.options.driver || window.sqlitePlugin\n this.sqlite = sqlite\n } catch (e) {\n throw new DriverPackageNotInstalledError(\n \"Cordova-SQLite\",\n \"cordova-sqlite-storage\",\n )\n }\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -131,7 +131,7 @@ export class CordovaQueryRunner extends AbstractSqliteQueryRunner {
|
|
|
131
131
|
* (because it can clear all your database).
|
|
132
132
|
*/
|
|
133
133
|
async clearDatabase() {
|
|
134
|
-
await this.query(`PRAGMA foreign_keys = OFF
|
|
134
|
+
await this.query(`PRAGMA foreign_keys = OFF`);
|
|
135
135
|
try {
|
|
136
136
|
const selectViewDropsQuery = `SELECT 'DROP VIEW "' || name || '";' as query FROM "sqlite_master" WHERE "type" = 'view'`;
|
|
137
137
|
const dropViewQueries = await this.query(selectViewDropsQuery);
|
|
@@ -141,7 +141,7 @@ export class CordovaQueryRunner extends AbstractSqliteQueryRunner {
|
|
|
141
141
|
await Promise.all(dropTableQueries.map((q) => this.query(q["query"])));
|
|
142
142
|
}
|
|
143
143
|
finally {
|
|
144
|
-
await this.query(`PRAGMA foreign_keys = ON
|
|
144
|
+
await this.query(`PRAGMA foreign_keys = ON`);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
// -------------------------------------------------------------------------
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/cordova/CordovaQueryRunner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAA;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,8CAA8C,CAAA;AAExF,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAE5D;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,yBAAyB;IAM7D,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,MAAqB;QAC7B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED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,sDAAsD,CACzD,CAAA;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,aAAa;QACf,MAAM,IAAI,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAA;QAC9C,IAAI;YACA,MAAM,oBAAoB,GAAG,0FAA0F,CAAA;YACvH,MAAM,eAAe,GAAoB,MAAM,IAAI,CAAC,KAAK,CACrD,oBAAoB,CACvB,CAAA;YAED,MAAM,qBAAqB,GAAG,4HAA4H,CAAA;YAC1J,MAAM,gBAAgB,GAAoB,MAAM,IAAI,CAAC,KAAK,CACtD,qBAAqB,CACxB,CAAA;YAED,MAAM,OAAO,CAAC,GAAG,CACb,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CACrD,CAAA;YACD,MAAM,OAAO,CAAC,GAAG,CACb,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CACtD,CAAA;SACJ;gBAAS;YACN,MAAM,IAAI,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAA;SAChD;IACL,CAAC;IAED,4EAA4E;IAC5E,oBAAoB;IACpB,4EAA4E;IAE5E;;OAEG;IACO,WAAW,CACjB,aAA4B,EAC5B,aAAqB,CAAC;QAEtB,OAAO,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,CAAA;IAC5E,CAAC;CACJ","file":"CordovaQueryRunner.js","sourcesContent":["import { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { CordovaDriver } from \"./CordovaDriver\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { TypeORMError } from \"../../error\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class CordovaQueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Database driver used by connection.\n */\n driver: CordovaDriver\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: CordovaDriver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n }\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = OFF`)\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = ON`)\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters?: any[],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n const databaseConnection = await this.connect()\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n\n try {\n const raw = await new Promise<any>(async (ok, fail) => {\n databaseConnection.executeSql(\n query,\n parameters,\n (raw: any) => ok(raw),\n (err: any) => fail(err),\n )\n })\n\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime = queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n ) {\n this.driver.connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n }\n\n const result = new QueryResult()\n\n if (query.substr(0, 11) === \"INSERT INTO\") {\n result.raw = raw.insertId\n } else {\n let resultSet = []\n for (let i = 0; i < raw.rows.length; i++) {\n resultSet.push(raw.rows.item(i))\n }\n\n result.records = resultSet\n result.raw = resultSet\n }\n\n if (useStructuredResult) {\n return result\n } else {\n return result.raw\n }\n } catch (err) {\n this.driver.connection.logger.logQueryError(\n err,\n query,\n parameters,\n this,\n )\n throw new QueryFailedError(query, parameters, err)\n }\n }\n\n /**\n * Insert a new row with given values into the given table.\n * Returns value of the generated column if given and generate column exist in the table.\n // todo: implement new syntax\n async insert(tableName: string, keyValues: ObjectLiteral): Promise<InsertResult> {\n const keys = Object.keys(keyValues);\n const columns = keys.map(key => `\"${key}\"`).join(\", \");\n const values = keys.map(key => \"?\").join(\",\");\n const generatedColumns = this.connection.hasMetadata(tableName) ? this.connection.getMetadata(tableName).generatedColumns : [];\n const sql = columns.length > 0 ? (`INSERT INTO \"${tableName}\"(${columns}) VALUES (${values})`) : `INSERT INTO \"${tableName}\" DEFAULT VALUES`;\n const parameters = keys.map(key => keyValues[key]);\n\n return new Promise<InsertResult>(async (ok, fail) => {\n this.driver.connection.logger.logQuery(sql, parameters, this);\n const __this = this;\n const databaseConnection = await this.connect();\n databaseConnection.executeSql(sql, parameters, (resultSet: any) => {\n const generatedMap = generatedColumns.reduce((map, generatedColumn) => {\n const value = generatedColumn.isPrimary && generatedColumn.generationStrategy === \"increment\" && resultSet.insertId ? resultSet.insertId : keyValues[generatedColumn.databaseName];\n if (!value) return map;\n return OrmUtils.mergeDeep(map, generatedColumn.createValueMap(value));\n }, {} as ObjectLiteral);\n\n ok({\n result: undefined,\n generatedMap: Object.keys(generatedMap).length > 0 ? generatedMap : undefined\n });\n }, (err: any) => {\n __this.driver.connection.logger.logQueryError(err, sql, parameters, this);\n fail(err);\n });\n });\n }*/\n\n /**\n * Would start a transaction but this driver does not support transactions.\n */\n async startTransaction(): Promise<void> {\n throw new TypeORMError(\n \"Transactions are not supported by the Cordova driver\",\n )\n }\n\n /**\n * Would start a transaction but this driver does not support transactions.\n */\n async commitTransaction(): Promise<void> {\n throw new TypeORMError(\n \"Transactions are not supported by the Cordova driver\",\n )\n }\n\n /**\n * Would start a transaction but this driver does not support transactions.\n */\n async rollbackTransaction(): Promise<void> {\n throw new TypeORMError(\n \"Transactions are not supported by the Cordova driver\",\n )\n }\n\n /**\n * Removes all tables from the currently connected database.\n * Be careful with using this method and avoid using it in production or migrations\n * (because it can clear all your database).\n */\n async clearDatabase(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = OFF;`)\n try {\n const selectViewDropsQuery = `SELECT 'DROP VIEW \"' || name || '\";' as query FROM \"sqlite_master\" WHERE \"type\" = 'view'`\n const dropViewQueries: ObjectLiteral[] = await this.query(\n selectViewDropsQuery,\n )\n\n const selectTableDropsQuery = `SELECT 'DROP TABLE \"' || name || '\";' as query FROM \"sqlite_master\" WHERE \"type\" = 'table' AND \"name\" != 'sqlite_sequence'`\n const dropTableQueries: ObjectLiteral[] = await this.query(\n selectTableDropsQuery,\n )\n\n await Promise.all(\n dropViewQueries.map((q) => this.query(q[\"query\"])),\n )\n await Promise.all(\n dropTableQueries.map((q) => this.query(q[\"query\"])),\n )\n } finally {\n await this.query(`PRAGMA foreign_keys = ON;`)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Parametrizes given object of values. Used to create column=value queries.\n */\n protected parametrize(\n objectLiteral: ObjectLiteral,\n startIndex: number = 0,\n ): string[] {\n return Object.keys(objectLiteral).map((key, index) => `\"${key}\"` + \"=?\")\n }\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/driver/cordova/CordovaQueryRunner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAA;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,8CAA8C,CAAA;AAExF,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;A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4B,EAC5B,aAAqB,CAAC;QAEtB,OAAO,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,CAAA;IAC5E,CAAC;CACJ","file":"CordovaQueryRunner.js","sourcesContent":["import { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { CordovaDriver } from \"./CordovaDriver\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { TypeORMError } from \"../../error\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class CordovaQueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Database driver used by connection.\n */\n driver: CordovaDriver\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: CordovaDriver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n }\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = OFF`)\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = ON`)\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters?: any[],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n const databaseConnection = await this.connect()\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n\n try {\n const raw = await new Promise<any>(async (ok, fail) => {\n databaseConnection.executeSql(\n query,\n parameters,\n (raw: any) => ok(raw),\n (err: any) => fail(err),\n )\n })\n\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime = queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n ) {\n this.driver.connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n }\n\n const result = new QueryResult()\n\n if (query.substr(0, 11) === \"INSERT INTO\") {\n result.raw = raw.insertId\n } else {\n let resultSet = []\n for (let i = 0; i < raw.rows.length; i++) {\n resultSet.push(raw.rows.item(i))\n }\n\n result.records = resultSet\n result.raw = resultSet\n }\n\n if (useStructuredResult) {\n return result\n } else {\n return result.raw\n }\n } catch (err) {\n this.driver.connection.logger.logQueryError(\n err,\n query,\n parameters,\n this,\n )\n throw new QueryFailedError(query, parameters, err)\n }\n }\n\n /**\n * Insert a new row with given values into the given table.\n * Returns value of the generated column if given and generate column exist in the table.\n // todo: implement new syntax\n async insert(tableName: string, keyValues: ObjectLiteral): Promise<InsertResult> {\n const keys = Object.keys(keyValues);\n const columns = keys.map(key => `\"${key}\"`).join(\", \");\n const values = keys.map(key => \"?\").join(\",\");\n const generatedColumns = this.connection.hasMetadata(tableName) ? this.connection.getMetadata(tableName).generatedColumns : [];\n const sql = columns.length > 0 ? (`INSERT INTO \"${tableName}\"(${columns}) VALUES (${values})`) : `INSERT INTO \"${tableName}\" DEFAULT VALUES`;\n const parameters = keys.map(key => keyValues[key]);\n\n return new Promise<InsertResult>(async (ok, fail) => {\n this.driver.connection.logger.logQuery(sql, parameters, this);\n const __this = this;\n const databaseConnection = await this.connect();\n databaseConnection.executeSql(sql, parameters, (resultSet: any) => {\n const generatedMap = generatedColumns.reduce((map, generatedColumn) => {\n const value = generatedColumn.isPrimary && generatedColumn.generationStrategy === \"increment\" && resultSet.insertId ? resultSet.insertId : keyValues[generatedColumn.databaseName];\n if (!value) return map;\n return OrmUtils.mergeDeep(map, generatedColumn.createValueMap(value));\n }, {} as ObjectLiteral);\n\n ok({\n result: undefined,\n generatedMap: Object.keys(generatedMap).length > 0 ? generatedMap : undefined\n });\n }, (err: any) => {\n __this.driver.connection.logger.logQueryError(err, sql, parameters, this);\n fail(err);\n });\n });\n }*/\n\n /**\n * Would start a transaction but this driver does not support transactions.\n */\n async startTransaction(): Promise<void> {\n throw new TypeORMError(\n \"Transactions are not supported by the Cordova driver\",\n )\n }\n\n /**\n * Would start a transaction but this driver does not support transactions.\n */\n async commitTransaction(): Promise<void> {\n throw new TypeORMError(\n \"Transactions are not supported by the Cordova driver\",\n )\n }\n\n /**\n * Would start a transaction but this driver does not support transactions.\n */\n async rollbackTransaction(): Promise<void> {\n throw new TypeORMError(\n \"Transactions are not supported by the Cordova driver\",\n )\n }\n\n /**\n * Removes all tables from the currently connected database.\n * Be careful with using this method and avoid using it in production or migrations\n * (because it can clear all your database).\n */\n async clearDatabase(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = OFF`)\n try {\n const selectViewDropsQuery = `SELECT 'DROP VIEW \"' || name || '\";' as query FROM \"sqlite_master\" WHERE \"type\" = 'view'`\n const dropViewQueries: ObjectLiteral[] = await this.query(\n selectViewDropsQuery,\n )\n\n const selectTableDropsQuery = `SELECT 'DROP TABLE \"' || name || '\";' as query FROM \"sqlite_master\" WHERE \"type\" = 'table' AND \"name\" != 'sqlite_sequence'`\n const dropTableQueries: ObjectLiteral[] = await this.query(\n selectTableDropsQuery,\n )\n\n await Promise.all(\n dropViewQueries.map((q) => this.query(q[\"query\"])),\n )\n await Promise.all(\n dropTableQueries.map((q) => this.query(q[\"query\"])),\n )\n } finally {\n await this.query(`PRAGMA foreign_keys = ON`)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Parametrizes given object of values. Used to create column=value queries.\n */\n protected parametrize(\n objectLiteral: ObjectLiteral,\n startIndex: number = 0,\n ): string[] {\n return Object.keys(objectLiteral).map((key, index) => `\"${key}\"` + \"=?\")\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -58,7 +58,7 @@ export class ExpoDriver extends AbstractSqliteDriver {
|
|
|
58
58
|
// working properly. this also makes onDelete work with sqlite.
|
|
59
59
|
*/
|
|
60
60
|
databaseConnection.transaction((tsx) => {
|
|
61
|
-
tsx.executeSql(`PRAGMA foreign_keys = ON
|
|
61
|
+
tsx.executeSql(`PRAGMA foreign_keys = ON`, [], (t, result) => {
|
|
62
62
|
ok(databaseConnection);
|
|
63
63
|
}, (t, err) => {
|
|
64
64
|
fail({ transaction: t, error: err });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/expo/ExpoDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAA;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAG7E,MAAM,OAAO,UAAW,SAAQ,oBAAoB;IAGhD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,UAAsB;QAC9B,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;QAErC,kDAAkD;QAClD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ;YACtB,MAAM,IAAI,uBAAuB,CAAC,UAAU,CAAC,CAAA;QAEjD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,MAAM,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAA;QAErE,sBAAsB;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;IACrC,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,UAAU;QACZ,OAAO,IAAI,OAAO,CA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C,YAAY,CAC/C,IAAI,CAAC,OAAO,CAAC,QAAQ,CACxB,CAAA;gBACD;;;kBAGE;gBACF,kBAAkB,CAAC,WAAW,CAC1B,CAAC,GAAQ,EAAE,EAAE;oBACT,GAAG,CAAC,UAAU,CACV,0BAA0B,EAC1B,EAAE,EACF,CAAC,CAAM,EAAE,MAAW,EAAE,EAAE;wBACpB,EAAE,CAAC,kBAAkB,CAAC,CAAA;oBAC1B,CAAC,EACD,CAAC,CAAM,EAAE,GAAQ,EAAE,EAAE;wBACjB,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;oBACxC,CAAC,CACJ,CAAA;gBACL,CAAC,EACD,CAAC,GAAQ,EAAE,EAAE;oBACT,IAAI,CAAC,GAAG,CAAC,CAAA;gBACb,CAAC,CACJ,CAAA;aACJ;YAAC,OAAO,KAAK,EAAE;gBACZ,IAAI,CAAC,KAAK,CAAC,CAAA;aACd;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","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 { DataSource } from \"../../data-source/DataSource\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\n\nexport class ExpoDriver extends AbstractSqliteDriver {\n options: ExpoConnectionOptions\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\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.driver) throw new DriverOptionNotSetError(\"driver\")\n\n // load sqlite package\n this.sqlite = this.options.driver\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._db.close()\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: ReplicationMode): QueryRunner {\n if (!this.queryRunner) 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(\n this.options.database,\n )\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(\n (tsx: any) => {\n tsx.executeSql(\n `PRAGMA foreign_keys = ON`,\n [],\n (t: any, result: any) => {\n ok(databaseConnection)\n },\n (t: any, err: any) => {\n fail({ transaction: t, error: err })\n },\n )\n },\n (err: any) => {\n fail(err)\n },\n )\n } catch (error) {\n fail(error)\n }\n })\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -94,7 +94,7 @@ export class ExpoQueryRunner extends AbstractSqliteQueryRunner {
|
|
|
94
94
|
async beforeMigration() {
|
|
95
95
|
const databaseConnection = await this.connect();
|
|
96
96
|
return new Promise((ok, fail) => {
|
|
97
|
-
databaseConnection.exec([{ sql: "PRAGMA foreign_keys = OFF
|
|
97
|
+
databaseConnection.exec([{ sql: "PRAGMA foreign_keys = OFF", args: [] }], false, (err) => (err ? fail(err) : ok()));
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
@@ -103,7 +103,7 @@ export class ExpoQueryRunner extends AbstractSqliteQueryRunner {
|
|
|
103
103
|
async afterMigration() {
|
|
104
104
|
const databaseConnection = await this.connect();
|
|
105
105
|
return new Promise((ok, fail) => {
|
|
106
|
-
databaseConnection.exec([{ sql: "PRAGMA foreign_keys = ON
|
|
106
|
+
databaseConnection.exec([{ sql: "PRAGMA foreign_keys = ON", args: [] }], false, (err) => (err ? fail(err) : ok()));
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/expo/ExpoQueryRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAA;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,8CAA8C,CAAA;AACxF,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAA;AAEnF,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAqB5D;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,yBAAyB;IAW1D,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,MAAkB;QAC1B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,gBAAgB;QAClB,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAA;QAC/B,IAAI;YACA,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAA;SAC7D;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAA;YAChC,MAAM,GAAG,CAAA;SACZ;QAED,IAAI,IAAI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,KAAK,CAAA;gBAChC,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;YAChC,CAAC,CACJ,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","file":"ExpoQueryRunner.js","sourcesContent":["import { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { TransactionNotStartedError } from \"../../error/TransactionNotStartedError\"\nimport { ExpoDriver } from \"./ExpoDriver\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n// Needed to satisfy the Typescript compiler\ninterface IResultSet {\n insertId: number | undefined\n rowsAffected: number\n rows: {\n length: number\n item: (idx: number) => any\n _array: any[]\n }\n}\ninterface ITransaction {\n executeSql: (\n sql: string,\n args: any[] | undefined,\n ok: (tsx: ITransaction, resultSet: IResultSet) => void,\n fail: (tsx: ITransaction, err: any) => void,\n ) => void\n}\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class ExpoQueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Database driver used by connection.\n */\n driver: ExpoDriver\n\n /**\n * Database transaction object\n */\n private transaction?: ITransaction\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: ExpoDriver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n }\n\n /**\n * Starts transaction. Within Expo, all database operations happen in a\n * transaction context, so issuing a `BEGIN TRANSACTION` command is\n * redundant and will result in the following error:\n *\n * `Error: Error code 1: cannot start a transaction within a transaction`\n *\n * Instead, we keep track of a `Transaction` object in `this.transaction`\n * and continue using the same object until we wish to commit the\n * transaction.\n */\n async startTransaction(): Promise<void> {\n this.isTransactionActive = true\n try {\n await this.broadcaster.broadcast(\"BeforeTransactionStart\")\n } catch (err) {\n this.isTransactionActive = false\n throw err\n }\n\n if (this.transactionDepth > 0) {\n await this.query(`SAVEPOINT typeorm_${this.transactionDepth}`)\n }\n this.transactionDepth += 1\n\n await this.broadcaster.broadcast(\"AfterTransactionStart\")\n }\n\n /**\n * Commits transaction.\n * Error will be thrown if transaction was not started.\n * Since Expo will automatically commit the transaction once all the\n * callbacks of the transaction object have been completed, \"committing\" a\n * transaction in this driver's context means that we delete the transaction\n * object and set the stage for the next transaction.\n */\n async commitTransaction(): Promise<void> {\n if (\n !this.isTransactionActive &&\n typeof this.transaction === \"undefined\"\n )\n throw new TransactionNotStartedError()\n\n await this.broadcaster.broadcast(\"BeforeTransactionCommit\")\n\n if (this.transactionDepth > 1) {\n await this.query(\n `RELEASE SAVEPOINT typeorm_${this.transactionDepth - 1}`,\n )\n } else {\n this.transaction = undefined\n this.isTransactionActive = false\n }\n this.transactionDepth -= 1\n\n await this.broadcaster.broadcast(\"AfterTransactionCommit\")\n }\n\n /**\n * Rollbacks transaction.\n * Error will be thrown if transaction was not started.\n * This method's functionality is identical to `commitTransaction()` because\n * the transaction lifecycle is handled within the Expo transaction object.\n * Issuing separate statements for `COMMIT` or `ROLLBACK` aren't necessary.\n */\n async rollbackTransaction(): Promise<void> {\n if (\n !this.isTransactionActive &&\n typeof this.transaction === \"undefined\"\n )\n throw new TransactionNotStartedError()\n\n await this.broadcaster.broadcast(\"BeforeTransactionRollback\")\n\n if (this.transactionDepth > 1) {\n await this.query(\n `ROLLBACK TO SAVEPOINT typeorm_${this.transactionDepth - 1}`,\n )\n } else {\n this.transaction = undefined\n this.isTransactionActive = false\n }\n this.transactionDepth -= 1\n\n await this.broadcaster.broadcast(\"AfterTransactionRollback\")\n }\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n const databaseConnection = await this.connect()\n return new Promise((ok, fail) => {\n databaseConnection.exec(\n [{ sql: \"PRAGMA foreign_keys = OFF;\", args: [] }],\n false,\n (err: any) => (err ? fail(err) : ok()),\n )\n })\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n const databaseConnection = await this.connect()\n return new Promise((ok, fail) => {\n databaseConnection.exec(\n [{ sql: \"PRAGMA foreign_keys = ON;\", args: [] }],\n false,\n (err: any) => (err ? fail(err) : ok()),\n )\n })\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters?: any[],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n return new Promise<any>(async (ok, fail) => {\n const databaseConnection = await this.connect()\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n // All Expo SQL queries are executed in a transaction context\n databaseConnection.transaction(\n async (transaction: ITransaction) => {\n if (typeof this.transaction === \"undefined\") {\n await this.startTransaction()\n this.transaction = transaction\n }\n this.transaction.executeSql(\n query,\n parameters,\n (t: ITransaction, raw: IResultSet) => {\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime =\n queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n ) {\n this.driver.connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n }\n\n const result = new QueryResult()\n\n // return id of inserted row, if query was insert statement.\n if (query.substr(0, 11) === \"INSERT INTO\") {\n result.raw = raw.insertId\n }\n\n if (raw?.hasOwnProperty(\"rowsAffected\")) {\n result.affected = raw.rowsAffected\n }\n\n if (raw?.hasOwnProperty(\"rows\")) {\n let resultSet = []\n for (let i = 0; i < raw.rows.length; i++) {\n resultSet.push(raw.rows.item(i))\n }\n\n result.raw = resultSet\n result.records = resultSet\n }\n\n if (useStructuredResult) {\n ok(result)\n } else {\n ok(result.raw)\n }\n },\n (t: ITransaction, err: any) => {\n this.driver.connection.logger.logQueryError(\n err,\n query,\n parameters,\n this,\n )\n fail(new QueryFailedError(query, parameters, err))\n },\n )\n },\n async (err: any) => {\n await this.rollbackTransaction()\n fail(err)\n },\n () => {\n this.isTransactionActive = false\n this.transaction = undefined\n },\n )\n })\n }\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/driver/expo/ExpoQueryRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAA;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,8CAA8C,CAAA;AACxF,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAA;AAEnF,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAqB5D;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,yBAAyB;IAW1D,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,MAAkB;QAC1B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,gBAAgB;QAClB,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAA;QAC/B,IAAI;YACA,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAA;SAC7D;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAA;YAChC,MAAM,GAAG,CAAA;SACZ;QAED,IAAI,IAAI,CAAC,gBAAgB,GAAG,CAAC,EAAE;YAC3B,MAAM,IAAI,CAAC,KAAK,CAAC,qBAAqB,IAAI,CAAC,gBAAgB,EA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A;IACN,CAAC;CACJ","file":"ExpoQueryRunner.js","sourcesContent":["import { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { TransactionNotStartedError } from \"../../error/TransactionNotStartedError\"\nimport { ExpoDriver } from \"./ExpoDriver\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n// Needed to satisfy the Typescript compiler\ninterface IResultSet {\n insertId: number | undefined\n rowsAffected: number\n rows: {\n length: number\n item: (idx: number) => any\n _array: any[]\n }\n}\ninterface ITransaction {\n executeSql: (\n sql: string,\n args: any[] | undefined,\n ok: (tsx: ITransaction, resultSet: IResultSet) => void,\n fail: (tsx: ITransaction, err: any) => void,\n ) => void\n}\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class ExpoQueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Database driver used by connection.\n */\n driver: ExpoDriver\n\n /**\n * Database transaction object\n */\n private transaction?: ITransaction\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: ExpoDriver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n }\n\n /**\n * Starts transaction. Within Expo, all database operations happen in a\n * transaction context, so issuing a `BEGIN TRANSACTION` command is\n * redundant and will result in the following error:\n *\n * `Error: Error code 1: cannot start a transaction within a transaction`\n *\n * Instead, we keep track of a `Transaction` object in `this.transaction`\n * and continue using the same object until we wish to commit the\n * transaction.\n */\n async startTransaction(): Promise<void> {\n this.isTransactionActive = true\n try {\n await this.broadcaster.broadcast(\"BeforeTransactionStart\")\n } catch (err) {\n this.isTransactionActive = false\n throw err\n }\n\n if (this.transactionDepth > 0) {\n await this.query(`SAVEPOINT typeorm_${this.transactionDepth}`)\n }\n this.transactionDepth += 1\n\n await this.broadcaster.broadcast(\"AfterTransactionStart\")\n }\n\n /**\n * Commits transaction.\n * Error will be thrown if transaction was not started.\n * Since Expo will automatically commit the transaction once all the\n * callbacks of the transaction object have been completed, \"committing\" a\n * transaction in this driver's context means that we delete the transaction\n * object and set the stage for the next transaction.\n */\n async commitTransaction(): Promise<void> {\n if (\n !this.isTransactionActive &&\n typeof this.transaction === \"undefined\"\n )\n throw new TransactionNotStartedError()\n\n await this.broadcaster.broadcast(\"BeforeTransactionCommit\")\n\n if (this.transactionDepth > 1) {\n await this.query(\n `RELEASE SAVEPOINT typeorm_${this.transactionDepth - 1}`,\n )\n } else {\n this.transaction = undefined\n this.isTransactionActive = false\n }\n this.transactionDepth -= 1\n\n await this.broadcaster.broadcast(\"AfterTransactionCommit\")\n }\n\n /**\n * Rollbacks transaction.\n * Error will be thrown if transaction was not started.\n * This method's functionality is identical to `commitTransaction()` because\n * the transaction lifecycle is handled within the Expo transaction object.\n * Issuing separate statements for `COMMIT` or `ROLLBACK` aren't necessary.\n */\n async rollbackTransaction(): Promise<void> {\n if (\n !this.isTransactionActive &&\n typeof this.transaction === \"undefined\"\n )\n throw new TransactionNotStartedError()\n\n await this.broadcaster.broadcast(\"BeforeTransactionRollback\")\n\n if (this.transactionDepth > 1) {\n await this.query(\n `ROLLBACK TO SAVEPOINT typeorm_${this.transactionDepth - 1}`,\n )\n } else {\n this.transaction = undefined\n this.isTransactionActive = false\n }\n this.transactionDepth -= 1\n\n await this.broadcaster.broadcast(\"AfterTransactionRollback\")\n }\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n const databaseConnection = await this.connect()\n return new Promise((ok, fail) => {\n databaseConnection.exec(\n [{ sql: \"PRAGMA foreign_keys = OFF\", args: [] }],\n false,\n (err: any) => (err ? fail(err) : ok()),\n )\n })\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n const databaseConnection = await this.connect()\n return new Promise((ok, fail) => {\n databaseConnection.exec(\n [{ sql: \"PRAGMA foreign_keys = ON\", args: [] }],\n false,\n (err: any) => (err ? fail(err) : ok()),\n )\n })\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters?: any[],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n return new Promise<any>(async (ok, fail) => {\n const databaseConnection = await this.connect()\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n // All Expo SQL queries are executed in a transaction context\n databaseConnection.transaction(\n async (transaction: ITransaction) => {\n if (typeof this.transaction === \"undefined\") {\n await this.startTransaction()\n this.transaction = transaction\n }\n this.transaction.executeSql(\n query,\n parameters,\n (t: ITransaction, raw: IResultSet) => {\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime =\n queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n ) {\n this.driver.connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n }\n\n const result = new QueryResult()\n\n // return id of inserted row, if query was insert statement.\n if (query.substr(0, 11) === \"INSERT INTO\") {\n result.raw = raw.insertId\n }\n\n if (raw?.hasOwnProperty(\"rowsAffected\")) {\n result.affected = raw.rowsAffected\n }\n\n if (raw?.hasOwnProperty(\"rows\")) {\n let resultSet = []\n for (let i = 0; i < raw.rows.length; i++) {\n resultSet.push(raw.rows.item(i))\n }\n\n result.raw = resultSet\n result.records = resultSet\n }\n\n if (useStructuredResult) {\n ok(result)\n } else {\n ok(result.raw)\n }\n },\n (t: ITransaction, err: any) => {\n this.driver.connection.logger.logQueryError(\n err,\n query,\n parameters,\n this,\n )\n fail(new QueryFailedError(query, parameters, err))\n },\n )\n },\n async (err: any) => {\n await this.rollbackTransaction()\n fail(err)\n },\n () => {\n this.isTransactionActive = false\n this.transaction = undefined\n },\n )\n })\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -72,7 +72,7 @@ export class NativescriptDriver extends AbstractSqliteDriver {
|
|
|
72
72
|
db.resultType(this.sqlite.RESULTSASOBJECT);
|
|
73
73
|
// we need to enable foreign keys in sqlite to make sure all foreign key related features
|
|
74
74
|
// working properly. this also makes onDelete work with sqlite.
|
|
75
|
-
db.execSQL(`PRAGMA foreign_keys = ON
|
|
75
|
+
db.execSQL(`PRAGMA foreign_keys = ON`, [], (err, result) => {
|
|
76
76
|
if (err)
|
|
77
77
|
return fail(err);
|
|
78
78
|
// We are all set
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/nativescript/NativescriptDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAA;AAE9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AAGnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAC7E,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAA;AAI3F;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,oBAAoB;IAiBxD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,UAAsB;QAC9B,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAwC,CAAA;QAClE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;QAEjC,kDAAkD;QAClD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACxB,MAAM,IAAI,uBAAuB,CAAC,UAAU,CAAC,CAAA;SAChD;QAED,sBAAsB;QACtB,IAAI,CAAC,gBAAgB,EA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AAC,YAAY;aAC1C,EACD,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAC3B,CAAA;YAED,IAAI,IAAI,CAAC,MAAM,CACX,IAAI,CAAC,OAAO,CAAC,QAAQ,EACrB,OAAO,EACP,CAAC,GAAU,EAAE,EAAO,EAAO,EAAE;gBACzB,IAAI,GAAG;oBAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;gBAEzB,uCAAuC;gBACvC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;gBAE1C,yFAAyF;gBACzF,+DAA+D;gBAC/D,EAAE,CAAC,OAAO,CACN,0BAA0B,EAC1B,EAAE,EACF,CAAC,GAAU,EAAE,MAAW,EAAO,EAAE;oBAC7B,IAAI,GAAG;wBAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;oBACzB,iBAAiB;oBACjB,EAAE,CAAC,EAAE,CAAC,CAAA;gBACV,CAAC,CACJ,CAAA;YACL,CAAC,CACJ,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED;;OAEG;IACO,gBAAgB;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QACzB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACd,MAAM,IAAI,8BAA8B,CACpC,cAAc,EACd,qBAAqB,CACxB,CAAA;SACJ;IACL,CAAC;CACJ","file":"NativescriptDriver.js","sourcesContent":["import { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\"\nimport { NativescriptConnectionOptions } from \"./NativescriptConnectionOptions\"\nimport { NativescriptQueryRunner } from \"./NativescriptQueryRunner\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { ColumnType } from \"../types/ColumnTypes\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\n\n/**\n * Organizes communication with sqlite DBMS within Nativescript.\n */\nexport class NativescriptDriver extends AbstractSqliteDriver {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: NativescriptConnectionOptions\n\n /**\n * Nativescript driver module\n * this is most likely `nativescript-sqlite`\n * but user can pass his own\n */\n driver: any\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\n super(connection)\n\n this.connection = connection\n this.options = connection.options as NativescriptConnectionOptions\n this.database = this.options.database\n this.driver = this.options.driver\n\n // validate options to make sure everything is set\n if (!this.options.database) {\n throw new DriverOptionNotSetError(\"database\")\n }\n\n // load sqlite package\n this.loadDependencies()\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().then(ok).catch(fail)\n })\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner {\n if (!this.queryRunner) {\n this.queryRunner = new NativescriptQueryRunner(this)\n }\n\n return this.queryRunner\n }\n\n normalizeType(column: {\n type?: ColumnType\n length?: number | string\n precision?: number | null\n scale?: number\n }): string {\n if ((column.type as any) === Buffer) {\n return \"blob\"\n }\n\n return super.normalizeType(column)\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 {},\n {\n readOnly: this.options.readOnly,\n key: this.options.key,\n multithreading: this.options.multithreading,\n migrate: this.options.migrate,\n iosFlags: this.options.iosFlags,\n androidFlags: this.options.androidFlags,\n },\n this.options.extra || {},\n )\n\n new this.sqlite(\n this.options.database,\n options,\n (err: Error, db: any): any => {\n if (err) return fail(err)\n\n // use object mode to work with TypeORM\n db.resultType(this.sqlite.RESULTSASOBJECT)\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 db.execSQL(\n `PRAGMA foreign_keys = ON`,\n [],\n (err: Error, result: any): any => {\n if (err) return fail(err)\n // We are all set\n ok(db)\n },\n )\n },\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 this.sqlite = this.driver\n if (!this.driver) {\n throw new DriverPackageNotInstalledError(\n \"Nativescript\",\n \"nativescript-sqlite\",\n )\n }\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -53,7 +53,7 @@ export class ReactNativeDriver extends AbstractSqliteDriver {
|
|
|
53
53
|
const databaseConnection = db;
|
|
54
54
|
// we need to enable foreign keys in sqlite to make sure all foreign key related features
|
|
55
55
|
// working properly. this also makes onDelete work with sqlite.
|
|
56
|
-
databaseConnection.executeSql(`PRAGMA foreign_keys = ON
|
|
56
|
+
databaseConnection.executeSql(`PRAGMA foreign_keys = ON`, [], (result) => {
|
|
57
57
|
ok(databaseConnection);
|
|
58
58
|
}, (error) => {
|
|
59
59
|
fail(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/react-native/ReactNativeDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAA;AAE9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAGjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAC7E,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAA;AAG3F,MAAM,OAAO,iBAAkB,SAAQ,oBAAoB;IAGvD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,UAAsB;QAC9B,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjB,IAAI,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CAAA;SACvB;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,8BAA8B,CACpC,cAAc,EACd,6BAA6B,CAChC,CAAA;SACJ;IACL,CAAC;CACJ","file":"ReactNativeDriver.js","sourcesContent":["import { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\"\nimport { ReactNativeConnectionOptions } from \"./ReactNativeConnectionOptions\"\nimport { ReactNativeQueryRunner } from \"./ReactNativeQueryRunner\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\n\nexport class ReactNativeDriver extends AbstractSqliteDriver {\n options: ReactNativeConnectionOptions\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\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 // 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: ReplicationMode): 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 {},\n {\n name: this.options.database,\n location: this.options.location,\n },\n this.options.extra || {},\n )\n\n this.sqlite.openDatabase(\n options,\n (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(\n `PRAGMA foreign_keys = ON`,\n [],\n (result: any) => {\n ok(databaseConnection)\n },\n (error: any) => {\n fail(error)\n },\n )\n },\n (error: any) => {\n fail(error)\n },\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 const sqlite =\n this.options.driver || require(\"react-native-sqlite-storage\")\n this.sqlite = sqlite\n } catch (e) {\n throw new DriverPackageNotInstalledError(\n \"React-Native\",\n \"react-native-sqlite-storage\",\n )\n }\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -104,14 +104,14 @@ export class SqliteDriver extends AbstractSqliteDriver {
|
|
|
104
104
|
// in the options, if encryption key for SQLCipher is setted.
|
|
105
105
|
// Must invoke key pragma before trying to do any other interaction with the database.
|
|
106
106
|
if (this.options.key) {
|
|
107
|
-
await run(`PRAGMA key = ${JSON.stringify(this.options.key)}
|
|
107
|
+
await run(`PRAGMA key = ${JSON.stringify(this.options.key)}`);
|
|
108
108
|
}
|
|
109
109
|
if (this.options.enableWAL) {
|
|
110
|
-
await run(`PRAGMA journal_mode = WAL
|
|
110
|
+
await run(`PRAGMA journal_mode = WAL`);
|
|
111
111
|
}
|
|
112
112
|
// we need to enable foreign keys in sqlite to make sure all foreign key related features
|
|
113
113
|
// working properly. this also makes onDelete to work with sqlite.
|
|
114
|
-
await run(`PRAGMA foreign_keys = ON
|
|
114
|
+
await run(`PRAGMA foreign_keys = ON`);
|
|
115
115
|
return databaseConnection;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/sqlite/SqliteDriver.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,IAA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,kBAAkB,CAAA;IAC7B,CAAC;IAED;;OAEG;IACO,gBAAgB;QACtB,IAAI;YACA,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YACnE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,CAAA;SACjC;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,8BAA8B,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;SAChE;IACL,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,uBAAuB,CAAC,QAAgB;QACpD,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;IACxC,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,eAAe;QAC3B,kIAAkI;QAClI,IAAI,KAAK,EAAE,MAAM,EACb,YAAY,EACZ,sBAAsB,GACzB,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE;YACxC,MAAM,IAAI,CAAC,uBAAuB,CAAC,sBAAsB,CAAC,CAAA;YAC1D,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CACvB,WAAW,sBAAsB,SAAS,YAAY,GAAG,CAC5D,CAAA;SACJ;IACL,CAAC;IAES,mBAAmB;QACzB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;QACvC,OAAO,IAAI,CAAC,OAAO,CACf,UAAU,CAAC,SAAS,CAAC;YACjB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,CAC5C,CAAA;IACL,CAAC;CACJ","file":"SqliteDriver.js","sourcesContent":["import mkdirp from \"mkdirp\"\nimport path from \"path\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { SqliteQueryRunner } from \"./SqliteQueryRunner\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { SqliteConnectionOptions } from \"./SqliteConnectionOptions\"\nimport { ColumnType } from \"../types/ColumnTypes\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { filepathToName, isAbsolute } from \"../../util/PathUtils\"\n\n/**\n * Organizes communication with sqlite DBMS.\n */\nexport class SqliteDriver extends AbstractSqliteDriver {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: SqliteConnectionOptions\n\n /**\n * SQLite underlying library.\n */\n sqlite: any\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\n super(connection)\n\n this.connection = connection\n this.options = connection.options as SqliteConnectionOptions\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 // 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((err: any) =>\n err ? fail(err) : ok(),\n )\n })\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner {\n if (!this.queryRunner) this.queryRunner = new SqliteQueryRunner(this)\n\n return this.queryRunner\n }\n\n normalizeType(column: {\n type?: ColumnType\n length?: number | string\n precision?: number | null\n scale?: number\n }): string {\n if ((column.type as any) === Buffer) {\n return \"blob\"\n }\n\n return super.normalizeType(column)\n }\n\n async afterConnect(): Promise<void> {\n return this.attachDatabases()\n }\n\n /**\n * For SQLite, the database may be added in the decorator metadata. It will be a filepath to a database file.\n */\n buildTableName(\n tableName: string,\n _schema?: string,\n database?: string,\n ): string {\n if (!database) return tableName\n if (this.getAttachedDatabaseHandleByRelativePath(database))\n return `${this.getAttachedDatabaseHandleByRelativePath(\n database,\n )}.${tableName}`\n\n if (database === this.options.database) return tableName\n\n // we use the decorated name as supplied when deriving attach handle (ideally without non-portable absolute path)\n const identifierHash = filepathToName(database)\n // decorated name will be assumed relative to main database file when non absolute. Paths supplied as absolute won't be portable\n const absFilepath = isAbsolute(database)\n ? database\n : path.join(this.getMainDatabasePath(), database)\n\n this.attachedDatabases[database] = {\n attachFilepathAbsolute: absFilepath,\n attachFilepathRelative: database,\n attachHandle: identifierHash,\n }\n\n return `${identifierHash}.${tableName}`\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n */\n protected async createDatabaseConnection() {\n await this.createDatabaseDirectory(this.options.database)\n\n const databaseConnection: any = await new Promise((ok, fail) => {\n const connection = new this.sqlite.Database(\n this.options.database,\n (err: any) => {\n if (err) return fail(err)\n ok(connection)\n },\n )\n })\n\n // Internal function to run a command on the connection and fail if an error occured.\n function run(line: string): Promise<void> {\n return new Promise((ok, fail) => {\n databaseConnection.run(line, (err: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n // in the options, if encryption key for SQLCipher is setted.\n // Must invoke key pragma before trying to do any other interaction with the database.\n if (this.options.key) {\n await run(`PRAGMA key = ${JSON.stringify(this.options.key)};`)\n }\n\n if (this.options.enableWAL) {\n await run(`PRAGMA journal_mode = WAL;`)\n }\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 await run(`PRAGMA foreign_keys = ON;`)\n\n return databaseConnection\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 const sqlite = this.options.driver || PlatformTools.load(\"sqlite3\")\n this.sqlite = sqlite.verbose()\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"SQLite\", \"sqlite3\")\n }\n }\n\n /**\n * Auto creates database directory if it does not exist.\n */\n protected async createDatabaseDirectory(fullPath: string): Promise<void> {\n await mkdirp(path.dirname(fullPath))\n }\n\n /**\n * Performs the attaching of the database files. The attachedDatabase should have been populated during calls to #buildTableName\n * during EntityMetadata production (see EntityMetadata#buildTablePath)\n *\n * https://sqlite.org/lang_attach.html\n */\n protected async attachDatabases() {\n // @todo - possibly check number of databases (but unqueriable at runtime sadly) - https://www.sqlite.org/limits.html#max_attached\n for await (const {\n attachHandle,\n attachFilepathAbsolute,\n } of Object.values(this.attachedDatabases)) {\n await this.createDatabaseDirectory(attachFilepathAbsolute)\n await this.connection.query(\n `ATTACH \"${attachFilepathAbsolute}\" AS \"${attachHandle}\"`,\n )\n }\n }\n\n protected getMainDatabasePath(): string {\n const optionsDb = this.options.database\n return path.dirname(\n isAbsolute(optionsDb)\n ? optionsDb\n : path.join(process.cwd(), optionsDb),\n )\n }\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/driver/sqlite/SqliteDriver.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAA;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAK5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAA;AAE9E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjE;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,oBAAoB;IAelD,4EAA4E;IAC5E,cAAc;IAC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QAAQ,CAAC,CAAC,CAAA;IACxC,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,eAAe;QAC3B,kIAAkI;QAClI,IAAI,KAAK,EAAE,MAAM,EACb,YAAY,EACZ,sBAAsB,GACzB,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE;YACxC,MAAM,IAAI,CAAC,uBAAuB,CAAC,sBAAsB,CAAC,CAAA;YAC1D,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CACvB,WAAW,sBAAsB,SAAS,YAAY,GAAG,CAC5D,CAAA;SACJ;IACL,CAAC;IAES,mBAAmB;QACzB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;QACvC,OAAO,IAAI,CAAC,OAAO,CACf,UAAU,CAAC,SAAS,CAAC;YACjB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,CAC5C,CAAA;IACL,CAAC;CACJ","file":"SqliteDriver.js","sourcesContent":["import mkdirp from \"mkdirp\"\nimport path from \"path\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { SqliteQueryRunner } from \"./SqliteQueryRunner\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { SqliteConnectionOptions } from \"./SqliteConnectionOptions\"\nimport { ColumnType } from \"../types/ColumnTypes\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { filepathToName, isAbsolute } from \"../../util/PathUtils\"\n\n/**\n * Organizes communication with sqlite DBMS.\n */\nexport class SqliteDriver extends AbstractSqliteDriver {\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: SqliteConnectionOptions\n\n /**\n * SQLite underlying library.\n */\n sqlite: any\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\n super(connection)\n\n this.connection = connection\n this.options = connection.options as SqliteConnectionOptions\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 // 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((err: any) =>\n err ? fail(err) : ok(),\n )\n })\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner {\n if (!this.queryRunner) this.queryRunner = new SqliteQueryRunner(this)\n\n return this.queryRunner\n }\n\n normalizeType(column: {\n type?: ColumnType\n length?: number | string\n precision?: number | null\n scale?: number\n }): string {\n if ((column.type as any) === Buffer) {\n return \"blob\"\n }\n\n return super.normalizeType(column)\n }\n\n async afterConnect(): Promise<void> {\n return this.attachDatabases()\n }\n\n /**\n * For SQLite, the database may be added in the decorator metadata. It will be a filepath to a database file.\n */\n buildTableName(\n tableName: string,\n _schema?: string,\n database?: string,\n ): string {\n if (!database) return tableName\n if (this.getAttachedDatabaseHandleByRelativePath(database))\n return `${this.getAttachedDatabaseHandleByRelativePath(\n database,\n )}.${tableName}`\n\n if (database === this.options.database) return tableName\n\n // we use the decorated name as supplied when deriving attach handle (ideally without non-portable absolute path)\n const identifierHash = filepathToName(database)\n // decorated name will be assumed relative to main database file when non absolute. Paths supplied as absolute won't be portable\n const absFilepath = isAbsolute(database)\n ? database\n : path.join(this.getMainDatabasePath(), database)\n\n this.attachedDatabases[database] = {\n attachFilepathAbsolute: absFilepath,\n attachFilepathRelative: database,\n attachHandle: identifierHash,\n }\n\n return `${identifierHash}.${tableName}`\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n */\n protected async createDatabaseConnection() {\n await this.createDatabaseDirectory(this.options.database)\n\n const databaseConnection: any = await new Promise((ok, fail) => {\n const connection = new this.sqlite.Database(\n this.options.database,\n (err: any) => {\n if (err) return fail(err)\n ok(connection)\n },\n )\n })\n\n // Internal function to run a command on the connection and fail if an error occured.\n function run(line: string): Promise<void> {\n return new Promise((ok, fail) => {\n databaseConnection.run(line, (err: any) => {\n if (err) return fail(err)\n ok()\n })\n })\n }\n // in the options, if encryption key for SQLCipher is setted.\n // Must invoke key pragma before trying to do any other interaction with the database.\n if (this.options.key) {\n await run(`PRAGMA key = ${JSON.stringify(this.options.key)}`)\n }\n\n if (this.options.enableWAL) {\n await run(`PRAGMA journal_mode = WAL`)\n }\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 await run(`PRAGMA foreign_keys = ON`)\n\n return databaseConnection\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 const sqlite = this.options.driver || PlatformTools.load(\"sqlite3\")\n this.sqlite = sqlite.verbose()\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"SQLite\", \"sqlite3\")\n }\n }\n\n /**\n * Auto creates database directory if it does not exist.\n */\n protected async createDatabaseDirectory(fullPath: string): Promise<void> {\n await mkdirp(path.dirname(fullPath))\n }\n\n /**\n * Performs the attaching of the database files. The attachedDatabase should have been populated during calls to #buildTableName\n * during EntityMetadata production (see EntityMetadata#buildTablePath)\n *\n * https://sqlite.org/lang_attach.html\n */\n protected async attachDatabases() {\n // @todo - possibly check number of databases (but unqueriable at runtime sadly) - https://www.sqlite.org/limits.html#max_attached\n for await (const {\n attachHandle,\n attachFilepathAbsolute,\n } of Object.values(this.attachedDatabases)) {\n await this.createDatabaseDirectory(attachFilepathAbsolute)\n await this.connection.query(\n `ATTACH \"${attachFilepathAbsolute}\" AS \"${attachHandle}\"`,\n )\n }\n }\n\n protected getMainDatabasePath(): string {\n const optionsDb = this.options.database\n return path.dirname(\n isAbsolute(optionsDb)\n ? optionsDb\n : path.join(process.cwd(), optionsDb),\n )\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -713,7 +713,7 @@ export class AbstractSqliteQueryRunner extends BaseQueryRunner {
|
|
|
713
713
|
dbPath =
|
|
714
714
|
this.driver.getAttachedDatabaseHandleByRelativePath(database);
|
|
715
715
|
}
|
|
716
|
-
await this.query(`PRAGMA foreign_keys = OFF
|
|
716
|
+
await this.query(`PRAGMA foreign_keys = OFF`);
|
|
717
717
|
const isAnotherTransactionActive = this.isTransactionActive;
|
|
718
718
|
if (!isAnotherTransactionActive)
|
|
719
719
|
await this.startTransaction();
|
|
@@ -741,7 +741,7 @@ export class AbstractSqliteQueryRunner extends BaseQueryRunner {
|
|
|
741
741
|
throw error;
|
|
742
742
|
}
|
|
743
743
|
finally {
|
|
744
|
-
await this.query(`PRAGMA foreign_keys = ON
|
|
744
|
+
await this.query(`PRAGMA foreign_keys = ON`);
|
|
745
745
|
}
|
|
746
746
|
}
|
|
747
747
|
// -------------------------------------------------------------------------
|