-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbmgr.coffee
103 lines (82 loc) · 2.33 KB
/
dbmgr.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
class CBase
constructor: (@cname) ->
@coll = DbMgr.mdb().collection(@cname)
# if it exists, maybe log count() # else create
setUniqueIndex: (field) ->
@coll.ensureIndex( { field : 1 }, {unique:true} )
validate: ->
add: (doc) ->
console.log("cb inserting another")
@coll.insert( doc )
delete: ->
all: (cb) ->
console.log("cb all of " + @cname + ":")
@coll.find({}).toArray (err, ca) =>
cb(null, ca)
dump: ->
console.log("cb dump of " + @cname + ":")
@coll.find({}).forEach (t) =>
console.log("cbdump-" + @cname + ": "+t.name)
findById: ->
findByName: ->
searchText: ->
# * required; ^ reference
# { *name, address, year, geoAddress, ^pics, ^notes }
class Church extends CBase
constructor: () ->
super "Church"
#@setUniqueIndex("name");
validate: (aDoc) ->
getLatLon: (cb) ->
@coll.find({} , {"name":1, "latlon":1}).toArray (err, ca) =>
cb(null,ca)
# { *name, *church, year, loc, ^pics, ^notes } # primary note or Description?
class Brass extends CBase
constructor: () ->
super "Brass"
#@setUniqueIndex("name");
validate: (aDoc) ->
# { *name, *brass, yearRubbed, pics, notes } # primary note or Description?
class Rubbing extends CBase
constructor: () ->
super "Rubbing"
#@setUniqueIndex("name");
validate: (aDoc) ->
# { *name, *urlFull, urlThumb }
class Pic extends CBase
constructor: () ->
super "Pic"
#@setUniqueIndex("name");
validate: (aDoc) ->
# { *id?, *richText, dateCreated } # track updates?/changes?
class Note extends CBase
constructor: () ->
#super "Note"
@setUniqueIndex("name");
validate: (aDoc) ->
# log of db changes?
# do we need a class Colindex to track autoincrement index numbers
class DbMgr
@initConn: (mdbUser, mdbPwd, mdbHost, mdbPort, mdbDbName) ->
@_mdbConnStr = "mongo://" + mdbUser + ":" + mdbPwd + "@" + mdbHost + ":" + mdbPort + "/" + mdbDbName
@Mongolian = require("mongolian")
console.log("initConn: "+@_mdbConnStr)
@_mdb = new @Mongolian(@_mdbConnStr)
@mdb: =>
return(@_mdb)
@church: =>
return(@_church)
@brass: =>
return(@_brass)
@rubbing: =>
return(@_rubbing)
@pic: =>
return(@_pic)
@note: =>
return(@_note)
@test2: ->
console.log("t2")
@_church.add()
@_church.dump()
@_brass.dump()
module.exports = DbMgr