Open vitaly-t opened 8 years ago
You are not the first one to make that mistake, and I just updated the documentation to underline this.
From https://github.com/vitaly-t/pg-promise#connection
Object db represents the database protocol, with lazy database connection, i.e. only the actual query methods acquire and release the connection. Therefore, you should create only one global/shared db object per connection details.
on your code here: https://github.com/lukasmartinelli/postgis-editor/blob/b13ab81b99dc49d486fd62067f56651a10e78208/src/database.js#L25
You should know that that code does nothing really. It doesn't connect to the database, merely creates a new database object, as this library uses lazy connection. This is why in all the examples
db
is created once, globally.See also related: http://stackoverflow.com/questions/36120435/verify-database-connection-with-pg-promise-when-starting-an-app
And since event extend is triggered for each such object, it would only reduce the performance, trying to extend every new instance created, while quite pointlessly.