Skip to content

Commit

Permalink
update how to connect to connect and query a Turso db section
Browse files Browse the repository at this point in the history
  • Loading branch information
ruheni committed Nov 3, 2023
1 parent f6f7f28 commit 10cf9a6
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions content/300-guides/050-database/900-turso.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,46 @@ There are a number of differences between Turso and SQLite to consider. You shou
- **Remote and embedded SQLite databases**. libSQL uses HTTP to connect to the remote SQLite database. libSQL also supports remote database replicas and embedded replicas. Embedded replicas enable you to replicate your primary database inside your application.
- **Making schema changes**. Since libSQL uses HTTP to connect to the remote database, this makes it incompatible with Prisma Migrate. However, you can use [`prisma migrate diff`](/reference/api-reference/command-reference#migrate-diff) <span class="api"></span> to create a schema migration and then apply the changes to your database using [Turso's CLI](https://docs.turso.tech/reference/turso-cli).

## Connect and query your primary database
## How to connect and query a Turso database

<br />
The subsequent section covers how you can create a Turso database, retrieve your database credentials and connect to your database.

<details>
### How to provision a database and retrieve database credentials

<summary>
Expand to learn how to provision a database and retrieve your credentials on
Turso
</summary>
<Admonition>

Ensure that you have the [Turso CLI](https://docs.turso.tech/reference/turso-cli) installed to manage your databases.

1. To provision a database on Turso, run the following command:
</Admonition>

```terminal
turso db create turso-prisma-db
```
If you don't have an existing database, you can provision a database by running the following command:

2. Retrieve the database's connection string:
```terminal
turso db create turso-prisma-db
```

```terminal
turso db show turso-prisma-db
```
The above command will create a database in the closest region to your location.

3. Create an authentication token that will allow you to connect to the database:
Run the following command to retrieve your database's connection string:

```terminal
turso db tokens create turso-prisma-db
```
```terminal
turso db show turso-prisma-db
```

4. Update your `.env` file with the authentication token and connection string:
Next, create an authentication token that will allow you to connect to the database:

```text file=.env
TURSO_AUTH_TOKEN="eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9..."
TURSO_DATABASE_URL="libsql://turso-prisma-db-user.turso.io"
```
```terminal
turso db tokens create turso-prisma-db
```

Update your `.env` file with the authentication token and connection string:

```text file=.env
TURSO_AUTH_TOKEN="eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9..."
TURSO_DATABASE_URL="libsql://turso-prisma-db-user.turso.io"
```

</details>
### How to connect to a Turso database

To get started, enable the `driverAdapters` Preview feature flag:

Expand Down Expand Up @@ -158,7 +159,7 @@ To update your database schema:

For subsequent migrations, repeat the above steps to apply changes to your database. This workflow does not support tracking the history of applied migrations.

## How to connect and query from an embedded replica
## How to connect to and query an embedded Turso database

Turso supports [embedded replicas](https://blog.turso.tech/introducing-embedded-replicas-deploy-turso-anywhere-2085aa0dc242). Turso's embedded replicas enable you to have a copy of your primary, remote database _inside_ your application. Embedded replicas behave similarly to a local SQLite database. Database queries are faster because your database is inside your application.

Expand Down

0 comments on commit 10cf9a6

Please sign in to comment.