Closed stealthAngel closed 3 years ago
@stealthAngel There is no reason why you should not. take care that your query is wrong it should be
let query = `
CREATE TABLE IF NOT EXISTS test (
id INTEGER PRIMARY KEY NOT NULL,
name TEXT NOT NULL
);
Having change the query it works, tell me if you have still an issue. i will update react-sqlite-app-starter to demonstrate it
@jepiqueau
It still fails, unfortunately. Even if I only call await sqlite.createConnection("myDB")
without anything else, it fails.
sqlite = useSQLite({
onProgressImport,
onProgressExport
});
useEffect(() => {
const initialize = async (): Promise<Boolean> => {
try {
let db: SQLiteDBConnection = await sqlite.createConnection("myDB");
return true;
}
catch (err: any) {
return false;
}
}
if(sqlite.isAvailable) {
initialize().then(async res => {
if(res) {
} else {
console.error('failed');
console.log(res);
}
});
}
}, []);
logs failed :(
This code works outside app.tsx. But not within app.tsx.
it's like the sqlite variable is not set only when used outside.
the reason for wanting the sqlite code available in the app.tsx is that I want to check for existing tables only once, otherwise I'd have to do it on every other page.
@stealthAngel i have updated react-sqlite-app-starter 3.2.2-3 and implement your code in the App.ts. For having the Web implementation working you need to update @capacitor-community/sqlite@3.2.2-3 and jeep-sqlite Stencil component to 1.2.1. Voilà
@stealthAngel Did you made some progress? Is it working now? If yes can you close the issue
Thank you so much sir!
This issue is solved.
If you can maybe help me with one last thing. Is the database stored somewhere. I don't know which location.
Love you brother
@stealthAngel location is platform dependent
Android: in data/data/YOUR_PACKAGE/databases
iOS: in the Document folder of YOUR_APPLICATION
Electron: in User/Databases/APP_NAME/
Web: in Web browser INDEXEDDB storage as a localforage store under the jeepSqliteStore name and databases table
Hope this will help you in your development Feel free to close the issue
Thank you brother!
The reason I want this is so I can initialize the tables if they don't exist on startup. Is there any way? Thank you.
This same code without
sqlite = useSQLite({ onProgressImport, onProgressExport });
works if you place it in a place like.tab1.tsx