@nyffels/mynodeorm
Advanced tools
Comparing version 1.0.0-alpha110 to 1.0.0-alpha111
@@ -12,8 +12,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import mysql from 'mysql2/promise'; | ||
import { DeclarationStorage } from "../models/index.js"; | ||
export function setConnection() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
if (!isNil(global.connection)) { | ||
return; | ||
} | ||
global.connection = yield mysql.createConnection(process.env["Database"]); | ||
const declaration = DeclarationStorage.get().declaration; | ||
if (!declaration) { | ||
throw new Error("No declaration found."); | ||
} | ||
const options = declaration.getConnectionOptions(); | ||
global.connection = yield mysql.createConnection({ | ||
host: options.host, | ||
user: options.user, | ||
database: options.database, | ||
password: options.password, | ||
port: (_a = options.port) !== null && _a !== void 0 ? _a : 3306, | ||
timezone: 'Z', | ||
supportBigNumbers: true, | ||
bigNumberStrings: false, | ||
}); | ||
}); | ||
@@ -20,0 +36,0 @@ } |
@@ -21,6 +21,8 @@ import { propertyType } from "./property.models.js"; | ||
private _tables; | ||
private _options; | ||
get name(): string; | ||
get tables(): DatabaseTable<any>[]; | ||
getConnectionOptions(): ConnectionOptions; | ||
getTable<T = any>(name: string): DatabaseTable<T>; | ||
constructor(); | ||
constructor(options: ConnectionOptions); | ||
declareTable<T>(classObject: object, dbTableName?: string | null): DatabaseTable<T>; | ||
@@ -86,2 +88,9 @@ } | ||
} | ||
export interface ConnectionOptions { | ||
host: string; | ||
user: string; | ||
database: string; | ||
password: string; | ||
port?: number; | ||
} | ||
export {}; |
@@ -55,2 +55,5 @@ import { Factory } from "./factory.models.js"; | ||
} | ||
getConnectionOptions() { | ||
return this._options; | ||
} | ||
getTable(name) { | ||
@@ -63,5 +66,6 @@ const table = this._tables.find(t => t.name === name); | ||
} | ||
constructor( /* name: string = "default" // We currently restrict the library to one connection. the groundwork for multi declarations is laid, but not implemented compeletely. */) { | ||
constructor(options /* name: string = "default" // We currently restrict the library to one connection. the groundwork for multi declarations is laid, but not implemented compeletely. */) { | ||
this._tables = []; | ||
this._name = "default"; // name => See text above; | ||
this._options = options; | ||
DeclarationStorage.add(this); | ||
@@ -68,0 +72,0 @@ } |
{ | ||
"name": "@nyffels/mynodeorm", | ||
"version": "1.0.0-alpha110", | ||
"version": "1.0.0-alpha111", | ||
"description": "A full-fledged ORM framework for NodeJS and MySQL with develop friendly code aimed to handle database migrations, MySQL Query builder / helper and property mapping.", | ||
@@ -5,0 +5,0 @@ "private": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
166246
2554
1