meteor / postgres-packages

Early preview of PostgreSQL support for Meteor (deprecated, here for historical reasons)
http://meteor-postgres.readthedocs.org/
158 stars 25 forks source link

Print out all records and fields from a table using console.log #42

Closed yoonghm closed 8 years ago

yoonghm commented 8 years ago

I have a table

todo=# \d+ items
                                                    Table "public.items"
 Column |         Type          |                     Modifiers                      | Storage  | Stats target | Description 
--------+-----------------------+----------------------------------------------------+----------+--------------+-------------
 id     | integer               | not null default nextval('items_id_seq'::regclass) | plain    |              | 
 task   | character varying(64) |                                                    | extended |              | 

It has the following records

todo=# select * from items;
 id |     task      
----+---------------
  1 | Eat lunch
  2 | Eat dinner
  3 | Eat breakfast
  4 | Study
  5 | Sleep
  6 | Bath
(6 rows)

How to you print out all records, all columns from the table? I did that but it is not correct:

Items = new PG.Table("items");
var records = Items.select('id', 'task').orderBy('id').fetch();
for (var x in records) {
  console.log(x);
}

which gives

0
1
2
3
4
5
robfallows commented 8 years ago
Items = new PG.Table("items");
var records = Items.select('id', 'task').orderBy('id').fetch();
for (var x in records) {
  console.log(records[x]);
}

or

Items = new PG.Table("items");
var records = Items.select('id', 'task').orderBy('id').fetch();
_.each(records, (row) => {
  console.log(row);
}
yoonghm commented 8 years ago

thanks will try out. should be updated to the document.