Ember and Postgresql(table values) to json format

Helloo! I am having problems with the response of my queries sent to ember cli app. For example, I have my models:

 import DS from 'ember-data';

 var attr= DS.attr;
 export default DS.Model.extend({
 author: DS.belongsTo('author'),

 title: attr('string'),
 body: attr('string'),
 date: attr('date')

import DS from 'ember-data';

export default DS.Model.extend({
posts: DS.hasMany('post'),
name: DS.attr('string')

So ember expects a response in the following json format:

var posts= [
    id: 1,
    date: new Date(2014,5,4,9,0,0),
    body:"mmm yum"
    id: 2,
    date: new Date(2015,1,1,9,0,0),
    body: "Try these poison apples"

 var authors= [{
    id: 1,
    name: "George",

***My problem is if I am getting my information from a query using Postgresql, how do I send the resulting rows in that format, I have a table with the author_id and the post_id that the author posted. Help please, thanks!!!

You are not reading data from postgresql using ember. You are using some server-side technology. This is where you need to convert your data into JSON.

Maybe if you told us what you are using, someone who uses the same could help you. So… what’d that be?

Hii, I am using node js, example (HTTP GET):

var client = new pg.Client(conString);

var query = client.query({
text : "SELECT * FROM post natural join event"

   query.on("row", function(row, result) {

query.on("end", function(result) {

var response = {
  'posts' : result.rows,
  'users': what goes here???  (array of post ids--> posts: [1,2,2...] (ids of posts that a specific user posted)

I don’t know node.js unfortunately, but I believe JSON.stringify should be available? If so, you should use it to convert your data into JSON.

You could use https://github.com/SeyZ/jsonapi-serializer if you are on node.