Skip to content

Conversation

@michaelbarnes
Copy link
Contributor

This pull request adds documentation for a new use case example on pre-seeding SQLite databases to optimize initial sync times, and updates the documentation index to include this new example.

Documentation updates:

  • Added a new guide, pre-seeded-sqlite.mdx, explaining how to pre-generate and distribute SQLite databases to clients, including server-side preparation, JWT usage, and client-side integration.
  • Updated the use case example list in usage/use-case-examples.mdx to include "Pre-seeded SQLite Databases" as a new card.
  • Modified docs.json to add the new pre-seeded SQLite example to the documentation navigation structure.

"usage/use-case-examples/raw-tables",
"usage/use-case-examples/custom-write-checkpoints"
"usage/use-case-examples/custom-write-checkpoints",
"usage/use-case-examples/pre-seeded-sqlite"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the use case examples are roughly ordered alphabetically, with data pipelines at the bottom since it's enterprise only. could you put this between postgis and prioritized sync?

@@ -0,0 +1,103 @@
---
title: "Pre-Seeding SQLite Databases"
description: "Optimizing Initial Sync by pre-Seeding SQLite Databases."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case inconsistency


To achieve this, you can run server-side processes to pre-generate and seed SQLite files. These files can then be uploaded to blob storage, such as AWS S3, Azure Blob Storage, or Google Cloud Storage, to be downloaded directly by the client applications, bypassing the initial sync process.

The [PowerSync Node.js SDK](/client-sdk-references/node) comes in handy in these scenarios, because you can use it to on the server in Node.js applications.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grammar error


The [PowerSync Node.js SDK](/client-sdk-references/node) comes in handy in these scenarios, because you can use it to on the server in Node.js applications.

<Card title="nodejs-react-native-sqlite-seeder" icon="github" href="https://github.com/powersync-community/nodejs-react-native-sqlite-seeder">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This card appears without context, should it be accompanied with some description text?

# Main Concepts

## Generate a client specific JWT token
In the event you want to dynamically populate the SQLite database with data, you can generate a JWT token that is scoped to a specific client device. On the servier side application you would typically query the source database directly and fetch the IDs required in your sync rules to satisfy the conditions of the parameter queries.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo


## Client Side Usage

When the client applicaitons boot, before connecting to the PowerSync instance, check if the pre-seeded SQLite database exists in the blob storage. If it does, download it and use when initializing the PowerSyncDatabase class.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

When the client applicaitons boot, before connecting to the PowerSync instance, check if the pre-seeded SQLite database exists in the blob storage. If it does, download it and use when initializing the PowerSyncDatabase class.

<Warning>
It's important to note that when the client downloads the pre-seeded SQLite database that it's stored in a permanent location on the device. This means that the database will not be deleted when the app is uninstalled or restarted.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you uninstall from iOS all app data will be deleted, this is not possible. I think this only caters for crashes/restarts, not uninstall

Depending on which PowerSync SDK you are using, you may need to use framework specific methods to store the file in a permanent location on the device. For example, in React Native + Expo you can use the [`expo-file-system`](https://docs.expo.dev/versions/latest/sdk/filesystem/) module to store the file in a permanent location on the device.
</Warning>

Once the database is downloaded, insert a new client_id key into the ps_kv table and connect to the PowerSync instance.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to use backtick formatting for client_id and ps_kv

It's important that you insert a new client_id key into the ps_kv table to avoid conflicts when the client connects to the PowerSync instance.
</Tip>

At this point the client should be able to connect to the PowerSync instance and sync the data as normal, bypassing the initial sync process.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest rephrasing to make this more clear. what does "as normal" mean? it means resume syncing from where the snapshot was created and where the service operation history is at, right?

# Main Concepts

## Generate a client specific JWT token
In the event you want to dynamically populate the SQLite database with data, you can generate a JWT token that is scoped to a specific client device. On the servier side application you would typically query the source database directly and fetch the IDs required in your sync rules to satisfy the conditions of the parameter queries.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the token scoped to a device or a user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants