Giter Club home page Giter Club logo

Comments (11)

oneworks avatar oneworks commented on August 16, 2024 1

from nodejs-idb-pconnector.

kadler avatar kadler commented on August 16, 2024

Obviously it counts in hex 😂

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on August 16, 2024

The above statement creates 16 connections. Is this expected?

@oneworks That is not expected, it should create 10 connections.

I tried to recreate the issue with:

const {DBPool} = require('idb-pconnector');

const pool = new DBPool({ url: "*LOCAL" }, { debug: true , incrementSize: 10});

console.log(`Pool contains: ${pool.connections.length} connections`);

my output was

Creating Connection 0...
Connection 0 created
Creating Connection 1...
Connection 1 created
Creating Connection 2...
Connection 2 created
Creating Connection 3...
Connection 3 created
Creating Connection 4...
Connection 4 created
Creating Connection 5...
Connection 5 created
Creating Connection 6...
Connection 6 created
Creating Connection 7...
Connection 7 created
Creating Connection 8...
Connection 8 created
Creating Connection 9...
Connection 9 created
Pool contains: 10 connections

I'm only seeing 10 connections created.

Are you redirecting stdout to a log file?

When you have debug set to true then Creating connection output is printed at startup each time.

from nodejs-idb-pconnector.

oneworks avatar oneworks commented on August 16, 2024

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on August 16, 2024

@oneworks

Looks to me that output from your node app is being appended each time to that file.

Seems like it was run twice.

Creating Connection 0...
Connection 0 created
Creating Connection 1...
Connection 1 created
Creating Connection 2...
Connection 2 created
Creating Connection 3...
Connection 3 created
Creating Connection 4...
Connection 4 created
Creating Connection 5...
Connection 5 created
Creating Connection 6...
Connection 6 created
Connection 7 created
Creating Connection 8...
Connection 8 created
Creating Connection 9...
Connection 9 created
Creating Connection 0...
Connection 0 created
Creating Connection 1...
Connection 1 created
Creating Connection 2...
Connection 2 created
Creating Connection 3...
Connection 3 created
Creating Connection 4...
Connection 4 created
Creating Connection 5...
Connection 5 created
Creating Connection 6...
Connection 6 created
Creating Connection 7...
Connection 7 created

What weird is that output ends after connection 7 was created.

Is the above output the full log from the file?

from nodejs-idb-pconnector.

oneworks avatar oneworks commented on August 16, 2024

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on August 16, 2024

@oneworks

In this case why not just use DBPool.runSql() directly within the post route?

I think that would be more efficient and simpler than wrapping with the helper script.

from nodejs-idb-pconnector.

oneworks avatar oneworks commented on August 16, 2024

from nodejs-idb-pconnector.

abmusse avatar abmusse commented on August 16, 2024

FYI, DBPool provides a prepare, bind, and execute helper: DBPool.prepareExecute().

I would highly recommend using helper functions provided:

  • DBPool.runSql()
  • DBPool.prepareExecute()

directly instead of recreating that functionality

If you wanted to stick to using db_promise.js helper script I would only require DBPool within that file.

So that you avoid creating unused connections.

from nodejs-idb-pconnector.

oneworks avatar oneworks commented on August 16, 2024

from nodejs-idb-pconnector.

markdirish avatar markdirish commented on August 16, 2024

For your first question, yes that will create 10 connections. But when you call 'require('x');', node retuns the exact same object in each file. Using this behavior, we create a file, something like pool.js, and then do your pool initialization there:

const { DBPool } = require("idb-pconnector");
const pool = new DBPool({ url: "*LOCAL" }, { debug: true, incrementSize: 10 });

module.exports = pool;

Then, in all your other files, you can have:

...
const pool = require('./pool');
...

This will share the same pool object in all your files, so you only create 10 connections and not 10 x # of files.

As for your second question, I'm accustomed to only using the UPPERCASE variables. @abmusse might know if there's some configuration option.

from nodejs-idb-pconnector.

Related Issues (20)

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.