skip to Main Content

I’m working on a system deals with dynamic properties.

If I want to create a vertex, I can do it like this before that:

select * from ag_catalog.cypher('people',$$ create (nyk:person{name:'nyk'}) return nyk $$) as (v ag_catalog.agtype);

But now, I don’t know the property, the property is given by the user as a json object.
The property may be {name:'asdf'} or {name:'asdf', age:25} or {name:'asdf', work:'programmer'} ....
I don’t know what property will get.

The problem is same when using the delete,update or get method.
So how to deal with that? Can I bind the property with a json parameter?

2

Answers


  1. You can later use the SET clause to insert the properties. Assuming that {name: 'John Doe'} is the JSON provided by the user, the following code demonstrates its usage:

    SELECT * FROM cypher('test', $$
      CREATE (:Person)                   
    $$) AS (res agtype);                      
     res 
    -----
    (0 rows)
    
    SELECT * FROM cypher('test', $$
      MATCH (n:Person)
      SET n = {name: 'John Doe'} 
      RETURN n                
    $$) AS (res agtype);
                                              res                                   
           
    -----------------------------------------------------------------------------------------
     {"id": 1407374883553281, "label": "Person", "properties": {"name": "John Doe"}}::vertex
    (1 row)
    

    If you intend to incorporate user input, you’ll need to use one of the drivers available for AGE, such as the Python driver.

    Login or Signup to reply.
  2. You can use any driver support to read the data from the user and then assign that read data according to the properties.
    You can view different driver support here at github.
    Once the data is read then it can be stored accordingly.
    like below

    SELECT * FROM cypher('test', $$
      MATCH (s:Persons)
      SET s = {name: 'Talha'} 
      RETURN s                
    $$) AS (res agtype);
                    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search