以前のリビジョンの文書です
expoに含まれるデータベース
SQLite
import { Constants, SQLite } from 'expo';
const db = SQLite.openDatabase('SampleDatabase.db');
・・・
componentDidMount(e){
db.transaction(tx => {
tx.executeSql(
'create table if not exists items (id integer primary key not null, done int, value text);'
);
});
db.transaction(
tx => {
tx.executeSql('insert into items (done, value) values (0, ?)', ["safa"]);
tx.executeSql('select * from items', [], (_, { rows }) =>
console.log(JSON.stringify(rows))
);
},
null,
console.log("test")
);
tx.executeSql(sqlStatement, arguments, success, error)
sqlStatement:SQL
arguments:SQLに?を使用すると、置換え変数にできる。(プリペアードステートメント)
success,error:それぞれ自身のトランザクションと、結果の2つのパラメータが返る。
tx.executeSql('select * from items where name=?',
["safa"],
(tran, { rows }
) => console.log(JSON.stringify(rows))
);