neumino / chateau

Another (awesome) data explorer for RethinkDB
207 stars 38 forks source link

easiest way to delete 1 element from array in field? #67

Open mspanish opened 7 years ago

mspanish commented 7 years ago

Hello and thanks again for this great app! I've hacked it up so that I can view colors from arrays inside of fields, and I'm planning to try and expose a new route that deletes any color I click on. Hackish I know! But would serve my needs for now. Is there any better way to do this? If anybody wants my hack I'll post it - here's a screenshot. colors_hack

mspanish commented 7 years ago

Got it working! Created a simple route like this:

exports.removeColor = function (req, res) {
    var primaryKey = req.body.primary;
    var db = req.body.db;
    var table = req.body.table;
    var colors = req.body.colors;

r.db(db).table(table).get(primaryKey).update({colors:colors}).run( connection, {timeFormat: 'raw'}, function(error, result) {
        if (error) handleError(error);
        res.json({
            error: error,
            result: result
        });
    })
}

Then when I click on a color, I pass the id and the new color array (I added lodash to the front end to do that quickly).