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