{"id":20,"date":"2011-04-19T23:51:00","date_gmt":"2011-04-19T14:51:00","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=20"},"modified":"2016-06-06T13:34:38","modified_gmt":"2016-06-06T04:34:38","slug":"node-js-postgresql","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/node-js\/20","title":{"rendered":"node.js + postgresql"},"content":{"rendered":"<p>node.js\u3067DB\u306bpostgresql\u3092\u4f7f\u3063\u3066\u307f\u308b\u3002<\/p>\n<p>node-postgres\u306a\u3093\u3066\u4fbf\u5229\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u3042\u308b\u306e\u3067\u3068\u3066\u3082\u7c21\u5358\u3002<\/p>\n<p>node-postgres<br \/>\n<a href=\"https:\/\/github.com\/brianc\/node-postgres#readme\">https:\/\/github.com\/brianc\/node-postgres#readme<\/a><\/p>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306fnpm\u3067\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >$ npm install pg<\/pre>\n<p>\u30a6\u30c1\u306e\u74b0\u5883\u3067\u306f\u300cpg_config\u304c\u7121\u3044\u3088\uff01\u300d\u3068\u6012\u3089\u308c\u305f\u306e\u3067\u3001yum\u3067postgresql-devel\u3092\u5165\u308c\u3001\u518d\u5ea6\u4e0a\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u305f\u3089\u554f\u984c\u306a\u304f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3042\u3063\u305f\u30b5\u30f3\u30d7\u30eb\u3092\u5b9f\u884c<\/p>\n<pre class=\"lang:js decode:true \" >var pg = require('pg');\r\n\/\/or native libpq bindings\r\n\/\/var pg = require('pg').native\r\n\r\nvar conString = 'tcp:\/\/\uff1c\u30a2\u30ab\u30a6\u30f3\u30c8\uff1e:\uff1c\u30d1\u30b9\u30ef\u30fc\u30c9\uff1e@localhost\/postgres';\r\n\r\n\r\nvar client = new pg.Client(conString);\r\nclient.connect(function(err) {\r\n  if(err) {\r\n    return console.error('could not connect to postgres', err);\r\n  }\r\n  client.query('SELECT NOW() AS &quot;theTime&quot;', function(err, result) {\r\n    if(err) {\r\n      return console.error('error running query', err);\r\n    }\r\n    console.log(result.rows[0].theTime);\r\n    \/\/output: Tue Jan 15 2013 19:12:47 GMT-600 (CST)\r\n    client.end();\r\n  });\r\n});<\/pre>\n<p>\u7279\u306b\u554f\u984c\u306a\u304f\u3059\u3093\u306a\u308a\u5b9f\u884c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>SQL\u306e\u76f4\u66f8\u304d\u306a\u3093\u3066\u5acc\u3060\u3041\uff01\u3063\u3066\u4eba\u306fFastLegS\u3068\u3044\u3046ORM\u304c\u3042\u308b\u306e\u3067\u305d\u3061\u3089\u3092\u4f7f\u3063\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>FastLegS<br \/>\n<a href=\"https:\/\/github.com\/didit-tech\/FastLegS#readme\">https:\/\/github.com\/didit-tech\/FastLegS#readme<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>node.js\u3067DB\u306bpostgresql\u3092\u4f7f\u3063\u3066&hellip;<\/p>\n","protected":false},"author":1,"featured_media":5090,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-20","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":5,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":61,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions\/61"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/5090"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}