@adonisjs/lucid
Version:
SQL ORM built on top of Active Record pattern
50 lines (49 loc) • 1.42 kB
JavaScript
;
/*
* @adonisjs/lucid
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestsTruncator = void 0;
/**
* Migrator class to be used for testing.
*/
class TestsTruncator {
constructor(ace, connectionName) {
Object.defineProperty(this, "ace", {
enumerable: true,
configurable: true,
writable: true,
value: ace
});
Object.defineProperty(this, "connectionName", {
enumerable: true,
configurable: true,
writable: true,
value: connectionName
});
}
async runCommand(commandName, args = []) {
if (this.connectionName) {
args.push(`--connection=${this.connectionName}`);
}
const command = await this.ace.exec(commandName, args);
if (command.exitCode) {
if (command.error) {
throw command.error;
}
else {
throw new Error(`"${commandName}" failed`);
}
}
}
async run() {
await this.runCommand('migration:run', ['--compact-output']);
return () => this.runCommand('db:truncate');
}
}
exports.TestsTruncator = TestsTruncator;