Ticket #87: __init__.py

File __init__.py, 1.9 KB (added by Jason Huggins, 19 years ago)
Line 
1"""
2This is the core database connection.
3
4All CMS code assumes database SELECT statements cast the resulting values as such:
5 * booleans are mapped to Python booleans
6 * dates are mapped to Python datetime.date objects
7 * times are mapped to Python datetime.time objects
8 * timestamps are mapped to Python datetime.datetime objects
9
10Right now, we're handling this by using psycopg's custom typecast definitions.
11If we move to a different database module, we should ensure that it either
12performs the appropriate typecasting out of the box, or that it has hooks that
13let us do that.
14"""
15
16from django.conf.settings import DATABASE_ENGINE
17
18try:
19 dbmod = __import__('django.core.db.backends.%s' % DATABASE_ENGINE, '', '', [''])
20except ImportError, exc:
21 # The database backend wasn't found. Display a helpful error message
22 # listing all possible database backends.
23 from django.core.exceptions import ImproperlyConfigured
24 import os
25 backend_dir = os.path.join(__path__[0], 'backends')
26 available_backends = [f[:-3] for f in os.listdir(backend_dir) if f.endswith('.py') and not f.startswith('__init__')]
27 available_backends.sort()
28 raise ImproperlyConfigured, "Could not load database backend: %s. Is your DATABASE_ENGINE setting (currently, %r) spelled correctly? Available options are: %s" % \
29 (exc, DATABASE_ENGINE, ", ".join(map(repr, available_backends)))
30
31DatabaseError = dbmod.DatabaseError
32db = dbmod.DatabaseWrapper()
33dictfetchone = dbmod.dictfetchone
34dictfetchmany = dbmod.dictfetchmany
35dictfetchall = dbmod.dictfetchall
36dictfetchall = dbmod.dictfetchall
37get_last_insert_id = dbmod.get_last_insert_id
38get_date_extract_sql = dbmod.get_date_extract_sql
39get_date_trunc_sql = dbmod.get_date_trunc_sql
40get_table_list = dbmod.get_table_list
41get_relations = dbmod.get_relations
42OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING
43DATA_TYPES = dbmod.DATA_TYPES
44DATA_TYPES_REVERSE = dbmod.DATA_TYPES_REVERSE
45EMPTY_STR_EQUIV = dbmod.EMPTY_STR_EQUIV
Back to Top