Skip to main content

gqlalchemy.vendors.memgraph

Memgraph Objects

class Memgraph(DatabaseClient)

get_indexes

def get_indexes() -> List[MemgraphIndex]

Returns a list of all database indexes (label and label-property types).

ensure_indexes

def ensure_indexes(indexes: List[MemgraphIndex]) -> None

Ensures that database indexes match input indexes.

get_constraints

def get_constraints(
) -> List[Union[MemgraphConstraintExists, MemgraphConstraintUnique]]

Returns a list of all database constraints (label and label-property types).

new_connection

def new_connection() -> Connection

Creates new Memgraph connection.

create_stream

def create_stream(stream: MemgraphStream) -> None

Create a stream.

start_stream

def start_stream(stream: MemgraphStream) -> None

Start a stream.

get_streams

def get_streams() -> List[str]

Returns a list of all streams.

drop_stream

def drop_stream(stream: MemgraphStream) -> None

Drop a stream.

create_trigger

def create_trigger(trigger: MemgraphTrigger) -> None

Creates a trigger.

get_triggers

def get_triggers() -> List[str]

Returns a list of all database triggers.

drop_trigger

def drop_trigger(trigger: MemgraphTrigger) -> None

Drop a trigger.

drop_triggers

def drop_triggers() -> None

Drops all triggers in the database.

init_disk_storage

def init_disk_storage(on_disk_db: OnDiskPropertyDatabase) -> None

Adds and OnDiskPropertyDatabase to the database so that any property that has a Field(on_disk=True) can be stored to and loaded from an OnDiskPropertyDatabase.

remove_on_disk_storage

def remove_on_disk_storage() -> None

Removes the OnDiskPropertyDatabase from the database.

save_node

def save_node(node: Node) -> Node

Saves node to the database. If the node._id is not None it fetches the node with the same id from the database and updates it's fields. If the node has unique fields it fetches the nodes with the same unique fields from the database and updates it's fields. Otherwise it creates a new node with the same properties. Null properties are ignored.

load_node

def load_node(node: Node) -> Optional[Node]

Loads a node from the database. If the node._id is not None it fetches the node from the database with that internal id. If the node has unique fields it fetches the node from the database with those unique fields set. Otherwise it tries to find any node in the database that has all properties set to exactly the same values. If no node is found or no properties are set it raises a GQLAlchemyError.

load_relationship

def load_relationship(relationship: Relationship) -> Optional[Relationship]

Returns a relationship loaded from the database. If the relationship._id is not None it fetches the relationship from the database that has the same internal id. Otherwise it returns the relationship whose relationship._start_node_id and relationship._end_node_id and all relationship properties that are not None match the relationship in the database. If there is no relationship like that in the database, or if there are multiple relationships like that in the database, throws GQLAlchemyError.

save_relationship

def save_relationship(relationship: Relationship) -> Optional[Relationship]

Saves a relationship to the database. If relationship._id is not None it finds the relationship in the database and updates it's properties with the values in relationship. If relationship._id is None, it creates a new relationship. If you want to set a relationship._id instead of creating a new relationship, use load_relationship first.

get_procedures

def get_procedures(starts_with: Optional[str] = None,
update: bool = False) -> List["QueryModule"]

Return query procedures.

Maintains a list of query modules in the Memgraph object. If starts_with is defined then return those modules that start with starts_with string.

Arguments:

  • starts_with - Return those modules that start with this string. (Optional)
  • update - Whether to update the list of modules in self.query_modules. (Optional)

add_query_module

def add_query_module(file_path: str, module_name: str) -> "Memgraph"

Function for adding a query module in Python written language to Memgraph. Example can be found in the functions below (with_kafka_stream, with_power_bi).

The module is synced dynamically then with the database to enable higher processing capabilities.

Arguments:

  • file_name str - path to file containing module.
  • module_name str - name of the module.

Returns:

  • Memgraph - Memgraph object.

with_kafka_stream

def with_kafka_stream() -> "Memgraph"

Load kafka stream query module.

Returns:

  • Memgraph - Memgraph instance

with_power_bi

def with_power_bi() -> "Memgraph"

Load power_bi stream query module.

Returns:

  • Memgraph - Memgraph instance