bluejoyq

add sqlite module and database manage module

......@@ -93,7 +93,7 @@ const styles = StyleSheet.create({
},
infoContainer:{
flexDirection:'row',
justifyContent:'space-around',
justifyContent:'center',
alignItems:'center',
width: '100%'
},
......
import * as SQLite from 'expo-sqlite';
import { Modal } from 'react-native';
import { openDatabase,transaction,executeSql } from 'expo-sqlite';
import { rejects } from 'assert';
let sqlite = {};
let db = openDatabase("score.db");
db.transaction( ( tx ) => {
tx.executeSql(`CREATE TABLE IF NOT EXISTS district (id int AUTO_INCREMENT,score int, PRIMARY KEY (id));`);
});
sqlite.insert = ( score ) => {
db.transaction( ( tx ) => {
tx.executeSql( `INSERT INTO district (score) VALUES (${score});` );
});
}
sqlite.select = ( ) => {
return new Promise( (resolve ,rejects)=>{
db.transaction( ( tx ) => {
tx.executeSql( `SELECT score FROM district WHERE 1 ORDER BY id DESC LIMIT 5;`, [], ( tx, result ) => {
resolve(result.rows._array);
}, ( err )=>{
console.log("err -> ",err);
});
});
})
}
module.exports = sqlite;
\ No newline at end of file
......@@ -31,7 +31,8 @@
"react-redux": "^7.1.3",
"react-thunk": "^1.0.0",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0"
"redux-thunk": "^2.3.0",
"expo-sqlite": "~7.0.0"
},
"devDependencies": {
"babel-preset-expo": "^7.1.0",
......