tursodatabase / turso-docs

Turso reference documentation
https://docs.turso.tech
MIT License
11 stars 48 forks source link

Incorrect way to create SQLite client for Astro project #222

Closed webberpuma closed 1 month ago

webberpuma commented 1 month ago

Path: /sdk/ts/guides/astro

The document uses the following to create a client:

import { createClient } from "@libsql/client/web";

export const turso = createClient({
  url: process.env.TURSO_DATABASE_URL!,
  authToken: process.env.TURSO_AUTH_TOKEN,
});

Which results in the following error:

Error [LibsqlError]: URL_INVALID: The URL is not in a valid format

The reason is environment variables are obtained incorrect. Check the official doc in Astro: https://docs.astro.build/en/guides/environment-variables/#getting-environment-variables

The correct way should be:

import { createClient } from "@libsql/client/web";

export const turso = createClient({
  url: import.meta.env.TURSO_DATABASE_URL!,
  authToken: import.meta.env.TURSO_AUTH_TOKEN,
});
notrab commented 1 month ago

Hey @webberpuma

I’ll get this updated, thanks so much. However, there’s an even better approach using the new :env package. See an example here: https://youtu.be/jU3dbZOaS9g?si=fG5Mxz-l6im5Z4lZ

webberpuma commented 1 month ago

Hey @webberpuma

I’ll get this updated, thanks so much. However, there’s an even better approach using the new :env package. See an example here: https://youtu.be/jU3dbZOaS9g?si=fG5Mxz-l6im5Z4lZ

@notrab Thank you for the new Info!