What should I put into parenthesis?

Asked

Viewed 58 times

0

Hello I’m starting to program now and I was following a video lesson and following the teacher’s steps, however arrived in a part that he installed the sqlite, however his version was previous to mine and changed something within the Database.js of sqlite, after a lot of head breaking I discovered, however I do not know how to proceed precisely because it is very early yet...

When I write const dbConnection = sqlite.open()

within the parentheses of . open appears the balloon written

open(config: Isqlite.Config): Promise<Database<Database, Statement>>

inside the Database.js file in the open() part is like this :

open() {
    return new Promise((resolve, reject) => {
        let { filename, mode, driver } = this.config;
        if (!filename) {
            throw new Error('sqlite: filename is not defined');
        }
        if (!driver) {
            throw new Error('sqlite: driver is not defined');
        }
        if (mode) {
            this.db = new driver(filename, mode, err => {
                if (err) {
                    return reject(err);
                }
                resolve();
            });
        }
        else {
            this.db = new driver(filename, err => {
                if (err) {
                    return reject(err);
                }
                resolve();
            });
        }
    });
}

what I should write inside the parentheses?

in the video class the teacher wrote like this:

const dbConnection = sqlite.open('banco.sqlite', { Promise})

but I already know that this is not right

1 answer

0

You are trying to initialize the bank asynchronously, so the promise.

As promises need to be resolved for you to see some result, so you have two options:

async function conectaNoBanco(){
  const banco = await sqlite.open('dados de conexao')
  return banco
}

const conexao = await conectaNoBanco()

or:

sqlite.open('dados de conexao').then(database => {resto do teu codigo})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.