| [ Web Proxy ] |
| Viewing: https://memgraph.com/docs/custom-query-modules/cpp/cpp-api | [Back] [Original] |
This is the API documentation for mgp.hpp, which contains declarations of all
functions in the C++ API for implementing query module procedures and
functions. The source file can be found in the Memgraph installation directory,
under /usr/include/memgraph.
To see how to implement query modules in C++, take a look at the example we provided.
If you install any C++ modules after running Memgraph, youll need to load them into Memgraph or restart Memgraph in order to use them.
With this API its possible to extend your Cypher queries with functions
and procedures with AddProcedure and AddFunction.
The API needs memory access to add procedures and functions, this can be done
with mgp::MemoryDispatcherGuard guard(memory);. Old code used mgp::memory = memory;, but this is not thread-safe and has been deprecated. v2.18.1 onwards
you should modify your C++ modules and recompile. v2.21 onwards setting
mgp::memory will cause a compilation error, so the guard has to be used.
Functions are simple operations that return a single value and can be used in any expression or predicate.
Procedures are more complex computations that may modify the graph, and their
output is available to later processing steps in your query. A procedure may
only be run from CALL clauses. The output is a stream of records that is
made accessible with a YIELD clause.
Add a procedure to your query module. The procedure is registered as [QUERY_MODULE_NAME].[PROC_NAME]
and can be used in Cypher queries.
void AddProcedure(
mgp_proc_cb callback,
std::string_view name,
ProcedureType proc_type,
std::vector<Parameter> parameters,
std::vector<Return> returns,
mgp_module *module,
mgp_memory *memory);{
callback: procedure callbackname: procedure nameproc_type: procedure type (read/write)parameters: vector (list) of procedure parametersreturns: vector (list) of procedure return valuesmodule: the query module that the procedure is added tomemory: access to memoryEnum class for Cypher procedure types.
ProcedureType::Read: read procedureProcedureType::Write: write procedureAdd a batch procedure to your query module. The procedure is registered as [QUERY_MODULE_NAME].[PROC_NAME]
and can be used in Cypher queries.
void AddBatchProcedure(
mgp_proc_cb callback,
mgp_proc_initializer initializer,
mgp_proc_cleanup cleanup,
std::string_view name,
ProcedureType proc_type,
std::vector<Parameter> parameters,
std::vector<Return> returns,
mgp_module *module,
mgp_memory *memory);{
callback: procedure callback, invoked through OpenCypherinitializer: procedure initializer, invoked before callbackcleanup: procedure cleanup, invoked after batching is donename: procedure nameproc_type: procedure type (read/write)parameters: vector (list) of procedure parametersreturns: vector (list) of procedure return valuesmodule: the query module that the procedure is added tomemory: access to memoryEnum class for Cypher procedure types.
ProcedureType::Read: read procedureProcedureType::Write: write procedureAdd a function to your query module. The function is registered as [QUERY_MODULE_NAME].[FUNC_NAME]
and can be used in Cypher queries.
void AddFunction(
mgp_func_cb callback,
std::string_view name,
std::vector<Parameter> parameters,
std::vector<Return> returns,
mgp_module *module,
mgp_memory *memory);{
callback: function callbackname: function nameparameters: vector (list) of function parametersreturns: vector (list) of function return valuesmodule: the query module that the procedure is added tomemory: access to memoryRepresents a procedure/function parameter. Parameters are defined by their name, type, and (if optional) default value.
Creates a non-optional parameter with the given name and type.
Parameter(std::string_view name, Type type)Creates an optional Boolean parameter with the given name and default_value.
Parameter(std::string_view name, Type type, bool default_value)Creates an optional integer parameter with the given name and default_value.
Parameter(std::string_view name, Type type, int default_value)Creates an optional floating-point parameter with the given name and default_value.
Parameter(std::string_view name, Type type, double default_value)Creates an optional string parameter with the given name and default_value.
Parameter(std::string_view name, Type type, std::string_view default_value)
Parameter(std::string_view name, Type type, const char *default_value)Creates a non-optional list parameter with the given name and item_type.
The list_type parameter is organized as follows: {Type::List, Type::[ITEM_TYPE]}.
Parameter(std::string_view name, std::pair<Type, Type> list_type)Creates an optional list parameter with the given name, item_type, and default_value.
The list_type parameter is organized as follows: {Type::List, Type::[ITEM_TYPE]}.
Parameter(std::string_view name, std::pair<Type, Type> list_type, Value default_value)| Name | Type | Description |
|---|---|---|
name | std::string_view | parameter name |
type_ | Type | parameter type |
list_item_type_ | Type | (list parameters) item type |
optional | bool | whether the parameter is optional |
default_value | Value | (optional parameters) default value |
Represents a procedure/function return value. Values are defined by their name and type.
Creates a return value with the given name and type.
Return(std::string_view name, Type type)Creates a return value with the given name and list_type.
The list_type parameter is organized as follows: {Type::List, Type::[ITEM_TYPE]}.
Return(std::string_view name, std::pair<Type, Type> list_type)| Name | Type | Description |
|---|---|---|
name | std::string_view | return name |
type_ | Type | return type |
list_item_type_ | Type | (list values) item type |
Factory class for Record.
explicit RecordFactory(mgp_result *result)| Name | Description |
|---|---|
NewRecord | Adds a new result record. |
SetErrorMessage | Sets the given error message. |
Adds a new result record.
Record NewRecord() constSets the given error message.
void SetErrorMessage(std::string_view error_msg) const void SetErrorMessage(const char *error_msg) constRepresents a record - the building block of Cypher procedure results. Each result is a stream of records, and a functions record is a sequence of (field name: output value) pairs.
explicit Record(mgp_result_record *record)| Name | Description |
|---|---|
Insert | Inserts a value of given type under field field_name. |
Inserts a value of given type under field field_name.
void Insert(const char *field_name, bool value) void Insert(const char *field_name, std::int64_t value) void Insert(const char *field_name, double value) void Insert(const char *field_name, std::string_view value) void Insert(const char *field_name, const char *value) void Insert(const char *field_name, const List &value) void Insert(const char *field_name, const Map &value) void Insert(const char *field_name, const Node &value) void Insert(const char *field_name, const Relationship &value) void Insert(const char *field_name, const Path &value) void Insert(const char *field_name, const Date &value) void Insert(const char *field_name, const LocalTime value) void Insert(const char *field_name, const LocalDateTime value) void Insert(const char *field_name, const ZonedDateTime value) void Insert(const char *field_name, const Duration value) void Insert(const char *field_name, const Point2d &value) void Insert(const char *field_name, const Point3d &value) void Insert(const char *field_name, const Enum &value) void Insert(const char *field_name, const Value &value)Represents a result - the single return value of a Cypher function.
explicit Result(mgp_func_result *result)| Name | Description |
|---|---|
SetValue | Sets a return value of given type. |
SetErrorMessage | Sets the given error message. |
Sets a return value of given type.
void SetValue(bool value) void SetValue(std::int64_t value) void SetValue(double value) void SetValue(std::string_view value) void SetValue(const char *value) void SetValue(const List &value) void SetValue(List &&value) void SetValue(const Map &value) void SetValue(Map &&value) void SetValue(const Node &value) void SetValue(const Relationship &value) void SetValue(const Path &value) void SetValue(const Date &value) void SetValue(const LocalTime &value) void SetValue(const LocalDateTime &value) void SetValue(const ZonedDateTime &value) void SetValue(const Duration &value) void SetValue(const Point2d &value) void SetValue(const Point3d &value) void SetValue(const Enum &value) void SetValue(const Value &value)Sets the given error message.
void SetErrorMessage(std::string_view error_msg) const void SetErrorMessage(const char *error_msg) constThis section covers the interface for working with the Memgraph DB graph using the C++ API. A description of data types is available in the reference guide.
explicit Graph(mgp_graph *graph)| Name | Description |
|---|---|
Order | Returns the graph order (number of nodes). |
Size | Returns the graph size (number of relationships). |
Nodes (GraphNodes) | Returns an iterable structure of the graphs nodes. |
Relationships | Returns an iterable structure of the graphs relationships. |
GetNodeById | Returns the graph node with the given ID. |
ContainsNode | Returns whether the graph contains the given node (accepts node or its ID). |
ContainsRelationship | Returns whether the graph contains the given relationship (accepts relationship or its ID). |
IsMutable | Returns whether the graph is mutable. |
IsTransactional | Returns whether the graph is in a transactional storage mode. |
CreateNode | Creates a node and adds it to the graph. |
DeleteNode | Deletes a node from the graph. |
DetachDeleteNode | Deletes a node and all its incident edges from the graph. |
CreateRelationship | Creates a relationship of type type between nodes from and to and adds it to the graph. |
DeleteRelationship | Deletes a relationship from the graph. |
SetFrom | Changes the from (start) node of the given relationship. |
SetTo | Changes the to (end) node of the given relationship. |
ChangeType | Changes the relationship type. |
Returns the graph order (number of nodes).
int64_t Order() constReturns the graph size (number of relationships).
int64_t Size() constReturns an iterable structure of the graphs nodes.
GraphNodes Nodes() constReturns an iterable structure of the graphs relationships.
GraphRelationships Relationships() constReturns the graph node with the given ID.
Node GetNodeById(Id node_id) constReturns whether the graph contains a node with the given ID.
bool ContainsNode(Id node_id) constReturns whether the graph contains the given node.
bool ContainsNode(const Node &node) constbool ContainsRelationship(Id relationship_id) constbool ContainsRelationship(const Relationship &relationship) constReturns whether the graph is mutable.
bool IsMutable() constReturns whether the graph is in a transactional storage mode.
bool IsTransactional() constCreates a node and adds it to the graph.
Node CreateNode();Deletes a node from the graph.
void DeleteNode(const Node &node)Deletes a node and all its incident edges from the graph.
void DetachDeleteNode(const Node &node)Creates a relationship of type type between nodes from and to and adds it to the graph.
Relationship CreateRelationship(const Node &from, const Node &to, std::string_view type)Deletes a relationship from the graph.
void DeleteRelationship(const Relationship &relationship)Changes the from (start) node of the given relationship.
void SetFrom(Relationship &relationship, const Node &new_from)Changes the to (end) node of the given relationship.
void SetTo(Relationship &relationship, const Node &set_to)Changes the relationship type
void ChangeType(Relationship &relationship, std::string_view new_type);Auxiliary class providing an iterable view of the nodes contained in the graph.
GraphNodes values may only be used for iteration to obtain the values stored within.
explicit GraphNodes(mgp_vertices_iterator *nodes_iterator)| Name | Type | Description |
|---|---|---|
Iterator | GraphNodes::Iterator | Const forward iterator for GraphNodes. |
| Name | Description |
|---|---|
beginendcbegincend | Returns the beginning/end of the GraphNodes iterator. |
Auxiliary class providing an iterable view of the relationships contained in the graph.
GraphRelationships values may only be used for iteration to obtain the values stored within.
explicit GraphRelationships(mgp_graph *graph)| Name | Type | Description |
|---|---|---|
Iterator | GraphRelationships::Iterator | Const forward iterator for GraphRelationships. |
| Name | Description |
|---|---|
beginendcbegincend | Returns the beginning/end of the GraphRelationship iterator. |
Represents a node (vertex) of the Memgraph graph.
Creates a Node from the copy of the given mgp_vertex.
explicit Node(mgp_vertex *ptr)
explicit Node(const mgp_vertex *const_ptr)Copy and move constructors:
Node(const Node &other)
Node(Node &&other) noexcept| Name | Description |
|---|---|
IsDeleted | Returns whether the node has been deleted. |
Id | Returns the nodes ID. |
Labels | Returns an iterable & indexable structure of the nodes labels. |
HasLabel | Returns whether the node has the given label. |
Properties | Returns an iterable & indexable structure of the nodes properties. |
InRelationships | Returns an iterable structure of the nodes inbound relationships. |
OutRelationships | Returns an iterable structure of the nodes outbound relationships. |
AddLabel | Adds a label to the node. |
RemoveLabel | Removes a label from the node. |
SetProperty | Set the value of the nodes property. |
SetProperties | Update the nodes properties. |
GetProperty | Get value of nodes property |
RemoveProperty | Removes the nodes property |
InDegree | Get the in degree of the node. |
OutDegree | Get the out degree of the node. |
ToString | Returns the nodes string representation. |
Returns whether the node has been deleted.
bool IsDeleted() constReturns the nodes ID.
mgp::Id Id() constReturns an iterable & indexable structure of the nodes labels.
class Labels Labels() constReturns whether the node has the given label.
bool HasLabel(std::string_view label) constReturns an iterable & indexable structure of the nodes properties.
std::unordered_map<std::string, mgp::Value> Properties() constGets value of nodes property.
mgp::value GetProperty(const std::string& property) constSets the value of the nodes property.
void SetProperty(std::string key, std::string value)Updates the nodes properties with the given map.
void SetProperties(std::unordered_map<std::string_view, Value> properties)Removes the nodes property.
void RemoveProperty(std::string property)Returns an iterable structure of the nodes inbound relationships.
Relationships InRelationships() constReturns an iterable structure of the nodes outbound relationships.
Relationships OutRelationships() constAdds a label to the node.
void AddLabel(std::string_view label)Removes a label from a node.
void RemoveLabel(std::string_view label)Returns the in degree of a node.
size_t InDegree() constReturns the out degree of a node.
size_t OutDegree() constReturns the nodes string representation, which has this format: (id: node_id, labels: node_labels, properties: node_properties_map).
std::string ToString() const| Name | Description |
|---|---|
operator[] | Returns the value of the nodes property_name property. |
operator==operator!=operator< | comparison operators |
Returns the value of the nodes property_name property.
Value operator[](std::string_view property_name) constRepresents a relationship (edge) of the Memgraph graph.
Creates a Relationship from the copy of the given mgp_edge.
explicit Relationship(mgp_edge *ptr)
explicit Relationship(const mgp_edge *const_ptr)Copy and move constructors:
Relationship(const Relationship &other)
Relationship(Relationship &&other) noexcept| Name | Description |
|---|---|
IsDeleted | Returns whether the relationship has been deleted. |
Id | Returns the relationships ID. |
Type | Returns the relationships type. |
Properties | Returns an iterable & indexable structure of the relationships properties. |
SetProperty | Set the value of the relationships property. |
SetProperties | Update the relationships properties. |
RemoveProperty | Removes the relationships property. |
GetProperty | Get value of relationships property. |
From | Returns the relationships source node. |
To | Returns the relationships destination node. |
ToString | Returns the relationships string representation. |
Returns whether the relationship has been deleted.
bool IsDeleted() constReturns the relationships ID.
mgp::Id Id() constReturns the relationships type.
std::string_view Type() constReturns an iterable & indexable structure of the relationships properties.
std::unordered_map<std::string, mgp::Value> Properties() constGets value of the relationships property.
mgp::value GetProperty(const std::string& property) constSets the value of the relationships property.
void SetProperty(std::string key, std::string value)Updates the relationships properties with the given map.
void SetProperties(std::unordered_map<std::string_view, Value> properties)Removes the relationships property.
void RemoveProperty(std::string property)Returns the relationships source node.
Node From() constReturns the relationships source node.
Node To() constReturns the relationships string representation, which has this format:
(node_from.ToString())-(type: relationship_type, id: relationship_id, properties: relationship_properties_map)->(node_to.ToString()).
std::string ToString() const| Name | Description |
|---|---|
operator[] | Returns the value of the relationships property_name property. |
operator==operator!=operator< | comparison operators |
Returns the value of the relationships property_name property.
Value operator[](std::string_view property_name) constObject is hashable using
std::hash<mgp::Relationship>Auxiliary class providing an iterable view of the relationships adjacent to a node.
Relationships values may only be used for iteration to obtain the values stored within.
explicit Relationships(mgp_edges_iterator *relationships_iterator)| Name | Type | Description |
|---|---|---|
Iterator | Relationships::Iterator | Const forward iterator for Relationships. |
| Name | Description |
|---|---|
beginendcbegincend | Returns the beginning/end of the Relationships iterator. |
Represents the unique ID possessed by all Memgraph nodes and relationships.
| Name | Description |
|---|---|
FromUint | Constructs an Id object from uint64_t. |
FromInt | Constructs an Id object from int64_t. |
AsUint | Returns the ID value as uint64_t. |
AsInt | Returns the ID value as int64_t. |
Constructs an Id object from uint64_t.
static Id FromUint(uint64_t id)Constructs an Id object from int64_t.
static Id FromInt(int64_t id)Returns the ID value as uint64_t.
int64_t AsUint() constReturns the ID value as int64_t.
int64_t AsInt() const| Name | Description |
|---|---|
operator==operator!=operator< | comparison operators |
Represents a view of node labels.
explicit Labels(mgp_vertex *node_ptr)Copy and move constructors:
Labels(const Labels &other)
Labels(Labels &&other) noexcept| Name | Type | Description |
|---|---|---|
Iterator | Labels::Iterator | Const forward iterator for Labels. |
| Name | Description |
|---|---|
Size | Returns the number of the labels, i.e. the size of their list. |
beginendcbegincend | Returns the beginning/end of the Labels iterator. |
Returns the number of the labels, i.e. the size of their list.
size_t Size() const| Name | Description |
|---|---|
operator[] | Returns the nodes label at position index. |
Returns the nodes label at position index.
std::string_view operator[](size_t index) constRepresents a date with a year, month, and day.
Creates a Date object from the copy of the given mgp_date.
explicit Date(mgp_date *ptr)
explicit Date(const mgp_date *const_ptr)Creates a Date object from the given string representing a date in the ISO 8601 format
(YYYY-MM-DD, YYYYMMDD, or YYYY-MM).
explicit Date(std::string_view string)Creates a Date object with the given year, month, and day properties.
Date(int year, int month, int day)Copy and move constructors:
Date(const Date &other)
Date(Date &&other) noexcept| Name | Description |
|---|---|
Now | Returns the current Date. |
Year | Returns the dates year property. |
Month | Returns the dates month property. |
Day | Returns the dates day property. |
Timestamp | Returns the dates timestamp (microseconds since Unix epoch). |
ToString | Returns the dates string representation. |
Returns the current Date.
static Date Now()Returns the dates year property.
int Year() constReturns the dates month property.
int Month() constReturns the dates day property.
int Day() constReturns the dates timestamp (microseconds since Unix epoch).
int64_t Timestamp() constReturns the dates string representation, which has this format: year-month-day.
std::string ToString() const| Name | Description |
|---|---|
operator+operator- | arithmetic operators |
operator==operator< | comparison operators |
Date operator-(const Duration &dur) constDuration operator-(const Date &other) constReturns the value of the relationships property_name property.
Value operator[](std::string_view property_name) constObject is hashable using
std::hash<mgp::Date>Represents a time within the day without timezone information.
Creates a LocalTime object from the copy of the given mgp_local_time.
explicit LocalTime(mgp_local_time *ptr)
explicit LocalTime(const mgp_local_time *const_ptr)Creates a LocalTime object from the given string representing a date in the ISO 8601 format
([T]hh:mm:ss, [T]hh:mm, [T]hhmmss, [T]hhmm, or [T]hh).
explicit LocalTime(std::string_view string)Creates a LocalTime object with the given hour, minute, second, millisecond, and microsecond properties.
LocalTime(int hour, int minute, int second, int millisecond, int microsecond)Copy and move constructors:
LocalTime(const LocalTime &other)
LocalTime(LocalTime &&other) noexcept| Name | Description |
|---|---|
Now | Returns the current LocalTime. |
Hour | Returns the objects hour property. |
Minute | Returns the objects minute property. |
Second | Returns the objects second property. |
Millisecond | Returns the objects millisecond property. |
Microsecond | Returns the objects microsecond property. |
Timestamp | Returns the objects timestamp (microseconds since Unix epoch). |
ToString | Returns the objects string representation. |
Returns the current LocalTime.
static LocalTime Now()Returns the objects hour property.
int Hour() constReturns the objects minute property.
int Minute() constReturns the objects second property.
int Second() constReturns the objects millisecond property.
int Millisecond() constReturns the objects microsecond property.
int Microsecond() constReturns the objects timestamp (microseconds since Unix epoch).
int64_t Timestamp() constReturns the objects string representation, which has this format: hour:minute:second,microsecond milisecond.
std::string ToString() const| Name | Description |
|---|---|
operator+operator- | arithmetic operators |
operator==operator< | comparison operators |
LocalTime operator-(const Duration &dur) constDuration operator-(const LocalDateTime &other) constObject is hashable using
std::hash<mgp::LocalTime>Temporal type representing a date and a local time.
Creates a LocalDateTime object from the copy of the given mgp_local_date_time.
explicit LocalDateTime(mgp_local_date_time *ptr)
explicit LocalDateTime(const mgp_local_date_time *const_ptr)Creates a LocalDateTime object from the given string representing a date in the ISO 8601 format
(YYYY-MM-DDThh:mm:ss, YYYY-MM-DDThh:mm, YYYYMMDDThhmmss, YYYYMMDDThhmm, or YYYYMMDDThh).
explicit LocalDateTime(std::string_view string)Creates a LocalDateTime object with the given year, month, day, hour, minute, second, millisecond,
and microsecond properties.
LocalDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond)Copy and move constructors:
LocalDateTime(const LocalDateTime &other)
LocalDateTime(LocalDateTime &&other) noexcept| Name | Description |
|---|---|
Now | Returns the current LocalDateTime. |
Year | Returns the objects year property. |
Month | Returns the objects month property. |
Day | Returns the objects day property. |
Hour | Returns the objects hour property. |
Minute | Returns the objects minute property. |
Second | Returns the objects second property. |
Millisecond | Returns the objects millisecond property. |
Microsecond | Returns the objects microsecond property. |
Timestamp | Returns the objects timestamp (microseconds since Unix epoch). |
ToString | Returns the objects string representation. |
Returns the current LocalDateTime.
static LocalDateTime Now()Returns the objects year property.
int Year() constReturns the objects month property.
int Month() constReturns the objects day property.
int Day() constReturns the objects hour property.
int Hour() constReturns the objects minute property.
int Minute() constReturns the objects second property.
int Second() constReturns the objects millisecond property.
int Millisecond() constReturns the objects microsecond property.
int Microsecond() constReturns the dates timestamp (microseconds since Unix epoch).
int64_t Timestamp() constReturns the objects string representation, which has this format: year-month-dayThour:minute:second,microsecond milisecond.
std::string ToString() const| Name | Description |
|---|---|
operator+operator- | arithmetic operators |
operator==operator< | comparison operators |
LocalDateTime operator-(const Duration &dur) constDuration operator-(const LocalDateTime &other) constObject is hashable using
std::hash<mgp::LocalDateTime>Temporal type representing a date-time with timezone information.
Creates a ZonedDateTime object from the copy of the given mgp_zoned_date_time.
explicit ZonedDateTime(mgp_zoned_date_time *ptr)
explicit ZonedDateTime(const mgp_zoned_date_time *const_ptr)Creates a ZonedDateTime object from the given string representing a date in the ISO 8601 format
(YYYY-MM-DDThh:mm:ss, YYYY-MM-DDThh:mm, YYYYMMDDThhmmss, YYYYMMDDThhmm, or YYYYMMDDThh).
The string can also include timezone information as a numeric offset (+HH:MM or -HH:MM) or
a named timezone identifier ([America/New_York]).
explicit ZonedDateTime(std::string_view string)Creates a ZonedDateTime object with the given year, month, day, hour, minute, second,
millisecond, microsecond, and offset_in_minutes properties.
ZonedDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond,
int offset_in_minutes)Creates a ZonedDateTime object with the given year, month, day, hour, minute, second,
millisecond, microsecond, and timezone_name properties.
ZonedDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond,
std::string_view timezone_name)ZonedDateTime(const ZonedDateTime &other)
ZonedDateTime(ZonedDateTime &&other) noexcept| Name | Description |
|---|---|
Now | Returns the current ZonedDateTime. |
Year | Returns the objects year property. |
Month | Returns the objects month property. |
Day | Returns the objects day property. |
Hour | Returns the objects hour property. |
Minute | Returns the objects minute property. |
Second | Returns the objects second property. |
Millisecond | Returns the objects millisecond property. |
Microsecond | Returns the objects microsecond property. |
Offset | Returns the objects timezone offset in minutes. |
Timezone | Returns the objects timezone name. |
Timestamp | Returns the objects timestamp (microseconds since Unix epoch). |
ToString | Returns the objects string representation. |
Returns the current ZonedDateTime.
static ZonedDateTime Now()Returns the objects year property.
int Year() constReturns the objects month property.
int Month() constReturns the objects day property.
int Day() constReturns the objects hour property.
int Hour() constReturns the objects minute property.
int Minute() constReturns the objects second property.
int Second() constReturns the objects millisecond property.
int Millisecond() constReturns the objects microsecond property.
int Microsecond() constReturns the objects timezone string property.
char const *Timezone() constReturns the objects offset property.
int Offset() constReturns the objects timestamp (microseconds from Unix epoch).
int64_t Timestamp() constReturns the objects string representation.
std::string ToString() const| Name | Description |
|---|---|
operator+operator- | arithmetic operators |
operator==operator< | comparison operators |
ZonedDateTime operator-(const Duration &dur) constDuration operator-(const ZonedDateTime &other) constObject is hashable using
std::hash<mgp::ZonedDateTime>Represents a period of time in Memgraph.
Creates a Duration object from the copy of the given mgp_duration.
explicit Duration(mgp_duration *ptr)
explicit Duration(const mgp_duration *const_ptr)Creates a Duration object from the given string in the following format: P[nD]T[nH][nM][nS], where (1)
n stands for a number, (2) capital letters are used as a separator, (3) each field in [] is optional,
and (4) only the last field may be a non-integer.
explicit Duration(std::string_view string)Creates a Duration object from the given number of microseconds.
explicit Duration(int64_t microseconds)Creates a Duration object with the given day, hour, minute, second, millisecond, and microsecond properties.
Duration(double day, double hour, double minute, double second, double millisecond, double microsecond)Copy and move constructors:
Duration(const Duration &other)
Duration(Duration &&other) noexcept| Name | Description |
|---|---|
Microseconds | Returns the duration as microseconds. |
ToString | Returns the durations string representation. |
Returns the duration as microseconds.
int64_t Microseconds() constReturns the durations string representation, which has this format: microseconds ms.
std::string ToString() const| Name | Description |
|---|---|
operator+operator- | arithmetic operators |
operator==operator< | comparison operators |
Duration operator-(const Duration &other) constDuration operator-() constObject is hashable using
std::hash<mgp::Duration>Represents a 2D point with x and y coordinates and a spatial reference identifier (SRID).
Creates a Point2d object from the copy of the given mgp_point_2d.
explicit Point2d(mgp_point_2d *ptr)
explicit Point2d(const mgp_point_2d *const_ptr)Creates a Point2d object with the given x, y coordinates and srid.
Point2d(double x, double y, uint16_t srid)Supported SRIDs: 4326 (WGS-84), 7203 (Cartesian 2D).
Copy and move constructors:
Point2d(const Point2d &other)
Point2d(Point2d &&other) noexcept| Name | Description |
|---|---|
X | Returns the x coordinate. |
Y | Returns the y coordinate. |
Srid | Returns the spatial reference identifier (SRID). |
ToString | Returns the points string representation. |
Returns the x coordinate of the point.
double X() constReturns the y coordinate of the point.
double Y() constReturns the SRID (spatial reference identifier) of the point.
uint16_t Srid() constReturns the points string representation.
std::string ToString() const| Name | Description |
|---|---|
operator== | comparison operator |
operator!= | comparison operator |
Object is hashable using
std::hash<mgp::Point2d>Represents a 3D point with x, y, and z coordinates and a spatial reference identifier (SRID).
Creates a Point3d object from the copy of the given mgp_point_3d.
explicit Point3d(mgp_point_3d *ptr)
explicit Point3d(const mgp_point_3d *const_ptr)Creates a Point3d object with the given x, y, z coordinates and srid.
Point3d(double x, double y, double z, uint16_t srid)Supported SRIDs: 4979 (WGS-84 3D), 9157 (Cartesian 3D).
Copy and move constructors:
Point3d(const Point3d &other)
Point3d(Point3d &&other) noexcept| Name | Description |
|---|---|
X | Returns the x coordinate. |
Y | Returns the y coordinate. |
Z | Returns the z coordinate. |
Srid | Returns the spatial reference identifier (SRID). |
ToString | Returns the points string representation. |
Returns the x coordinate of the point.
double X() constReturns the y coordinate of the point.
double Y() constReturns the z coordinate of the point.
double Z() constReturns the SRID (spatial reference identifier) of the point.
uint16_t Srid() constReturns the points string representation.
std::string ToString() const| Name | Description |
|---|---|
operator== | comparison operator |
operator!= | comparison operator |
Object is hashable using
std::hash<mgp::Point3d>Represents an enum value with a type name and value name.
Note: Enum values can be received as procedure input and inspected (type name, value name, equality), but cannot be returned from procedures.
Creates an Enum object from the copy of the given mgp_enum.
explicit Enum(mgp_enum *ptr)
explicit Enum(const mgp_enum *const_ptr)Creates an Enum from type name and value name strings.
Enum(std::string_view type_name, std::string_view value_name)Copy and move constructors:
Enum(const Enum &other)
Enum(Enum &&other) noexcept| Name | Description |
|---|---|
TypeName | Returns the type name of the enum. |
ValueName | Returns the value name of the enum. |
ToString | Returns the enums string representation. |
Returns the type name of the enum (e.g. "Status" for Status.Active).
std::string_view TypeName() constReturns the value name of the enum (e.g. "Active" for Status.Active).
std::string_view ValueName() constReturns the enums string representation.
std::string ToString() const| Name | Description |
|---|---|
operator== | comparison operator |
operator!= | comparison operator |
Object is hashable using
std::hash<mgp::Enum>A path is a data structure consisting of alternating nodes and relationships, with the start and end points of a path necessarily being nodes.
Creates a Path from the copy of the given mgp_path.
explicit Path(mgp_path *ptr)
explicit Path(const mgp_path *const_ptr)Creates a Path starting with the given start_node.
explicit Path(const Node &start_node)Copy and move constructors:
Path(const Path &other)
Path(Path &&other) noexcept| Name | Description |
|---|---|
ContainsDeleted | Returns whether the path contains any deleted nodes or relationships. |
Length | Returns the path length (number of relationships). |
GetNodeAt | Returns the node at the given index. The index must be less than or equal to length of the path. |
GetRelationshipAt | Returns the relationship at the given index. The index must be less than length of the path. |
Expand | Adds a relationship continuing from the last node on the path. |
Pop | Removes the last node and the last relationship from the path. |
ToString | Returns the paths string representation. |
Returns whether the path contains any deleted nodes or relationships.
bool ContainsDeleted() constReturns the path length (number of relationships).
size_t Length() constReturns the node at the given index. The index must be less than or equal to length of the path.
Node GetNodeAt(size_t index) constReturns the relationship at the given index. The index must be less than the length of the path.
Relationship GetRelationshipAt(size_t index) constAdds a relationship continuing from the last node on the path.
void Expand(const Relationship &relationship)Removes the last node and the last relationship from the path.
void Pop()Returns the paths string representation, which has nearly the same format as Relationship.ToString(), the difference being that Path.ToString() can have multiple nodes and relationships in its string representation, for example: (node)-(relationship)->(node)-(relationship)->(node).
std::string ToString() const| Name | Description |
|---|---|
operator==operator!= | comparison operators |
Object is hashable using
std::hash<mgp::Path>A list containing any number of values of any supported type.
Creates a List from the copy of the given mgp_list.
explicit List(mgp_list *ptr)
explicit List(const mgp_list *const_ptr)Creates an empty List.
explicit List()Creates a List with the given capacity.
explicit List(size_t capacity)Creates a List from the given vector.
explicit List(const std::vector<Value> &values)
explicit List(std::vector<Value> &&values)Creates a List from the given initializer_list.
explicit List(std::initializer_list<Value> list)Copy and move constructors:
List(const List &other)
List(List &&other) noexcept| Name | Type | Description |
|---|---|---|
Iterator | List::Iterator | Const forward iterator for List containers. |
| Name | Description |
|---|---|
ContainsDeleted | Returns whether the list contains any deleted values (Node, Relationship, or containers holding them). |
Size | Returns the size of the list. |
Empty | Returns whether the list is empty. |
Append | Appends the given value to the list. |
AppendExtend | Extends the list and appends the given value to it. |
Reserve | Ensure underlying capacity is at least n. |
beginendcbegincend | Returns the beginning/end of the List iterator. |
ToString | Returns the lists string representation. |
Returns whether the path contains any deleted values (Node, Relationship, or containers holding them).
bool ContainsDeleted() constReturns the size of the list.
size_t Size() constReturns whether the list is empty.
bool Empty() constAppends the given value to the list. The value is copied.
void Append(const Value &value)Extends the list and appends the given value to it. The value is copied.
void AppendExtend(const Value &value)Returns the lists string representation, which has this format: [element.ToString(), element.ToString()].
std::string ToString() const| Name | Description |
|---|---|
operator[] | Returns the value at the given index. |
operator==operator!= | comparison operators |
Returns the reference of the value at the given index.
Value operator[](size_t index) constObject is hashable using
std::hash<mgp::List>A map of key-value pairs where keys are strings, and values can be of any supported type. The pairs are represented as MapItems.
Creates a Map from the copy of the given mgp_map.
explicit Map(mgp_map *ptr)
explicit Map(const mgp_map *const_ptr)Creates an empty Map.
explicit Map()Creates a Map from the given STL map.
explicit Map(const std::map<std::string_view, Value> &items)
explicit Map(std::map<std::string_view, Value> &&items)Creates a Map from the given initializer_list (map items correspond to initializer list pairs).
Map(std::initializer_list<std::pair<std::string_view, Value>> items)Copy and move constructors:
Map(const Map &other)
Map(Map &&other) noexcept| Name | Type | Description |
|---|---|---|
Iterator | List::Iterator | Const forward iterator for List containers. |
| Name | Description |
|---|---|
ContainsDeleted | Returns whether the map contains any deleted values (Node, Relationship, or containers holding them). |
Size | Returns the size of the map. |
Empty | Returns whether the map is empty. |
At | Returns the value at the given key. |
Insert | Inserts the given key-value pair into the map. |
Update | Inserts or updates the value at the given key. |
Erase | Erases a mapping by key. |
beginendcbegincend | Returns the beginning/end of the Map iterator. |
ToString | Returns the maps string representation. |
KeyExists | Checks if the key exists in a map. |
Returns whether the path contains any deleted values (Node, Relationship, or containers holding them).
bool ContainsDeleted() constReturns the size of the map.
size_t Size() constReturns whether the map is empty.
bool Empty() constReturns the value at the given key.
Value At(std::string_view key) constInserts the given key-value pair into the map. The value is copied.
void Insert(std::string_view key, const Value &value)Inserts the given key-value pair into the map. Takes ownership of value by moving it.
The behavior of accessing value after performing this operation is undefined.
void Insert(std::string_view key, Value &&value)Updates the key-value pair in the map. If the key doesnt exist, the value gets inserted.
The value is copied.
void Update(std::string_view key, const Value &value)Updates the key-value pair in the map. If the key doesnt exist, the value gets inserted.
The value is copied. Takes the ownership of value by moving it.
The behavior of accessing value after performing this operation is undefined.
void Update(std::string_view key, Value &&value)Erases the element associated with the key from the map, if it doesnt exist nothing happens.
void Erase(std::string_view key);Returns the maps string representation, which has this format: {key1 : value1.ToString(), key2: value2.ToString()}.
std::string ToString() constReturns true if key is present in the map, otherwise false.
bool KeyExists(std::string_view key) const;| Name | Description |
|---|---|
operator[] | Returns the value at the given key. |
operator==operator!= | comparison operators |
Returns the reference of the value at the given key.
Value operator[](std::string_view key) constObject is hashable using
std::hash<mgp::Map>Auxiliary data structure representing key-value pairs where keys are strings, and values can be of any supported type.
| Name | Type | Description |
|---|---|---|
key | std::string_view | Key for accessing the value stored in a MapItem. |
value | Value | The stored value. |
| Name | Description |
|---|---|
operator==operator!=operator< | comparison operators |
Object is hashable using
std::hash<mgp::MapItem>Represents a value of any type supported by Memgraph. The data types are described in the reference guide.
Creates a Value from the copy of the given mgp_value.
explicit Value(mgp_value *ptr)Create a reference type Value
explicit Value(RefType /**/, mgp_value *ptr)Create a reference type Value
explicit Value(RefType /**/, mgp_value *ptr)Create a Value by moving the given mgp_value ptr
explicit Value(StealType /**/, mgp_value *ptr)Creates a null Value.
explicit Value()Basic type constructors:
explicit Value(bool value)
explicit Value(int64_t value)
explicit Value(double value)
explicit Value(const char *value)
explicit Value(std::string_view value)Container type constructors:
explicit Value(const List &value)
explicit Value(List &&value)
explicit Value(const Map &value)
explicit Value(Map &&value)Graph element type constructors:
explicit Value(const Node &value)
explicit Value(Node &&value)
explicit Value(const Relationship &value)
explicit Value(Relationship &&value)
explicit Value(const Path &value)
explicit Value(Path &&value)Temporal type constructors:
explicit Value(const Date &value)
explicit Value(Date &&value)
explicit Value(const LocalTime &value)
explicit Value(LocalTime &&value)
explicit Value(const LocalDateTime &value)
explicit Value(LocalDateTime &&value)
explicit Value(const ZonedDateTime &value)
explicit Value(ZonedDateTime &&value)
explicit Value(const Duration &value)
explicit Value(Duration &&value)Spatial type constructors:
explicit Value(const Point2d &value)
explicit Value(Point2d &&value)
explicit Value(const Point3d &value)
explicit Value(Point3d &&value)Enum type constructors:
explicit Value(const Enum &value)
explicit Value(Enum &&value)Copy and move constructors:
Value(const Value &other)
Value(Value &&other) noexcept| Name | Description |
|---|---|
ptr | Returns the pointer to the stored value. |
Type | Returns the type of the value. |
Value[TYPE] | Returns a value of given type. |
Is[TYPE] | Returns whether the value is of given type. |
ToString | Returns the values string representation. |
IsRef | Returns whether the value is a reference type |
Returns the C API pointer to the stored value.
mgp_value *ptr() constReturns the type of the value, i.e. the type stored in the Value object.
mgp::Type Type() constDepending on the exact function called, returns a typed value of the appropriate type.
Throws an exception if the type stored in the Value object is not compatible with the function called.
An overloaded function is available which returns a modifiable (non-const) value of the appropriate type.
bool ValueBool() const
bool ValueBool()int64_t ValueInt() const
int64_t ValueInt()double ValueDouble const
double ValueDoubledouble ValueNumeric const
double ValueNumericstd::string_view ValueString() const
std::string_view ValueString()List ValueList() const
List ValueList()Map ValueMap() const
Map ValueMap()Node ValueNode() const
Node ValueNode()Relationship ValueRelationship() const
Relationship ValueRelationship()Path ValuePath() const
Path ValuePath()Date ValueDate() const
Date ValueDate()LocalTime ValueLocalTime() const
LocalTime ValueLocalTime()LocalDateTime ValueLocalDateTime() const
LocalDateTime ValueLocalDateTime()ZonedDateTime ValueZonedDateTime() const
ZonedDateTime ValueZonedDateTime()Duration ValueDuration() const
Duration ValueDuration()Point2d ValuePoint2d() const
Point2d ValuePoint2d()Point3d ValuePoint3d() const
Point3d ValuePoint3d()Enum ValueEnum() const
Enum ValueEnum()Returns whether the value stored in the Value object is of the type in the call.
bool IsNull() constbool IsBool() constbool IsInt() constbool IsDouble() constbool IsNumeric() constbool IsString() constbool IsList() constbool IsMap() constbool IsNode() constbool IsRelationship() constbool IsPath() constbool IsDate() constbool IsLocalTime() constbool IsLocalDateTime() constbool IsZonedDateTime() constbool IsDuration() constbool IsPoint2d() constbool IsPoint3d() constbool IsEnum() constReturns the values string representation. It does this by finding the type of the object wrapped inside the Value object, calling its ToString() function or casting the object to string, depending on its type. The table below shows the appropriate action for each type.
| Data type | String method used |
|---|---|
Null | Returns "" |
Numeric | Casts numeric type to string. |
Bool | Returns either "false" or "true", depending on the bools value. |
String | Returns the string. |
List | Returns List.ToString(). |
Map | Returns Map.ToString(). |
Node | Returns Node.ToString(). |
Relationship | Returns Relationship.ToString(). |
Path | Returns Path.ToString(). |
Date | Returns Date.ToString(). |
LocalTime | Returns LocalTime.ToString(). |
LocalDateTime | Returns LocalDateTime.ToString(). |
ZonedDateTime | Returns ZonedDateTime.ToString(). |
Duration | Returns Duration.ToString(). |
std::string ToString() constReturns whether the value is a reference type.
bool Value::IsRef() const| Name | Description |
|---|---|
operator==operator!= operator< | comparison operators |
Object is hashable using
std::hash<mgp::Value>Additionally, operator << is overloaded for Value and usage of this operator will print the value of the mgp::Value instance (currently doesnt support values of type Path, Map and List).
std::ostream &operator<<(std::ostream &os, const mgp::Value &value)Enumerates the data types supported by Memgraph and its C++ API. The types are listed and described in the reference guide.
Type::NullType::AnyType::BoolType::IntType::DoubleType::StringType::ListType::MapType::NodeType::RelationshipType::PathType::DateType::LocalTimeType::LocalDateTimeType::ZonedDateTimeType::DurationType::Point2dType::Point3dType::EnumAdditionally, operator<< is overloaded for Type enum, and usage of this operator will print the type represented by mgp::Type enum.
std::ostream &operator<<(std::ostream &os, const mgp::Type &type)Represents the headers/columns of the query being executed through the C++ API.
ExecutionHeaders(mgp_execution_headers *headers);This constructor is automatically called during the query execution logic if the user needs headers.
| Name | Description |
|---|---|
Size | Returns the size of the headers/columns. |
At | Returns the header at a specific index. |
begin | Returns an iterator at the beginning position for the headers. |
cbegin | Returns a const iterator at the beginning position for the headers. |
end | Returns an iterator at the ending position for the headers. |
cend | Returns a const iterator at the ending position for the headers. |
Returns the size of the headers/columns.
size_t Size() constReturns the header at a specific index.
std::string At(size_t index) constReturns an iterator at the beginning position for the headers.
Iterator begin()Returns a const iterator at the beginning position for the headers.
Iterator cbegin()Returns an iterator at the ending position for the headers.
Iterator end()Returns a const iterator at the ending position for the headers.
Iterator cend()| Name | Description |
|---|---|
operator[] | Returns a header at a specific index. |
Returns a header at a specific index.
std::string_view operator[](size_t index) constRepresents the object which is able to execute a query through the C++ API.
QueryExecution(mgp_graph *graph);Query execution needs the mgp_graph object because it stores the database context.
| Name | Description |
|---|---|
ExecuteQuery | Executes the query through the C++ API. |
Executes the query through the C++ API.
ExecutionResult ExecuteQuery(std::string_view query, Map params = Map()) const ExecutionResult ExecuteQuery(std::string query, Map params = Map()) constRepresents the object which is able to handle the pulling logic of the query being executed through the C++ API.
ExecutionResult(mgp_execution_result *result, mgp_graph *graph);The result object is stored in the ExecutionResult to handle the pulling logic. Database context is also needed.
| Name | Description |
|---|---|
Headers | Returns the headers/columns of the executing query. |
PullOne | Returns one result row from the executing query. |
Returns the headers/columns of the executing query.
ExecutionHeaders Headers() constReturns one result row from the executing query.
std::optional<ExecutionRow> PullOne() constRepresents a row in the database pulled from the query being executed through the C++ API.
ExecutionRow(mgp_map *row);The mgp_map objects stores the header/column names as keys, and the corresponding values (mgp_value) as map values.
| Name | Description |
|---|---|
Size | Returns the size of the row. |
Empty | Returns true if the row has no values. |
At | Returns a row value from the given column key. |
KeyExists | Returns true if the column exists in a row. |
Values | Returns a map of column keys and row values. |
Returns the size of the row.
size_t Size() constReturns true if the row has no values.
bool Empty() constReturns a row value from the given column key.
Value At(std::string_view key) constReturns true if the column exists in a row.
bool KeyExists(std::string_view key) constReturns a map of column keys and row values.
Map Values() const| Name | Description |
|---|---|
operator[] | Returns a row value from the given column key. |
Returns a row value from the given column key.
Value operator[](std::string_view key) constThis section describes C++ API methods for database operations beyond graph manipulation.
Text search is an experimental feature introduced in Memgraph 2.15.1. Refer to the text search page for an overview of its capabilities.
To use text search, start memgraph with the --experimental-enabled=text-search
flag.
Search the named text index for the given query and get a list of the nodes whose text-indexed properties match the given query.
List SearchTextIndex(
mgp_graph *memgraph_graph,
std::string_view index_name,
std::string_view search_query,
text_search_mode search_mode);memgraph_graph: the graphindex_name: the name of the given text indexsearch_query: the query with which to search the text indexsearch_mode: one of SPECIFIED_PROPERTIES, REGEX, and ALL_PROPERTIESAggregate over the results of the search over the named text index and get a JSON-formatted string with the results of the aggregation.
List AggregateOverTextIndex(
mgp_graph *memgraph_graph,
std::string_view index_name,
std::string_view search_query,
std::string_view aggregation_query);memgraph_graph: the graphindex_name: the name of the given text indexsearch_query: the query with which to search the text indexaggregation_query: the query (JSON-format) with which to aggregate over
search resultsDuring operation, the following exceptions may be thrown.
| Exception | Message |
|---|---|
ValueException | various (handles unknown/unexpected types) |
NotFoundException | Node with ID [ID] not found! |
NotEnoughMemoryException | Not enough memory! |
UnknownException | Unknown exception! |
AllocationException | Could not allocate memory! |
InsufficientBufferException | Buffer is not sufficient to process procedure! |
IndexException | Index value out of bounds! |
OutOfRangeException | Index out of range! |
LogicException | Logic exception, check the procedure signature! |
DeletedObjectException | Object is deleted! |
InvalidArgumentException | Invalid argument! |
InvalidIDException | Invalid ID! |
KeyAlreadyExistsException | Key you are trying to set already exists! |
ImmutableObjectException | Object you are trying to change is immutable! |
ValueConversionException | Error in value conversion! |
SerializationException | Error in serialization! |
TextSearchException | various (indicates issues with the text search utility) |
| Web Proxy Viewer | New URL | Original Page |