marmelab / postgres-queries Goto Github PK
View Code? Open in Web Editor NEWQuery builder for PostgreSQL in Node.js, built for async
Home Page: https://marmelab.com/postgres-queries/
License: MIT License
Query builder for PostgreSQL in Node.js, built for async
Home Page: https://marmelab.com/postgres-queries/
License: MIT License
Say I have the following code with a character
table, some readable fields, and other writable fields:
const { updateOne } = crud({
table: 'character',
writableCols: ['user_id', 'name', 'position'],
returnCols: ['id', 'uuid', 'user_id', 'name', 'position'],
});
If I want to update a whole character
object like:
const character = {
id: 42,
uuid: 'uuid',
user_id: 1,
name: 'name',
position: 'position',
...otherFields,
};
await client.namedQuery(updateOne(character.id, character));
I get the following warnings, because of the non-writable fields:
⚠ warning Ignoring filter: id. Allowed columns: user_id,name,position
⚠ warning Ignoring filter: uuid. Allowed columns: user_id,name,position
⚠ warning Ignoring filter: room. Allowed columns: user_id,name,position
⚠ warning Ignoring filter: avatar. Allowed columns: user_id,name,position
⚠ warning Ignoring filter: inventory. Allowed columns: user_id,name,position
I have several issues with this warning:
I would suggest to replace this warning by a debug log for the update query, and in the case of the select have a message more like:
⚠ postgres-queries The "select" query received non-filterable fields in parameter and ignored them: "id, uuid, room, ...". The available fields are: "..."
It would be awesome to have an exaustive documentation on how to migrate from co-postgres-queries
.
What features are supported by postgres-queries and what are not, and what are the workaround.
Select query don't use "returningQuery" function as other queries. FInd for which reason and maybe fix it.
The original pg-pool instance is an event emitter.
Since pg-pool is wrapped, we can not access to the emitter nor listen to the events (for logging or debugging purpose).
We would like to wrap the on
function to the pool:
import Pool from 'postgres-queries/pool';
const pool = new Pool(clientOptions, poolingOptions);
pool.on(error => {
// log
});
Or have access to the original pool instance:
import Pool from 'postgres-queries/pool';
const pool = new Pool(clientOptions, poolingOptions);
pool.originalPoolInstance.on(error => {
// log
});
On SelectOne Query, we use "primaryKey" as key of an object of the second parameter of sanitizeIdentifier.
Here is the error provided by TypeScript:
[ts] Un nom de propriété calculée doit être de type 'string', 'number', 'symbol' ou 'any'.
Since "primaryKey" can also be an arrya of keys, it can produce some errors since we can't attribute an array as key of an object.
Here is the concerned code part:
... return rawParameters => { const parameters = sanitizeIdentifier(identifiers, { ...(typeof rawParameters === 'object' ? rawParameters : { [primaryKey]: rawParameters }), ...permanentFilters, }); ...
In the old crud, there's a specific "allowPrimaryKeyUpdate" attribute which is passed from parameters to the UpdateOneQuery.
It's seems that this attribute is unused / useless (i've searched it in coPostgreQueries globally). I've don't replicate it in this new version.
Please confirm me that this attribute has no utility ?
Explicit :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.