grafeo.GrafeoDB¶
The main database class.
Constructor¶
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
path | str | None | Database file path (None for in-memory) |
Examples¶
# In-memory database
db = grafeo.GrafeoDB()
# Persistent database
db = grafeo.GrafeoDB("my_graph.db")
Query Methods¶
execute()¶
Execute a GQL query.
execute_cypher()¶
Execute a Cypher query.
execute_gremlin()¶
Execute a Gremlin query.
execute_graphql()¶
Execute a GraphQL query.
execute_sparql()¶
Execute a SPARQL query.
execute_sql()¶
Execute a SQL/PGQ query.
Node Operations¶
create_node()¶
Create a node with labels and properties.
add_node_label()¶
Add a label to an existing node.
remove_node_label()¶
Remove a label from a node.
get_node_labels()¶
Get all labels for a node.
Transaction Methods¶
begin_transaction()¶
Start a new transaction.
Admin Methods¶
info()¶
Get database information.
detailed_stats()¶
Get detailed statistics.
schema()¶
Get schema information.
validate()¶
Validate database integrity.
Example¶
import grafeo
db = grafeo.GrafeoDB()
# Execute queries
db.execute("INSERT (:Person {name: 'Alix', age: 30})")
result = db.execute("MATCH (p:Person) RETURN p.name")
for row in result:
print(row['p.name'])
# Use transactions
with db.begin_transaction() as tx:
tx.execute("INSERT (:Person {name: 'Gus'})")
tx.commit()