-
Notifications
You must be signed in to change notification settings - Fork 12
Use case example: Pre seeded sqlite use case #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| "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" |
There was a problem hiding this comment.
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." | |||
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
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:
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.usage/use-case-examples.mdxto include "Pre-seeded SQLite Databases" as a new card.docs.jsonto add the new pre-seeded SQLite example to the documentation navigation structure.