Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique name for parameterized prepared statements #283

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Tuarisa
Copy link
Contributor

@Tuarisa Tuarisa commented Dec 2, 2023

Introducing Unique Naming for Parameterized Prepared Statements

The Pg module consistently utilizes prepared statements for parameterized queries, even when a name isn't explicitly provided. To enhance this process, I have implemented a custom name generator based on the crypto SHA1 algorithm, known for its speed. This is particularly beneficial in applications where SQL queries are frequently repeated with varying parameters. This improvement aims to streamline operations by reducing the number of additional database queries.

  • tests and linter show no problems (npm t)
  • tests are added/updated for bug fixes and new features
  • code is properly formatted (npm run fmt)
  • description of changes is added in CHANGELOG.md
  • update .d.ts typings

@Tuarisa
Copy link
Contributor Author

Tuarisa commented Dec 7, 2023

What is the fastest node.js hashing algorithm : https://medium.com/@chris_72272/what-is-the-fastest-node-js-hashing-algorithm-c15c1a0e164e

@Tuarisa
Copy link
Contributor Author

Tuarisa commented Dec 7, 2023

@tshemsedinov check please

lib/database.js Outdated Show resolved Hide resolved
@@ -1,6 +1,9 @@
'use strict';

const { Pool } = require('pg');
const createHash = require('node:crypto').createHash;

const hash = (data) => createHash('sha1').update(data).digest('base64');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider move to metautil or local submodule

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants