Created
March 24, 2018 11:23
-
-
Save prs-watch/7b89cd8b729ce26a6399a5a06ab32a09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CyperUtils: | |
| """ | |
| Cypher QueryのUtilクラス。 | |
| CREATE文を作成する。 | |
| """ | |
| @classmethod | |
| def create_node_query(cls, name, label, properties, is_create = True): | |
| """ | |
| ノードのCREATE/MERGE文生成。 | |
| @param name ノード名。 | |
| @param label ノードラベル。 | |
| @param properties ノードプロパティ値。 | |
| @param is_created プレフィックスフラグ。FalseでMERGE文にする。(デフォルト: CREATE文) | |
| @return query クエリ。 | |
| """ | |
| prop_part = cls._convert_map_to_str(properties) | |
| return '${prefix} (${name}:${label}{{${properties}}})'.format( | |
| prefix = 'CREATE' if is_create else 'MERGE', | |
| name = name, | |
| label = label, | |
| properties = prop_part, | |
| ) | |
| @classmethod | |
| def create_relation_query(cls, start, end, rel_name, rel_label, rel_props, is_create = True): | |
| """ | |
| リレーションのCREATE文生成。 | |
| @param start 開始ノード。 | |
| @param end 終了ノード。 | |
| @param rel_name リレーション名。 | |
| @param rel_label リレーションラベル。 | |
| @param rel_props リレーションプロパティ値。 | |
| @return query クエリ。 | |
| """ | |
| prop_part = cls._convert_map_to_str(rel_props) | |
| return '${prefix} (${start})-[${rel_name}:${rel_label}{{${rel_props}}}]->(${end})'.format( | |
| prefix = 'CREATE' if is_create else 'MERGE', | |
| start = start, | |
| rel_name = rel_name, | |
| rel_label = rel_label, | |
| rel_props = prop_part, | |
| end = end | |
| ) | |
| def _convert_map_to_str(properties): | |
| """ | |
| map(dictionay)型を文字列に変換。 | |
| @param properties プロパティ値。(dictionary) | |
| @return str 文字列。 | |
| """ | |
| strs = ['{key}:"{val}"'.format(key = key, val = properties[key]) for key in properties.keys()] | |
| return ','.join(strs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment