Constraint = Constraint
Literal = Literal
- def __init__(self, *args, **kwargs):
- self._db_con = MySQLdb.connect(*args, **kwargs)
- self._db_con_autocommit = MySQLdb.connect(*args, **kwargs)
+ def __init__(self, host="localhost", user=None, passwd=None, *args, **kwargs):
+ self._db_con = MySQLdb.connect(host=host, user=user, passwd=passwd)
+ self._db_con_autocommit = MySQLdb.connect(host=host, user=user, passwd=passwd)
+ super(Connection, self).__init__(*args, **kwargs)
def query(self, sql, db=None):
if db is None:
#
##############################################################################
-import msgpack
from cursor import Cursor
import uuid
values = {
'id': doc_id,
'name': field_name,
- 'value': msgpack.dumps(field_value),
+ 'value': self.database.connection.serializer.dumps(field_value),
}
if type(field_value) in (int, float):
values['number'] = field_value
Constraint = dbutils.Constraint
Literal = dbutils.Literal
- def __init__(self, *args, **kwargs):
- self._db_con = None
+ def __init__(self, serializer=None, *args, **kwargs):
+ if serializer is None:
+ import msgpack
+ self.serializer = msgpack
+ else:
+ self.serializer = serializer
def __getattr__(self, db_name):
return Database(self, db_name)
#
##############################################################################
-import msgpack
class Cursor(object):
def __init__(self, collection, spec=None, fields=None, **kwargs):
self.Constraint = collection.database.connection.Constraint
self.Literal = collection.database.connection.Literal
+ self.serializer = collection.database.connection.serializer
+
self.collection = collection
self.spec = spec
if self.collection.exists():
field_type = 'number'
else:
field_type = 'value'
- field_value = msgpack.dumps(field_value)
+ field_value = self.serializer.dumps(field_value)
fields = [self.Field(table_field, 'id')]
tables = [table_field]
else:
document = {}
if '_id' in self.fields:
- document['_id'] = msgpack.loads(res[0])
+ document['_id'] = self.serializer.loads(res[0])
fields_without_id = filter(lambda x: x != '_id', self.fields)
for i in xrange(len(fields_without_id)):
if not res[i + 1] is None:
- document[fields_without_id[i]] = msgpack.loads(res[i + 1])
+ document[fields_without_id[i]] = self.serializer.loads(res[i + 1])
return document
else:
return None