Skip to content

Add NewSyncedDatabaseConnector #64

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 6 commits into from
May 28, 2025
Merged

Conversation

levydsa
Copy link
Contributor

@levydsa levydsa commented May 27, 2025

Resolves #60.

@levydsa levydsa marked this pull request as draft May 27, 2025 20:14
@levydsa levydsa marked this pull request as ready for review May 27, 2025 22:04
@levydsa
Copy link
Contributor Author

levydsa commented May 27, 2025

Also tested this with a AWS server and the TestEncryption test fails. Is this expected?

@penberg penberg requested a review from Copilot May 28, 2025 07:01
Copy link

@Copilot 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

Adds a new constructor for synced connectors and refactors existing sync setup to use a unified helper with offline support.

  • Introduces NewSyncedDatabaseConnector for always-on syncing, with an offline mode flag
  • Refactors openEmbeddedReplicaConnector into openSyncConnector and updates C bindings to use a config struct
  • Extends libsql_config in the C header with an offline field and updates the workflow for end-to-end testing

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
libsql.go Added NewSyncedDatabaseConnector, refactored sync helper, and updated CGo binding to use libsql_open_sync_with_config
lib/include/libsql.h Extended libsql_config with offline and added tracing API
.github/workflows/test.yml Added CI steps to install libsql server and run tests on macOS and Linux
Comments suppressed due to low confidence (2)

lib/include/libsql.h:69

  • The C function libsql_open_sync_with_config is invoked from Go but not declared in this header. Add its prototype to libsql.h so cgo can locate and link it correctly.
int libsql_sync2(libsql_database_t db, replicated *out_replicated, const char **out_err_msg);

libsql.go:141

  • There are no tests for the new offline sync path introduced by NewSyncedDatabaseConnector. Consider adding unit or integration tests covering both online and offline modes.
func NewSyncedDatabaseConnector(dbPath string, primaryUrl string, opts ...Option) (*Connector, error) {

return openEmbeddedReplicaConnector(dbPath, primaryUrl, authToken, readYourWrites, encryptionKey, syncInterval)
return openSyncConnector(dbPath, primaryUrl, authToken, readYourWrites, encryptionKey, syncInterval, false)
}

Copy link
Preview

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

[nitpick] Add a Go doc comment for NewSyncedDatabaseConnector explaining its parameters, behavior, and how the offline flag differs from NewEmbeddedReplicaConnector.

Suggested change
// NewSyncedDatabaseConnector creates a Connector for a synchronized database.
//
// Parameters:
// - dbPath: The file path to the local database.
// - primaryUrl: The URL of the primary database to synchronize with.
// - opts: A variadic list of options to configure the connector (e.g., encryption key, sync interval).
//
// Behavior:
// This function initializes a Connector that synchronizes the local database with a primary database.
// It applies the provided options to configure the connector. If any errors occur during option application,
// they are aggregated and returned.
//
// Difference from NewEmbeddedReplicaConnector:
// The `offline` flag passed to `openSyncConnector` is set to `true` in this function, indicating that
// the connector operates in synchronized mode. In contrast, `NewEmbeddedReplicaConnector` sets the `offline`
// flag to `false`, indicating embedded replica mode.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@penberg penberg left a comment

Choose a reason for hiding this comment

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

Looks good, @avinassh can you also review for sanity?

@avinassh
Copy link
Member

Also tested this with a AWS server and the TestEncryption test fails. Is this expected?

new server does not support encryption yet

@levydsa levydsa merged commit e72e5bf into tursodatabase:main May 28, 2025
2 checks passed
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.

Offline write support
3 participants