@cheetah.js/orm 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/orm.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { ConnectionSettings, DriverInterface } from './driver/driver.interface';
2
+ import { LoggerService, Service } from '@cheetah.js/core';
3
+ import { SqlBuilder } from './SqlBuilder';
4
+
5
+ @Service()
6
+ export class Orm<T extends DriverInterface = DriverInterface> {
7
+ driverInstance: T;
8
+ static instance: Orm<any>
9
+ public connection: ConnectionSettings<T>
10
+
11
+ constructor(public logger: LoggerService) {
12
+ Orm.instance = this
13
+ }
14
+
15
+ static getInstance(): Orm<any> {
16
+ return Orm.instance
17
+ }
18
+
19
+ public setConnection(connection: ConnectionSettings<T>) {
20
+ this.connection = connection
21
+ // @ts-ignore
22
+ this.driverInstance = new this.connection.driver(connection)
23
+ }
24
+
25
+ createQueryBuilder<Model>(model: new() => Model): SqlBuilder<Model> {
26
+ return new SqlBuilder<Model>(model)
27
+ }
28
+
29
+ connect(): Promise<void> {
30
+ return this.driverInstance.connect()
31
+ }
32
+
33
+ disconnect(): Promise<void> {
34
+ return this.driverInstance.disconnect()
35
+ }
36
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,3 @@
1
+ export function getDefaultLength(type: string): number {
2
+ return null;
3
+ }