42-django-couchdb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
diff --git a/django_couchdb/backends/couchdb/base.py b/django_couchdb/backends/couchdb/base.py
index 5d5f2ee..6447aec 100644
--- a/django_couchdb/backends/couchdb/base.py
+++ b/django_couchdb/backends/couchdb/base.py
@@ -40,8 +40,10 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.ops = DatabaseOperations()
self.validation = BaseDatabaseValidation()
- def _cursor(self, settings):
+ def _cursor(self, settings=None):
if self.connection is None:
+ if settings is None:
+ from django.conf import settings
if not settings.DATABASE_HOST:
raise ImproperlyConfigured, \
'Please, fill out DATABASE_HOST in the settings module ' \
diff --git a/django_couchdb/backends/couchdb/introspection.py b/django_couchdb/backends/couchdb/introspection.py
index 5ce7939..aa46c81 100644
--- a/django_couchdb/backends/couchdb/introspection.py
+++ b/django_couchdb/backends/couchdb/introspection.py
@@ -12,4 +12,4 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
return list(cursor.server.__iter__())
def get_table_description(self, cursor, table_name):
- return cursor.server[table_name]['_meta']
+ return cursor.server[table_name]['meta']
diff --git a/django_couchdb/backends/couchdb/nodes.py b/django_couchdb/backends/couchdb/nodes.py
index dc39a02..c7b0264 100644
--- a/django_couchdb/backends/couchdb/nodes.py
+++ b/django_couchdb/backends/couchdb/nodes.py
@@ -57,7 +57,7 @@ class Lookup(object):
def lookup_in(self):
- params = '{'+','.join('%s: 1' % x for x in self.params) + '}'
+ params = '{'+','.join('"%s": 1' % x for x in self.params) + '}'
return "(typeof "+self.table_alias+" == \"undefined\" || " + \
self.table_alias+ "." + process_name(self.name) + " in %s)" % params
@@ -65,8 +65,7 @@ class Lookup(object):
def get_where_node(BaseNode):
class WhereNode(BaseNode):
def make_atom(self, child, qn):
- #~ table_alias, name, db_type, lookup_type, value_annot, params = child
- lookup = Lookup(*child)
+ lookup = Lookup(*(child[0]+child[1:]))
return lookup.as_sql(), []
return WhereNode
diff --git a/django_couchdb/backends/couchdb/utils.py b/django_couchdb/backends/couchdb/utils.py
index 065c9c9..a5fb206 100644
--- a/django_couchdb/backends/couchdb/utils.py
+++ b/django_couchdb/backends/couchdb/utils.py
@@ -68,7 +68,7 @@ class SQL(object):
# self.params --- (model opts, field_params)
opts = self.params[0]
table = server.create(opts.db_table)
- meta = {'_id': '_meta'}
+ meta = {'_id': 'meta'}
if opts.unique_together:
meta['UNIQUE'] = list(opts.unique_together)
for field, field_params in self.params[1].iteritems():
@@ -77,19 +77,19 @@ class SQL(object):
if value:
params_list.append(param)
meta[field] = params_list
- table['_meta'] = meta
+ table['meta'] = meta
def execute_add_foreign_key(self, server):
# self.params - (r_table, r_col, table)
table = server[self.params[0]]
- meta = table['_meta']
+ meta = table['meta']
try:
refs = meta['REFERENCES']
except KeyError:
refs = []
refs.append('%s=%s' % (self.params[1], self.params[2]))
meta['REFERENCES'] = refs
- table['_meta'] = meta
+ table['meta'] = meta
def execute_insert(self, server, params):
# self.params --- (table name, columns, values)
@@ -101,7 +101,7 @@ class SQL(object):
else:
obj = {}
- views = process_views(table['_meta'], self.params[1], self.params[2])
+ views = process_views(table['meta'], self.params[1], self.params[2])
for key, view, val in izip(self.params[1], views, params):
if key=='id':
key = '_id'
@@ -122,7 +122,7 @@ class SQL(object):
columns.append(unquote_name(col))
values.append(val)
views.append(v)
- views = process_views(table['_meta'], columns, views)
+ views = process_views(table['meta'], columns, views)
for d in view:
obj = table[d.id]
for key, view, val in izip(columns, views, values):
@@ -140,7 +140,7 @@ class SQL(object):
else:
table_name = table.name
map_fun = "function ("+table_name+") { var _d = " + table_name+ ";"
- map_fun += "if ("+table_name+"._id!=\"_meta\") {"
+ map_fun += "if ("+table_name+"._id!=\"meta\") {"
if where:
map_fun += "if ("+process_where(where)+") {"
@@ -169,7 +169,7 @@ class SQL(object):
map_fun += "}}"
if where:
map_fun += '}'
- #~ print "MAP_FUN:", map_fun
+ # print "MAP_FUN:", map_fun
view = table.query(map_fun)
return view