Skip to content

Instantly share code, notes, and snippets.

@ldct
Last active September 13, 2018 07:26
Show Gist options
  • Save ldct/95780105d278fedb3842 to your computer and use it in GitHub Desktop.
Save ldct/95780105d278fedb3842 to your computer and use it in GitHub Desktop.
postgres 9.6 ubuntu 15.04
sudo apt-get install git build-essential curl xclip
sudo apt-get install bison flex libreadline-dev libz-dev
git clone git://git.postgresql.org/git/postgresql.git
cd postgresql; ./configure; make; sudo make install
cd contrib; make; sudo make install
sudo adduser postgres
sudo mkdir /usr/local/pgsql/data
sudo chown postgres -R /usr/local/pgsql/data
sudo -i -u postgres
LC_ALL=en_US.UTF-8 /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
(this should print a "you can start the database..." message)
# usage
sudo -i -u postgres
/usr/local/pgsql/bin/psql
\l
CREATE DATABASE db_name;
\c db_name;
\d+
CREATE TABLE table_name (abc TEXT, def TEXT[]);
# postgres.js
var pg = require('pg');
var deasync = require('deasync');
var process = require('process');
var connectionString = 'postgresql://postgres@localhost/main';
var client = new pg.Client(connectionString);
client.connect(function (err) {
if(err) {
console.error('could not connect to postgres', err);
process.exit(1);
}
console.log('PSQL is running');
});
exports.runQuery = function(query, args, cb) {
var query = client.query(query, args);
var ret = [];
query.on('error', function(err) {
cb(err);
});
query.on('row', function(row) {
ret.push(row);
});
query.on('end', function() {
cb(null, ret);
});
}
exports.runQuerySync = deasync(exports.runQuery);
function runCommand(query) {
exports.runQuery(query, [], function(err, res) {
if (err) console.log(err);
});
}
var fs = require('fs');
// var init_script = fs.readFileSync('./init.sql', 'utf8');
// runCommand(init_script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment