0

hye huys, i need help for delete and update using pouchdb. for the now create and read data can work. just delete and update not work yet. this is my database

application.service('Database', ['$q', '$window',
function($q, $window)
{
    var db = new $window.PouchDB('web-sample');

    this.delete = function(documentId, documentRev, options)
    {
        return $q.when(db.delete(documentId, documentRev, options));
    };

    this.get = function(documentId)
    {
        return $q.when(db.get(documentId));
    };
}

]);

and this is my service

application.service('Arrears', ['$q', 'Database',
function($q, Database)
{
    this.remove = function(documentId, documentRev, options)
        {
          return Database.delete(documentId, documentRev, options);
        };


    this.update = function()
    {
        return Database.update()
    };
}

]);

this is my controller.

application.controller('ArrearsManagementReadAllController', ['$location', '$mdSidenav', '$routeParams', '$scope', 'arrears',
function($location, $mdSidenav, $routeParams, $scope, arrears)
{
    $scope.arrears = arrears;
    $scope.remove = function(id)
    {
        $location.path('/arrears_management/all');
    };

    var arrears = {
        owner_name: '',
        owner_id: '',
        account_no: '',
        title_no: '',
        address: '',
        house_no: '',
        floor: '',
        lot: '',
        block: '',
        locality: '',
        total_outstanding: '',
        last_receipt_no: '',
        last_pay_date: '',
        last_paid_amount: '',
    };

    var actions = {};

    actions.submit = function(arrears)
    {
        Arrears.update(arrears).
            then(function(response)
            {
                $location.path('/arrears_management/all');
            });
    };
}]);

if you all know how to solve my problems please comment. thanks

1 Answer 1

0

When trying to delete, you may get a conflict, so may need to retry the delete but when using a recursive call use a counter for a set number of retries and then throw an error, catching the result, if it cannot delete for some reason other than a conflict.

Likewise, when trying to update you will need to first get the latest document revision before attempting the put. Again you need to handle conflicts such as the 404 and 409 errors. If you get a 404 try deleting the revision before retrying. With a 409 just do a retry. Again if using a recursive call probably best to do a set number of retries and then throw an error for other conditions and catch the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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