这是我的编码
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);
});
我收到一条错误消息:SQLite.openDatabase 不是函数
我已经安装了软件包
npx expo install expo-sqlite
并导入
import * as SQLite from 'expo-sqlite';
如果您查看文档,https://docs.expo.dev/versions/latest/sdk/sqlite/,不再只有 openDatabase
SQLite.openDatabaseSync
(和 SQLite.openDatabaseAsync
)。所以我的猜测是将 openDatabase
更改为 openDatabaseSync
应该可以解决问题(尽管未经测试)。