From 4948dc547ef11e1a1f60e83d87480ca7c9ecf127 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 29 Nov 2020 16:27:40 +0800 Subject: [PATCH] feat: add persy --- __database/persy/Cargo.lock | 195 +++++++++++++++++++++++++++++++++ __database/persy/Cargo.toml | 12 ++ __database/persy/src/main.rs | 25 +++++ __database/persy/storage.persy | Bin 0 -> 4512 bytes 4 files changed, 232 insertions(+) create mode 100644 __database/persy/Cargo.lock create mode 100644 __database/persy/Cargo.toml create mode 100644 __database/persy/src/main.rs create mode 100644 __database/persy/storage.persy diff --git a/__database/persy/Cargo.lock b/__database/persy/Cargo.lock new file mode 100644 index 0000000..4819453 --- /dev/null +++ b/__database/persy/Cargo.lock @@ -0,0 +1,195 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "build_const" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "crc" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +dependencies = [ + "build_const", +] + +[[package]] +name = "data-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993a608597367c6377b258c25d7120740f00ed23a2252b729b1932dd7866f908" + +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "getrandom" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "libc" +version = "0.2.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" + +[[package]] +name = "linked-hash-map" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "persy" +version = "0.1.0" +dependencies = [ + "persy 0.11.1", +] + +[[package]] +name = "persy" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16644402c98caa98049d27fa0ef73dcf4bfc71bc23a7ebdad3fef5f6e42a5d70" +dependencies = [ + "byteorder", + "crc", + "data-encoding", + "fs2", + "linked-hash-map", + "rand", + "unsigned-varint", + "zigzag", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "unsigned-varint" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fdeedbf205afadfe39ae559b75c3240f24e257d0ca27e85f85cb82aa19ac35" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "zigzag" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70b40401a28d86ce16a330b863b86fd7dbee4d7c940587ab09ab8c019f9e3fdf" +dependencies = [ + "num-traits", +] diff --git a/__database/persy/Cargo.toml b/__database/persy/Cargo.toml new file mode 100644 index 0000000..aa053b0 --- /dev/null +++ b/__database/persy/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "persy" +version = "0.1.0" +authors = ["Hatter Jiang "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +persy="0.11" + + diff --git a/__database/persy/src/main.rs b/__database/persy/src/main.rs new file mode 100644 index 0000000..6568dac --- /dev/null +++ b/__database/persy/src/main.rs @@ -0,0 +1,25 @@ +use persy::{Persy, Config}; +use std::path::PathBuf; + +fn main() -> Result<(), Box> { + let file = "./storage.persy"; + if !PathBuf::from(file).exists() { + Persy::create("./storage.persy")?; + } + let persy = Persy::open("./storage.persy",Config::new())?; + + let mut tx = persy.begin()?; + + if !tx.exists_segment("seg").ok().unwrap_or(false) { + tx.create_segment("seg")?; + } + + let data = vec![1;20]; + let id = tx.insert("seg", &data)?; + println!("Persy id: {}", id); + + let prepared = tx.prepare()?; + prepared.commit()?; + + Ok(()) +} diff --git a/__database/persy/storage.persy b/__database/persy/storage.persy new file mode 100644 index 0000000000000000000000000000000000000000..432c983d7a028696bfe633f7180011ef99093395 GIT binary patch literal 4512 zcmZQzfB+5{?Eqo0K>4H8Xb6mkz_1MgF0NtgHR3(ye~Wmv!&4=*->l*3u~A>)4*@PV zn7qIO2ut7r6Q>A_38fb>-+cyQqLXZ_=psNqM*<`7T!=U;X8FR%z`*@LK!A~f14y_8HP`M^AoU@TZL7A6R!V}X)D zQIKR6BLmRXDrB2f7bpQutpb`_1yc*t3(>QV5v*w)BeE`o2OwSR7=hZ>0hNt{(GVC7 z0Rka_rG4@61JjF}oega;odOAr4AAT(sDNN1L}3a?>Cq4v4S}H*0-*MV$O8!}Ml66B vpRlpP$_AbUh053#9jRrgh;m~hQf_{+uRk1jqs3ri=evp0xvh@Q1Q5