Hi @porsager, hope things are good! 👋
It appears that postgres.camel is not working with DELETE ... RETURNING queries? 🤔 Or am I doing something wrong?
Config:
const postgresJsConfig = {
ssl: Boolean(process.env.POSTGRES_URL),
transform: {
...postgres.camel,
undefined: null,
},
};
Query:
export const deleteAnimalInsecure = cache(
async (animalToDelete: Pick<Animal, 'id'>) => {
const [animal] = await sql<Animal[]>`
DELETE FROM animals
WHERE
id = ${animalToDelete.id}
RETURNING
animals.*
`;
return animal;
},
);
Result (snake case):
{
"animal": {
"id": 3,
"first_name": "Trevor",
"type": "iguana",
"accessory": "plastic fork collection",
"birth_date": "2020-08-17T00:00:00.000Z"
}
}
Expected result (camel case):
{
"animal": {
"id": 3,
"firstName": "Trevor",
"type": "iguana",
"accessory": "plastic fork collection",
"birthDate": "2020-08-17T00:00:00.000Z"
}
}
Camel case results are returned for other RETURNING queries such as UPDATE ... RETURNING queries (as well as other non-RETURNING queries such as SELECT queries):
export const updateAnimalInsecure = cache(async (updatedAnimal: Animal) => {
const [animal] = await sql<Animal[]>`
UPDATE animals
SET
first_name = ${updatedAnimal.firstName},
type = ${updatedAnimal.type},
accessory = ${updatedAnimal.accessory},
birth_date = ${updatedAnimal.birthDate}
WHERE
id = ${updatedAnimal.id}
RETURNING
animals.*
`;
return animal;
});
Hi @porsager, hope things are good! 👋
It appears that
postgres.camelis not working withDELETE ... RETURNINGqueries? 🤔 Or am I doing something wrong?Config:
Query:
Result (snake case):
{ "animal": { "id": 3, "first_name": "Trevor", "type": "iguana", "accessory": "plastic fork collection", "birth_date": "2020-08-17T00:00:00.000Z" } }Expected result (camel case):
{ "animal": { "id": 3, "firstName": "Trevor", "type": "iguana", "accessory": "plastic fork collection", "birthDate": "2020-08-17T00:00:00.000Z" } }Camel case results are returned for other
RETURNINGqueries such asUPDATE ... RETURNINGqueries (as well as other non-RETURNINGqueries such asSELECTqueries):