1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 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(())
//! }
//! ```
pub use ;
pub use ;
pub use ;
pub use UriService;
pub use SyncPostgresUriRegister;
pub use InMemoryUriRegister;