# data_store **Repository Path**: Geoyee/data_store ## Basic Information - **Project Name**: data_store - **Description**: 持久化存储数据仓库 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-05-05 - **Last Updated**: 2024-05-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # data_store 一个基于 msgpack 和 sqlite3 的数据仓库类,可以对数据进行持久化存储 ## 示例 ```c++ #include "datastore.hpp" DataStore ds; int a = 543; std::string c = "Hello World!"; std::vector e = {84.65, 74.23}; // 存取数据 ds.put("a", a); ds.put("c", c); ds.put("e", e); // 读取数据 int a2 = ds.get("a"); int c2 = ds.get("c"); int e2 = ds.get>("e"); ``` 由于数据存储在数据库中,因此当程序崩溃或其他情况下,重启程序仍然可以取到之前保存的数据。同时存储 msgpack 序列化的数据,能够更好的节约内存 ```c++ #include "datastore.hpp" DataStore ds; // 读取数据 int a3 = ds.get("a"); // ok int c3 = ds.get("c"); // ok int e3 = ds.get>("e"); // ok ``` 程序正常退出前再清理数据库,下次重启程序后拥有全新的数据仓库 ```c++ ... ds.finish(); ```