witten
/
luminotes
Archived
1
0
Fork 0

Added backend property to determine the current database backend. Also fixed timestamp regular expression.

This commit is contained in:
Dan Helfman 2008-08-19 14:18:08 -07:00
parent 71c48b8f05
commit a5dfc2f826
1 changed files with 9 additions and 1 deletions

View File

@ -20,6 +20,9 @@ class Database( object ):
ID_BITS = 128 # number of bits within an id ID_BITS = 128 # number of bits within an id
ID_DIGITS = "0123456789abcdefghijklmnopqrstuvwxyz" ID_DIGITS = "0123456789abcdefghijklmnopqrstuvwxyz"
POSTGRESQL_BACKEND = 0
SQLITE_BACKEND = 1
# caching Notebooks causes problems because different users have different read_write/owner values # caching Notebooks causes problems because different users have different read_write/owner values
CLASSES_NOT_TO_CACHE = ( Notebook, ) CLASSES_NOT_TO_CACHE = ( Notebook, )
@ -48,7 +51,7 @@ class Database( object ):
from datetime import datetime from datetime import datetime
from pytz import utc from pytz import utc
TIMESTAMP_PATTERN = re.compile( "^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d).(\d+)\+\d\d:\d\d$" ) TIMESTAMP_PATTERN = re.compile( "^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d).(\d+)(?:\+\d\d:\d\d$)?" )
def convert_timestamp( value ): def convert_timestamp( value ):
( year, month, day, hours, minutes, seconds, fractional_seconds ) = \ ( year, month, day, hours, minutes, seconds, fractional_seconds ) = \
@ -68,6 +71,7 @@ class Database( object ):
self.__connection = connection or \ self.__connection = connection or \
Connection_wrapper( sqlite.connect( "luminotes.db", detect_types = sqlite.PARSE_DECLTYPES, check_same_thread = False ) ) Connection_wrapper( sqlite.connect( "luminotes.db", detect_types = sqlite.PARSE_DECLTYPES, check_same_thread = False ) )
self.__pool = None self.__pool = None
self.__backend = Database.SQLITE_BACKEND
else: else:
import psycopg2 as psycopg import psycopg2 as psycopg
from psycopg2.pool import PersistentConnectionPool from psycopg2.pool import PersistentConnectionPool
@ -96,6 +100,8 @@ class Database( object ):
), ),
) )
self.__backend = Database.POSTGRESQL_BACKEND
self.__cache = cache self.__cache = cache
try: try:
@ -378,6 +384,8 @@ class Database( object ):
if self.__pool: if self.__pool:
self.__pool.closeall() self.__pool.closeall()
backend = property( lambda self: self.__backend )
def end_transaction( function ): def end_transaction( function ):
""" """