@@ -68,6 +68,8 @@ macro_rules! impl_inner_method {
6868 $enum_name:: Sled ( inner) => inner. $name( $( $args, ) * ) ,
6969 #[ cfg( feature = "sqlite" ) ]
7070 $enum_name:: Sqlite ( inner) => inner. $name( $( $args, ) * ) ,
71+ #[ cfg( feature = "wasm-db" ) ]
72+ $enum_name:: LocalStorage ( inner) => inner. $name( $( $args, ) * ) ,
7173 }
7274 }
7375}
@@ -89,11 +91,16 @@ pub enum AnyDatabase {
8991 #[ cfg_attr( docsrs, doc( cfg( feature = "sqlite" ) ) ) ]
9092 /// Sqlite embedded database using [`rusqlite`]
9193 Sqlite ( sqlite:: SqliteDatabase ) ,
94+ #[ cfg( feature = "wasm-db" ) ]
95+ #[ cfg_attr( docsrs, doc( cfg( feature = "wasm-db" ) ) ) ]
96+ /// Browser LocalStorage database based on [`gloo_storage`]
97+ LocalStorage ( localstorage:: LocalStorageDatabase ) ,
9298}
9399
94100impl_from ! ( memory:: MemoryDatabase , AnyDatabase , Memory , ) ;
95101impl_from ! ( sled:: Tree , AnyDatabase , Sled , #[ cfg( feature = "key-value-db" ) ] ) ;
96102impl_from ! ( sqlite:: SqliteDatabase , AnyDatabase , Sqlite , #[ cfg( feature = "sqlite" ) ] ) ;
103+ impl_from ! ( localstorage:: LocalStorageDatabase , AnyDatabase , LocalStorage , #[ cfg( feature = "wasm-db" ) ] ) ;
97104
98105/// Type that contains any of the [`BatchDatabase::Batch`] types defined by the library
99106pub enum AnyBatch {
@@ -107,6 +114,10 @@ pub enum AnyBatch {
107114 #[ cfg_attr( docsrs, doc( cfg( feature = "sqlite" ) ) ) ]
108115 /// Sqlite embedded database using [`rusqlite`]
109116 Sqlite ( <sqlite:: SqliteDatabase as BatchDatabase >:: Batch ) ,
117+ #[ cfg( feature = "wasm-db" ) ]
118+ #[ cfg_attr( docsrs, doc( cfg( feature = "wasm-db" ) ) ) ]
119+ /// Browser LocalStorage database based on [`gloo_storage`]
120+ LocalStorage ( <gloo_storage:: LocalStorage as BatchDatabase >:: Batch ) ,
110121}
111122
112123impl_from ! (
@@ -116,6 +127,7 @@ impl_from!(
116127) ;
117128impl_from ! ( <sled:: Tree as BatchDatabase >:: Batch , AnyBatch , Sled , #[ cfg( feature = "key-value-db" ) ] ) ;
118129impl_from ! ( <sqlite:: SqliteDatabase as BatchDatabase >:: Batch , AnyBatch , Sqlite , #[ cfg( feature = "sqlite" ) ] ) ;
130+ impl_from ! ( <localstorage:: LocalStorageDatabase as BatchDatabase >:: Batch , AnyBatch , LocalStorage , #[ cfg( feature = "wasm-db" ) ] ) ;
119131
120132impl BatchOperations for AnyDatabase {
121133 fn set_script_pubkey (
@@ -326,6 +338,8 @@ impl BatchDatabase for AnyDatabase {
326338 AnyDatabase :: Sled ( inner) => inner. begin_batch ( ) . into ( ) ,
327339 #[ cfg( feature = "sqlite" ) ]
328340 AnyDatabase :: Sqlite ( inner) => inner. begin_batch ( ) . into ( ) ,
341+ #[ cfg( feature = "wasm-db" ) ]
342+ AnyDatabase :: LocalStorage ( inner) => inner. begin_batch ( ) . into ( ) ,
329343 }
330344 }
331345 fn commit_batch ( & mut self , batch : Self :: Batch ) -> Result < ( ) , Error > {
@@ -345,6 +359,11 @@ impl BatchDatabase for AnyDatabase {
345359 AnyBatch :: Sqlite ( batch) => db. commit_batch ( batch) ,
346360 _ => unimplemented ! ( "Other batch shouldn't be used with Sqlite db." ) ,
347361 } ,
362+ #[ cfg( feature = "wasm-db" ) ]
363+ AnyDatabase :: LocalStorage ( db) => match batch {
364+ AnyBatch :: LocalStorage ( batch) => db. commit_batch ( batch) ,
365+ _ => unimplemented ! ( "Other batch shouldn't be used with LocalStorage db." ) ,
366+ } ,
348367 }
349368 }
350369}
@@ -402,6 +421,10 @@ pub enum AnyDatabaseConfig {
402421 #[ cfg_attr( docsrs, doc( cfg( feature = "sqlite" ) ) ) ]
403422 /// Sqlite embedded database using [`rusqlite`]
404423 Sqlite ( SqliteDbConfiguration ) ,
424+ #[ cfg( feature = "wasm-db" ) ]
425+ #[ cfg_attr( docsrs, doc( cfg( feature = "wasm-db" ) ) ) ]
426+ /// Browser LocalStorage database based on [`gloo_storage`]
427+ LocalStorage ( ( ) ) ,
405428}
406429
407430impl ConfigurableDatabase for AnyDatabase {
@@ -418,10 +441,15 @@ impl ConfigurableDatabase for AnyDatabase {
418441 AnyDatabaseConfig :: Sqlite ( inner) => {
419442 AnyDatabase :: Sqlite ( sqlite:: SqliteDatabase :: from_config ( inner) ?)
420443 }
444+ #[ cfg( feature = "wasm-db" ) ]
445+ AnyDatabaseConfig :: LocalStorage ( inner) => {
446+ AnyDatabase :: LocalStorage ( localstorage:: LocalStorageDatabase :: from_config ( inner) ?)
447+ }
421448 } )
422449 }
423450}
424451
425452impl_from ! ( ( ) , AnyDatabaseConfig , Memory , ) ;
426453impl_from ! ( SledDbConfiguration , AnyDatabaseConfig , Sled , #[ cfg( feature = "key-value-db" ) ] ) ;
427454impl_from ! ( SqliteDbConfiguration , AnyDatabaseConfig , Sqlite , #[ cfg( feature = "sqlite" ) ] ) ;
455+ impl_from ! ( ( ) , AnyDatabaseConfig , LocalStorage , #[ cfg( feature = "wasm-db" ) ] ) ;
0 commit comments