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';
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With