apoc.systemdb.export.metadata

过程 Apoc 扩展

签名

apoc.systemdb.export.metadata(config = {} :: MAP?) :: (file :: STRING?, source :: STRING?, format :: STRING?, nodes :: INTEGER?, relationships :: INTEGER?, properties :: INTEGER?, time :: INTEGER?, rows :: INTEGER?, batchSize :: INTEGER?, batches :: INTEGER?, done :: BOOLEAN?, data :: STRING?)

输入参数

名称 类型 默认

config

MAP?

{}

配置参数

该过程支持以下配置参数

表 1. 配置参数
名称 (name) type 默认 description(描述)

filename

字符串

"metadata"

文件名前缀。例如:metadata.customProcedures.dbName.cypher

features

List<String>

["CypherProcedure", "CypherFunction", "Uuid", "Trigger", "DataVirtualizationCatalog"]

一个列表,用于指示要导出哪些功能。可选值包括:"CypherProcedure", "CypherFunction", "Uuid", "Trigger", "DataVirtualizationCatalog"。

输出参数

名称 类型

file

STRING?

source

STRING?

format

STRING?

节点

整数?

relationships

整数?

属性

整数?

time

整数?

rows

整数?

batchSize

整数?

batches

整数?

done

布尔值?

data

STRING?

使用示例

要使用此过程,我们必须通过在 apoc.conf 中设置以下属性来启用它:

apoc.conf
apoc.export.file.enabled=true

如果我们执行在数据库 neo4j 中执行以下查询:

CALL apoc.trigger.add('trig','RETURN $alpha', {phase: 'after'}, {params: {alpha: 1} });
CALL apoc.trigger.add('trigTwo','RETURN 1', null);
CALL apoc.trigger.pause('trigTwo');
CALL apoc.custom.declareFunction('funNameOne(val = 2 :: INTEGER) :: NODE ', 'MATCH (t:Target {value : $val}) RETURN t');
CALL apoc.custom.declareProcedure('procNameOne(one = 2 ::INTEGER?, two = 3 :: INTEGER?) :: (sum :: INTEGER) ', 'RETURN $one + $two as sum');
CALL apoc.custom.asProcedure('procName','RETURN $input as answer','read',[['answer','number']],[['input','int','42']], 'Procedure that answer to the Ultimate Question of Life, the Universe, and Everything');
CALL apoc.custom.asFunction('funName','RETURN $input as answer','long', [['input','number']], false);
CREATE CONSTRAINT person_cons ON (p:Person) ASSERT p.alpha IS UNIQUE;
CALL apoc.uuid.install('Person', {addToSetLabels: true, uuidProperty: 'alpha'});
CALL apoc.dv.catalog.add("dvName", {type: 'CSV', url: 'file://myUrl', query: 'map.name = $name and map.age = $age', desc: "person's details", labels: ['Person']});

并在数据库 another 中执行:

CALL apoc.trigger.add('trigAnother','RETURN 1', null);

如果我们执行:

CALL apoc.systemdb.export.metadata()

我们将获得以下文件:

metadata.customProcedures.neo4j.cypher
CALL apoc.custom.declareFunction('funNameOne(val = 2 :: INTEGER?) :: (NODE?)', 'MATCH (t:Target {value : $val}) RETURN t' , false, '');
CALL apoc.custom.declareProcedure('procNameOne(one = 2 :: INTEGER?, two = 3 :: INTEGER?) :: (sum :: INTEGER?)', 'RETURN $one + $two as sum' , 'READ', '');
CALL apoc.custom.declareProcedure('procName(input = 42 :: INTEGER?) :: (answer :: NUMBER?)', 'RETURN $input as answer' , 'READ', 'Procedure that answer to the Ultimate Question of Life, the Universe, and Everything');
CALL apoc.custom.declareFunction('funName(input :: NUMBER?) :: (INTEGER?)', 'RETURN $input as answer' , false, '');
metadata.dvCatalogs.neo4j.cypher
CALL apoc.dv.catalog.add('dvName', {name:"dvName",url:"file://myUrl",desc:"person's details",labels:["Person"],query:"map.name = $name and map.age = $age",params:["$name","$age"],type:"CSV"});
metadata.triggers.neo4j.cypher
CALL apoc.trigger.add('trig', 'RETURN $alpha', {phase:"after"},{params: {alpha:1}});
CALL apoc.trigger.add('trigTwo', 'RETURN 1', null,{params: {}});
CALL apoc.trigger.pause('trigTwo');
metadata.uuids.neo4j.cypher
CALL apoc.uuid.install('Person', {uuidProperty:"alpha",addToSetLabels:true}) YIELD label RETURN label;
CALL apoc.uuid.install('Person', {uuidProperty:"beta",addToSetLabels:null}) YIELD label RETURN label;
metadata.uuids.schema.neo4j.cypher
CREATE CONSTRAINT IF NOT EXISTS ON (n:Person) ASSERT n.alpha IS UNIQUE;
CREATE CONSTRAINT IF NOT EXISTS ON (n:Person) ASSERT n.beta IS UNIQUE;

这样我们就可以使用 apoc.cypher.run* 过程将所有内容导入到另一个数据库中。

metadata.uuids.schema.neo4j.cypher
CALL apoc.cypher.runSchemaFile("metadata.uuids.schema.neo4j.cypher");
CALL apoc.cypher.runFiles(["metadata.customProcedures.neo4j.cypher", "metadata.dvCatalogs.neo4j.cypher", "metadata.triggers.neo4j.cypher", "metadata.uuids.neo4j.cypher"])

我们可以通过配置参数 features 来选择想要导出的内容(这是一个字符串列表,可选值包括 "customProcedures", "triggers", "uuids", "dvCatalogs")。例如:

CALL apoc.systemdb.export.metadata({features: ["triggers", "uuids"]})

将仅导出 metadata.triggers.neo4j.cyphermetadata.uuids.neo4j.cypher 文件。

因此,我们可以选择文件名前缀,例如如果我们想导出文件名为 customName.triggers.neo4j.cypher 等的文件,我们可以执行:

CALL apoc.systemdb.export.metadata({filename: "customName"})
© . This site is unofficial and not affiliated with Neo4j, Inc.