Refactor JSONB functions: Improved API, Documentation, and Data Structures #75
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces several enhancements to the JSONB functions:
1. New Data Structures:
OwnedJsonb
andRawJsonb
Two new structs have been added:
OwnedJsonb
: This struct represents a JSONB value that owns its underlying data (aVec<u8>
). It provides ownership over the binary JSONB representation, facilitating easier manipulation and passing of JSONB data within the application.RawJsonb
: This struct is a lightweight wrapper around a borrowed byte slice (&[u8]
). It provides a convenient way to work with JSONB data without unnecessary copying, making it more memory-efficient for operations on existing data.RawJsonb
is primarily used for read-only operations or when passing JSONB data to functions without transferring ownership.2. API Redesign: Improved Function Interfaces
The JSONB function interfaces have been significantly redesigned to improve clarity, consistency, and ease of use. Key improvements include:
&[u8]
parameters: The previous API often passed raw byte slices (&[u8]
) directly to functions. This approach obscured the data's meaning and made the code harder to understand. The introduction ofOwnedJsonb
andRawJsonb
eliminates the need for these opaque byte slices, leading to a cleaner and more readable API.RawJsonb
hides the internal binary encoding details, making it significantly easier to extend the library to support additional JSONB dialects (other database implementations of JSONB, like SQLite and PostgreSQL) in the future.These changes result in a more maintainable, extensible, and user-friendly library.
3. Enhanced Documentation:
Comprehensive documentation, including detailed usage examples, has been added to all functions. This improves the understandability and usability of the library.
part of #73