dimanche 9 octobre 2016

Node Express mssql returns json format without serializer and name of object

I'm using Node express for the back-end of my application to retrieve data from a MSSQL database. I want to approach this server by another application, made with Ember. Ember DS does not know how to deal with the format returned by MSSQL.

Format returned by MSSQL is in the form:

[{  
    "var1": "abc",
    "var2": "def",
    "var3": 3
{ 
    ... 
}]

And, if understood correctly, should be in the form of:

{
    'modelName': [{     
        "_id": 1
        "var1": "abc",
        "var2": "def",
        "var3": 3
    },
    { 
        ... 
    }]
}

Hence, it misses both the name of the record (modelName) and an ID/Serial. I want to fix this within the Express server and not in the serializer of the Ember application. I can't find how to modify the JSON output of MSSQL within Express to the one Ember understands. Help would be highly appreciated!

I'm using (and be have to stick to) MSSQL 14.




Aucun commentaire:

Enregistrer un commentaire