Sunday, 16 April 2017

RethinkDB - Delete table with Angular

Okay so I created this live poll web app using RethinkDB and Nodejs: https://codeforgeek.com/2016/03/building-real-time-polling-app-rethinkdb-nodejs/

I want to implement a delete button that deletes the table and all the polls. I found the delete command: https://rethinkdb.com/api/python/delete/ And I put it in my polls.js (models\polls.js), look at delete() :

deletePolls(callback) {
    async.waterfall([
      function(callback) {
        var pollObject = new db();
        pollObject.connectToDb(function(err,connection) {
          if(err) {
            return callback(true,"Error connecting to database");
          }
          callback(null,connection);
        });
      },
      function(connection,callback) {
        rethinkdb.table('poll').delete().run(connection,function(err,cursor) {
          connection.close();
          if(err) {
            return callback(true,"Error deleting polls to database");
          }
          cursor.toArray(function(err, result) {
            if(err) {
              return callback(true,"Error reading cursor");
            }
            callback(null,result)
          });
        });
      }
    ],function(err,data) {
      callback(err === null ? false : true,data);
    });
}

I added a delete.html and added that page in the index.html (views):

<md-menu>
      <md-button ng-href="/#/delete">Delete all.</md-button>
</md-menu>

And in the app.js (views/js/app.js):

.when('/delete',{
            templateUrl: 'delete.html'
 })

The button opens my html page. But I don't know where do I set the call for the deletePolls function, where I should be able to delete the table from the base. The result would be a live poll where you can view and create polls, and when you press delete button, it deletes all questions (polls).



via IkePr

No comments:

Post a Comment