@spinajs/orm
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -11,4 +11,4 @@ import { QueryContext } from './interfaces'; | ||
abstract ping(): Promise<boolean>; | ||
abstract connect(): Promise<void>; | ||
abstract disconnect(): Promise<void>; | ||
abstract connect(): Promise<OrmDriver>; | ||
abstract disconnect(): Promise<OrmDriver>; | ||
abstract tableInfo(name: string, schema?: string): Promise<IColumnDescriptor[]>; | ||
@@ -15,0 +15,0 @@ resolve(container: IContainer): void; |
@@ -1,2 +0,4 @@ | ||
import { AsyncResolveStrategy, Container, IContainer } from "@spinajs/di"; | ||
import { Configuration } from '@spinajs/configuration'; | ||
import { AsyncResolveStrategy, Container } from "@spinajs/di"; | ||
import { Log } from "@spinajs/log"; | ||
import { ClassInfo } from "@spinajs/reflection"; | ||
@@ -11,7 +13,11 @@ import { OrmMigration } from "./interfaces"; | ||
Container: Container; | ||
private Log; | ||
private Configuration; | ||
protected Log: Log; | ||
protected Configuration: Configuration; | ||
migrateUp(name?: string): Promise<void>; | ||
reloadTableInfo(): Promise<void>; | ||
resolveAsync(container: IContainer): Promise<void>; | ||
resolveAsync(): Promise<void>; | ||
protected registerModel<T extends ModelBase<any>>(model: Class<T>): void; | ||
protected registerMigration<T extends OrmMigration>(migration: Class<T>): void; | ||
private createConnections; | ||
private applyModelMixins; | ||
} |
@@ -52,26 +52,39 @@ "use strict"; | ||
} | ||
async resolveAsync(container) { | ||
const connections = this.Configuration.get("db.connections", []); | ||
try { | ||
for (const c of connections) { | ||
const driver = container.resolve(c.Driver, [container, c]); | ||
if (!driver) { | ||
this.Log.warn(`No Orm driver was found for DB ${c.Driver}, connection: ${c.Name}`, lodash_1.default.pick(c, CFG_PROPS)); | ||
continue; | ||
} | ||
this.Connections.set(c.Name, driver); | ||
async resolveAsync() { | ||
await this.createConnections(); | ||
await this.reloadTableInfo(); | ||
this.applyModelMixins(); | ||
} | ||
registerModel(model) { | ||
this.Models.push({ | ||
file: `${model.name}.registered`, | ||
name: model.name, | ||
type: model, | ||
}); | ||
} | ||
registerMigration(migration) { | ||
this.Migrations.push({ | ||
file: `${migration.name}.registered`, | ||
name: migration.name, | ||
type: migration, | ||
}); | ||
} | ||
async createConnections() { | ||
const connections = await Promise.all(this.Configuration.get("db.connections", []) | ||
.map((c) => { | ||
return this.Container.resolve(c.Driver, [this.Container, c]); | ||
}) | ||
.filter(c => c !== null) | ||
.map(c => c.connect())); | ||
connections.forEach(c => { | ||
this.Connections.set(c.Options.Name, c); | ||
this.Log.info(`Found ORM driver ${c.Options.Name} with parameters ${lodash_1.default.pick(c.Options, CFG_PROPS)}`); | ||
}); | ||
} | ||
applyModelMixins() { | ||
this.Models.forEach((m) => { | ||
for (const mixin in model_1.MODEL_STATIC_MIXINS) { | ||
m.type[mixin] = (model_1.MODEL_STATIC_MIXINS[mixin]).bind(m.type); | ||
} | ||
await Promise.all(Array.from(this.Connections.values()).map((d) => { | ||
return d.connect(); | ||
})); | ||
for (const m of this.Models) { | ||
for (const mixin in model_1.MODEL_STATIC_MIXINS) { | ||
m.type[mixin] = (model_1.MODEL_STATIC_MIXINS[mixin]).bind(m.type); | ||
} | ||
} | ||
await this.reloadTableInfo(); | ||
} | ||
catch (err) { | ||
this.Log.error("Cannot initialize ORM module", err); | ||
} | ||
}); | ||
} | ||
@@ -78,0 +91,0 @@ } |
{ | ||
"name": "@spinajs/orm", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "SpinaJS Orm module", | ||
@@ -69,3 +69,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@spinajs/configuration": "^1.0.0", | ||
"@spinajs/configuration": "^1.0.4", | ||
"@spinajs/di": "^1.0.3", | ||
@@ -72,0 +72,0 @@ "@spinajs/exceptions": "^1.0.0", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
153812
2079