GoogleCloudPlatform / cloud-sql-nodejs-connector

A JavaScript library for connecting securely to your Cloud SQL instances
Apache License 2.0
66 stars 8 forks source link

Missing example for using sql server with prisma #362

Closed haydizzledizzle closed 2 months ago

haydizzledizzle commented 2 months ago

Description

I'm not quite sure if this is a documentation issue or it's not possible to do currently. There are examples for mysql and postgres on how to connect to prisma using the connector.startLocalProxy function. I'm trying to connect to prisma but using sql server. I'm still not sure if it's possible to do this or not but it's not clear to me how to tell prisma to connect using the unix socket via the connection string I pass to prisma.

Solution

An example of connecting to sql server via prisma using connector.startLocalProxy (if it's possible to do). If this is not possible then perhaps the documentation for Using a Local Proxy Tunnel can explicitly say it's not possible for sql server or potentially an overload for startLocalProxy to support sql server connections

Additional Context

Currently I have this working using the workaround mentioned in this issue but ideally I would just use the connector.startLocalProxy function. I suspect the issue here might be that startLocalProxy uses unix sockets and that sql server doesn't support connecting this way?

I'm also trying to run this out of a v2 cloud function (so cloud run) if that makes any difference

jackwotherspoon commented 2 months ago

Hi @haydizzledizzle!

Currently Cloud SQL for SQL Server is not supported via the connector.startLocalProxy for the exact reason you assumed which is that SQL Server does not support unix domain socket connections.

We can definitely do a better job at highlight this in documentation.

I put up #365 to add a clear note of this in our README

haydizzledizzle commented 2 months ago

Thanks for updating the docs @jackwotherspoon. Is it on the radar to implement a solution for sql server such as done in this issue? I might go forward with this as a workaround for now but was wondering if it's something you would recommend against or if you have any other ideas for connecting via prisma using sql server. Thanks!

jackwotherspoon commented 2 months ago

Is it on the radar to implement a solution for sql server such as done in this issue?

It is definitely on the radar but probably not in the near future (coming month or two). We wanted to first roll out .startLocalProxy with a Unix socket approach, see how it lands and have it used for a bit of time so we can fix any bugs before we add support for SQL Server via a TCP port implementation.

I might go forward with this as a workaround for now but was wondering if it's something you would recommend against or if you have any other ideas for connecting via prisma using sql server.

The workaround code is very similar to what we would eventually add to this package so it is definitely a viable option.

Are you using a Public or Private IP SQL Server instance? If you are using a Private IP then you could just connect directly to the instance over TCP, by using the Private IP address as the host and port 1433.