Created
March 16, 2015 17:03
-
-
Save brianc/35e36fb4db6b645ed65f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var moment = require('moment') | |
var pg = require('pg') | |
pg.connect(function(err, client, done) { | |
client.query('CREATE TEMP TABLE items(name text, created_at timestamptz)') | |
var insert = 'INSERT INTO items(name, created_at) VALUES($1, $2)' | |
client.query(insert, ['2012', new Date(2012, 01, 01)]) | |
client.query(insert, ['2013', new Date(2013, 01, 01)]) | |
client.query(insert, ['2014', new Date(2014, 01, 01)]) | |
client.query(insert, ['2015', new Date(2015, 01, 01)]) | |
client.query('SELECT * FROM items ORDER BY created_at', function(err, result) { | |
console.log('order by', result.rows) | |
}) | |
client.query('SELECT * FROM items ORDER BY created_at DESC', function(err, result) { | |
console.log('order by DESC', result.rows) | |
done() | |
pg.end() | |
}) | |
}) |
Author
brianc
commented
Mar 16, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment