Skip to content

Update remote_encryption builder to take encryption object instead of option#2127

Merged
avinassh merged 2 commits intotursodatabase:mainfrom
avinassh:builder-option
Jul 13, 2025
Merged

Update remote_encryption builder to take encryption object instead of option#2127
avinassh merged 2 commits intotursodatabase:mainfrom
avinassh:builder-option

Conversation

@avinassh
Copy link
Copy Markdown
Member

@avinassh avinassh commented Jul 13, 2025

In builder pattern, it is better to take the Object itself instead of Option<Object>. So

pub fn remote_encryption(mut self, encryption_context: Option<EncryptionContext>) -> Builder<T> {}

changed to

pub fn remote_encryption(mut self, encryption_context: EncryptionContext) -> Builder<T> {}

This follows the existing practices, and consistent with the code.

@avinassh avinassh requested review from Copilot and penberg July 13, 2025 10:06
@avinassh avinassh changed the title Update remote_encryption builder to take encryption object instead of option Update remote_encryption builder to take encryption object instead of option Jul 13, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the builder API so that remote_encryption takes an EncryptionContext directly instead of an Option<EncryptionContext>, and updates all call sites and examples to match.

  • Change remote_encryption signature in all builder impls to accept EncryptionContext and wrap it in Some(...).
  • Update the sync protocol code to conditionally call remote_encryption when an Option<EncryptionContext> is present.
  • Revise the example (encryption_sync.rs) to demonstrate the new usage pattern.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
libsql/src/database/builder.rs Updated remote_encryption method signatures for RemoteReplica, SyncedDatabase, and Remote; adjusted sync protocol code to apply it conditionally.
libsql/examples/encryption_sync.rs Modified example to construct the builder first and then call .remote_encryption(...) only when needed.
Comments suppressed due to low confidence (3)

libsql/src/database/builder.rs:309

  • Add a unit test to verify that calling remote_encryption correctly sets inner.remote_encryption to Some(encryption_context) for each builder variant.
        pub fn remote_encryption(mut self, encryption_context: EncryptionContext) -> Builder<RemoteReplica> {

libsql/examples/encryption_sync.rs:30

  • [nitpick] The variable name enc is abbreviated and may be unclear; consider using encryption_context or context to match the API and improve readability.
    if let Some(enc) = encryption {

libsql/src/database/builder.rs:307

  • [nitpick] The remote_encryption method is duplicated across three different builder implementations; consider extracting a shared trait or helper macro to DRY up this logic.
        /// Set the encryption context if the database is encrypted in remote server.

@avinassh avinassh added this pull request to the merge queue Jul 13, 2025
Merged via the queue into tursodatabase:main with commit 8352741 Jul 13, 2025
19 checks passed
@avinassh avinassh deleted the builder-option branch July 13, 2025 10:33
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