planetscale / database-js

A Fetch API-compatible PlanetScale database driver
https://planetscale.com/docs/tutorials/planetscale-serverless-driver
Apache License 2.0
1.17k stars 35 forks source link

Local Connection Fails #104

Closed techgerm closed 1 year ago

techgerm commented 1 year ago

Scenario

  1. I run pscale connect galaxy --port 3309 locally to connect to my PlanetScale DB
  2. I attempt to connect my T3 app using import { connect } from "@planetscale/database";

Problem

  1. When I use url to connect to my local db connection, it does not use the specified port - instead is uses port 443:

    const connection = connect({
    url: "mysql://root@127.0.0.1:3309"
    });

    Screenshot 2023-04-09 at 8 13 19 PM

  2. When I use host & username to connect to my local db connection, it uses the correct port but it fails with a ERR_SSL_WRONG_VERSION_NUMBER status code

    const connection = connect({
    host: "127.0.0.1:3309",
    username: "root"
    });

    Screenshot 2023-04-09 at 8 12 30 PM

I'd love to be able to use this package instead of prisma for my next project.

Anything that can be done to help here would be greatly appreciated!

mattrobenolt commented 1 year ago

This is correct. We don't have an equivalent yet since this driver speaks HTTP and pscale connect is mysql. So in this case, it's not a deficit of database-js, just a fundamental difference in protocol.  On Apr 9, 2023, at 20:29, Germán Pineda @.***> wrote: Scenario

I run pscale connect galaxy --port 3309 locally to connect to my PlanetScale DB I attempt to connect my T3 app using import { connect } from @.***/database";

Problem

When I use url to connect to my local db connection, it does not use the specified port - instead is uses port 443:

const connection = connect({ url: @.***:3309" });

When I use host & username to connect to my local db connection, it uses the correct port but it fails with a ERR_SSL_WRONG_VERSION_NUMBER status code

const connection = connect({ host: "127.0.0.1:3309", username: "root" });

I'd love to be able to use this package instead of prisma for my next project. Anything that can be done to help here would be greatly appreciated!

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

techgerm commented 1 year ago

@mattrobenolt thanks for the quick response and clarification! In that case, do you know how I can specify a DB branch in this configuration?

mattrobenolt commented 1 year ago

When you create credentials, they're bound to a branch. So you'd just create credentials for the branch you want, and it'll work. Are you observing something differently?

techgerm commented 1 year ago

Ah that's my mistake, didn't realize that was the case. Thanks again for your help!

Out of curiosity, are there any future plans to bridge the protocols?

mattrobenolt commented 1 year ago

Bride them how? I have some plans. 👀 But curious what you have in mind.

techgerm commented 1 year ago

Hmm let me give it some thought and I'll get back to you!

Jolg42 commented 1 year ago

(Maybe unrelated to your issue? Feel free to ignore)

From what I see, the ERR_SSL_WRONG_VERSION_NUMBER error is caused because fetch tries to do some SSL logic here on a non SSL endpoint.

Changing these 2 lines and switching https to http should make it work. https://github.com/planetscale/database-js/blob/488e48b04cfb25b001050d6dbeebe8dd9b0a6f65/src/index.ts#L203 https://github.com/planetscale/database-js/blob/488e48b04cfb25b001050d6dbeebe8dd9b0a6f65/src/index.ts#L254

janpio commented 1 year ago

Related: https://github.com/planetscale/database-js/issues/135