# timeid
A compact, time-based unique ID generator with SQLite tracking.
Each ID encodes the current Unix timestamp using a custom base character set and ensures uniqueness by storing used IDs in a local SQLite database (`~/.timeid.sqlite` by default).
---
## ๐ฆ Features
- ๐ Guarantees uniqueness by checking past IDs in a local database.
- ๐ Easily decodes IDs back to human-readable timestamps.
- ๐ Optional memo and tag can be saved with each ID.
- ๐พ Uses SQLite under the hood for lightweight local persistence.
---
## ๐ง Usage
Add to your `Cargo.toml`:
```toml
[dependencies]
timeid = "0.0.1"
```
Then use in your code:
```rust
use timeid::TimeId;
fn main() -> rusqlite::Result<()> {
let id = TimeId::gen()?; // Generate a new ID
println!("Generated ID: {}", id);
let readable = TimeId::parse(&id); // Parse ID back to datetime
println!("Parsed: {}", readable);
let count = TimeId::status()?; // Check total generated
println!("Stored rows: {}", count);
Ok(())
}
```
---
## ๐ Resetting the Database
You can reset the SQLite database:
```rust
TimeId::reset(None)?;
```
This deletes and recreates the default `~/.timeid.sqlite`.
---
## ๐งช Testing
To test:
```bash
cargo test -- --nocapture
```
---
## ๐ Storage Path
By default, the SQLite file is stored at:
- macOS/Linux: `~/.timeid.sqlite`
- Windows: `%USERPROFILE%/.timeid.sqlite`
You can override the path by passing a custom one to `reset()` or modifying the internal `init()` function.
---
## ๐ License
MIT License
---
## โจ Author
Nick ([@loyoming](mailto:loyoming@gmail.com))