File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const fs = require ( 'fs' )
4
+ const path = require ( 'path' )
5
+ const mongoose = require ( 'mongoose' )
6
+ const config = require ( 'config' )
7
+ const db = { }
8
+
9
+ mongoose . Promise = global . Promise
10
+ mongoose . connect ( config . get ( 'db.uri' ) , { useNewUrlParser : true } )
11
+
12
+ // import all file in this dir, except index.js
13
+ fs . readdirSync ( __dirname )
14
+ . filter ( function ( file ) {
15
+ return ( file . indexOf ( '.' ) !== 0 ) && ( file !== 'index.js' )
16
+ } )
17
+ . forEach ( function ( file ) {
18
+ var model = require ( path . join ( __dirname , file ) )
19
+ db [ model . modelName ] = model
20
+ } )
21
+
22
+ db . mongoose = mongoose
23
+ module . exports = db
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const mongoose = require ( 'mongoose' )
4
+ const Schema = mongoose . Schema
5
+
6
+ const Transaction = new Schema ( {
7
+ hash : {
8
+ type : String ,
9
+ index : true ,
10
+ unique : true
11
+ } ,
12
+ block : {
13
+ type : Number ,
14
+ index : true
15
+ } ,
16
+ fromAccount : {
17
+ type : String ,
18
+ index : true
19
+ } ,
20
+ toAccount : {
21
+ type : String ,
22
+ index : true
23
+ } ,
24
+ tokenAmount : {
25
+ type : Number
26
+ } ,
27
+ isProcess : {
28
+ type : Boolean
29
+ }
30
+ } , { timestamps : true } )
31
+
32
+ module . exports = mongoose . model ( 'Transaction' , Transaction )
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const mongoose = require ( 'mongoose' )
4
+ const Schema = mongoose . Schema
5
+
6
+ const Wallet = new Schema ( {
7
+ address : {
8
+ type : String ,
9
+ index : true ,
10
+ unique : true
11
+ } ,
12
+ balance : {
13
+ type : Number ,
14
+ index : true
15
+ } ,
16
+ transactionCount : {
17
+ type : Number ,
18
+ index : true
19
+ }
20
+ } , { timestamps : true } )
21
+
22
+ module . exports = mongoose . model ( 'Wallet' , Wallet )
You can’t perform that action at this time.
0 commit comments