diff --git a/src/common/FakerMethods.js b/src/common/FakerMethods.js index fe7c7ec4..e401fa11 100644 --- a/src/common/FakerMethods.js +++ b/src/common/FakerMethods.js @@ -134,7 +134,7 @@ export default class { { name: 'phoneNumberFormat', group: 'phone', types: ['string'] }, { name: 'phoneFormats', group: 'phone', types: ['string'] }, - { name: 'number', group: 'random', types: ['string', 'number'], params: ['min', 'max'] }, + { name: 'number', group: 'datatype', types: ['string', 'number'], params: ['min', 'max'] }, { name: 'float', group: 'random', types: ['string', 'float'], params: ['min', 'max'] }, { name: 'arrayElement', group: 'random', types: ['string'] }, { name: 'arrayElements', group: 'random', types: ['string'] }, diff --git a/src/main/libs/clients/PostgreSQLClient.js b/src/main/libs/clients/PostgreSQLClient.js index 8e5fa190..af9a4a56 100644 --- a/src/main/libs/clients/PostgreSQLClient.js +++ b/src/main/libs/clients/PostgreSQLClient.js @@ -1147,8 +1147,10 @@ export class PostgreSQLClient extends AntaresCore { */ async commitTab (tabUid) { const connection = this._connectionsToCommit.get(tabUid); - if (connection) - return await connection.query('COMMIT'); + if (connection) { + await connection.query('COMMIT'); + return this.destroyConnectionToCommit(tabUid); + } } /** @@ -1158,14 +1160,16 @@ export class PostgreSQLClient extends AntaresCore { */ async rollbackTab (tabUid) { const connection = this._connectionsToCommit.get(tabUid); - if (connection) - return await connection.query('ROLLBACK'); + if (connection) { + await connection.query('ROLLBACK'); + return this.destroyConnectionToCommit(tabUid); + } } destroyConnectionToCommit (tabUid) { const connection = this._connectionsToCommit.get(tabUid); if (connection) { - connection.destroy(); + connection.end(); this._connectionsToCommit.delete(tabUid); } } diff --git a/src/main/libs/clients/SQLiteClient.js b/src/main/libs/clients/SQLiteClient.js index 3b1e2407..1323434e 100644 --- a/src/main/libs/clients/SQLiteClient.js +++ b/src/main/libs/clients/SQLiteClient.js @@ -9,6 +9,7 @@ export class SQLiteClient extends AntaresCore { super(args); this._schema = null; + this._connectionsToCommit = new Map(); } _getTypeInfo (type) { @@ -21,7 +22,11 @@ export class SQLiteClient extends AntaresCore { * @memberof SQLiteClient */ async connect () { - this._connection = sqlite(this._params.databasePath, { + this._connection = this.getConnection(); + } + + getConnection () { + return sqlite(this._params.databasePath, { fileMustExist: true, readonly: this._params.readonly }); @@ -446,6 +451,40 @@ export class SQLiteClient extends AntaresCore { async killProcess () {} + /** + * + * @param {string} tabUid + * @returns {Promise} + */ + async commitTab (tabUid) { + const connection = this._connectionsToCommit.get(tabUid); + if (connection) { + connection.prepare('COMMIT').run(); + return this.destroyConnectionToCommit(tabUid); + } + } + + /** + * + * @param {string} tabUid + * @returns {Promise} + */ + async rollbackTab (tabUid) { + const connection = this._connectionsToCommit.get(tabUid); + if (connection) { + connection.prepare('ROLLBACK').run(); + return this.destroyConnectionToCommit(tabUid); + } + } + + destroyConnectionToCommit (tabUid) { + const connection = this._connectionsToCommit.get(tabUid); + if (connection) { + connection.close(); + this._connectionsToCommit.delete(tabUid); + } + } + /** * CREATE TABLE * @@ -666,6 +705,7 @@ export class SQLiteClient extends AntaresCore { details: false, split: true, comments: true, + autocommit: true, ...args }; @@ -679,7 +719,20 @@ export class SQLiteClient extends AntaresCore { .filter(Boolean) .map(q => q.trim()) : [sql]; - const connection = this._connection; + + let connection; + + if (!args.autocommit && args.tabUid) { // autocommit OFF + if (this._connectionsToCommit.has(args.tabUid)) + connection = this._connectionsToCommit.get(args.tabUid); + else { + connection = this.getConnection(); + connection.prepare('BEGIN TRANSACTION').run(); + this._connectionsToCommit.set(args.tabUid, connection); + } + } + else// autocommit ON + connection = this._connection; for (const query of queries) { if (!query) continue;