var pg = require('pg');

function PoemsRepository(dbConfig) {
	this.dbConfig = dbConfig || {
		database: "pocolab",
		host: "localhost"
	};
}

PoemsRepository.prototype.create = function create(poem_data, callback) {
	pg.connect(this.dbConfig, function(err, client, done) {
		client.query("insert into poems (name) values ($1) returning id", [poem_data.name], function(err, result) {
			var poem = { id: result.rows[0].id, name: poem_data.name };
			callback(err, poem);
			done();
		});
	});
};

PoemsRepository.prototype.read = function read(poem_id, callback) {
	pg.connect(this.dbConfig, function(err, client, done) {
		client.query("select * from poems where id = $1", [poem_id], function(err, result) {
			callback(err, result.rows[0]);
			done();
		});
	});
};

PoemsRepository.prototype.destroy = function destroy(poem_id, callback) {
	pg.connect(this.dbConfig, function(err, client, done) {
		client.query("delete from poems where id = $1", [poem_id], function(err, result) {
			callback(err);
			done();
		});
	});
};

PoemsRepository.prototype.all = function all(callback) {
	pg.connect(this.dbConfig, function(err, client, done) {
		client.query("select * from poems", function(err, result) {
			callback(err, result.rows);
			done();
		});
	});
};

module.exports = PoemsRepository;

@@ -84,59 +84,8 @@
 nfig
- %7C%7C %7B%0A%09%09database: %22pocolab%22,%0A%09%09host: %22localhost%22%0A%09%7D
 ;%0A%7D%0A

Remove dbConfig defaults. Config file is required.