Skip to content

Commit

Permalink
Move dbToJson to Location
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Kruijsen committed Apr 5, 2013
1 parent ebb4752 commit 05d072a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.config.defaults({
Location.connect(app.config.get('MONGOHQ_URL'))

read = ->
Waterdata.dbToJson (error, res) ->
Location.toJson (error, res) ->
console.log res
Location.db.close()

Expand Down
5 changes: 0 additions & 5 deletions lib/lib.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ Waterdata =
writeToDb: (object, callback) ->
Location.update {lokatie:object.lokatie}, object, {upsert: true}, callback

# Turn the database into json. Dynamic for now.
dbToJson: (callback) ->
Location.find {}, '-_id', (error, res) ->
callback(error, res)

processWaterdata: (callback) ->
# get the zipfile
console.log 'Starting'
Expand Down
7 changes: 7 additions & 0 deletions lib/models.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ schema = mongoose.Schema {
},
laatstBijgewerkt: String
}

Location = mongoose.model 'Location', schema

Location.connect = (url) ->
mongoose.connect(url)

# Turn the database into json. Dynamic for now.
Location.toJson = (callback) ->
Location.find {}, '-_id', (error, res) ->
callback(error, res)

exports.Location = Location
3 changes: 1 addition & 2 deletions web.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
flatiron = require 'flatiron'
Waterdata = require('./lib/lib').Waterdata
Location = require('./lib/models').Location

app = flatiron.app
Expand All @@ -14,7 +13,7 @@ app.config.defaults({
Location.connect(app.config.get('MONGOHQ_URL'))

read = ->
Waterdata.dbToJson (error, json) =>
Location.toJson (error, json) =>
@res.writeHead(200, {'Content-Type': 'application/json'})
@res.write JSON.stringify(json)
@res.end()
Expand Down

0 comments on commit 05d072a

Please sign in to comment.