Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
Expo SQLite Database isn't initialising in react native

I am trying to create Database for my react native app using expo's SQLite and followed its documentation for it but I think Database isn't initializing.

Documentation: expo-sqlite

App.js:

console.log("init () above");

init()
  .then(() => {
    console.log("DATABASE INITIALIZED");
  })
  .catch(() => {
    console.log("FAILED DATABSE INITIALIZATION", err);
  });

console.log("init () below");

//Nothing logs in console

Console:

init () above
init () below
places: Array []

I created the promise as init() which returns an error if it fails and when it resolves it logs a success message DATABASE INITIALIZED. But I am not getting any output.

helper/db:

import * as SQLite from "expo-sqlite";

const db = SQLite.openDatabase("places.db");

export const init = () => {
  const promiseDB = new Promise((resolve, reject) => {
    db.transaction((tx) => {
      tx.executeSql(
        "CREATE TABLE PLACES IF NOT EXISTS places (id INTEGER PRIMARY KEY NOT NULL, title TEXT NOT NULL, imageUri TEXT NOT NULL, address TEXT NOT NULL, lat REAL NOT NULL, lng REAL NOT NULL)"
      );
      [],
        () => {
          resolve();
        },
        (_, err) => {
          reject(err);
        };
    });
  });
  return promiseDB;
};


I am not getting any errors and also not the success message in the console. I don't know what's the issue and what I am doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You didn't write your function correctly, you forgot a curly bracket and added and empty array of arguments where you shouldn't have.

Also in your query you wrote CREATE TABLE PLACES IF NOT EXISTS places. It believe the proper syntax would be CREATE TABLE IF NOT EXISTS places.

The order of arguments in transaction is callback, errorCallback, successCallback. https://docs.expo.dev/versions/latest/sdk/sqlite/#database

The order of the arguments in executeSql is sqlStatement, arguments, callback, errorCallback. https://docs.expo.dev/versions/latest/sdk/sqlite/#sqltransaction

This should create your table:

return new Promise((resolve, reject) => {
        db.transaction(
            function (tx) {
                tx.executeSql("CREATE TABLE IF NOT EXISTS places (id INTEGER PRIMARY KEY NOT NULL, title TEXT NOT NULL, imageUri TEXT NOT NULL, address TEXT NOT NULL, lat REAL NOT NULL, lng REAL NOT NULL)");
            },
            function (error) {
                reject(error.message);
            },
            function () {
                resolve(true);
                console.log('Created database OK');
            }
      );
});

An exemple for when you need to add arguments:

return new Promise((resolve, reject) => {
    db.transaction(
        function (tx) {
            tx.executeSql(
                'SELECT * FROM TABLE_NAME WHERE name=?;',
                [name],
                function (tx, resultSet) {
                    let data = [];
                    for (let i = 0, c = resultSet.rows.length;i < c;i++) {
                        data.push(resultSet.rows.item(i));
                    }
                    resolve(data);
                },
                function (tx, error) {
                    reject(error.message);
                }
            );
        },
        function (error) {
            reject(error.message);
        }
    );
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!