Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
  • Loading branch information
ruheni and Jolg42 authored Oct 25, 2023
1 parent f86b674 commit d24b348
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions content/300-guides/050-database/900-turso.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Many aspects of using Prisma with Turso are just like using Prisma with any othe

There are a number of differences between Turso and SQLite to consider. You should be aware of the following when deciding to use Turso and Prisma:

- **Remote and embedded SQLite databases**. libSQL uses HTTP to connect to the database and uses a remote file over a local file. libSQL also supports remote database replicas and embedded replicas. Embedded replicas enable you to replicate your primary database inside your application.
- **Remote and embedded SQLite databases**. libSQL uses HTTP to connect to the database and uses a remote database over a local 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
Expand Down Expand Up @@ -71,7 +71,7 @@ datasource db {
npx prisma generate
```

Install the libSQL database client and Prisma adapter for libSQL:
Install the libSQL database client and Prisma adapter for libSQL packages:

```sh
npm install @libsql/client @prisma/adapter-libsql
Expand All @@ -93,13 +93,13 @@ const adapter = new PrismaLibSQL(libsql)
const prisma = new PrismaClient({ adapter })
```

You can use Prisma Client as you normally would with full type-safety as you normally would in your project.
You can use Prisma Client as you normally would with full type-safety in your project.

<!-- TODO: how to connect to a remote database replica -->

## How to connect and query from an embedded replica

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. This is similar to having an embedded or SQLite 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. This is similar to having a local SQLite database.

When your app initially establishes a connection to your database, the primary database will fulfill the query:

Expand All @@ -113,7 +113,7 @@ The embedded replica will fulfill subsequent read queries. The libSQL client pro

![Embedded Replica: Local DB reads](./images/embedded-replica-read.png)

With embedded replicas, this setup guarantees your app is fast because the data will be readily available locally.
With embedded replicas, this setup guarantees a responsive application, because the data will be readily available locally and faster to access.

Like a read replica setup you may be familiar with, write operations are forwarded to the primary remote database and executed before being propagated to all embedded replicas.

Expand Down Expand Up @@ -141,7 +141,7 @@ const sync = async () => await libsql.sync()
const adapter = new PrismaLibSQL(libsql)

const prismaClientSingleton = () => {
sync()
await sync()
return new PrismaClient({ adapter })
}
```
Expand Down

0 comments on commit d24b348

Please sign in to comment.