Ayoub
Ayoub
DTDrizzle Team
Created by Ayoub on 3/28/2024 in #help
Dynamic query columns projection
SOLUTION: did this
const createProjectionObject = (columns: string[]) => {
const projection = {};
columns.forEach((column) => {
projection[column] = sql`${sql.identifier(column)}`;
});
return projection;
};
const projectionObject = createProjectionObject(fieldsProjection(info)); // it takes GraphQL info object and gets the selected fields
const queryResult = await db.select(projectionObject).from(drivers).limit(limit).offset(offset)
const createProjectionObject = (columns: string[]) => {
const projection = {};
columns.forEach((column) => {
projection[column] = sql`${sql.identifier(column)}`;
});
return projection;
};
const projectionObject = createProjectionObject(fieldsProjection(info)); // it takes GraphQL info object and gets the selected fields
const queryResult = await db.select(projectionObject).from(drivers).limit(limit).offset(offset)
2 replies