timeid

Crates.iotimeid
lib.rstimeid
version0.0.1
created_at2025-06-01 01:32:19.623157+00
updated_at2025-06-01 01:32:19.623157+00
descriptionA simple crate to generate unique, timestamp-based IDs with memo/tag support stored in local SQLite
homepage
repositoryhttps://github.com/nicklawman/timeid
max_upload_size
id1696825
size16,939
nick (nicklawman)

documentation

README

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:

[dependencies]
timeid = "0.0.1"

Then use in your code:

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:

TimeId::reset(None)?;

This deletes and recreates the default ~/.timeid.sqlite.


๐Ÿงช Testing

To test:

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)

Commit count: 0

cargo fmt