olalonde / pgtools Goto Github PK
View Code? Open in Web Editor NEWPure Node.js implementation of PostgreSQL's createdb and dropdb tools.
License: MIT License
Pure Node.js implementation of PostgreSQL's createdb and dropdb tools.
License: MIT License
I am a newbie regarding nodejs and promises, learning as I go... :)
I have been having a problem where this module interferes with pg-promise. Pg-promise will connect to the public database instead of the specified database.. it seems to be reusing the connection created by this module. When I don't use pgtools functionality pg-promise will work as expected.
This might be due to the connection not being closed properly.
Issue:
pgtools fails to return a status when run.
This happens in cli and programmatic use.
Reproduce problem:
Using node v14.14.0, postgres v13.0
Attempt to connect with an invalid configuration or with a valid configuration. In both cases, nothing is returned. The callbacks are ignored, no errors or notice of success is displayed.
I've tested that this problem does not occur in node v12.18.3, postgres v12.4
I suspect that this is an issue with node v14.
A similar issue seems to be happening in sequelize/sequelize#12158
What seemed to work there was updating the pg dependency.
Solution:
This is what @sohel-ahmed-ansari proposes #21, which solves this issue.
I've tested that solution on node v14.14.0 and I only did simple tests but it seems to work properly.
How I tested that:
"resolutions": { "pg": "8.4.0", "pg-connection-string": "2.4.0" }
"preinstall": "npx npm-force-resolutions"
To avoid this workaround, one can also do manually what pgtools does: use pg directly, connecting to a default database first.
When
npm i -S pgtools
I have
error Couldn't find any versions for "event-stream" that matches "3.3.6"
When connecting to a webserver in the config options does pgtools need it to be tcp, udp, http, or something else?
Hi all, it would be nice to be able to specify owner of created db.
In March, the project seemed to get a good Yargs patch which fixes numerous transitive security vulnerabilities.
However, seems the version was not published - the latest to download from Npm is v1.0.0 which still contains Yargs v5.x.
Is it possible to cut a release including the most recent dep upgrade?
Thanks!
Ref: #50
Is this possible?
dropdb errors are working for me generally - ie the following code will reach the console.error line if the database doesn't already exist:
pgtools
.dropdb(config, testDbName)
.catch((error)=>{
console.log(error);
})
However if I happen to have the database open in pgAdmin3 it won't drop the database and it won't throw an error.
From the travis-ci.org website:
Please be aware travis-ci.org will be shutting down in several weeks, with all accounts migrating to travis-ci.com. Please stay tuned here for more information.
It's a good moment to move to GitHub actions.
timeout-minutes
to something like 5 (GitHub had some errors in the past where jobs wouldn't stop)pgtools not connecting to postgres with SSL enabled.
throws error
ERR: (node:67) UnhandledPromiseRejectionWarning: error: SSL required
at Parser.parseErrorMessage (/opt/meshcentral/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/opt/meshcentral/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/opt/meshcentral/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket. (/opt/meshcentral/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at Socket.Readable.push (_stream_readable.js:213:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
yargs 5.0.0
uses yargs-parser 3.2.0
which has a vulnerability, is it possible to use a newer version of yargs?
I was trying to implement what this issue was asking for at a higher level: #3
I wrote this out:
import pgtools from 'pgtools'
import CONFIG from './db-config.json'
function handleDropErrors (err) {
console.dir(err.message.indexOf(`does not exist`), {colors: true, depth: 3})
if (err.message.indexOf(`does not exist`) === -1) {
console.error(err)
} else {
console.error(`got here`, err)
// createDb()
return Promise.resolve()
}
}
function createDb() {
// calls pgtools.createdb()
}
pgtools.dropdb(CONFIG, CONFIG.database)
.then(createDb, handleDropErrors)
.catch(handleDropErrors)
But I keep getting the following stack trace:
Unhandled rejection error: database "mydb" does not exist
at Connection.parseE (/Users/mmarcus/dev/emma-exercise/node_modules/pgtools/node_modules/pg/lib/connection.js:567:11)
at Connection.parseMessage (/Users/mmarcus/dev/emma-exercise/node_modules/pgtools/node_modules/pg/lib/connection.js:391:17)
at Socket.<anonymous> (/Users/mmarcus/dev/emma-exercise/node_modules/pgtools/node_modules/pg/lib/connection.js:129:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
AFACT, I am handling the error, I'm just choosing to swallow it if the error is a specific error.
What's even more odd, is that w/ both native and Bluebird promises.. this kind of logic seems to work just fine for "swallowing" a promise rejection.
Native: https://repl.it/JgPz
Bluebird: https://repl.it/JgQa/1
I'm at a loss at this point :-(
Hello. Running current version of your tool. Running node 14.x. I have a script (https://github.com/RobStafford/To-Do-Calendar/blob/main/database/schemaPostgres.js) which has run successfully dozens of times. Now, when you run it, a console.log before or after the .createdb command fires, but nothing inside the command. Nothing is logged--no successes or failures. I have a teammate who was having the same problem the day before, then mine started acting the same way. That makes me suspect it might be related to a PR on our project, but I can't for the life of me see what the problem is. Help?
Given that the current code errors out if you try to create an existing database, wouldn't it be better to just create it if it doesn't exist? Conversely for dropping, only if the table exists should you drop?
If this is acceptable, I could probably send a pull request in fairly quickly.
I love this package, but it's not maintained anymore.
Does anybody know an alternative?
Or are you open to give more maintainers access to pgtools, @olalonde?
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.