`DELETE ... RETURNING` result not camel cased
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
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;
});
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the DELETE ... RETURNING example with the shown transform configuration, then compare it with the UPDATE ... RETURNING and SELECT examples. Investigate the result transformation path for DELETE ... RETURNING; done means fields such as first_name and birth_date are returned as firstName and birthDate without regressing the working cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100