mbr/simplekv — pull request #18 by jvrsantacruz (2014-10-08 23:04:59+00:00)
Title: Improves SQLAlchemy has_key method using SQL EXISTS clause

It uses SQL EXISTS clause instead of fetching a record and comparing it against None.

See the current query:

return None != self.bind.execute(
select([self.table.c.key], self.table.c.key == key).limit(1)
).first()

This fragment of code can result a bit problematic due to de comparision
of a sqlalchemy RowProxy against None, which should be using the `is` operator also.

The proposed query:

return self.bind.execute(
select([exists().where(self.table.c.key == key)])
).scalar()

Returns a boolean directly from the database,
and it should be allegedly faster while keeping it ANSI SQL.

Congrats for the library, it's easy to use and fun to extend.