I'm trying to read data in one file from an SQLite database and return it to display in a different file.
Firstly, I'd like to be able to manipulate the data prior to displaying it, for example, return the results into an array I can loop through, run some calculations, then update the rows. Secondly, I'd like to display it in the component, but I can't even seem to do that.
I have a TSX file where I store my CRUD functions. Here's my read one that I want to call from a different file:
export const ReadSingleProject = (projectID: string) => { SQLite.openDatabase({ name: "database.db", createFromLocation: "~database.db", location: "Library", }).then((db) => { db.transaction((tx) => { tx.executeSql("SELECT * FROM projects WHERE projectID=?", [projectID], (tx, results) => { var len = results.rows.length; if (len > 0) { return results.rows.raw(); } } ); }) .catch((error: string) => { console.log(error); }) .then(() => { db.close().catch((error: string) => { console.log(error); }); }); });};
And then in my component file, I'm simply trying to bring in the results:
useEffect(() => { let project = ReadSingleProject(projectID); }, []);
But this 'project' object comes back saying undefined. I've tried splitting the results into a JSON object in File 1 and returning that to populate a JSON object File 2, but there doesn't appear to be any data, even though when I console log in File 1, the results are there correctly.
Could anyone help, please?
Thanks