SQLite open database file

#1

Hello,

I need to use SQLite for the project and the problem is that I have static local.db file, which should be opened when the application starts as DB. I’m just little bit confused because I’m not able to find the way to open this file as DB.

I tried const db = SQLite.openDatabase(“local.db”); but it seems to be not working for me. The file is stored in the root of my app directory. Could you please help me to figure it out please?

Thanks.

EDIT:

I tried to add

"packagerOpts": {
      "assetExts": ["db"]
    },

into my app.json file and use:

Expo.FileSystem.downloadAsync(
    Expo.Asset.fromModule(require("./assets/db/local.db")).uri,
    `${Expo.FileSystem.documentDirectory}SQLite/local.db`
  );

to get my db file from assets but terminal keeps saying Unable to resolve "./assets/db/local.db" from "App.js".

EDIT 2:
db file is probably binary formatted. Is it a problem for expo to import/open binary formatted file?

1 Like
#2

I found a workaround for this bug. Look here unable-to-load-obj-file-using-require for details. :slight_smile:

1 Like
closed #3

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.