<commit_before>import rethinkdb as r
import database

class Database(database.Database):
	#class variable

	def __init__(self):
		database.Database.__init__(self, 'rethinkdb')
		#instance properties
		self.connection = None
		self.host = 'localhost'
		self.port = 28015
		self.timeout = 20
		self.database_name = 'radiowcs'
		self.auth_key = ''
		self.table_name = 'playlist'

	def __enter__(self):
		return self

	def __exit__(self, type, value, traceback):
		if (self.connection != None):
			self.connection.close()

	def connect(self):
		"""Opens/reopens connection to the database"""
		if (self.connection != None):
			self.connection.close()
		self.connection = r.connect(
			host=self.host,
			port=self.port,
			db=self.database_name,
			auth_key=self.auth_key,
			timeout=self.timeout
		)

	def reconnect(self):
		""" Closes and reopens connection, cancels outstanding requests"""
		assert self.connection != None
		self.connection.reconnect(noreply_wait=False)

	def configure(self):
		"""Creates required database and tables/collections"""
		self.connect()
		try:
			r.db_create(self.connection.db).run(self.connection)
			r.table_create(self.table_name).run(self.connection)
			r.
			print 'Database setup completed.'
		except r.RqlRuntimeError:
			print 'App database already exists..'

	def insert(self, item):
		"""
			Insert an item into the database
			:param item: item being inserted
			:type item: dict
		"""
		assert self.connection != None
		assert type(self.table_name) is str<commit_msg>Add secondary index 'date' to db<commit_after>import rethinkdb as r
import database

class Database(database.Database):
	#class variable

	def __init__(self):
		database.Database.__init__(self, 'rethinkdb')
		#instance properties
		self.connection = None
		self.host = 'localhost'
		self.port = 28015
		self.timeout = 20
		self.database_name = 'radiowcs'
		self.auth_key = ''
		self.table_name = 'playlist'

	def __enter__(self):
		return self

	def __exit__(self, type, value, traceback):
		if (self.connection != None):
			self.connection.close()

	def connect(self):
		"""Opens/reopens connection to the database"""
		if (self.connection != None):
			self.connection.close()
		self.connection = r.connect(
			host=self.host,
			port=self.port,
			db=self.database_name,
			auth_key=self.auth_key,
			timeout=self.timeout
		)

	def reconnect(self):
		""" Closes and reopens connection, cancels outstanding requests"""
		assert self.connection != None
		self.connection.reconnect(noreply_wait=False)

	def configure(self):
		"""Creates required database and tables/collections"""
		self.connect()
		try:
			r.db_create(self.connection.db).run(self.connection)
			r.table_create(self.table_name).run(self.connection)
			r.table(self.table_name).index_create('date')
			print 'Database setup completed.'
		except r.RqlRuntimeError:
			print 'App database already exists..'

	def insert(self, item):
		"""
			Insert an item into the database
			:param item: item being inserted
			:type item: dict
		"""
		assert self.connection != None
		assert type(self.table_name) is str
{'fraction_non_alphanumeric': 0.11875405580791694, 'fraction_numerical': 0.004542504866969501, 'mean_word_length': 4.172818791946309, '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': '6775155', 'n_tokens_mistral': 1114, 'n_tokens_neox': 969, 'n_words': 244}