<commit_before>mongo = require('mongodb')
ObjectID = mongo.ObjectID

uri = 'mongodb://127.0.0.1:27017/invisible'
db = undefined

mongo.connect uri, (err, database) ->
    throw err if err?
    db = database
    console.log("connected to #{uri}")


module.exports = (app) ->
	app.get("/invisible/:modelName", query)
	app.post("/invisible/:modelName", save)
	app.get("/invisible/:modelName/:id", show)
	app.put("/invisible/:modelName/:id", update)
	app.delete("/invisible/:modelName/:id", remove)

#rest controllers
query = (req, res) -> 
    col = db.collection(req.params.modelName)
    col.find().toArray (err, results) ->
        return next(err) if err?
        res.send(results)

save = (req, res) ->
    col = db.collection(req.params.modelName)
    col.insert req.body, safe:true, (err, result) ->
        return next(err) if err?
        res.send(200, result)

show = (req, res) ->
    col = db.collection(req.params.modelName)

    try
        id = new ObjectID(req.params.id)
    catch err
        console.log('Invalid Object Id')
        res.send(404)

    col.findOne {_id: new ObjectID(req.params.id)}, (err, result) ->
        return next(err) if err?
        if result?
            res.send(200, result)
        else
            res.send(404)

update = (req, res) ->
    col = db.collection(req.params.modelName)

    try
        id = new ObjectID(req.params.id)
    catch err
        console.log('Invalid Object Id')
        res.send(404)

    col.findAndModify { _id: id}, [['_id','asc']], {$set: req.body}, {new: true, upsert: false}, (err, result) ->
        return next(err) if err?
        if result
            res.send(200, result)
        else
            res.send(404)

remove = (req, res) ->
    col = db.collection(req.params.modelName)

    try
        id = new ObjectID(req.params.id)
    catch err
        console.log('Invalid Object Id')
        res.send(404)

    col.remove { _id: id}, (err, result) ->
        return next(err) if err?
        if result?
            res.send(200)
        else
            res.send(404)
<commit_msg>fixed post route<commit_after>mongo = require('mongodb')
ObjectID = mongo.ObjectID

uri = 'mongodb://127.0.0.1:27017/invisible'
db = undefined

mongo.connect uri, (err, database) ->
    throw err if err?
    db = database
    console.log("connected to #{uri}")


module.exports = (app) ->
	app.get("/invisible/:modelName", query)
	app.post("/invisible/:modelName", save)
	app.get("/invisible/:modelName/:id", show)
	app.put("/invisible/:modelName/:id", update)
	app.delete("/invisible/:modelName/:id", remove)

#rest controllers
query = (req, res) -> 
    col = db.collection(req.params.modelName)
    col.find().toArray (err, results) ->
        return next(err) if err?
        res.send(results)

save = (req, res) ->
    col = db.collection(req.params.modelName)
    col.insert req.body, safe:true, (err, result) ->
        return next(err) if err?
        res.send(200, result[0])

show = (req, res) ->
    col = db.collection(req.params.modelName)

    try
        id = new ObjectID(req.params.id)
    catch err
        console.log('Invalid Object Id')
        res.send(404)

    col.findOne {_id: new ObjectID(req.params.id)}, (err, result) ->
        return next(err) if err?
        if result?
            res.send(200, result)
        else
            res.send(404)

update = (req, res) ->
    col = db.collection(req.params.modelName)

    try
        id = new ObjectID(req.params.id)
    catch err
        console.log('Invalid Object Id')
        res.send(404)

    col.findAndModify { _id: id}, [['_id','asc']], {$set: req.body}, {new: true, upsert: false}, (err, result) ->
        return next(err) if err?
        if result
            res.send(200, result)
        else
            res.send(404)

remove = (req, res) ->
    col = db.collection(req.params.modelName)

    try
        id = new ObjectID(req.params.id)
    catch err
        console.log('Invalid Object Id')
        res.send(404)

    col.remove { _id: id}, (err, result) ->
        return next(err) if err?
        if result?
            res.send(200)
        else
            res.send(404)

{'fraction_non_alphanumeric': 0.1528785679729076, 'fraction_numerical': 0.0200774068698597, 'mean_word_length': 2.305355715427658, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1602204', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1392, 'n_words': 324}