pub struct SyncPostgresUriRegister { /* private fields */ }Expand description
Synchronous PostgreSQL URI register
This is a synchronous wrapper around PostgresUriRegister for use in
synchronous Rust applications. It uses a lightweight current-thread Tokio
runtime internally to execute async operations.
All methods have the same semantics as their async counterparts but block the calling thread until completion.
§Example
use uri_register::SyncPostgresUriRegister;
fn main() -> uri_register::Result<()> {
let register = SyncPostgresUriRegister::new(
"postgres://localhost/mydb",
"uri_register",
20,
10_000
)?;
let id = register.register_uri("https://example.com")?;
println!("URI registered with ID: {}", id);
Ok(())
}Implementations§
Source§impl SyncPostgresUriRegister
impl SyncPostgresUriRegister
Sourcepub fn new(
database_url: &str,
table_name: &str,
max_connections: u32,
cache_size: usize,
) -> Result<Self>
pub fn new( database_url: &str, table_name: &str, max_connections: u32, cache_size: usize, ) -> Result<Self>
Create a new synchronous PostgreSQL URI register with default cache (Moka/W-TinyLFU)
This is the backwards-compatible constructor that uses Moka caching by default.
§Arguments
database_url- PostgreSQL connection stringtable_name- Name of the database tablemax_connections- Maximum number of connections in the poolcache_size- Number of URI-to-ID mappings to cache
Sourcepub fn new_with_cache_strategy(
database_url: &str,
table_name: &str,
max_connections: u32,
cache_size: usize,
cache_strategy: Option<CacheStrategy>,
use_tls: Option<bool>,
) -> Result<Self>
pub fn new_with_cache_strategy( database_url: &str, table_name: &str, max_connections: u32, cache_size: usize, cache_strategy: Option<CacheStrategy>, use_tls: Option<bool>, ) -> Result<Self>
Create a new synchronous PostgreSQL URI register with custom cache strategy and TLS
§Arguments
database_url- PostgreSQL connection stringtable_name- Name of the database tablemax_connections- Maximum number of connections in the poolcache_size- Number of URI-to-ID mappings to cachecache_strategy- Optional cache strategy (defaults to Moka if None)use_tls- Optional TLS flag (defaults to false/None for backwards compatibility)
Sourcepub fn register_uri(&self, uri: &str) -> Result<u64>
pub fn register_uri(&self, uri: &str) -> Result<u64>
Register a single URI and return its ID (blocking)
If the URI already exists, returns the existing ID. If the URI is new, creates a new ID and returns it.
Sourcepub fn register_uri_batch(&self, uris: &[String]) -> Result<Vec<u64>>
pub fn register_uri_batch(&self, uris: &[String]) -> Result<Vec<u64>>
Register multiple URIs in batch and return their IDs (blocking)
The returned vector maintains order correspondence with the input.
Sourcepub fn register_uri_batch_hashmap(
&self,
uris: &[String],
) -> Result<HashMap<String, u64>>
pub fn register_uri_batch_hashmap( &self, uris: &[String], ) -> Result<HashMap<String, u64>>
Register multiple URIs in batch and return a HashMap (blocking)
Sourcepub fn stats(&self) -> Result<RegisterStats>
pub fn stats(&self) -> Result<RegisterStats>
Get statistics about the register (blocking)