Completed
Push — master ( d362a9...56faa4 )
by Mark
14s queued 11s
created

src/Store/Store.ts   A

Complexity

Total Complexity 12
Complexity/F 1.71

Size

Lines of Code 74
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 57
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 12
mnd 5
bc 5
fnc 7
bpm 0.7141
cpm 1.7142
noi 0

7 Functions

Rating   Name   Duplication   Size   Complexity  
A Store.add 0 3 1
A Store.useConnection 0 3 1
A Store.useConnections 0 6 1
A Store.use 0 4 2
A Store.connection 0 3 3
A Store.database 0 3 3
A Store.addConnection 0 3 1
1
import Database from "./Database.js";
2
import Table from "./Table.js";
3
import Connection from "./Connection";
4
import Index from "./Table/Index";
5
import {ConnectionInterface, DatabaseInterface, StoreInterface} from "../JeloquentInterfaces";
6
7
/**
8
 *
9
 */
10
class Store implements StoreInterface {
11
12
    classInstances: object;
13
14
    numberOfModelCreated: number;
15
16
    private connections: Map<string, ConnectionInterface>;
17
18
    private databases: Map<string, DatabaseInterface>;
19
20
    private useConnectionName: string;
21
22
    private useDatabase: string;
23
24
    constructor() {
25
        this.classInstances = {};
26
        this.databases = new Map();
27
        this.connections = new Map();
28
        this.numberOfModelCreated = 0;
29
        this.useDatabase = 'default';
30
        this.useConnectionName = 'default';
31
        globalThis.Store = this;
32
    }
33
34
    add(database: DatabaseInterface): void {
35
        this.databases.set(database.name, database);
36
    }
37
38
    addConnection(connection: ConnectionInterface, name = 'default'): void {
39
        this.connections.set(name, connection);
40
    }
41
42
    connection(): ConnectionInterface|null {
43
        return this.connections.get(this.useConnectionName) ?? null;
44
    }
45
46
    database(): DatabaseInterface|null {
47
        return this.databases.get(this.useDatabase) ?? null;
48
    }
49
50
    use(storeName = 'default'): void {
51
        this.useDatabase = storeName;
52
        this.databases.get(this.useDatabase)?.setIndexes();
53
    }
54
55
    useConnection(name = 'default'): void {
56
        this.useConnectionName = name;
57
    }
58
59
    /**
60
     * @deprecated
61
     */
62
    useConnections(name:string): void {
63
        this.useConnection(name);
64
    }
65
}
66
67
68
export {
69
    Store,
70
    Database,
71
    Table,
72
    Connection,
73
    Index,
74
};