4 个版本 (破坏性更改)
0.5.0 | 2023 年 6 月 22 日 |
---|---|
0.4.0 | 2023 年 2 月 26 日 |
0.3.0 | 2023 年 1 月 6 日 |
0.1.0 | 2022 年 12 月 6 日 |
#1191 在 并发 中
每月 68 次下载
在 datacake 中使用
345KB
7.5K SLoC
Datacake SQLite
datacake-eventual-consistency Storage
特质的预构建实现,允许您立即设置持久集群而无需实现正确存储的任何麻烦。
更多信息请参阅 https://github.com/lnx-search/datacake
设置
需要注意的是,这个包默认包含了 SQLite,但可以通过传递 default-features = false
来禁用。
示例
use anyhow::Result;
use datacake_eventual_consistency::EventuallyConsistentStoreExtension;
use datacake_node::{
ConnectionConfig,
Consistency,
DCAwareSelector,
DatacakeNodeBuilder,
};
use datacake_sqlite::SqliteStorage;
static KEYSPACE: &str = "sqlite-store";
#[tokio::test]
async fn test_basic_sqlite_cluster() -> Result<()> {
let _ = tracing_subscriber::fmt::try_init();
let store = SqliteStorage::open_in_memory().await?;
let addr = test_helper::get_unused_addr();
let connection_cfg = ConnectionConfig::new(addr, addr, Vec::<String>::new());
let node = DatacakeNodeBuilder::<DCAwareSelector>::new(1, connection_cfg)
.connect()
.await?;
let store = node
.add_extension(EventuallyConsistentStoreExtension::new(store))
.await?;
let handle = store.handle();
handle
.put(KEYSPACE, 1, b"Hello, world".to_vec(), Consistency::All)
.await
.expect("Put value.");
let doc = handle
.get(KEYSPACE, 1)
.await
.expect("Get value.")
.expect("Document should not be none");
assert_eq!(doc.id(), 1);
assert_eq!(doc.data(), b"Hello, world");
handle
.del(KEYSPACE, 1, Consistency::All)
.await
.expect("Del value.");
let doc = handle.get(KEYSPACE, 1).await.expect("Get value.");
assert!(doc.is_none(), "No document should not exist!");
handle
.del(KEYSPACE, 2, Consistency::All)
.await
.expect("Del value which doesnt exist locally.");
let doc = handle.get(KEYSPACE, 2).await.expect("Get value.");
assert!(doc.is_none(), "No document should not exist!");
node.shutdown().await;
Ok(())
}
依赖项
~30–43MB
~670K SLoC