[GitHub] [incubator-age] pdpotter commented on issue #113: How to work with dynamic property
pdpotter commented on issue #113: URL: https://github.com/apache/incubator-age/issues/113#issuecomment-913432980 I understood the question as "How can I attach properties and values to a vertex if I don't know the properties beforehand". Are the properties predefined (e.g., the user can enter some properties such as "name", "age", "job" information, but no others), are is the user completely free to enter data? I see two possible solutions (I assume the "system" you are talking about consists of some application logic): 1. Parse the data entered by the user and construct the correct query (specifically the part `name:$name, age: $age` in the example below) in your application logic. Make sure to check if the properties ("name", "age", "job") only contain certain characters (or if the allowed properties are predefined: check if they are in this predefined list) to prevent [SQL injections](https://en.wikipedia.org/wiki/SQL_injection). Example of a query with properties "name" and "age": ``` SELECT * from ag_catalog.cypher( 'people', $$ CREATE (nyk:person{name:$name, age: $age}) RETURN nyk, $1 $$ ) as (v ag_catalog.agtype); ``` where you then pass the values as json text string: ``` '{"name": "Jane", "age": 35}' ``` 2. Enter the data entered by the user as a map under a specific property (e.g., "data"). I don't know if this has repercussions on the querying performance. Example: ``` SELECT * from ag_catalog.cypher( 'people', $$ CREATE (nyk:person{data:$data}) RETURN nyk, $1 $$ ) as (v ag_catalog.agtype); ``` with as parameter ``` '{"data": {"name": "Jane", "age": 35}}' ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@age.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [incubator-age] pdpotter commented on issue #113: How to work with dynamic property
pdpotter commented on issue #113: URL: https://github.com/apache/incubator-age/issues/113#issuecomment-918093763 Example for the second solution: Create person nodes ``` SELECT * FROM ag_catalog.cypher( 'people', $$ CREATE (a:Person {data:{name:'Jane', 'age': 35}}) $$ ) as (a ag_catalog.agtype); a --- (0 rows) SELECT * FROM ag_catalog.cypher( 'people', $$ CREATE (a:Person {data:{name:'Will', age: 21}}) $$ ) as (a ag_catalog.agtype); a --- (0 rows) ``` Retrieve all persons with age 21 ``` SELECT * FROM ag_catalog.cypher( 'people', $$MATCH(n {data:{age:21}}) RETURN n$$ ) as (n ag_catalog.agtype); n - {"id": 844424930131974, "label": "Person", "properties": {"data": {"age": 21, "name": "Will"}}}::vertex (1 row) ``` Retrieve all persons with age greater than 25 ``` SELECT * FROM cypher( 'people', $$MATCH(n) WHERE n.data.age > 25 RETURN n$$ ) as (n agtype); n - {"id": 844424930131973, "label": "Person", "properties": {"data": {"age": 35, "name": "Jane"}}}::vertex (1 row) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@age.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [incubator-age] pdpotter commented on issue #113: How to work with dynamic property
pdpotter commented on issue #113: URL: https://github.com/apache/incubator-age/issues/113#issuecomment-1113007891 I think this issue has been resolved, I close the issue. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@age.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org