README.md 1.5 KB
Newer Older
Arnaud Kress's avatar
Arnaud Kress committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
# neo4j-tcl

This is a Tcl extension for Neo4j wrapping the C driver.

## Installation
You will need to install the C Neo4j driver you can found [here](https://github.com/cleishm/libneo4j-client).
After cloning this repository, type the following commands:
```bash
autoconf
./configure --with-tcl=/path/to/tcl/lib
make
make install
```

## Usage
Here is a little example:
```tcl
package require neo4j

set db [neo4j_connect -host myhost -user neo4j -password mypasswd]
# Simple query
set query {MATCH (p:Person)-[:Likes]->(m:Movie) RETURN p,m}
if {[catch {set res [neo4j_query $db $query $params]} res]} {
    # error !
    puts stderr $res
} else {
    foreach row $res {
        foreach col $row {
            puts $col
        }
    }   
}
neo4j_disconnect $db 
```

You can also run queries with named parameters
```tcl
set query {MATCH (p:Person {name: $n}) RETURN p}
set res [neo4j_query $db $query n "Julio"]
```

It is possible to get the output as a flat list; -llist, a list of lists (list of tuples) is the default.
```tcl
set res [neo4j_query $db $query -list n "Julio"]
```

A list containing the type (to distinguish between nodes and relationships) and the content; the content is a dict with a list of labels and a dict of properties.
```tcl 
{NEO4J_NODE {labels {Person Student} properties {name Julio age 26}}
```
And for a relationship, a dict with the type and a dict of properties.
```tcl
{NEO4J_RELATIONSHIP {type Knows properties {since 2010}}}
```
A path is represented as a list of nodes and relationships.