GithubHelp home page GithubHelp logo

mgclient's Introduction

Actions Status

mgclient

mgclient is a C library interface for Memgraph database.

Building and installing on Apple

To build and install mgclient from source you will need:

  • CMake version >= 3.8
  • OpenSSL version >= 1.0.2
  • Apple LLVM/clang >= 8.0.0

Once everything is in place, create a build directory inside the project root directory and configure the build by running CMake from it:

mkdir build
cd build
cmake ..

NOTE: Dealing with OpenSSL might be a bit tricky. If OpenSSL is not available on the system, please use, e.g., brew package manager to install OpenSSL with the following command:

brew install [email protected]

If cmake can't locate OpenSSL, please set OPENSSL_ROOT_DIR to a valid path. Examples follow:

# M1 with brew installed
cmake -DOPENSSL_ROOT_DIR="$(brew --prefix openssl)" ..

# Using only ls command
cmake -DOPENSSL_ROOT_DIR="$(ls -rd -- /usr/local/Cellar/[email protected]/* | head -n 1)" ..

After running CMake, you should see a Makefile in the build directory. Then you can build the project by running:

make

This will build two mgclient library flavours: a static library (named libmgclient.a) and a shared library (named libmgclient.dylib).

To install the libraries and corresponding header files run:

make install

This will install to system default installation directory. If you want to change this location, use -DCMAKE_INSTALL_PREFIX option when running CMake.

Building and installing on Linux

To build and install mgclient from source you will need:

  • CMake version >= 3.8
  • OpenSSL version >= 1.0.2
  • gcc >= 8 or clang >= 8

To install minimum compile dependencies on Debian / Ubuntu:

apt-get install -y git cmake make gcc g++ libssl-dev

On RedHat / CentOS / Fedora:

yum install -y git cmake make gcc gcc-c++ openssl-devel

Once everything is in place, create a build directory inside the source directory and configure the build by running CMake from it:

mkdir build
cd build
cmake ..

After running CMake, you should see a Makefile in the build directory. Then you can build the project by running:

make

This will build two mgclient library flavours: a static library (usually named libmgclient.a) and a shared library (usually named libmgclient.so).

To install the libraries and corresponding header files run:

make install

This will install to system default installation directory. If you want to change this location, use -DCMAKE_INSTALL_PREFIX option when running CMake.

If you want to build and run tests, in the build directory run:

cmake -DBUILD_TESTING=ON -DBUILD_TESTING_INTEGRATION=ON ..
ctest

Building and installing on Windows

To build and install mgclient from source on Windows you will need:

  • CMake version >= 3.8
  • OpenSSL version >= 1.0.2
  • MinGW: gcc >= 8 or Windows Compiler (take a look here to understand versioning in a bit more details): VS >= 17 2022, MSVC >= 14.34, C >= 19.34

Windows Compiler

mkdir build
cd build
cmake ..
cmake --build .

Depending on where OpenSSL is installed you might need to define OPENSSL_ROOT_DIR, example follows:

cmake -DOPENSSL_ROOT_DIR="$VCPKG_ROOT\installed\x64-windows" ..

To install OpenSSL vcpkg can be used:

vcpkg install openssl:x64-windows

or you can download and install OpenSSL from here.

MinGW

  • Install MSYS2 from https://www.msys2.org/.
  • Install MinGW toolchain with the following command:
    pacman -S --needed git base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain mingw-w64-i686-cmake mingw-w64-x86_64-cmake mingw-w64-i686-openssl mingw-w64-x86_64-openssl
    

Once the environment is ready, please run:

mkdir build
cd build
cmake .. -G "MinGW Makefiles"
cmake --build . --target install

Building WASM (Linux only)

Compiling mgclient for wasm requires the Emscripten sdk. This is automated in the following steps:

  1. mkdir build && cd build
  2. cmake .. -DWASM=ON
  3. make

Now there should be an mgclient.js and an mgclient.wasm found in mgclient/build/

Using the library

The library provides header files located under the include folder. All library functionality is documented in these files in Doxygen format. You can also build HTML version of the documentation by running doxygen command from project root directory.

Examples

All the examples of the usage of the mgclient are contained in the examples folder, including the C++ wrapper.

An example on how to include mgclient inside a CMake project is located under examples/CMakeLists.txt.

mgclient's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mgclient's Issues

Synchronous calls to server?

Hi, this looks like its synchronous blocking functions am I right? Then if I wish to make many calls, can I

  1. Do them in parallel threads, is it thread safe?
  2. Should I be doing them in threads, what if I want to run 1000 calls at the same time, 1000 threads?

Variable Length Cypher Query over all Relationship Types

Hello! Thank you VERY much for the great tool and, especially, for all the great docs & examples!

I'm trying to perform a query like:

MATCH p=(from)-[rel *1..3]->(to) WHERE from.name = "Bob" AND to.name = "Frank" RETURN p

I.e. All paths of length 1..3 from "Bob" to "Frank" regardless of the relation type. I see how to do a variable length query with certain relationships, but not with all. Am I missing something in the docs? I have all the relationship types, so I could just build a string (:FRIENDS_WITH:RELATED_TO:DATED) and add the *1..3 at the end. But I just want to see if I'm missing something before I add that complexity. THANK YOU!

[BUG] Mgclient "failed to send chunk data" error when running execute_and_fetch() in Python Flask Application

Memgraph version Which version did you use?

2.6

Environment Some information about the environment you are using Memgraph
on: operating system, how do you connect, with or without docker, which driver
etc.

Operating System: Amazon Linux 2.
Use Docker w/ default settings.

Describe the bug A clear and concise description of what the bug is.

I have a Python Flask web application. One of the pages has a form that when submitted, calls Memgraph.exceute_and_fetch() to query the Memgraph database using data in the form. The returned data will then be used to populate a Memgraph Orb graph and render it to the user on new page.

Sometimes, instead of receiving node/edge data from the query, a Database Error will be returned, typically on users' first session or first session in a while. Specifically, this is an mgclient error that say "failed to send chunk data". Upon page refresh/form resubmission, the query is successful and the results render as normal and the error is not encountered again (until a future session, typically hours or day(s) later).

To Reproduce Steps to reproduce the behavior:

  1. Have Memgraph instance running and connect to that Memgraph instance using GQLAlchemy in a Python Flask Application.
  2. Have a page in the Flask Application with a form in it, and upon form submission, will run a query using GQL Alchemy's Memgraph.execute_and_fetch() method.
  3. If successful, the query will run as normal and return intended results/redirect users to the right page. However, on occasion (for a reason I can't quite narrow down), the mgclient error will be thrown. (Picture below)
  4. If the error is thrown, refreshing page and resubmitting form should always result in query being successful.

Expected behavior A clear and concise description of what you expected to
happen.

I expect the query to be successful on the first try, rather than upon a form resubmission (or repeating the excecute_and_fetch() call on the backend to ensure users don't see the error. This has "solved" the problem currently from a user standpoint, but we still see the error printed in the terminal logs. )

Logs If applicable, add logs of Memgraph, CLI output or screenshots to help
explain your problem.

image
image

Additional context Add any other context about the problem here.

DB and Query are initialized/run like this:

from gqlalchemy import Node, Field, Relationship, Memgraph, Path
db = Memgraph(host='host-link.net', port=7687)
query_result = db.execute_and_fetch(query=query, connection=db)
results = list(query_result)
  • Currently, the Flask app is being run in the same server as the Memgraph database.
  • Error text/throw seems to be found here:
    mg_session_set_error(session, "failed to send chunk data");

GQLAlchemy install fails because of mgclient dependencies

GQL is hard to install for usage on AWS Lambdas because of the dependencies, probably because OS environment is striped compared to conventional Linux images, so it probably requires a bit more steps.

The user tried to create an identical environment in custom docker image, running amazonlinux:2 :
pip3 install -t python gqlalchamy

First, the typical issues with OpenSSL not being visible popped out:

CMake Error at /usr/share/cmake3/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY) (found
  version "1.0.2k") 

After installing OpenSSL-static, zlib, and zlib-static, the OpenSSL issue disappeared, and a strange linker failure was hit:

image

The user moved to the Neo4j Python driver.

Full context: https://discord.com/channels/842007348272169002/842338690109931520/1146269544118227054

Add zig compatibility

SOURCE: https://discord.com/channels/842007348272169002/842008652377751582/1191840879812554834

export CC="zig cc"
export CXX="zig c++"
cmake ..
make

zig.build

exe.linkLibC();
exe.linkSystemLibrary("mgclient");

TODO: Add under examples

const mgclient = @cImport(
    @cInclude("mgclient.h"),
);
pub fn main() !void {
    const initialization = mgclient.mg_init();
    std.debug.print("we initialized mgclient? {d}\n", .{initialization});
    const mg_client_version = mgclient.mg_client_version();
    std.debug.print("Here is the mgclient version from zig: {s}\n", .{mg_client_version});
}

can not be used when making a PIE object; recompile with -fPIE

  • CentOS 7
  • CMake 3.20.2
  • OpenSSL 1.1.1k
  • GCC 8.5.0

I build this project in CentOS 7 and I want to take use of it in Rust.
However, it reported this error that I can not handle. I am not familiar with cmake so it is hard to solve it.

  = note: /usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/libmgclient.a(mgclient.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
          /usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/libmgclient.a(mgmessage.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
          /usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/libmgclient.a(mgsession.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
          /usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/libmgclient.a(mgsession-decoder.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
          /usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/libmgclient.a(mgsession-encoder.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
          /usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/libmgclient.a(mgtransport.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
          /usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/libmgclient.a(mgvalue.c.o): relocation R_X86_64_32 against symbol `mg_system_allocator' can not be used when making a PIE object; recompile with -fPIE
          /usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/libmgclient.a(mgsocket.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
          /usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/libmgclient.a(mgallocator.c.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE
          collect2: error: ld returned 1 exit status

I try to add "-no-pie" option but it did not help at all.

set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE -no-pie")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -no-pie")

# Set default build type to 'Release'
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.