memgraph-d ~main

D bindings for the memgraph DB


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

ubuntu macos windows coverage

memgraph-d

D bindings for the memgraph DB

Memgraph DB is © Memgraph Ltd., see https://memgraph.com

Please note that all structs are only thin wrappers around the native mg_* types and that no copying or allocations are being made.

Example

import std.stdio, std.conv;
import memgraph;

int main() {
  auto client = Client.connect();
  if (!client) {
    writefln("Failed to connect: %s", client.status);
    return 1;
  }

  if (!client.run("CREATE INDEX ON :Person(id);")) {
    writefln("Failed to create index: %s %s", client.status, client.error);
    return 1;
  }

  if (!client.run("CREATE (:Person:Entrepreneur {id: 0, age: 40, name: 'John', " ~
                  "isStudent: false, score: 5.0});")) {
    writefln("Failed to add data: %s %s", client.status, client.error);
    return 1;
  }

  auto results = client.execute("MATCH (n) RETURN n;");
  foreach (r; results)
    writefln("%s", r[0]);

  writefln("Summary: %s", results.summary);
  writefln("Columns: %s", results.columns);

  return 0;
}

Output

Person:Entrepreneur {score:5 age:40 id:0 isStudent:false name:John}
Summary: {cost_estimate:1 type:r planning_time:0.000198 has_more:false plan_execution_time:0.000329302 parsing_time:4.0088e-05}
Columns: ["n"]

Prerequisites

To run the examples or the unit tests, a local Docker installation is required. Install Docker as appropriate for your platform.

docker pull memgraph/memgraph

Then start a local memgraph container with e.g.:

docker run -p 7687:7687 --name memgraph memgraph/memgraph --also-log-to-stderr --log-level=DEBUG

subsequently:

docker start memgraph

Building the library

dub build

This will pull the mgclient C interface for memgraph as a git submodule and build it locally. Please refer to https://github.com/memgraph/mgclient for the build requirements.

Building the examples

This package contains two examples that were adapted from the examples contained in the mgclient C interface library.

cd examples/basic
dub build
./run.sh

cd examples/advanced
dub build
./advanced 127.0.0.1 7687

Generate local documentation

dub build -b ddox

Run unittests and generate coverage data

dub test -b unittest-cov

Some useful commands

Start mgconsole via docker

IP=`docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' memgraph`
docker run -it --entrypoint=mgconsole memgraph/memgraph --host $IP --use-ssl=False

Use mgconsole to run a cypher script

docker run -i --entrypoint=mgconsole memgraph/memgraph --host $IP --use-ssl=False -output_format=csv < script.cql

History

  • v0.0.6 Use mgclient version to v1.4.0.
     Temporary fix for LocalDateTime UTC issue.
    
  • v0.0.5 Reduced number of memory allocations by ~95%, added proper pagination when fetching results,
     using native D temporal types, @nogc where possible and many more small improvements.
    
Authors:
  • Sinisa Susnjar
Dependencies:
none
Versions:
0.0.6 2023-Feb-11
0.0.5 2022-Jan-13
0.0.4 2021-Sep-30
0.0.3 2021-Sep-28
0.0.2 2021-Aug-13
Show all 8 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 28 downloads total

Score:
0.8
Short URL:
memgraph-d.dub.pm