Skip to content
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

[Fix] Common SDK fixes for Web and React Native #24

Merged
merged 22 commits into from
Nov 6, 2023

Conversation

stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented Nov 2, 2023

This PR contains some fixes identified when implementing the Web SDK:

  • Fixed: get, getAll and getOptional helper methods should execute inside a readLock for better concurrency
  • Removed user-id header from backend connector and remote headers
    The user-id field is not used and is not accepted for CORS
  • Added waitForReady method on PowerSyncDatabase
  • Fixed: Added correct typings for React hooks. Previously hooks would return any.
  • Bumps @journeyapps/react-native-quick-sqlite which has bug fixes from [Fix] Missing dependencies react-native-quick-sqlite#9
  • Updates SDK readme docs URL and new Github org repo location

TODO:

  • Bump package for react-native-quick-sqlite (currently cannot publish due to Github org permissions error)

@stevensJourney stevensJourney changed the title [Fix] Common SDK fixes for Web [Fix] Common SDK fixes for Web and React Native Nov 3, 2023
@stevensJourney stevensJourney marked this pull request as ready for review November 3, 2023 14:36
Comment on lines +63 to +66
* This provides a top-level read only execute method which is executed inside a read-lock.
* This is necessary since the high level `execute` method uses a write-lock under
* the hood. Helper methods such as `get`, `getAll` and `getOptional` are read only,
* and should use this method.
Copy link
Contributor

Choose a reason for hiding this comment

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

What is a top-level read-only execute method?
According to the comment, get, getAll and getOptional should use this, but it does not seem to be the case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The DB adapter and the powersync client expose SQL execution methods such as execute, getAll, get and getOptional on the class (top-level) e.g. db.execute(), db.get() and they also expose these methods in lock and transaction contexts e.g. tx.get().

The top-level get functions were previously using the top-level execute function which would actually schedule a writeLock and then use the writeLock's context execute method. These methods should actually be using a readLock instead since those can execute concurrently with writeLocks. This method provides a read only execute method on the DB adapter class as shorthand for starting a readLock and using it's execute method.

This method is used to create the top-level get helpers here https://github.com/journeyapps/powersync-react-native-sdk/blob/fc2eb5d9bf74e71ee3cd7fe896ecba5ca4f27081/packages/powersync-sdk-react-native/src/db/adapters/react-native-quick-sqlite/RNQSDBAdapter.ts#L30

Copy link
Contributor

@Manrich121 Manrich121 left a comment

Choose a reason for hiding this comment

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

100%

@stevensJourney stevensJourney merged commit 4d22c13 into main Nov 6, 2023
1 check passed
@stevensJourney stevensJourney deleted the web-sdk-common-changes branch November 6, 2023 08:29
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.

2 participants