apoc.cypher.runSchemaFiles
过程 Apoc 扩展
apoc.cypher.runSchemaFiles([files or urls],{statistics:true,timeout:10}) - 仅允许模式操作,运行文件中的每条模式语句,均以分号分隔
签名
apoc.cypher.runSchemaFiles(file :: LIST? OF STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?, fileName :: STRING?)
配置参数
该过程支持以下配置参数
| 名称 (name) | type | 默认 | description(描述) |
|---|---|---|---|
reportError |
boolean |
false |
返回一行包含键 |
statistics |
boolean |
true |
返回一行包含查询统计信息的附加行,利用了 |
timeout |
long |
10 |
单次查询超时时间(以秒为单位) |
queueCapacity |
long |
100 |
用于聚合结果的 |
parameters |
Map<String, Object> |
空映射 |
可与 |
从文件读取
默认情况下,禁止从文件系统导入。我们可以通过在 apoc.conf 中设置以下属性来启用它
apoc.import.file.enabled=true
如果我们尝试在未先设置此属性的情况下使用任何导入过程,将会收到以下错误消息
Failed to invoke procedure: Caused by: java.lang.RuntimeException: Import from files not enabled, please set apoc.import.file.enabled=true in your apoc.conf |
导入文件从 import 目录读取,该目录由 server.directories.import 属性定义。这意味着我们提供的任何文件路径都是相对于此目录的。如果我们尝试从绝对路径(例如 /tmp/filename)读取,将会收到类似于以下的错误消息
Failed to invoke procedure: Caused by: java.lang.RuntimeException: Can’t read url or key file:/path/to/neo4j/import/tmp/filename as json: /path/to/neo4j//import/tmp/filename (No such file or directory) |
我们可以通过在 apoc.conf 中设置以下属性来启用从文件系统任意位置读取文件
apoc.import.file.use_neo4j_config=false
|
Neo4j 现在可以从文件系统的任何位置读取,因此在设置此属性之前,请确保这是您的意图。 |
使用示例
本节中的示例基于以下文件
CREATE CONSTRAINT uniqueConstraint FOR (n:Person) REQUIRE n.name IS UNIQUE;
DROP CONSTRAINT uniqueConstraint;
我们可以通过运行以下查询来执行 createConstraint.cypher 和 dropConstraint.cypher 中的 Cypher 命令
CALL apoc.cypher.runSchemaFiles(["createConstraint.cypher", "dropConstraint.cypher"]);
| row | fileName |
|---|---|
结果 |
-1 |
createConstraint.cypher |
{constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 0, rows: 0, propertiesSet: 0, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 1, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 0, relationshipsCreated: 0, time: 0} |
-1 |
dropConstraint.cypher |
如果我们不想查看每条 Cypher 语句的统计信息,可以将 statistics 设置为 false
CALL apoc.cypher.runSchemaFiles(["createConstraint.cypher", "dropConstraint.cypher"], {statistics: false});
| row | fileName |
|---|