Skip to content

Commit

Permalink
more modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ruheni committed Nov 3, 2023
1 parent 10cf9a6 commit d368929
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions content/300-guides/050-database/900-turso.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,29 @@ To update your database schema:
1. Generate a migration file using `prisma migrate dev` against a local SQLite database:

```terminal
npx prisma migrate dev --name init # Migration name
npx prisma migrate dev --name init
```

2. Apply the migration using Turso's CLI:

```terminal
turso db shell turso-prisma-db < ./prisma/migrations/20230922132717_init/migration.sql # Replace `20230922132717_init` with the existing migration
turso db shell turso-prisma-db < ./prisma/migrations/20230922132717_init/migration.sql
```

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

## How to connect to and query an embedded Turso database
Replace `20230922132717_init` with the name of your migration.

</Admonition>

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

## Embedded Turso database replicas

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.

### How embedded database replicas work

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

![Embedded Replica: First remote read](./images/embedded-replica-remote-read.png)
Expand All @@ -185,7 +193,9 @@ Like a read replica setup you may be familiar with, write operations are forward
1. Database responds to the server with the updates from 1.
1. Write operations are propagated to the database replica.

How often to synchronize you need to synchronize data between your remote database and embedded replica is dependent on your application's data consistency needs. For example, you can use either middleware functions (e.g. Express and Fastify) or a cron job to synchronize the data.
Your application's data needs will determine how often you should synchronize data between your remote database and embedded database replica. For example, you can use either middleware functions (e.g. Express and Fastify) or a cron job to synchronize the data.

### How to connect and query an embedded database

To get started using embedded replicas with Prisma, add the `sync()` method from libSQL in your application. The example below shows how you can synchronize data using Express middleware.

Expand Down

0 comments on commit d368929

Please sign in to comment.