Skip to content

Commit

Permalink
Merge pull request #34 from cs50/sql
Browse files Browse the repository at this point in the history
fixed style, naming of cs50.sql
  • Loading branch information
dmalan authored Nov 1, 2017
2 parents 41b0c47 + 731dd6d commit b9e5dbd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cs50/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import warnings


class SQL(object):
"""Wrap SQLAlchemy to provide a simple SQL API."""

Expand All @@ -23,7 +24,7 @@ def __init__(self, url, **kwargs):

# log statements to standard error
logging.basicConfig(level=logging.DEBUG)
self.logger = logging.getLogger(__name__)
self.logger = logging.getLogger("cs50")

# create engine, raising exception if back end's module not installed
self.engine = sqlalchemy.create_engine(url, **kwargs)
Expand All @@ -36,7 +37,9 @@ class UserDefinedType(sqlalchemy.TypeDecorator):
"""
Add support for expandable values, a la https://bitbucket.org/zzzeek/sqlalchemy/issues/3953/expanding-parameter.
"""

impl = sqlalchemy.types.UserDefinedType

def process_literal_param(self, value, dialect):
"""Receive a literal parameter value to be rendered inline within a statement."""
def process(value):
Expand Down Expand Up @@ -109,7 +112,8 @@ def process(value):

# bind parameters before statement reaches database, so that bound parameters appear in exceptions
# http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.text
statement = statement.bindparams(sqlalchemy.bindparam(key, value=value, type_=UserDefinedType()))
statement = statement.bindparams(sqlalchemy.bindparam(
key, value=value, type_=UserDefinedType()))

# stringify bound parameters
# http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html#how-do-i-render-sql-expressions-as-strings-possibly-with-bound-parameters-inlined
Expand Down

0 comments on commit b9e5dbd

Please sign in to comment.