I'm trying a problem when trying to fetch data from the sqlite database, an error appears: undefined

export class AnimalDaoService {

    private db: BancoService,
    private Animal: AnimalService
  ) {

   * retorna todos os animais cadastrados 
  public getAnimais() {
    let listaAnimais = [];
    const sql = 'SELECT * FROM animal';

      .then(resultSet => {

        if (resultSet.rows.length > 0) {
          for (let i = 0; i < resultSet.rows.length; i++) {

            const animal = this.Animal.novoAnimal();

            animal.idanimal = resultSet.rows.item(i).idanimal;
            animal.numeroidentificacao = resultSet.rows.item(i).numeroidentificacao;
            animal.tipo = resultSet.rows.item(i).tipo;
            animal.sexo = resultSet.rows.item(i).sexo;
            animal.nome = resultSet.rows.item(i).nome;
            animal.altura = resultSet.rows.item(i).altura;
            animal.crista = resultSet.rows.item(i).crista;
            animal.rabo = resultSet.rows.item(i).rabo;
            animal.cor = resultSet.rows.item(i).cor;
            animal.classe = resultSet.rows.item(i).classe;
            animal.origem = resultSet.rows.item(i).origem;
            animal.status = resultSet.rows.item(i).status;
            animal.datanascimento = resultSet.rows.item(i).datanascimento;

      .catch(e => {
        alert("ERRO NO GET" + e[0]);

    return listaAnimais;

What exactly is the error… What is it that’s undefined?

the alert is just showing this, I have already reviewed the code several times and could not find it. The biggest problem is also that I have to keep generating builds all the time

change to

alert("ERRO NO GET" + e);

You cannot make asynchronous activity be synchronous, no matter how hard you try. async and await can make strides towards causing it to look synchronous, but I remain unconvinced of the utility of that.

getAnamais cannot return an array. It must return a Promise of one, and whoever calls it needs to be capable of handling that. This is why I suggest that the very first word of all functions involving futures be return. If you follow that rule, it becomes impossible to make the mistake you’re making here, and you will end up with something that looks like:

interface Animal {...}
getAnimais(): Promise<Animal[]> {
  return this.db.databaseObj.executeSql(...)
    .then(results => resultSet.rows);

the error that appears is: [object Object]

find out where the error was, on the following line:

const sql = ‘SELECT * FROM animal’;


the correct way:

this.db.databaseObj.executeSql( ‘SELECT * FROM animal’)