# Path: tornado/ncss.py
# class Server:
#             class Handler(tornado.web.RequestHandler):
#     def __init__(self, *, hostname='', port=8888, static_path='static'):
#     def register(self, url_pattern, handler, *, delete=None, get=None, patch=None, post=None, put=None, url_name=None, write_error=None, **kwargs):
#                 def delete(self, *args, **kwargs):
#                 def get(self, *args, **kwargs):
#                 def patch(self, *args, **kwargs):
#                 def post(self, *args, **kwargs):
#                 def put(self, *args, **kwargs):
#                 def get_field(self, name, default=None, strip=True):
#                 def get_fields(self, strip=True):
#                 def get_file(self, name, default=None):
#                 def get_files(self, name, default=None):
#                 def write_error(self, status_code, **kwargs):
#     def app(self, **kwargs):
#     def loop(self):
#     def run(self):


import sqlite3
from tornado.ncss import ncssbook_log
		# not a problem for us here using Tornado since it is single threaded
		GET = """SELECT * FROM {} WHERE id = last_insert_rowid()""".format(cls._table)
		c = cls._sql(GET)
		return cls(*c.fetchone())

	@classmethod
	def bulk_add(cls, items:[dict]):
		insert = """INSERT INTO {}\n""".format(cls._table)
		
		if items:
			for i, item in enumerate(items):
				if i  == 0:
					insert += 'SELECT '+ ', '.join('? AS {}'.format(attrib) for attrib in item.keys()) + '\n'
				else:
					places = ', '.join('?' * len(item))
					insert += 'UNION SELECT {}\n'.format(places)

			values = [value for item in items for value in item.values()]
		
			c = cls._sql(insert, values)

	def update(self, **kwargs):
		assert self.id is not None
		assert len(kwargs) != 0
		attribs, values = self._attribs(', ', kwargs)
		UPDATE = """UPDATE {} SET {} WHERE ID = ?""".format(self._table, attribs)
		self._sql(UPDATE, values + [self.id])
		self.__dict__.update(kwargs)

	def delete(self, **kwargs):

# Path: tornado/ncss.py
# class Server:
#             class Handler(tornado.web.RequestHandler):
#     def __init__(self, *, hostname='', port=8888, static_path='static'):
#     def register(self, url_pattern, handler, *, delete=None, get=None, patch=None, post=None, put=None, url_name=None, write_error=None, **kwargs):
#                 def delete(self, *args, **kwargs):
#                 def get(self, *args, **kwargs):
#                 def patch(self, *args, **kwargs):
#                 def post(self, *args, **kwargs):
#                 def put(self, *args, **kwargs):
#                 def get_field(self, name, default=None, strip=True):
#                 def get_fields(self, strip=True):
#                 def get_file(self, name, default=None):
#                 def get_files(self, name, default=None):
#                 def write_error(self, status_code, **kwargs):
#     def app(self, **kwargs):
#     def loop(self):
#     def run(self):


# Path: murder/db.py
import sqlite3
from tornado.ncss import ncssbook_log

		# not a problem for us here using Tornado since it is single threaded
		GET = """SELECT * FROM {} WHERE id = last_insert_rowid()""".format(cls._table)
		c = cls._sql(GET)
		return cls(*c.fetchone())

	@classmethod
	def bulk_add(cls, items:[dict]):
		insert = """INSERT INTO {}\n""".format(cls._table)
		
		if items:
			for i, item in enumerate(items):
				if i  == 0:
					insert += 'SELECT '+ ', '.join('? AS {}'.format(attrib) for attrib in item.keys()) + '\n'
				else:
					places = ', '.join('?' * len(item))
					insert += 'UNION SELECT {}\n'.format(places)

			values = [value for item in items for value in item.values()]
		
			c = cls._sql(insert, values)

	def update(self, **kwargs):
		assert self.id is not None
		assert len(kwargs) != 0
		attribs, values = self._attribs(', ', kwargs)
		UPDATE = """UPDATE {} SET {} WHERE ID = ?""".format(self._table, attribs)
		self._sql(UPDATE, values + [self.id])
		self.__dict__.update(kwargs)

	def delete(self, **kwargs):

		assert self.id is not None