Hello. so I’m returning a stream of user’s projects from a NestJS route (example simplified for clarity):
@Get('/user/projects')
async streamProjects(
@Req() req: FastifyRequest,
@Res() res: FastifyReply
) {
const readableStream = new Readable({
read() {},
});
const query = `SELECT a.*
FROM default:db.scope.projects a
WHERE a.userId='${req.userId}'
AND a.archived=false
ORDER BY a.updated DESC;`;
const queryStream = CouchbaseService.scope.query<ProjectType>(query);
queryStream.on('row', (projectRow: ProjectType) => {
readableStream.push(JSON.stringify(projectRow) + '\r\n');
});
queryStream.on('end', () => {
readableStream.push(null);
});
setStreamHeaders(res);
readableStream.pipe(res.raw);
}
as you can see, I have to call JSON.stringify on every document that I am returning to the user, which to me seemed inefficient because the documents are already stored as JSON in Couchbase.
I think you answered accurately that currently QueryOptions does not allow to specify a transcoder. So this should be a feature request : allow QueryOptions to specify to return the documents as strings, or allow it to specify a transcoder.