query

📁 octaviopavon/cypher-shell 📅 8 days ago
2
总安装量
2
周安装量
#65879
全站排名
安装命令
npx skills add https://github.com/octaviopavon/cypher-shell --skill query

Agent 安装分布

mcpjam 2
codebuddy 2
claude-code 2
junie 2
windsurf 2
zencoder 2

Skill 文档

cypher-shell Query

Runs Cypher via cypher-shell against the connected instance.

Pre-flight

source ~/.neo4j-connection 2>/dev/null || { echo "Not connected. Run /cypher-shell:connect first."; exit 1; }

Execution Pattern

source ~/.neo4j-connection && cypher-shell --format verbose "<QUERY>"

For export/CSV: use --format plain instead. For file input: cypher-shell -f <file> or cypher-shell < file.cypher With parameters: cypher-shell -P '{name: "Alice"}' "MATCH (n {name: \$name}) RETURN n;"

Interpret $ARGUMENTS

Full Cypher Query

If $ARGUMENTS contains Cypher keywords (MATCH, CREATE, MERGE, CALL, SHOW, RETURN, WITH, UNWIND, LOAD, DROP, DELETE, EXPLAIN, PROFILE, FILTER, LET, SEARCH, FINISH), run it directly.

Keyword Shortcuts

count

MATCH (n) RETURN labels(n) AS label, count(n) AS count ORDER BY count DESC;
MATCH ()-[r]->() RETURN type(r) AS type, count(r) AS count ORDER BY count DESC;

orphans

MATCH (n) WHERE NOT (n)--() RETURN labels(n) AS label, n.name AS name, count(*) AS count ORDER BY count DESC;

indexes

SHOW INDEXES YIELD name, type, labelsOrTypes, properties, state RETURN name, type, labelsOrTypes, properties, state;

constraints

SHOW CONSTRAINTS YIELD name, type, labelsOrTypes, properties RETURN name, type, labelsOrTypes, properties;

wipe

CRITICAL: Warn the user and ask for explicit confirmation before executing.

WARNING: DELETES ALL DATA
Database: $NEO4J_DATABASE (or default)
URI: $NEO4J_URI

Only after confirmation:

CALL { MATCH (n) WITH n LIMIT 10000 DETACH DELETE n } IN TRANSACTIONS OF 10000 ROWS;

Verify: MATCH (n) RETURN count(n) AS remaining;

No argument -> show usage examples.

cypher-shell CLI Reference

Key Flags

Flag Description Default
-a, --address, --uri Connection address neo4j://localhost:7687
-u, --username Username env NEO4J_USERNAME
-p, --password Password env NEO4J_PASSWORD
-d, --database Database env NEO4J_DATABASE
-f, --file FILE Execute .cypher file —
-P, --param PARAM Set param: -P '{a: 1}' []
--format {auto,verbose,plain} Output format auto
--access-mode {read,write} Access mode write
--non-interactive Force non-interactive false
--fail-fast Exit on first error (file mode) default
--fail-at-end Report errors at end (file mode) —
--sample-rows N Rows for table width calc 1000
--wrap {true,false} Wrap long columns true
--transaction-timeout e.g. 10m, 1h30m disable
--error-format {gql,legacy,stacktrace} Error display gql
--encryption {true,false,default} Connection encryption default
--impersonate USER Run as another user —
--change-password Change password and exit —
--enable-autocompletions Tab-complete (Neo4j 5+) false
--notifications Show query notifications false
--idle-timeout Auto-exit after idle disable
--log [FILE] Debug logging —
-v, --version Print version —
--driver-version Print driver version —

Shell Commands (interactive mode)

Command Description
:help List all commands
:exit / :quit Disconnect and exit
:use <db> Switch database
:source <file> Execute .cypher file
:param {k: v} Set parameters (Cypher map)
:param k => expr Set parameter (arrow syntax)
:param List current parameters
:param clear Clear all parameters
:begin Start explicit transaction
:commit Commit transaction
:rollback Rollback transaction
:history Command history
:connect Connect to a database
:disconnect Disconnect
:sysinfo System information
:impersonate <user> Impersonate user
:access-mode [read|write] View/set access mode

Env Vars (native cypher-shell support)

Variable Maps to
NEO4J_URI / NEO4J_ADDRESS -a
NEO4J_USERNAME -u
NEO4J_PASSWORD -p
NEO4J_DATABASE -d
NEO4J_CYPHER_SHELL_HISTORY --history

Cypher Quick Patterns

-- Find by property
MATCH (n:Label {prop: "value"}) RETURN n;

-- Pattern match
MATCH (a)-[:REL]->(b) RETURN a.name, b.name;

-- Variable-length paths
MATCH path = (a)-[*1..3]->(b) WHERE a.name = "x" RETURN path;

-- Shortest path
MATCH path = shortestPath((a {name:"x"})-[*]-(b {name:"y"})) RETURN path;

-- Aggregation
MATCH (n:Label) RETURN n.prop, count(n) ORDER BY count(n) DESC;

-- MERGE (upsert)
MERGE (n:Label {id: "x"})
ON CREATE SET n.created = timestamp()
ON MATCH SET n.updated = timestamp();

-- Batch delete
CALL { MATCH (n:Label) WITH n LIMIT 10000 DETACH DELETE n } IN TRANSACTIONS OF 10000 ROWS;

-- LOAD CSV
LOAD CSV WITH HEADERS FROM 'file:///data.csv' AS row
CREATE (:Label {name: row.name, age: toInteger(row.age)});

-- EXPLAIN / PROFILE
EXPLAIN MATCH (n)-[r]->(m) RETURN n, r, m;
PROFILE MATCH (n)-[r]->(m) RETURN n, r, m;

Cypher 25 (Neo4j 2025.06+): FILTER, LET, FINISH, WHEN, NEXT, SEARCH (vector), coll.* functions.