How it works
-
You configure a local file to be your main database.
- The
urlparameter in the client configuration.
- The
-
You configure a remote database to sync with.
- The
syncUrlparameter in the client configuration.
- The
-
You read from a database:
- Reads are always served from the local replica configured at
url.
- Reads are always served from the local replica configured at
-
You write to a database:
- Writes are always sent to the remote primary database configured at
syncUrl. - Any write transactions with reads are also sent to the remote primary database.
- Once the write is successful, the local database is updated with the changes automatically (read your own writes — can be disabled).
- Writes are always sent to the remote primary database configured at
Things to know
- Do not open the local database while the embedded replica is syncing. This can lead to data corruption.
- In certain contexts, such as serverless environments without a filesystem, you can’t use embedded replicas.
- 500 Databases
- 9GB of total storage
- 1 billion row reads
- Unlimited Embedded Replicas
Remote Replica Configuration
Specifies the local database path filename using relative path
/home/turso/app/database.db remember the back-slash at the begining.Authentication token for secure access. Generate from Get the database authentication token command
URL for synchronization purposes. generate from Get the database URL command
Integer value representing synchronization interval in seconds (optional, default:
5).Boolean value indicating whether to read your writes (optional, default:
true).String value for encryption purposes (optional, default: empty).
Usage Example
You should call
$db->sync() in the background whenever your application wants to sync the remote and local embedded replica. For example, you can call it every 5 minutes or every time the application starts.
