@@ -196,10 +196,12 @@ pub struct Options {
196196 pub encryptionCipher : Option < String > ,
197197 // Encryption key for local encryption at rest.
198198 pub encryptionKey : Option < String > ,
199+ // Encryption key for remote encryption at rest.
200+ pub remoteEncryptionKey : Option < String > ,
199201}
200202
201203/// Access mode.
202- ///
204+ ///
203205/// The `better-sqlite3` API allows the caller to configure the format of
204206/// query results. This struct encapsulates the different access mode configs.
205207struct AccessMode {
@@ -247,7 +249,17 @@ impl Database {
247249 . and_then ( |o| o. authToken . as_ref ( ) )
248250 . cloned ( )
249251 . unwrap_or_default ( ) ;
250- let builder = libsql:: Builder :: new_remote ( path. clone ( ) , auth_token) ;
252+ let mut builder = libsql:: Builder :: new_remote ( path. clone ( ) , auth_token) ;
253+ if let Some ( encryption_key) = opts
254+ . as_ref ( )
255+ . and_then ( |o| o. remoteEncryptionKey . as_ref ( ) )
256+ . cloned ( )
257+ {
258+ let encryption_context = libsql:: EncryptionContext {
259+ key : libsql:: EncryptionKey :: Base64Encoded ( encryption_key) ,
260+ } ;
261+ builder = builder. remote_encryption ( Some ( encryption_context) ) ;
262+ }
251263 rt. block_on ( builder. build ( ) ) . map_err ( Error :: from) ?
252264 } else if let Some ( options) = & opts {
253265 if let Some ( sync_url) = & options. syncUrl {
@@ -280,6 +292,15 @@ impl Database {
280292 builder = builder. encryption_config ( encryption_config) ;
281293 }
282294
295+ if let Some ( remote_encryption_key) = & options. remoteEncryptionKey {
296+ let encryption_context = libsql:: EncryptionContext {
297+ key : libsql:: EncryptionKey :: Base64Encoded (
298+ remote_encryption_key. to_string ( ) ,
299+ ) ,
300+ } ;
301+ builder = builder. remote_encryption ( Some ( encryption_context) ) ;
302+ }
303+
283304 if let Some ( period) = options. syncPeriod {
284305 if period > 0.0 {
285306 builder = builder. sync_interval ( std:: time:: Duration :: from_secs_f64 ( period) ) ;
@@ -865,9 +886,12 @@ impl Statement {
865886 }
866887}
867888
868-
869889#[ napi]
870- pub fn statement_iterate_sync ( stmt : & Statement , _env : Env , params : Option < napi:: JsUnknown > ) -> Result < RowsIterator > {
890+ pub fn statement_iterate_sync (
891+ stmt : & Statement ,
892+ _env : Env ,
893+ params : Option < napi:: JsUnknown > ,
894+ ) -> Result < RowsIterator > {
871895 let rt = runtime ( ) ?;
872896 let safe_ints = stmt. mode . safe_ints . load ( Ordering :: SeqCst ) ;
873897 let raw = stmt. mode . raw . load ( Ordering :: SeqCst ) ;
@@ -880,9 +904,8 @@ pub fn statement_iterate_sync(stmt: &Statement, _env: Env, params: Option<napi::
880904 let rows = stmt. query ( params) . await . map_err ( Error :: from) ?;
881905 let mut column_names = Vec :: new ( ) ;
882906 for i in 0 ..rows. column_count ( ) {
883- column_names. push (
884- std:: ffi:: CString :: new ( rows. column_name ( i) . unwrap ( ) . to_string ( ) ) . unwrap ( ) ,
885- ) ;
907+ column_names
908+ . push ( std:: ffi:: CString :: new ( rows. column_name ( i) . unwrap ( ) . to_string ( ) ) . unwrap ( ) ) ;
886909 }
887910 Ok :: < _ , napi:: Error > ( ( rows, column_names) )
888911 } ) ?;
0 commit comments