I encountered some issues with the code snippet provided above. After examining the event.target
, I believe that it should not be nullable within the if statement.
const importDatabase = async (event: Event) => {
if (event.target) {
const file = (event.target as HTMLInputElement).files[0]
const connection = getDbConnection()
const reader = new FileReader()
reader.onload = async (e) => {
const data = new Uint8Array(e.target!.result as ArrayBuffer)
console.info('Importing database...', data)
// const SQL = await initSqlJs()
// connection.driver.databaseConnection = new SQL.Database(data);
connection.sqljsManager.loadDatabase(data)
await connection.synchronize(false)
}
reader.readAsArrayBuffer(file)
}
}