UNPKG

922 BJavaScriptView Raw
1"use strict";
2
3const DAO = require("node-data-access-object");
4
5class Model {
6 get design() {
7 return {
8 type: "unset"
9 };
10 }
11
12 get connection() {
13 if(this._collection) {
14 return this._collection.connection;
15 }
16
17 return null;
18 }
19
20 get db() {
21 if(this._design) {
22 return this._design.db;
23 }
24 if(this._collection) {
25 return this._collection.db;
26 }
27 return null;
28 }
29
30 constructor() {
31 this._collection = null;
32 this._design = null;
33 }
34
35 createDesign() {
36 let design = this.design;
37
38 if(design.type !== "unset") {
39 this._design = new DAO.Design(this.design);
40 }
41
42 return this._design;
43 }
44
45 setCollection(collection) {
46 this._collection = collection;
47 }
48
49 static dbConnection(connectionName) {
50 return DAO.connection(connectionName);
51 }
52
53 static get prefix() {
54 return process.motif.context.prefix;
55 }
56}
57
58module.exports = Model;