doltgresql icon indicating copy to clipboard operation
doltgresql copied to clipboard

Cannot Connect To Doltgres with Slonik

Open alexhwoods opened this issue 1 year ago • 6 comments

Slonik is a popular JavaScript library to connect to Postgres. It is not an ORM - in fact I'd expect it to be pretty friendly with Doltgres.

Here is a reproduction. Here is the README of the reproduction just so I can show y'all what I mean:

Testing Slonik & Doltgres

  1. Confirm that Doltgres is running at the URL of your choice
psql postgresql://doltgres@localhost:5438/foo
psql (14.12 (Homebrew), server 15.0)
WARNING: psql major version 14, server major version 15.
         Some psql features might not work.
Type "help" for help.

foo=> \q
  1. Show that Slonik cannot connect to Doltgres
POSTGRES_URL=postgresql://doltgres@localhost:5438/foo bun run .
ECONNREFUSED: Failed to connect
 syscall: "connect"

This does work when I switch the Postgres URL to a normal Postgres database.

  1. Show that Slonik can connect to a normal Postgres database
POSTGRES_URL=postgresql://@localhost/foo bun run .
{
  now: 1722913364466,
}

alexhwoods avatar Aug 06 '24 03:08 alexhwoods

I think connect is fixed in main but not released. Getting this in the right repo

timsehn avatar Aug 06 '24 04:08 timsehn

I think connect is fixed in main but not released. Getting this in the right repo

Ah, thank you - sorry, yeah, I meant to have this in Doltgres.

And great!

alexhwoods avatar Aug 06 '24 13:08 alexhwoods

@alexhwoods Sorry for the delay on this, but I have your script running successfully. Well, not successfully, there are still some compatibility errors. But it connects fine. When I'm not running the doltgres server:

% POSTGRES_URL=postgresql://doltgres@localhost:5433/foo bun run
 .
ECONNREFUSED: Failed to connect
   errno: 16
 syscall: "connect"


Bun v1.1.22-canary.96+df33f2b2a (Linux x64)

When it's running:

% POSTGRES_URL=postgresql://doltgres@localhost:5433/foo bun run .
30 |     for (const typeParser of typeParsers) {
31 |         const postgresType = postgresTypes.find((maybeTargetPostgresType) => {
32 |             return maybeTargetPostgresType.typname === typeParser.name;
33 |         });
34 |         if (!postgresType) {
35 |             throw new Error('Database type "' + typeParser.name + '" not found.');
                       ^
error: Database type "interval" not found.
      at /c/Users/zachmu/node_modules/@slonik/pg-driver/dist/factories/createPgDriverFactory.js:35:19

Bun v1.1.22-canary.96+df33f2b2a (Linux x64)

Any chance you have the port mixed up, or it's unavailable for some other reason?

zachmu avatar Aug 08 '24 20:08 zachmu

I can get even farther if I change the problem line line this:

-            throw new Error('Database type "' + typeParser.name + '" not found.');
+            //            throw new Error('Database type "' + typeParser.name + '" not found.');
+           continue;

Then I hit an actual error, about DISCARD not being supported:

521 |         result = new this._Promise((resolve, reject) => {
522 |           query.callback = (err, res) => (err ? reject(err) : resolve(res))
523 |         }).catch((err) => {
524 |           // replace the stack trace that leads to `TCP.onStreamRead` with one that leads back to the
525 |           // application that created the query
526 |           Error.captureStackTrace(err)
                      ^
error: DISCARD is not yet supported
 code: "XX000"

      at /c/Users/zachmu/node_modules/pg/lib/client.js:526:17
      at processTicksAndRejections (native:1:1)

zachmu avatar Aug 08 '24 20:08 zachmu

I'll get to work converting DISCARD in the meantime, as well as fixing the type incompatibilities.

zachmu avatar Aug 08 '24 21:08 zachmu

@alexhwoods I've confirmed the application works after https://github.com/dolthub/doltgresql/pull/585 and https://github.com/dolthub/doltgresql/pull/596 are included. We'll have a release with those two changes for you on Monday.

zachmu avatar Aug 09 '24 23:08 zachmu

New release available here:

https://github.com/dolthub/doltgresql/releases/tag/v0.11.0

Please give it a shot and let us know if there are any further issues.

zachmu avatar Aug 12 '24 19:08 zachmu

@alexhwoods – thanks for taking the time to report this one so we could get it fixed! 🙏 The latest version of Doltgres should support this use case now.

Let us if you're still having problems or hit any other issues and we'll be happy to dig in!

fulghum avatar Sep 04 '24 20:09 fulghum