Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rust/rsmgp-batch-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
tarpaulin-report.html
14 changes: 14 additions & 0 deletions rust/rsmgp-batch-example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "rsmgp-batch-example"
version = "0.1.0"
authors = ["Josip Mrden <[email protected]>"]
edition = "2024"

[dependencies]
c_str_macro = "1.0.2"
rand = "0.9.1"
rsmgp-sys = { path = "../rsmgp-sys" }

[lib]
name = "rust_batch_example"
crate-type = ["cdylib"]
67 changes: 67 additions & 0 deletions rust/rsmgp-batch-example/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use c_str_macro::c_str;
use rsmgp_sys::memgraph::*;
use rsmgp_sys::mgp::*;
use rsmgp_sys::result::*;
use rsmgp_sys::rsmgp::*;
use rsmgp_sys::value::*;
use rsmgp_sys::{
close_module, define_batch_procedure_cleanup, define_batch_procedure_init, define_procedure,
define_type, init_module,
};
use std::cell::RefCell;
use std::ffi::CString;
use std::os::raw::c_int;
use std::panic;

thread_local! {
static COUNTER: RefCell<i32> = RefCell::new(0);
}

init_module!(|memgraph: &Memgraph| -> Result<()> {
memgraph.add_batch_read_procedure(
test_procedure,
c_str!("test_procedure"),
init_procedure,
cleanup_procedure,
&[],
&[],
&[define_type!("value", Type::Int)],
)?;

Ok(())
});

define_procedure!(test_procedure, |memgraph: &Memgraph| -> Result<()> {
println!("Entered test procedure!");
let value: i32 = COUNTER.with(|counter| {
let mut val = counter.borrow_mut();
*val += 1;
*val
});

if value != 10 {
let result = memgraph.result_record()?;
result.insert_mgp_value(
c_str!("value"),
&MgpValue::make_int(value as i64, memgraph)?,
)?;
std::thread::sleep(std::time::Duration::from_secs(1));
}

println!("Exiting test procedure! Value: {}", value);
Ok(())
});

define_batch_procedure_init!(init_procedure, |memgraph: &Memgraph| -> Result<()> {
println!("Entered init procedure!");
println!("Exiting init procedure!");
Ok(())
});

define_batch_procedure_cleanup!(cleanup_procedure, |memgraph: &Memgraph| -> Result<()> {
println!("Entered cleanup procedure!");
println!("Exiting cleanup procedure!");
Ok(())
});

close_module!(|| -> Result<()> { Ok(()) });
17 changes: 17 additions & 0 deletions rust/rsmgp-mysql/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "rsmgp-mysql"
version = "0.1.0"
authors = ["Josip Mrden <[email protected]>"]
edition = "2024"

[dependencies]
mysql = "26"
c_str_macro = "1.0.2"
rsmgp-sys = { path = "../rsmgp-sys" }
hex = "0.4.3"
chrono = { version = "0.4.41", features = ["serde"] }

[lib]
name = "mysql"
libprefix = ""
crate-type = ["cdylib"]
Loading
Loading