Is it possible to choose between libsql node vs. web client? #3122
Replies: 4 comments 3 replies
-
What's better than answering a question? Fixing the problem! Thanks, Drizzle devs, for solving this with the new in driver modules in Drizzle ORM! I still cannot find a way to do something similar in Drizzle Kit. There, I seem to be stuck with the web client on Deno for now. Hopefully that gets fixed, too.🤞 |
Beta Was this translation helpful? Give feedback.
-
I ran into this as well. I got drizzle-kit working though (albeit in a bit of a hacky way). If you haven't yet, make sure you've added the packages via
#!/bin/bash
deno run --node-modules-dir -A npm:drizzle-kit generate
npx drizzle-kit migrate I've got the above shell script... The first step will run drizzle-kit generate with node (which doesn't read the db so it works fine). That step will also generate a Running |
Beta Was this translation helpful? Give feedback.
-
@zephraph Thanks for sharing! I should mention that I also got it working in a hacky way. Here's mine, in case anyone else finds it useful, as well. After having Deno create a
I'm mucking with the @libsql/client package's exports, breaking the specific default export for Deno by changing the key to no-deno, so that it just yields the Node client, instead. This works just fine. It's nice to see that Deno has no problem running the Node client and drizzle-kit works perfectly, but it's frustrating that I can't find an elegant way to convince it to do so. |
Beta Was this translation helpful? Give feedback.
-
Does anyone know the reasoning behind |
Beta Was this translation helpful? Give feedback.
-
I've been trying out Drizzle with libsql on Deno.
It seems that I get the node client on Node and the web client on Deno, and that's just how it is. The web client can't do local files, so it can't take a
file:
URL as theurl
orsyncUrl
option, which is a pretty significant limitation. I've tested outside of Drizzle and, with the node/npm support in Deno 2, the libsql node client seems to work just fine.Looking at
drizzle()
from drizzle-orm/connect, I see that it just imports @libsql/client, and libsql-client uses conditional exports, such that for "deno" you get web.js.It seems that it's possible to specify a non-default condition for exports on Node, but not on Deno, at least not yet.
Fortunately, this is just the default export, and it's easy for clients to explicitly select one client or the other (import from @libsql/client/node vs. @libsql/client/web), but unfortunately, since drizzle does the import and creates the client for me, I'm forced to accept the default.
It looks like I can use the libsql-specific
drizzle()
and create the client myself:But...
The docs say to use this API "if you need a synchronous connection," and I really don't know what that means in this context. It looks like monodriver is doing basically the same thing under the covers, so I think it should be fine. Does anyone know better?
This doesn't help with drizzle-kit, which basically does the same thing as monodriver, just importing @libsql/client and relying on the conditional export to provide the right one.
So, have I missed something? Does Drizzle provide a way to select between the two libsql clients that works both for drizzle-orm and drizzle-kit?
If not, might it be reasonable to add such a mechanism? For example, I could imagine adding separate "libsql-node" and "libsql-web" clients that would do the specific imports. Or is the intent that this be handled by specifying the export condition, and so I just need to wait until Deno supports that?
Any insights would be greatly appreciated. I'm new to Drizzle, libsql, and Deno, and this is a pretty confusing tripping hazard, whereas everything else has gone really smoothly.
Beta Was this translation helpful? Give feedback.
All reactions