I’ve been working on this for 1 week as well, trying both ‘expo-sqlite’ and ‘react-native-sqlite-storage’ and I finally made it work on my dictionary app by editing the code on this expo forum: Cannot read from Bundled Database
That openDatabase code on Expo didn’t work on my app either.
Prior to this, I put the SQL data into ./asset/db/
import * as SQLite from 'expo-sqlite';
import * as FileSystem from 'expo-file-system';
import {Asset} from 'expo-asset';
import { openDatabase } from 'expo-sqlite';
export class DictionaryScreen extends React.Component{
state = {inputValue: "Look up the word"};
_handleTextChange = inputValue => {
this.setState({inputValue});
};
async openDatabase() {
if (!(await FileSystem.getInfoAsync(FileSystem.documentDirectory + 'SQLite')).exists) {
await FileSystem.makeDirectoryAsync(FileSystem.documentDirectory + 'SQLite');
}
await FileSystem.downloadAsync(
Asset.fromModule(require('/Users/***/***/assets/db/test.db')).uri,
FileSystem.documentDirectory + 'SQLite/test.db'
);
return SQLite.openDatabase('test.db');
}
db = openDatabase('test.db');
searchWord() {
this.db.transaction((tx) => {
tx.executeSql(
'SELECT word, mean FROM items WHERE word LIKE "%?%";',
[this.state.inputValue],
() => {
console.log("success");
},
() => {
console.log("failed");
}
);
});
};
render() {
return(
<SafeAreaView style={styles.container}>
<View style={styles.searchContainer}>
<MaterialCommunityIcons name="text-search" size={20}/>
<TextInput
style={styles.input}
onChangeText={this._handleTextChange}
onSubmitEditing={(inputValue) => this.searchWord(inputValue)}
value={this.inputValue}
placeholder='Look up the word'
keyboardType="default"
/>
<StatusBar style='light' />
</View>
</SafeAreaView>
);
}
}
Make sure all props are defined.
Hope this will help you.