I isn't able to manipulate factory data in controller

Hello everyone.

I am new in the Angular applications and are having a lot of difficulties in develop my app.

Tha fact is that i needed to create a database in sqlite to be used local in my android project. Every tutorial that i saw taught me to make it in a factory and call it in other pages.

The problem is, in a lot of situations a need to take that information and manipulate. I already was able to show it in the form but unfortunately i wasn’t capable of manipulate the object returned from factory.

Follow my code below:

factory sqlite:

var db = null;
var clienteselec = [];
var sqlite = angular.module('sqlite', ['ionic', 'ngCordova']);

sqlite.run(function ($ionicPlatform, $cordovaSQLite, $window) {
    $ionicPlatform.ready(function () {
        db = $cordovaSQLite.openDB({ name: "rollers.db", location: 1 });

        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS clientes (id integer primary key, nome varchar(40))");
        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS instalacao (id integer primary key, idCliente int, dataInst datetime)");
        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS manutencao (id integer primary key, idCliente int, idInstalacao int, dataManut datetime)");
        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS equipamento (id integer primary key, idInstalacao int, idManutencao int, TC int autoincrement, posicao varcar(1), Rolo varchar(40), dataEquip datetime)");
    });
})

sqlite.factory('clientesFactory', function ($cordovaSQLite, $rootScope) {
    return {
insert: function (Nome) {
            var query = "INSERT INTO clientes (nome) VALUES (?);";
            var values = [Nome];
            
            $cordovaSQLite.execute(db, query, values).then(
              function (res) {
                  alert('Cliente Cadastro com Sucesso!');

                  $cordovaSQLite.execute(db, "SELECT max(id) as id from clientes", []).then(
                      function (res) {
                          if (res.rows.length > 0) {
                              var valores = res.rows.item(0);
                              $rootScope.idCliente = valores.id;
                          }
                      }
                  );
              },
              function (err) {
                  alert('Cliente não cadastrado. Estamos verificando o problema!');
              }
            );
        },

        selectTodos: function(tab){
            var query = "SELECT * FROM " + tab;

            clienteselec = [];
            $cordovaSQLite.execute(db, query,[]).then(function (result) {
                if(result.rows.length){
                    for (var i = 0; i < result.rows.length; i++) {
                        clienteselec.push(result.rows.item(i));
                    }
                }else{
                    console.log("no data found!");
                }
            }, function(err){
                console.log("error" + err);
            });
        },
});

controller:

.controller('ClienteCtrl', ['clientesFactory', '$scope', '$state', '$window', '$rootScope', function (clientesFactory, $scope, $state, $window, $rootScope) {
    $scope.listaClientes = function() {
        clientesFactory.insert('teste');
        clientesFactory.selectTodos('clientes');
        $scope.seleciona = clienteselec;
    }
}])

html:

<ion-content padding>
    
<div ng-controller="ClienteCtrl">
        <button ng-click="listaClientes()">Novo Cliente</button>
        <!--<table>
            <tr ng-repeat="cli in clientes">
                <td></td>
            </tr>
        </table>-->    
        <ion-item ng-repeat="cli in seleciona">
            {{cli.nome}}
            <button ng-click="cadastraCliente({{cli.id}})">Novo</button>
            <button ng-click="instala({{cli.id}}, {{cli.nome}})">Instalação</button>
            <button ng-click="excluiCliente({{cli.id}}, {{cli.nome}})">Excluir</button>
    </div>

</ion-content>

If someone could help me i would stay really grateful. My job depends of the resolution of that problem. Thank you everyone.

yes you can use the update query
update: function (Nome,Id) {
db.transaction(function (tx) {
tx.executeSql("UPDATE clientes SET name=? WHERE id=? , [Nome, Id]); //for updating
},
function (error) {
console.log('Transaction ERROR: ’ + error.message);
}, function () {
console.log(‘Success’);
});
}
call this update function where you need to change the data

First of all, thank you for your response rahulpzy.

In my case i already can change the value of the column, because i already have the update function. The problem is, for example. Let’s say that i have a moment where i need to change a value in the view when the code of the client is ‘1’. How i create this if, if i don’t have the code in a variable or something like that in the controller?