Ah, right.
Like Martins suggested, you could take a look at how Handmade Hero has set up its worker threads and parcels out work. OBBG has a similar work queue. Both implementations were streamed at the time and archived on Youtube. You can use
HMH's episode guide to search for 'thread' or 'worker thread' or something along those lines to find the relevant bits.
How you return the data is up to you. It's hard to comment without knowing more about how you structured your program. Like what does the code that calls this callback look like. Do you have the caller allocate and own the memory or the worker. Who's in charge of freeing that memory again.
In this case it's probably simple because you have a handle to an sqlite database, so you'd have the thing that calls the callback expect a return value of that type, and then you'd return the handle. Then when that's done it can close the sqlite database using that same handle. (At least from what I can make out just by looking at that snippet. The other end of the equation is missing).
But, if I were you I would watch how Casey and Sean did their worker thread systems, you'd get a feel for some of the possible solutions.