Show HN: Sqlitemap, a persistent map implementation backed by SQLite for C++

4 bw-hro 0 5/11/2025, 8:46:11 PM github.com ↗
I have created sqlitemap, inspired by pythons sqlitedict. It offers an easy way to store key-value data into a SQLite database by implementing a map interface so that no sql needs to be written.

Main features:

- Persistent key-value storage using SQLite - Easy-to-use map-like interface in C++17 - Transactions - Custom encoding/decoding for keys and values

Minimal example:

  #include <bw/sqlitemap/sqlitemap.hpp>
  
  int main()
  {
    bw::sqlitemap::sqlitemap db("example.sqlite");
    
    // add some key-value pairs
    db["a"] = "first-item";
    db["b"] = "second-item";
    db["c"] = "third-item";
    db.commit();
    
    std::string item = db["b"]; // query key "b"
    std::cout << item << std::endl;
  }
Results in a SQLite database like this:

  $ sqlite3 example.sqlite 
  sqlite> SELECT * FROM unnamed;
  a|first-item
  b|second-item
  c|third-item
Maybe someone else will find it helpful too, any feedback welcome! More details/examples etc. can be found on Github: https://github.com/bw-hro/sqlitemap

Comments (0)

No comments yet