"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TypeormService", {
    enumerable: true,
    get: function() {
        return TypeormService;
    }
});
const _logger = require("../../handlers/logger");
const _datasource = require("../../data-source");
class TypeormService {
    loaded = false;
    dataSource;
    logger = new _logger.LoggerService(TypeormService.name);
    hasConnected() {
        if (!this.dataSource) {
            this.loadDataSources();
        }
        return this.dataSource.isInitialized ? 1 : 0;
    }
    getDataSource() {
        if (!this.dataSource) {
            this.loadDataSources();
        }
        return this.dataSource;
    }
    async createConnection() {
        const dataSource = this.loadDataSources();
        if (!dataSource.isInitialized) {
            const connection = await dataSource.initialize();
            await connection.runMigrations({
                transaction: "all"
            });
            this.logger.log("Typeorm connection initialized");
        } else {
            this.logger.log("Typeorm connection already initialized, skipping");
        }
        this.loaded = true;
    }
    loadDataSources() {
        this.dataSource = _datasource.AppDataSource;
        return this.dataSource;
    }
}

//# sourceMappingURL=typeorm.service.js.map