Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I'm converting an MS Access database to a webapp. I'm using Angular JS, Node JS with the express framework and MySQL as database.

In ms access you don't have any edit/save features. When you edit something, the database changes instantly. I like this. Feels smooth. So I want to have this the same way in the web app. My question is. Will there be any problems with this approach in my webbapp?

This is a piece of my node js code which updates the database with a restcall:

/*
 Post /api/products/ HTTP/1.1
 */
exports.editProduct = function(req, res) {
  console.log(req.body);
  var post  = [{title_en: req.body.title_en},req.params.id];
  if (connection) {
    connection.query("UPDATE products SET ?  WHERE id = ?",  post, function(err, rows, fields) {
      if (err) throw err;
      res.contentType('application/json');
      res.write(JSON.stringify(rows));
      res.end();
    });
  }
};

And on the client side I use the a the $resource object

       $scope.save = function(){
         $scope.product.$save(function(){
           console.log('Save successfull);
         });
       };

And in the view. I simply have inputs with ng-change:

<input ng-model="product.title_en" ng-change="save()".

Will this work good in production mode with a couple hundred users? Is the chances of blocking/crashing etc?

share|improve this question
    
The only thing I see is if (err) throw err; if there is an error the server crash so change it with a json response with a 500 status. By the way express has a build-in way to output json expressjs.com/api.html#res.json – Whisher Feb 2 '14 at 21:59
up vote 0 down vote accepted

The only thing I see is if (err) throw err; if there is an error the server crash so change it with a json response with a 500 status. By the way express has a build-in way to output json
It's better off to validate title_en and id

exports.editProduct = function(req, res) {
      console.log(req.body);
      var post  = [{title_en: req.body.title_en},req.params.id];
      if (connection) {
        connection.query("UPDATE products SET ?  WHERE id = ?",  post, function(err, rows, fields) {
          if (err) {
              return res.json(500,{ error: 'Cannot update the product' });
          }
          res.json(200,rows);
        });
      }

an other thing try to use restangular instead of resource it's a lot of fun :) };

share|improve this answer
1  
And there is no problem if 50 people at the same time using this restcall as they are typing in inputboxes? – Per Ström Feb 2 '14 at 22:04
    
It's a mysql issue not a node problem so Use transactions – Whisher Feb 3 '14 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.