Expand description
§URI Register
A high-performance, async-first URI to integer registration service with PostgreSQL backend.
This library provides a bidirectional mapping between URIs (strings) and integer IDs, optimized for batch operations and designed for use in distributed systems where stateless compute nodes need fast access to a global identifier registry.
Note: This library is async-only and requires an async runtime (e.g., tokio).
It is designed to mirror the API and behavior of the Python py-json-register library.
§Features
- Async-only - Built on tokio/sqlx for high concurrency
- Batch operations - Efficiently lookup or create thousands of mappings at once
- PostgreSQL backend - Durable, scalable, with connection pooling
- LRU caching - In-memory cache for frequently accessed URIs
- Flexible table types - Support for both logged (durable) and unlogged (faster) tables
§Use Cases
- String interning systems
- URL/URI deduplication and ID assignment
- Global identifier systems
- Any system needing global, persistent string-to-ID mappings
§Example
use uri_register::{UriService, PostgresUriRegister};
#[tokio::main]
async fn main() -> uri_register::Result<()> {
// Connect to PostgreSQL (schema must be initialized first)
let register = PostgresUriRegister::new("postgres://localhost/mydb", 20, 10_000).await?;
// Register a single URI
let id = register.register_uri("http://example.org/resource/1").await?;
println!("URI registered with ID: {}", id);
// Register multiple URIs in batch (much faster!)
let uris = vec![
"http://example.org/resource/2".to_string(),
"http://example.org/resource/3".to_string(),
"http://example.org/resource/4".to_string(),
];
let ids = register.register_uri_batch(&uris).await?;
// IDs maintain order: ids[i] corresponds to uris[i]
for (uri, id) in uris.iter().zip(ids.iter()) {
println!("{} -> {}", uri, id);
}
Ok(())
}Structs§
- Postgres
UriRegister - PostgreSQL-based URI register implementation with LRU cache
- Register
Stats - Statistics about the URI register
Enums§
- Error
- Error types for URI register operations
Traits§
- UriService
- A service for registering URIs and assigning unique integer IDs
Type Aliases§
- Result
- Result type alias for URI register operations