<commit_before>var _ = require('underscore');

module.exports = function(dbConfig) {
	var db = require('./poemlab_database')(dbConfig);

	return {
		create: function(user_data, callback) {
			var params = _.values(_.pick(user_data, ["username", "email", "password"]));
			db.query("insert into poets (name, email, password) values ($1, $2, $3) " +
					"returning id, name, email", params,
				function(err, result) {
					if (err) { return callback(err); }
					callback(null, result.rows[0]);
				}
			);
		},

		read: function(user_id, callback) {
			db.query("select * from poets where id = $1", [user_id], function(err, result) {
				if (err) { return callback(err); }
				callback(null, result.rows[0]);
			});
		},

		readByUsername: function(username, callback) {
			db.query("select * from poets where name = $1", [username], function(err, result) {
				if (err) { return callback(err); }
				callback(null, result.rows[0]);
			});
		},

		search: function(query, callback) {
			db.query("select * from poets where name ilike $1 limit 20", [query + "%"], function(err, result) {
				if (err) { return callback(err); }
				callback(null, result.rows);
			});
		},

		destroy: function(user_id, callback) {
			db.query("delete from poets where id = $1", [user_id], function(err, result) {
				callback(err);
			});
		},

		all: function(callback) {
			db.query("select * from poets", [], function(err, result) {
				if (err) { return callback(err); }
				callback(null, result.rows);<commit_msg>Add readByEmail function to PoetsRepository<commit_after>var _ = require('underscore');

module.exports = function(dbConfig) {
	var db = require('./poemlab_database')(dbConfig);

	return {
		create: function(user_data, callback) {
			var params = _.values(_.pick(user_data, ["username", "email", "password"]));
			db.query("insert into poets (name, email, password) values ($1, $2, $3) " +
					"returning id, name, email", params,
				function(err, result) {
					if (err) { return callback(err); }
					callback(null, result.rows[0]);
				}
			);
		},

		read: function(user_id, callback) {
			db.query("select * from poets where id = $1", [user_id], function(err, result) {
				if (err) { return callback(err); }
				callback(null, result.rows[0]);
			});
		},

		readByUsername: function(username, callback) {
			db.query("select * from poets where name = $1", [username], function(err, result) {
				if (err) { return callback(err); }
				callback(null, result.rows[0]);
			});
		},

		readByEmail: function(email, callback) {
			db.query("select * from poets where email = $1", [email], function(err, result) {
				if (err) { return callback(err); }
				callback(null, result.rows[0]);
			});
		},

		search: function(query, callback) {
			db.query("select * from poets where name ilike $1 limit 20", [query + "%"], function(err, result) {
				if (err) { return callback(err); }
				callback(null, result.rows);
			});
		},

		destroy: function(user_id, callback) {
			db.query("delete from poets where id = $1", [user_id], function(err, result) {
				callback(err);
			});
		},

		all: function(callback) {
			db.query("select * from poets", [], function(err, result) {
				if (err) { return callback(err); }
				callback(null, result.rows);
{'fraction_non_alphanumeric': 0.17692307692307693, 'fraction_numerical': 0.008, 'mean_word_length': 3.752923976608187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5094060', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1052, 'n_words': 267}