如何在neomodel
创建节点之前检查节点是否存在?有没有一种方法可以优化我的代码?
答案 0 :(得分:3)
您可能正在寻找其中一种批处理操作:
答案 1 :(得分:2)
我创建了自己的查询来做到这一点。检查它是否有帮助。
def exists(node=None, property=None, value=None):
filter_node = (":" + node) if node != None else ''
filter_value = ("{" + property + ": '" + value + "'}") if property != None and value != None else ''
return db.cypher_query("MATCH(n" + filter_node + filter_value + ")" + " return count(n) > 0 as exists;" )[0][0][0]
exists(node='User')
答案 2 :(得分:0)
您可以使用 first_or_none 检查节点是否存在。
示例:
SELECT t.NAME AS TableName, s.Name AS SchemaName, p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB, SUM(a.used_pages) * 8 AS UsedSpaceKB,(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM sys.tables t
INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id
WHERE t.NAME NOT LIKE 'dt%' AND t.is_ms_shipped = 0 AND i.OBJECT_ID > 255
GROUP BY t.Name, s.Name, p.Rows
ORDER BY UsedSpaceKB DESC