Coder Social home page Coder Social logo

postgres-queries's People

Contributors

alexisjanvier avatar djhi avatar floo51 avatar jpetitcolas avatar kmaschta avatar sedy-bot avatar zyhou avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postgres-queries's Issues

Bad warning message while updating, it uses filter warning

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:

  1. This is not filters but fields / columns.
  2. It is better to ignore non-writable fields, or get a debug message (instead of a warning) in the case of an update. Have a warning in the select case is right.
  3. It's better to batch the warning instead of a warn for each field. I extensively use update queries and this spam a lot in the console.
  4. It lacks of context in this message.

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: "..."

Migration from co-postgres-queries

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.

Original pg-pool event emitter isn't exposed

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
});

Investigate On SelectOne && SelectByOrdererIdentifiers

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, }); ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.