node-firebird-driver
Version:
Firebird Driver Interfaces for Node.js
46 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractClient = void 0;
/** AbstractClient implementation. */
class AbstractClient {
constructor() {
this.connected = true;
this.attachments = new Set();
}
/** Disposes this client's resources. */
async dispose() {
this.check();
try {
await Promise.all(Array.from(this.attachments).map((attachment) => attachment.disconnect()));
}
finally {
this.attachments.clear();
}
await this.internalDispose();
this.connected = false;
}
/** Connects to a database. */
async connect(uri, options) {
this.check();
const attachment = await this.internalConnect(uri, options || this.defaultConnectOptions);
this.attachments.add(attachment);
return attachment;
}
/** Creates a database. */
async createDatabase(uri, options) {
this.check();
const attachment = await this.internalCreateDatabase(uri, options || this.defaultCreateDatabaseOptions);
this.attachments.add(attachment);
return attachment;
}
get isValid() {
return !!this.connected;
}
check() {
if (!this.isValid) {
throw new Error('Client is already disposed.');
}
}
}
exports.AbstractClient = AbstractClient;
//# sourceMappingURL=client.js.map