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

Fix connection on deno 1.36.3 #673

Merged
merged 1 commit into from
Sep 12, 2023
Merged

Conversation

JorritPosthuma
Copy link
Contributor

@JorritPosthuma JorritPosthuma commented Sep 11, 2023

Running the following code on deno 1.36.3 using postgres 3.3.5:

import postgres from "postgres";

const sql = postgres();

sql`SELECT 1`.then((result) => {
  console.log(result);
});

export default sql;

Gave the following error:

error: Uncaught (in promise) TypeError: Class constructor Socket cannot be invoked without 'new'
    at createSocket (./node_modules/.deno/postgres@3.3.5/node_modules/postgres/src/connection.js:131:15)
    at Timeout.connect [as _onTimeout] (./node_modules/.deno/postgres@3.3.5/node_modules/postgres/src/connection.js:328:31)
    at cb (ext:deno_node/internal/timers.mjs:63:31)
    at Object.action (ext:deno_web/02_timers.js:153:11)
    at handleTimerMacrotask (ext:deno_web/02_timers.js:67:10)
    at eventLoopTick (ext:core/01_core.js:189:21)

Simple fix is as proposed. Also tested if it still works in node v20.5.1, which it does :)

@porsager
Copy link
Owner

Ah, I see - so deno has started consuming Postgres.js directly since their npm support launch? (curious why the won't allow it since Node.js does).

Even so, no reason we shouldn't make the change since node seems to prefer new as well.

@porsager porsager merged commit bf082a5 into porsager:master Sep 12, 2023
@porsager
Copy link
Owner

Thank you

@hastebrot
Copy link

hastebrot commented Oct 11, 2023

Great work!

I've replaced

/// <reference types="https://deno.land/x/postgresjs@v3.3.5/types/index.d.ts" />
import postgres from "https://deno.land/x/postgresjs@v3.3.5/mod.js";

with

import postgres from "npm:postgres@3.4.0";

and it works like a charm with full typing support.

Interestingly, my tests now run faster; could be because it now uses Deno's Node polyfills and they maybe implemented some part of it in Rust.

@porsager
Copy link
Owner

That was a great way to get the setup without my custom polyfills tested 😊

Did you not find speedups anyway since you crossed it? I'd be curious to remove my hacks in place of Denos, but only if no slowdowns are incurred.

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.

3 participants