libsql / libsql-node-sqlite3

node-sqlite3 compatible API for libSQL
MIT License
12 stars 1 forks source link

`libsql:` protocol support #3

Closed penberg closed 1 year ago

penberg commented 1 year ago

Currently, if you use the libsql: protocol, you get the following error:

  ClientError: Unexpected server response: 301

Reported by Dan Kochetov from Drizzle team.

honzasp commented 1 year ago

Huh, and if they change the protocol to ws:, it works? That's super weird, because the code explicitly handles libsql: URLs: https://github.com/libsql/libsql-node-sqlite3/blob/main/src/database.ts#L268

honzasp commented 1 year ago

Maybe they need to use libsqls: or wss:? If the database is on Turso, it needs TLS, and the 301 response looks like the server is trying to redirect from http to https.

penberg commented 1 year ago

I asked them to use https, which works.

honzasp commented 1 year ago

Yes, https is internally rewritten to wss. I'm still not sure whether silently rewriting HTTP schemes to WebSockets isn't a mistake, though!

CodingDoug commented 1 year ago

@honzasp I was thinking that using http or https in the URL is what allows someone to opt into the stateless HTTP implementation with any SDK, if that's what they want or need. Otherwise, it seems impossible without some other configuration in place.

For this library, maybe it would explicitly reject http-based URLs if the assumption is that websockets are always required to make good on compatibility with sqlite3.

honzasp commented 1 year ago

This issue was caused because libsql: used to mean ws:, but now it means wss:. I therefore consider it fixed :)

Also, the new major version will explicitly reject "http" and "https" URLs, suggesting to replace them with "ws" and "wss". This is done to be less confusing and compatible with @libsql/client.