Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b500ab0
Add spatial data types
gitbuda Aug 17, 2024
d58bab9
Add Point2D and Point3D + tests
gitbuda Aug 18, 2024
65ff828
Move to the latest mgclient
gitbuda Aug 24, 2024
dcb84ac
Fix linux build
gitbuda Aug 24, 2024
9a513b1
Merge branch 'master' into add-spatial-types
gitbuda Aug 24, 2024
eed064f
Try 1 ssl, print dir
gitbuda Aug 24, 2024
f15e007
Try 2 ssl, ls fix
gitbuda Aug 24, 2024
c8119e9
Try 3 ssl, ls fix
gitbuda Aug 24, 2024
7ac4a37
Try 4 ssl, ls fix
gitbuda Aug 24, 2024
b39c332
Try 5 ssl, ls fix
gitbuda Aug 24, 2024
46461e3
Try 6 ssl, ls fix
gitbuda Aug 24, 2024
9a10e81
Try 7 ssl, ls fix
gitbuda Aug 24, 2024
bb1425f
Try 8 ssl
gitbuda Aug 24, 2024
0dc11ed
Try 9 ssl
gitbuda Aug 24, 2024
525222b
Try 10 ssl
gitbuda Aug 24, 2024
373ebe2
Try 11 ssl
gitbuda Aug 24, 2024
bb2ae9b
Try 12 ssl
gitbuda Aug 24, 2024
fb7c9f6
Try 13 ssl
gitbuda Aug 24, 2024
8f6a78b
Try 14 ssl
gitbuda Aug 24, 2024
4510368
Try 15 ssl
gitbuda Aug 24, 2024
a99c4ed
Try 16 ssl
gitbuda Aug 24, 2024
db45240
Try 17 ssl
gitbuda Aug 24, 2024
adbad91
Try 18 ssl
gitbuda Aug 24, 2024
c341d57
Try 19 ssl
gitbuda Aug 24, 2024
8380c25
Try 20 ssl
gitbuda Aug 24, 2024
f844919
Try 21 ssl
gitbuda Aug 24, 2024
f515f8c
Try 22 ssl
gitbuda Aug 24, 2024
1faba59
Try 23 ssl
gitbuda Aug 24, 2024
18be18a
Try 24 ssl
gitbuda Aug 24, 2024
b52a1b1
Try 25 ssl
gitbuda Aug 24, 2024
a212ad5
Try 26 ssl
gitbuda Aug 24, 2024
48eb993
Try 27 ssl
gitbuda Aug 24, 2024
41f3a24
Try 28 ssl
gitbuda Aug 25, 2024
ca123ca
Try 29 ssl
gitbuda Aug 25, 2024
4c9dbfa
Try 30 ssl
gitbuda Aug 25, 2024
0fafc9b
Try 31 ssl
gitbuda Aug 25, 2024
0d2bcb5
Try 32 ssl
gitbuda Aug 25, 2024
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
34 changes: 16 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: CI

on: [push]

jobs:
Expand All @@ -9,11 +8,10 @@ jobs:
platform: [ubuntu-20.04, ubuntu-22.04]
mgversion: [2.19.0]
runs-on: ${{ matrix.platform }}

steps:
- name: Install system dependencies
run: sudo apt-get install -y git cmake make gcc g++ libssl-dev
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true

Expand Down Expand Up @@ -55,19 +53,15 @@ jobs:
run: |
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

- name: Install dependencies
run: |
yum install -y git cmake make gcc gcc-c++ openssl-devel epel-release clang

- name: Install rustup
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

- uses: actions/checkout@v2
with:
submodules: true

- name: Build the project
run: |
. "$HOME/.cargo/env"
Expand All @@ -79,29 +73,26 @@ jobs:
platform: [macos-latest]
target: [x86_64-apple-darwin]
runs-on: ${{ matrix.platform }}

steps:
- name: Install Rustup
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
sh rustup-init.sh -y --default-toolchain none
rustup target add ${{ matrix.target }}

- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true

- name: Build the client
run: cargo build --release

build_windows:
strategy:
matrix:
platform: [windows-2019]
platform: [windows-2022]
target: [x86_64-pc-windows-gnu]
arch:
- { mingw: 64, msys: x86_64 }
mgversion: [1.5]
- { mingw: 32, msys: x86_64 }
runs-on: ${{ matrix.platform }}

steps:
Expand All @@ -110,24 +101,31 @@ jobs:
# Disable the download progress bar which can cause perf issues
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
.\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none
.\rustup-init.exe -y --default-host=x86_64-pc-windows-gnu --default-toolchain=none
rustup target add ${{ matrix.target }}
del rustup-init.exe

- uses: msys2/setup-msys2@v2
# From https://github.com/msys2/setup-msys2?tab=readme-ov-file#msys2-location
id: msys2
with:
msystem: MINGW${{ matrix.arch.mingw }}
update: true
install: git mingw-w64-${{ matrix.arch.msys }}-toolchain mingw-w64-${{ matrix.arch.msys }}-cmake mingw-w64-${{ matrix.arch.msys }}-openssl
install: >-
git
mingw-w${{ matrix.arch.mingw }}-${{ matrix.arch.msys }}-toolchain
mingw-w${{ matrix.arch.mingw }}-${{ matrix.arch.msys }}-cmake
mingw-w${{ matrix.arch.mingw }}-${{ matrix.arch.msys }}-openssl

- name: Add mingw${{ matrix.arch.mingw }} to PATH
- name: Define required environment variables
run: |
echo "C:/msys64/mingw${{ matrix.arch.mingw }}/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
echo "CMAKE_GENERATOR=MinGW Makefiles" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
echo "OPENSSL_LIB_DIR=${{ steps.msys2.outputs.msys2-location }}/mingw${{ matrix.arch.mingw }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8

- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true

- name: Build the client
run: |
cargo build --release --target=${{ matrix.target }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ serde_json = "1.0.57"

[build-dependencies]
bindgen = "0.68.1"
cmake = "0.1.45"
cmake = "0.1.51"

[dev-dependencies.cargo-husky]
version = "1"
Expand Down
14 changes: 10 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,20 @@ fn build_mgclient_linux() -> PathBuf {
}

fn build_mgclient_windows() -> PathBuf {
// NOTE: The intention with the default here is to help desktop Windows users link OpenSSL
// default folder created when OpenSSL is manually installed.
let openssl_dir = PathBuf::from(
std::env::var("OPENSSL_LIB_DIR")
.unwrap_or_else(|_| "C:\\Program Files\\OpenSSL-Win64\\lib".to_string()),
);
println!("cargo:rustc-link-search=native={}", openssl_dir.display());
Config::new("mgclient")
.define("OPENSSL_ROOT_DIR", format!("{}", openssl_dir.display()))
.build()
if openssl_dir.exists() {
println!("cargo:rustc-link-search=native={}", openssl_dir.display());
Config::new("mgclient")
.define("OPENSSL_ROOT_DIR", format!("{}", openssl_dir.display()))
.build()
} else {
Config::new("mgclient").build()
}
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl Connection {
unsafe {
bindings::mg_session_params_destroy(mg_session_params);
if !trust_callback_ptr.is_null() {
Box::from_raw(trust_callback_ptr);
let _ = Box::from_raw(trust_callback_ptr);
}
};

Expand Down
20 changes: 19 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use rsmgclient::{ConnectParams, Connection, MgError, Value};
use std::collections::HashMap;

use rsmgclient::{ConnectParams, Connection, MgError, Point2D, QueryParam, Value};

fn execute_query() -> Result<(), MgError> {
// Connect to Memgraph.
Expand Down Expand Up @@ -29,6 +31,22 @@ fn execute_query() -> Result<(), MgError> {
}
connection.commit()?;

let mut query_params: HashMap<String, QueryParam> = HashMap::new();
query_params.insert(
"point2d".to_string(),
QueryParam::Point2D(Point2D {
srid: 7203,
x_longitude: 0.0,
y_latitude: 1.0,
}),
);
connection.execute("RETURN $point2d;", Some(&query_params))?;
for record in connection.fetchall()? {
for value in record.values {
println!("{}", value);
}
}

Ok(())
}

Expand Down
96 changes: 96 additions & 0 deletions src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,43 @@ use std::num::TryFromIntError;
use std::os::raw::c_char;
use std::slice;

/// Representation of Point2D spatial data type.
#[derive(Debug, PartialEq, Clone)]
pub struct Point2D {
pub srid: u16,
pub x_longitude: f64,
pub y_latitude: f64,
}

impl fmt::Display for Point2D {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Point2D({{ srid:{}, x:{}, y:{} }})",
self.srid, self.x_longitude, self.y_latitude
)
}
}

/// Representation of Point3D spatial data type.
#[derive(Debug, PartialEq, Clone)]
pub struct Point3D {
pub srid: u16,
pub x_longitude: f64,
pub y_latitude: f64,
pub z_height: f64,
}

impl fmt::Display for Point3D {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Point2D({{ srid:{}, x:{}, y:{}, z:{} }})",
self.srid, self.x_longitude, self.y_latitude, self.z_height
)
}
}

/// Representation of parameter value used in query.
pub enum QueryParam {
Null,
Expand All @@ -34,6 +71,8 @@ pub enum QueryParam {
LocalTime(NaiveTime),
LocalDateTime(NaiveDateTime),
Duration(Duration),
Point2D(Point2D),
Point3D(Point3D),
List(Vec<QueryParam>),
Map(HashMap<String, QueryParam>),
}
Expand All @@ -60,6 +99,12 @@ impl QueryParam {
QueryParam::Duration(x) => {
bindings::mg_value_make_duration(duration_to_mg_duration(x))
}
QueryParam::Point2D(x) => {
bindings::mg_value_make_point_2d(point2d_to_mg_point_2d(x))
}
QueryParam::Point3D(x) => {
bindings::mg_value_make_point_3d(point3d_to_mg_point_3d(x))
}
QueryParam::List(x) => bindings::mg_value_make_list(vector_to_mg_list(x)),
QueryParam::Map(x) => bindings::mg_value_make_map(hash_map_to_mg_map(x)),
}
Expand Down Expand Up @@ -135,6 +180,8 @@ pub enum Value {
LocalTime(NaiveTime),
LocalDateTime(NaiveDateTime),
Duration(Duration),
Point2D(Point2D),
Point3D(Point3D),
Map(HashMap<String, Value>),
Node(Node),
Relationship(Relationship),
Expand Down Expand Up @@ -241,6 +288,32 @@ pub(crate) fn mg_value_duration(mg_value: *const bindings::mg_value) -> Duration
Duration::days(days) + Duration::seconds(seconds) + Duration::nanoseconds(nanoseconds)
}

pub(crate) fn mg_value_point2d(mg_value: *const bindings::mg_value) -> Point2D {
let c_point2d = unsafe { bindings::mg_value_point_2d(mg_value) };
let srid = unsafe { bindings::mg_point_2d_srid(c_point2d) } as u16;
let x_longitude = unsafe { bindings::mg_point_2d_x(c_point2d) };
let y_latitude = unsafe { bindings::mg_point_2d_y(c_point2d) };
Point2D {
srid,
x_longitude,
y_latitude,
}
}

pub(crate) fn mg_value_point3d(mg_value: *const bindings::mg_value) -> Point3D {
let c_point3d = unsafe { bindings::mg_value_point_3d(mg_value) };
let srid = unsafe { bindings::mg_point_3d_srid(c_point3d) } as u16;
let x_longitude = unsafe { bindings::mg_point_3d_x(c_point3d) };
let y_latitude = unsafe { bindings::mg_point_3d_y(c_point3d) };
let z_height = unsafe { bindings::mg_point_3d_z(c_point3d) };
Point3D {
srid,
x_longitude,
y_latitude,
z_height,
}
}

pub(crate) fn mg_map_to_hash_map(mg_map: *const bindings::mg_map) -> HashMap<String, Value> {
unsafe {
let size = bindings::mg_map_size(mg_map);
Expand Down Expand Up @@ -433,6 +506,21 @@ pub(crate) fn duration_to_mg_duration(input: &Duration) -> *mut bindings::mg_dur
unsafe { bindings::mg_duration_make(0, days, seconds, nanoseconds) }
}

pub(crate) fn point2d_to_mg_point_2d(input: &Point2D) -> *mut bindings::mg_point_2d {
unsafe { bindings::mg_point_2d_make(input.srid, input.x_longitude, input.y_latitude) }
}

pub(crate) fn point3d_to_mg_point_3d(input: &Point3D) -> *mut bindings::mg_point_3d {
unsafe {
bindings::mg_point_3d_make(
input.srid,
input.x_longitude,
input.y_latitude,
input.z_height,
)
}
}

pub(crate) fn vector_to_mg_list(vector: &[QueryParam]) -> *mut bindings::mg_list {
let size = vector.len() as u32;
let mg_list = unsafe { bindings::mg_list_make_empty(size) };
Expand Down Expand Up @@ -466,6 +554,12 @@ impl Value {
bindings::mg_value_type_MG_VALUE_TYPE_DURATION => {
Value::Duration(mg_value_duration(c_mg_value))
}
bindings::mg_value_type_MG_VALUE_TYPE_POINT_2D => {
Value::Point2D(mg_value_point2d(c_mg_value))
}
bindings::mg_value_type_MG_VALUE_TYPE_POINT_3D => {
Value::Point3D(mg_value_point3d(c_mg_value))
}
bindings::mg_value_type_MG_VALUE_TYPE_LIST => {
Value::List(mg_value_list_to_vec(c_mg_value))
}
Expand Down Expand Up @@ -496,6 +590,8 @@ impl fmt::Display for Value {
Value::LocalTime(x) => write!(f, "'{}'", x),
Value::LocalDateTime(x) => write!(f, "'{}'", x),
Value::Duration(x) => write!(f, "'{}'", x),
Value::Point2D(x) => write!(f, "'{}'", x),
Value::Point3D(x) => write!(f, "'{}'", x),
Value::List(x) => write!(
f,
"{}",
Expand Down
Loading