Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite.openDatabase('dbname') is not a function in expo react native

Here's my coding

import * as SQLite from 'expo-sqlite';

const db = SQLite.openDatabase('myDatabase.db');

db.transaction((tx) => {
  tx.executeSql(
    'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)'
  );
})
  .then(() => {
    console.log('Table created successfully');
  })
  .catch((error) => {
    console.log('Error creating table:', error);
  });

I got a error message: SQLite.openDatabase is not a function

I have already install the package

npx expo install expo-sqlite

and import

import * as SQLite from 'expo-sqlite';
like image 524
C CB CCC Avatar asked Aug 19 '26 00:08

C CB CCC


1 Answers

If you look at the documentation, https://docs.expo.dev/versions/latest/sdk/sqlite/, there is no longer openDatabase only SQLite.openDatabaseSync (and SQLite.openDatabaseAsync). So my guess is changing openDatabase to openDatabaseSync should solve the issue (untested though).

like image 142
Harrie Pieters Avatar answered Aug 27 '26 00:08

Harrie Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!