Skip to content

Typed crud values #239

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

Merged
merged 3 commits into from
Aug 6, 2025
Merged

Typed crud values #239

merged 3 commits into from
Aug 6, 2025

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Aug 5, 2025

Most of our SDKs (I've checked Dart and JS) represent CrudEntry.opData and CrudEntry.previousValues as a Map<String, Any?>. In Kotlin however, we're using a Map<String, String?> (reported on Discord). This is somewhat unfortunate, as:

  1. It means that the Supabase connector will upload everything as a string, regardless of the actual type. While this isn't a huge problem since Postgrest will cast, it's also not great.
  2. It's a blocker if we want to represent binary data in the future.
  3. Since SQLite is dynamically typed, it would be nice to properly preserve type information so that users can act on the type of values at runtime.

This PR adds information to construct the type of values in opData and previousValues with backwards-compatibility in mind:

  1. As a technically-breaking change, the CrudEntry constructor is made internal. Users probably weren't invoking it directly though, that's an SDK responsibility.
  2. To keep the public Map<String, String?> type, this introduces the SqliteRow interface extending that type, while also providing a getter to get access to typed values.
  3. The interface also has a method to return a JsonObject, which we can use in the Supabase connector to upload values unchanged (giving users a serializable object without making SqliteRow serializable, which would blow up the framework size).

This way, existing reads on the fields still work because we have a Map<String, String?> type.

Copy link
Contributor

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

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

Happy with the changes here. This looks like a good solution which greatly improves the DX while maintaining backwards compatibility.

@simolus3 simolus3 merged commit 23e03b3 into main Aug 6, 2025
5 checks passed
@simolus3 simolus3 deleted the typed-crud-values branch August 6, 2025 13:53
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