OrientJS: How to get standard JSON (serialized) from request

I do not understand how to get standard JSON from an Oriijs request. I see people talking about "serializing" the result, but I don’t understand why and how to do it. There is a method toJSON(), but I see that it is used with fetchplans, etc.

I am trying to transfer a stream to a csv file and it is not working properly due to incorrect JSON format.

I would like to explain how and when to serialize. :-)

My request:

  return db.query(
    `SELECT 
      id,
      name,
      out('posted_to').name as page,
      out('posted_to').id as page_id,
      out('posted_to').out('is_language').name as language,
      out('posted_to').out('is_network').name as network 

    FROM post

    WHERE posted_at
      BETWEEN
        '${since}'
      AND
        '${until}'

      UNWIND 
        page,
        page_id,
        language,
        network
    `

My result:

[ { '@type': 'd',
    id: '207109605968597_1053732754639607',
    name: '10 maneiras pelas quais você está ferindo seus relacionamentos',
    page: 'Eu Amo o Meu Irmão',
    page_id: '207109605968597',
    language: 'portuguese',
    network: 'facebook',
    '@rid': { [String: '#-2:1'] cluster: -2, position: 1 },
    '@version': 0 },
  { '@type': 'd',
    id: '268487636604575_822548567865143',
    name: '10 maneiras pelas quais você está ferindo seus relacionamentos',
    page: 'Amo meus Filhos',
    page_id: '268487636604575',
    language: 'portuguese',
    network: 'facebook',
    '@rid': { [String: '#-2:3'] cluster: -2, position: 3 },
    '@version': 0 }]
+4
source share
2 answers

This is my dataset:

enter image description here

Query:

db.select('id','code').from('tablename').where({deleted:true}).all()
    .then(function (vertex) {
        console.log('Vertexes found: ');
        console.log(vertex);
});

Output:

Vertexes found:
[ { '@type': 'd',
    id: '6256650b-f5f2-4b55-ab79-489e8069b474',
    code: '4b7d99fa-16ed-4fdb-9baf-b33771c37cf4',
    '@rid': { [String: '#-2:0'] cluster: -2, position: 0 },
    '@version': 0 },
  { '@type': 'd',
    id: '2751c2a0-6b95-44c8-966a-4af7e240752b',
    code: '50356d95-7fe7-41b6-b7d9-53abb8ad3e6d',
    '@rid': { [String: '#-2:1'] cluster: -2, position: 1 },
    '@version': 0 } ]

If I add the command JSON.stringify():

Query:

db.select('id','code').from('tablename').where({deleted:true}).all()
    .then(function (vertex) {
        console.log('Vertexes found: ');
        console.log(JSON.stringify(vertex));
});

Output:

Vertexes found:
[{"@type":"d","id":"6256650b-f5f2-4b55-ab79-489e8069b474","code":"4b7d99fa-16ed-
4fdb-9baf-b33771c37cf4","@rid":"#-2:0","@version":0},{"@type":"d","id":"2751c2a0
-6b95-44c8-966a-4af7e240752b","code":"50356d95-7fe7-41b6-b7d9-53abb8ad3e6d","@ri
d":"#-2:1","@version":0}]

Hope this helps

0
source

, . :

db.query()

http- node . OrientDB Document , JSON . , , JSON.

http . , :

var request =  require("request");
var auth = "Basic " + new Buffer("root" + ":" + "root").toString("base64")

request(
        {
            url : encodeURI('http://localhost:2480/query/tech_graph/sql/'+queryInput+'/20'),
            headers : {
                "Authorization" : auth
            }
        },
        function (error, response, body) {
            console.log(body);
            return body;
        }
    );
0

Source: https://habr.com/ru/post/1621558/


All Articles