uri-register 0.3.0

A high-performance PostgreSQL-backed URI dictionary service for assigning unique integer IDs to URIs
Documentation
// Copyright TELICENT LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! # URI Register
//!
//! A URI to integer registration service with PostgreSQL backend.
//!
//! This library provides a bidirectional mapping between URIs (strings) and integer IDs,
//! optimised for batch operations and designed for use in distributed systems where
//! stateless compute nodes need fast access to a global identifier registry.
//!
//! **API:** Both async ([`PostgresUriRegister`]) and sync ([`SyncPostgresUriRegister`]) APIs available.
//! It is designed to mirror the API and behaviour 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
//! - **Configurable caching** - W-TinyLFU (Moka) or LRU caching 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
//!
//! ```rust,no_run
//! use uri_register::{PostgresUriRegister, UriService};
//!
//! #[tokio::main]
//! async fn main() -> uri_register::Result<()> {
//!     // Connect to PostgreSQL (schema must be initialized first)
//!     let register = PostgresUriRegister::new(
//!         "postgres://localhost/mydb",
//!         "uri_register",  // table name
//!         20,              // max connections
//!         10_000           // cache size (uses Moka/W-TinyLFU by default)
//!     ).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(())
//! }
//! ```

mod cache;
mod error;
mod postgres;
mod service;
mod sync;

#[cfg(any(test, feature = "test-utils"))]
mod memory;

#[cfg(feature = "python")]
mod python;

pub use cache::{CacheStats, CacheStrategy};
pub use error::{ConfigurationError, Error, Result};
pub use postgres::{PoolStats, PostgresUriRegister, RegisterStats};
pub use service::UriService;
pub use sync::SyncPostgresUriRegister;

#[cfg(any(test, feature = "test-utils"))]
pub use memory::InMemoryUriRegister;