I am using react native expo to do the init data load and insert it into DB. But seems the sequence is not my expectations.
and below is my init function
import { getData } from './GetData'
const db = SQLite.openDatabase('db.db') // returns Database object
const initDB = async (res: any) => {
await db.transaction(async tx => {
await tx.executeSql(`create table if not exists table (
id integer primary key AUTOINCREMENT not null,
...... // create db query
)`, [],
() => {
console.log("created table")
})
await tx.executeSql(insertQuery
, res.list,
() => {
console.log(`inserted data success`)
},
(_, err): boolean | any => {
console.log(`err: ${err}`)
}
)
})
}
export const initLoading = async () => {
const res = await getData() // get data from API
await initDB(res)
}
await new Promise(async resolve => {
await initLoading()
console.log("init done")
})
my expected console log should be
created table
inserted data success
init done
but the result is
init done
created table
inserted data success
what thing I am doing wrong to make the sequence incorrect?