Skip to content

Commit b5beb0c

Browse files
authored
Port to mgclient v1.2.0 (#25)
* Add mgclient as a submodule * Add Windows compile * Add MacOS compile
1 parent d00caf7 commit b5beb0c

File tree

12 files changed

+526
-2171
lines changed

12 files changed

+526
-2171
lines changed

.github/workflows/ci.yml

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,34 @@ name: CI
33
on: [push]
44

55
jobs:
6-
build_and_test:
6+
build_and_test_ubuntu:
77
strategy:
88
matrix:
9-
platform: [ubuntu-18.04]
9+
platform: [ubuntu-18.04, ubuntu-20.04]
10+
mgversion: [1.4.0, 1.5.0]
1011
runs-on: ${{ matrix.platform }}
12+
1113
steps:
1214
- name: Install system dependencies
1315
run: sudo apt-get install -y git cmake make gcc g++ libssl-dev
14-
- name: Download mgclient
15-
uses: actions/checkout@master
16+
- uses: actions/checkout@v2
1617
with:
17-
repository: memgraph/mgclient
18-
- name: Install mgclient
19-
run: |
20-
mkdir build
21-
cd build
22-
cmake ..
23-
make
24-
sudo make install
18+
submodules: true
19+
2520
- name: Cache Memgraph Docker image
26-
id: cache-memgraph-docker
21+
id: cache-memgraph-community-docker
2722
uses: actions/cache@v1
2823
with:
2924
path: ~/memgraph
30-
key: cache-memgraph-v1.1.0-docker-image
25+
key: cache-memgraph-v${{ matrix.mgversion }}-docker-image
3126
- name: Download Memgraph Docker image
32-
if: steps.cache-memgraph-docker.outputs.cache-hit != 'true'
27+
if: steps.cache-memgraph-community-docker.outputs.cache-hit != 'true'
3328
run: |
3429
mkdir ~/memgraph
35-
curl -L https://memgraph.com/download/memgraph/v1.1.0/docker/memgraph-1.1.0-community-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz
36-
30+
curl -L https://memgraph.com/download/memgraph/v${{ matrix.mgversion }}/docker/memgraph-${{ matrix.mgversion }}-community-docker.tar.gz > ~/memgraph/memgraph-docker.tar.gz
3731
- name: Load Memgraph Docker image
3832
run: docker load -i ~/memgraph/memgraph-docker.tar.gz
39-
- uses: actions/checkout@v2
33+
4034
- uses: actions-rs/toolchain@v1
4135
with:
4236
toolchain: stable
@@ -49,15 +43,73 @@ jobs:
4943

5044
- name: Run Memgraph
5145
run: |
52-
docker run -d -p 7687:7687 -v mg_lib:/var/lib/memgraph -v mg_log:/var/log/memgraph -v mg_etc:/etc/memgraph memgraph
46+
docker run -d -p 7687:7687 memgraph --telemetry-enabled=False
5347
5448
- name: Run cargo-tarpaulin
55-
uses: actions-rs/[email protected].2
49+
uses: actions-rs/[email protected].3
5650
with:
57-
args: '--out Html --ignore-tests'
58-
51+
args: '--out Html --ignore-tests --exclude-files mgclient/*'
5952
- name: Archive code coverage results
6053
uses: actions/upload-artifact@v1
6154
with:
6255
name: code-coverage-report
6356
path: tarpaulin-report.html
57+
58+
build_macos:
59+
strategy:
60+
matrix:
61+
platform: [macos-latest]
62+
target: [x86_64-apple-darwin]
63+
runs-on: ${{ matrix.platform }}
64+
65+
steps:
66+
- name: Install Rustup
67+
run: |
68+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
69+
sh rustup-init.sh -y --default-toolchain none
70+
rustup target add ${{ matrix.target }}
71+
72+
- uses: actions/checkout@v2
73+
with:
74+
submodules: true
75+
76+
- name: Build the client
77+
run: cargo build --release
78+
79+
build_windows:
80+
strategy:
81+
matrix:
82+
platform: [windows-2019]
83+
target: [x86_64-pc-windows-gnu]
84+
arch:
85+
- { mingw: 64, msys: x86_64 }
86+
mgversion: [1.5]
87+
runs-on: ${{ matrix.platform }}
88+
89+
steps:
90+
- name: Install Rustup using win.rustup.rs
91+
run: |
92+
# Disable the download progress bar which can cause perf issues
93+
$ProgressPreference = "SilentlyContinue"
94+
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
95+
.\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none
96+
rustup target add ${{ matrix.target }}
97+
del rustup-init.exe
98+
99+
- uses: msys2/setup-msys2@v2
100+
with:
101+
msystem: MINGW${{ matrix.arch.mingw }}
102+
update: true
103+
install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl
104+
105+
- name: Add mingw${{ matrix.arch.mingw }} to PATH
106+
run: |
107+
echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
108+
109+
- uses: actions/checkout@v2
110+
with:
111+
submodules: true
112+
113+
- name: Build the client
114+
run: |
115+
cargo build --release --target=${{ matrix.target }}

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "mgclient"]
2+
path = mgclient
3+
url = https://github.com/memgraph/mgclient

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rsmgclient"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
description = "Memgraph database adapter for Rust programming language."
55
authors = ["Memgraph Contributors <[email protected]>"]
66
license = "Apache-2.0"
@@ -23,6 +23,10 @@ maplit = "1.0.2"
2323
libc = "0.2"
2424
serial_test = "0.4.0"
2525

26+
[build-dependencies]
27+
bindgen = "0.58.1"
28+
cmake = "0.1.45"
29+
2630
[dev-dependencies.cargo-husky]
2731
version = "1"
2832
default-features = false

README.md

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,98 @@
44

55
`rsmgclient` is a Memgraph database adapter for Rust programming language.
66

7-
rsmgclient crate is the current implementation of the adapter. It is implemented as a wrapper
8-
around [mgclient](https://github.com/memgraph/mgclient), the official Memgraph client library.
7+
rsmgclient crate is the current implementation of the adapter. It is
8+
implemented as a wrapper around
9+
[mgclient](https://github.com/memgraph/mgclient), the official Memgraph client
10+
library.
911

1012
## Prerequisites
1113

1214
### Installation
1315

14-
`rsmgclient` is a wrapper around the [mgclient](https://github.com/memgraph/mgclient) Memgraph
15-
client library. To install it from sources you will need:
16-
- [Rust](https://doc.rust-lang.org/cargo/getting-started/installation.html) - 1.42.0 or above
17-
- A C compiler supporting C11 standard
18-
- [mgclient](https://github.com/memgraph/mgclient) has to be installed because `rsmgclient` statically links `mgclient`
19-
- [Memgraph](https://docs.memgraph.com/memgraph/quick-start)
16+
`rsmgclient` is a wrapper around the
17+
[mgclient](https://github.com/memgraph/mgclient) Memgraph client library. To
18+
install it from sources you will need:
2019

21-
Once prerequisites are met, if you want to use it as library for your own Rust project, you can
22-
install rsmgclient using `cargo` to download it from crates.io:
23-
```
24-
$ cargo install rsmgclient
20+
- [Rust](https://doc.rust-lang.org/cargo/getting-started/installation.html)
21+
1.42.0 or above
22+
- A C compiler supporting C11 standard
23+
- [Memgraph](https://docs.memgraph.com/memgraph/quick-start)
24+
25+
Once prerequisites are met, if you want to use it as library for your own Rust
26+
project, you can install rsmgclient using `cargo` to download it from
27+
crates.io:
28+
29+
```bash
30+
cargo install rsmgclient
2531
```
2632

2733
### Building from source
2834

29-
To use `rsmgclient` for contributing or just looking closely how it is made, you will need:
30-
- Cloned [rsmgclient](https://github.com/memgraph/rsmgclient) repository
31-
- [Rust](https://doc.rust-lang.org/cargo/getting-started/installation.html) - 1.42.0-nightly or above
32-
- A C compiler supporting C11 standard
33-
- [mgclient](https://github.com/memgraph/mgclient)
34-
- [Memgraph](https://docs.memgraph.com/memgraph/quick-start)
35+
To use `rsmgclient` for contributing or just looking closely how it is made,
36+
you will need:
3537

36-
Once rsmgclient is installed, you will need to build it and then you can run the test suite to verify
37-
it is working correctly.
38+
- Cloned [rsmgclient](https://github.com/memgraph/rsmgclient) repository
39+
- [Rust](https://doc.rust-lang.org/cargo/getting-started/installation.html)
40+
1.42.0-nightly or above
41+
- A C compiler supporting C11 standard
42+
- [Memgraph](https://docs.memgraph.com/memgraph/quick-start)
3843

39-
```
40-
$ cargo build
41-
$ cargo test
44+
Once rsmgclient is cloned, you will need to build it and then you can run
45+
the test suite to verify it is working correctly.
46+
47+
```bash
48+
cargo build
49+
cargo test
4250
```
4351

4452
## Documentation
4553

46-
Online documentation can be found on [docs.rs pages](https://docs.rs/rsmgclient/).
54+
Online documentation can be found on [docs.rs
55+
pages](https://docs.rs/rsmgclient/).
4756

4857
## Code sample
4958

5059
Here is an example showing some of the basic commands:
5160

5261
```rust
53-
use rsmgclient::{ConnectParams, Connection};
54-
55-
let connect_params = ConnectParams {
56-
host: Some(String::from("localhost")),
57-
..Default::default()
58-
};
59-
let mut connection = Connection::connect(&connect_params)?;
60-
61-
let query = "CREATE (u:User {name: 'Alice'})-[l:Likes]->(m:Software {name: 'Memgraph'}) RETURN u, l, m";
62-
let columns = connection.execute(query, None)?;
63-
println!("Columns: {}", columns.join(", "));
64-
65-
let records = connection.fetchall()?;
66-
for value in &records[0].values {
67-
println!("{}", value);
62+
use rsmgclient::{ConnectParams, Connection, MgError, Value};
63+
64+
fn execute_query() -> Result<(), MgError> {
65+
// Connect to Memgraph.
66+
let connect_params = ConnectParams {
67+
host: Some(String::from("localhost")),
68+
..Default::default()
69+
};
70+
let mut connection = Connection::connect(&connect_params)?;
71+
72+
// Create simple graph.
73+
connection.execute_without_results(
74+
"CREATE (p1:Person {name: 'Alice'})-[l1:Likes]->(m:Software {name: 'Memgraph'}) \
75+
CREATE (p2:Person {name: 'John'})-[l2:Likes]->(m);",
76+
)?;
77+
78+
// Fetch the graph.
79+
let columns = connection.execute("MATCH (n)-[r]->(m) RETURN n, r, m;", None)?;
80+
println!("Columns: {}", columns.join(", "));
81+
for record in connection.fetchall()? {
82+
for value in record.values {
83+
match value {
84+
Value::Node(node) => print!("{}", node),
85+
Value::Relationship(edge) => print!("-{}-", edge),
86+
value => print!("{}", value),
87+
}
88+
}
89+
println!();
90+
}
91+
connection.commit()?;
92+
93+
Ok(())
6894
}
6995

70-
connection.commit()?;
96+
fn main() {
97+
if let Err(error) = execute_query() {
98+
panic!("{}", error)
99+
}
100+
}
71101
```

0 commit comments

Comments
 (0)