Tino
Tino9mo ago

Turso with local db file

I wanted to try out Turso's syncURL feature and for that it creates a local db file to read from and syncs any written data remote first before it writes it locally. However, I am not getting that far due to the following issue: LibsqlError: URL_SCHEME_NOT_SUPPORTED: The client that uses Web standard APIs supports only "libsql:", "wss:", "ws:", "https:" and "http:" URLs, got "file:". For more information, please read https://github.com/libsql/libsql-client-ts#supported-urls Deno code:
// main.ts
createClient({
url: "file:local.db",
syncUrl: Deno.env.get("URL"),
authToken: Deno.env.get("TOKEN")
});
// main.ts
createClient({
url: "file:local.db",
syncUrl: Deno.env.get("URL"),
authToken: Deno.env.get("TOKEN")
});
The script has all permissions by deno run -A main.ts. Based on the error file: is simply not supported since Deno is allowing only web standard APIs? Any other way to allow this? I am just suprised this isn't working since the use case seems acceptable.
5 Replies
Deno AI Helper
Deno AI Helper9mo ago
Based on the documentation, Deno supports fetching file: URLs as of Deno 1.16. However, it only supports absolute file URLs, which means that fetch("./some.json") will not work. If you want to fetch some resource relative to the current module, you would want to use import.meta.url as the base. Here's an example from the documentation:
const response = await fetch(new URL("./config.json", import.meta.url));
const config = await response.json();
const response = await fetch(new URL("./config.json", import.meta.url));
const config = await response.json();
However, it's important to note that permissions are applied to reading resources, so an appropriate --allow-read permission is needed to be able to read a local file. Fetching locally only supports the GET method, and will reject the promise with any other method. A file that does not exist simply rejects the promise with a vague TypeError. In your case, it seems like the file: URL is not supported by the libsql client you're using. This is not a limitation of Deno itself, but rather the specific library. You might want to check the library's documentation or reach out to its maintainers for more information on how to use local files with it. 🦕
Tino
Tino9mo ago
if I run this with bun all works just fine. So it seems that the issue is not libsql but Deno or do I miss anything?
Tino
Tino9mo ago
the error message reads: error: Uncaught LibsqlError: URL_SCHEME_NOT_SUPPORTED: The client that uses Web standard APIs supports only "libsql:", "wss:", "ws:", "https:" and "http:" URLs, got "file:". For more information, please read https://github.com/libsql/libsql-client-ts#supported-urls
GitHub
GitHub - libsql/libsql-client-ts: TypeScript/JavaScript client API ...
TypeScript/JavaScript client API for libSQL. Contribute to libsql/libsql-client-ts development by creating an account on GitHub.
Tino
Tino9mo ago
and I guess with "client" it means Deno
Tino
Tino9mo ago
GitHub
Deno compatible local client · Issue #67 · libsql/libsql-client-ts
Hey I was very interested in learning how to use Turso on my most recent Deno project. I resorted to making a Deno compatible client for local development as Deno only had support for the web versi...