Skip to content

Commit f4c67bf

Browse files
committed
update sync example to work with encryption
1 parent 0f23f15 commit f4c67bf

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

example/sync/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ func run() (err error) {
1515
return fmt.Errorf("TURSO_URL environment variable not set")
1616
}
1717
authToken := os.Getenv("TURSO_AUTH_TOKEN")
18+
remoteEncryptionKey := os.Getenv("TURSO_REMOTE_ENCRYPTION_KEY")
1819
dir, err := os.MkdirTemp("", "libsql-*")
1920
if err != nil {
2021
return err
2122
}
2223
defer os.RemoveAll(dir)
2324

24-
connector, err := libsql.NewEmbeddedReplicaConnector(dir+"/test.db", primaryUrl, libsql.WithAuthToken(authToken))
25+
opts := []libsql.Option{libsql.WithAuthToken(authToken)}
26+
if remoteEncryptionKey != "" {
27+
opts = append(opts, libsql.WithRemoteEncryption(remoteEncryptionKey))
28+
}
29+
30+
connector, err := libsql.NewEmbeddedReplicaConnector(dir+"/test.db", primaryUrl, opts...)
2531
if err != nil {
2632
return err
2733
}
@@ -44,9 +50,14 @@ func run() (err error) {
4450
}
4551
}()
4652

53+
msg := "1. Sync with primary"
54+
if remoteEncryptionKey != "" {
55+
msg += " (encrypted db)"
56+
}
57+
4758
for {
4859
fmt.Println("What would you like to do?")
49-
fmt.Println("1. Sync with primary")
60+
fmt.Println(msg)
5061
fmt.Println("2. Select from test table")
5162
fmt.Println("3. Insert row to test table")
5263
fmt.Println("4. Exit")

0 commit comments

Comments
 (0)