@lucyjs/typeorm
Version:
lucyjs typeorm
74 lines (73 loc) • 3.12 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrmConfiguration = void 0;
const core_1 = require("@lucyjs/core");
const path_1 = __importDefault(require("path"));
const typeorm_1 = require("typeorm");
const error_1 = require("./error");
let OrmConfiguration = class OrmConfiguration {
async onInit() {
const { entities, ...config } = this.config;
const _entities = [...entities].map(item => path_1.default.resolve(process.cwd(), item));
const dataSource = new typeorm_1.DataSource({
...config,
entities: _entities,
logger: new (class {
logQuery() {
// throw new Error('Method not implemented.')
}
logQueryError(error) {
throw new error_1.DatabaseError(typeof error === 'string' ? error : error.message);
// throw new Error('Method not implemented.')
}
logQuerySlow() {
// throw new Error('Method not implemented.')
}
logSchemaBuild() {
// throw new Error('Method not implemented.')
}
logMigration() {
// throw new Error('Method not implemented.')
}
log() {
// throw new Error('Method not implemented.')
}
})(),
});
await dataSource
.initialize()
.then(() => { })
.catch(error => {
console.log(`连接失败: ${error}`);
});
}
onReady() {
// throw new Error('Method not implemented.')
}
};
exports.OrmConfiguration = OrmConfiguration;
__decorate([
(0, core_1.Config)('database'),
__metadata("design:type", Object)
], OrmConfiguration.prototype, "config", void 0);
__decorate([
(0, core_1.Init)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], OrmConfiguration.prototype, "onInit", null);
exports.OrmConfiguration = OrmConfiguration = __decorate([
(0, core_1.Configuration)()
], OrmConfiguration);