Skip to content

How to load a sqlite file ? #201

@Rafay78

Description

@Rafay78

I have a sqlite db that I want to load in my react native app, which already have data in it.

I am having trouble that how do I load mydb.sqlite database in my app due to no or less documentation on it and no or less community using it right now so no YT tutorials are available for this.

Please help me in this issue currently my code looks:

useEffect(() => {
try {
// require('../../../assets/hadiths.sqlite')
db = NitroSQLite.open({
name: 'hadiths.sqlite',
location: 'src/assets/hadiths.sqlite',
});
} catch (e) {
console.error('Failed to open database:', e);
}

setTimeout(() => {
  db.execute(
    `CREATE TABLE IF NOT EXISTS bukhari (
       id INTEGER PRIMARY KEY AUTOINCREMENT,
       hadith_number INTEGER,
       text TEXT,
       book_name TEXT
     );`,
  );
  let {rows} = db.execute(
    'SELECT name FROM sqlite_master WHERE type="table";',
  );
  console.log(rows?.item(0));
}, 1000);

}, []);

I have 6 tables but on testing I created the table on the go and resulted in success otherwise the already there data is not coming.
I placed my db file in the android/app/src/main/assets/db.sqlite and other paths in my src as well.
I have tried giving the location in every way nothing is working, what am I missing ?

Please guide

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions