couchdb anybody?

225 views
Skip to first unread message

mdipierro

unread,
Dec 7, 2010, 12:19:33 AM12/7/10
to web2py-users
I just added a partial and experiment support for couch in the new
DAL.

I have a problem and perhaps some of you may help me.

1) am running couchdbx on mac (download and click, starts couchdb, no
questions asked)

2) I am running the following python script

from sql import DAL, Field
db=DAL('couchdb://127.0.0.1:5984')
db.define_table('person',Field('name'))
id=db.person.insert(name='Jim')
print id
row=db.person(id)
print row #0
print db(db.person.id==id).update(name="john") #1
print db.person(id) #2
print row
del db.person[id]
print db.person(id)

It works, except that #1 returns 1 (update done) but #2 returns Jim,
not John.
What am I doing wrong?

You can only for one record by id.
Once this works fine, extending to more complex queries should be
easy.

I have not tried it with web2py sqlforms but it should work fine.

Notice the code of the adapter (ChouchDBAdapter) is very small. It can
be easily be extended to other NoSQL.

mdipierro

unread,
Dec 7, 2010, 1:08:13 AM12/7/10
to web2py-users
forget it. it works. The mistake is in what I am printing. This now
runs fine!

from sql import DAL, Field
db=DAL('couchdb://127.0.0.1:5984')
db.define_table('person',Field('name'))
id=db.person.insert(name='Jim')
print id
row=db.person(id)
print row
print db(db.person.id==id).update(name="john")
print db.person(id)
del db.person[id]

mr.freeze

unread,
Dec 7, 2010, 1:24:24 AM12/7/10
to web2py-users
Nice!

Bruno Rocha

unread,
Dec 7, 2010, 1:52:45 AM12/7/10
to web...@googlegroups.com
Very Nice!

I will help testing this in my production couchdb mirror tomorrow,

any news for mongodb?

2010/12/7 mdipierro <mdip...@cs.depaul.edu>

mdipierro

unread,
Dec 7, 2010, 1:55:05 AM12/7/10
to web2py-users
Denes had a prototype for the old DAL. I will talk to him and one of
us should try merge it with the new dal.

On Dec 7, 12:52 am, Bruno Rocha <rochacbr...@gmail.com> wrote:
> Very Nice!
>
> I will help testing this in my production couchdb mirror tomorrow,
>
> any news for mongodb?
>
> 2010/12/7 mdipierro <mdipie...@cs.depaul.edu>
Message has been deleted

David Marko

unread,
Dec 8, 2010, 2:57:29 PM12/8/10
to web...@googlegroups.com
I tried it but getting following error:

Traceback (most recent call last):
File "c:\java\web2py\gluon\main.py", line 488, in wsgibase
BaseAdapter.close_all_instances(BaseAdapter.rollback)
File "c:\java\web2py\gluon\sql.py", line 264, in close_all_instances
action(instance)
File "c:\java\web2py\gluon\sql.py", line 988, in rollback
return self.connection.rollback()
AttributeError: 'Server' object has no attribute 'rollback'

Changes are available in CouchDB but after every request I'm getting error above.

David

mdipierro

unread,
Dec 8, 2010, 3:25:49 PM12/8/10
to web2py-users
Please make sure you have the latest sql.py from trunk.
CouchDB should call the rollback at 2325 not the one at line 988.

Massimo

António Ramos

unread,
Dec 8, 2010, 3:44:11 PM12/8/10
to web...@googlegroups.com
For dummies why not a video tutorial on using couchdb with web2py?
I would help a lot for newcommers and for web2py in general!

Best regards
António


2010/12/8 mdipierro <mdip...@cs.depaul.edu>

mdipierro

unread,
Dec 8, 2010, 4:20:44 PM12/8/10
to web2py-users
Because the integration is not completed. Close but not done.


On Dec 8, 2:44 pm, António Ramos <ramstei...@gmail.com> wrote:
> For dummies why not a video tutorial on using couchdb with web2py?
> I would help a lot for newcommers and for web2py in general!
>
> Best regards
> António
>
> 2010/12/8 mdipierro <mdipie...@cs.depaul.edu>

Kevin

unread,
Dec 28, 2010, 4:09:46 PM12/28/10
to web2py-users
With CouchDB in particular, is there any thoughts for treating nested
structures as though they had been retrieved through a join?

Taking the following document:

{
_id: 'abcd1234',
type: 'person',
name: 'John Doe',
phones: ['555-555-3614', '555-555-1812'],
addresses: ['123 S Nowhere Ln...']
}

Because the phones and addresses, although nested objects, can be
added as top level objects to a view arbitrarily, and because self-
contained documents like the above are the way to do things in Couch,
it seems prudent to be able to simulate 'table' relationships in the
DAL in some way, in this example with phones and addresses being
understood as virtual tables so as to integrate with SQLTABLE and
CRUD, to name a few.

Additionally, when completed, will we be able to define arbitrary
predefined views as read-only tables that can only be filtered by key/
key-range? Temporary views will have noticeably slower performance,
which would make ad-hoc filters something to be discouraged.

黄祥

unread,
Sep 21, 2017, 3:33:49 AM9/21/17
to web2py-users
tested in web2py 2.15.4, ubuntu xenial 64 (vagrant), couchdb install via apt install couchdb, test in http browser (http://127.0.0.1:5984) :
{"couchdb":"Welcome","uuid":"xxx","version":"1.6.0","vendor":{"name":"Ubuntu","version":"15.10"}}

private/appconfig.ini
uri              = couchdb://127.0.0.1:5984
pool_size        = 10 ; ignored for sqlite
migrate_enabled  = true
migrate          = true
fake_migrate     = false
fake_migrate_all = false

return error traceback:

Traceback (most recent call last):
  File "/home/site/web2py/gluon/restricted.py", line 219, in restricted
    exec(ccode, environment)
  File "/home/site/web2py/applications/test/models/db.py", line 98, in <module>
    lazy_tables = True)
  File "/home/site/web2py/gluon/packages/dal/pydal/base.py", line 170, in __call__
    obj = super(MetaDAL, cls).__call__(*args, **kwargs)
  File "/home/site/web2py/gluon/packages/dal/pydal/base.py", line 475, in __init__
    "Failure to connect, tried %d times:\n%s" % (attempts, tb)
RuntimeError: Failure to connect, tried 5 times:
Traceback (most recent call last):
  File "/home/site/web2py/gluon/packages/dal/pydal/base.py", line 455, in __init__
    self._adapter = adapter(**kwargs)
  File "/home/site/web2py/gluon/packages/dal/pydal/adapters/__init__.py", line 40, in __call__
    obj = super(AdapterMeta, cls).__call__(*args, **kwargs)
  File "/home/site/web2py/gluon/packages/dal/pydal/adapters/base.py", line 37, in __init__
    self._load_dependencies()
  File "/home/site/web2py/gluon/packages/dal/pydal/adapters/base.py", line 59, in _load_dependencies
    self.parser = parsers.get_for(self)
  File "/home/site/web2py/gluon/packages/dal/pydal/helpers/_internals.py", line 22, in get_for
    "no %s found for object: %s" % (self.namespace, obj))
ValueError: no parser found for object: <pydal.adapters.couchdb.CouchDB object at 0x7f1f17ccfad0>

thanks and best regards,
stifan

黄祥

unread,
Sep 27, 2017, 10:25:35 AM9/27/17
to web2py-users
finally got it work, couchdb 2.1.0 (mac), extract and run apache couchdb.app, pip install couchdb (for python driver) and then running web2py 2.14.6 source (web2py recent version not work error traceback posted above)
error 1:
Traceback (most recent call last):
  File "/Users/MacBookPro/site/web2py/gluon/restricted.py", line 227, in restricted
    exec ccode in environment
  File "/Users/MacBookPro/site/web2py/applications/test/controllers/install_demo.py", line 490, in <module>
  File "/Users/MacBookPro/site/web2py/gluon/globals.py", line 417, in <lambda>
    self._caller = lambda f: f()
  File "/Users/MacBookPro/site/web2py/applications/test/controllers/install_demo.py", line 7, in index
    if db(db.auth_permission).isempty() and db(db.auth_membership).isempty():
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", line 1989, in isempty
    return not self.select(limitby=(0, 1), orderby_on_limitby=False)
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", line 2020, in select
    return adapter.select(self.query, fields, attributes)
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/adapters/couchdb.py", line 160, in select
    rows = [cols['value'] for cols in ctable.query(fn)]
  File "/Users/MacBookPro/site/lib/python2.7/site-packages/couchdb/client.py", line 1259, in __iter__
    return iter(self.rows)
  File "/Users/MacBookPro/site/lib/python2.7/site-packages/couchdb/client.py", line 1279, in rows
    self._fetch()
  File "/Users/MacBookPro/site/lib/python2.7/site-packages/couchdb/client.py", line 1265, in _fetch
    data = self.view._exec(self.options)
  File "/Users/MacBookPro/site/lib/python2.7/site-packages/couchdb/client.py", line 1165, in _exec
    }, **_encode_view_options(options))
  File "/Users/MacBookPro/site/lib/python2.7/site-packages/couchdb/http.py", line 566, in post_json
    **params)
  File "/Users/MacBookPro/site/lib/python2.7/site-packages/couchdb/http.py", line 585, in _request_json
    headers=headers, **params)
  File "/Users/MacBookPro/site/lib/python2.7/site-packages/couchdb/http.py", line 581, in _request
    credentials=self.credentials)
  File "/Users/MacBookPro/site/lib/python2.7/site-packages/couchdb/http.py", line 421, in request
    raise ServerError((status, error))
ServerError: (403, (u'forbidden', u'Temporary views are not supported in CouchDB'))

error 2:
Traceback (most recent call last):
  File "/Users/MacBookPro/site/web2py/gluon/restricted.py", line 227, in restricted
    exec ccode in environment
  File "/Users/MacBookPro/site/web2py/applications/test/models/db_schema_3_customer.py", line 161, in <module>
    auth_user_customer = db(db.customer.auth_user == auth.user_id).select().first()
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", line 2020, in select
    return adapter.select(self.query, fields, attributes)
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/adapters/couchdb.py", line 157, in select
    fn, colnames = self._select(query,fields,attributes)
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/adapters/couchdb.py", line 149, in _select
    query=self.expand(query),
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/adapters/couchdb.py", line 50, in expand
    return BaseAdapter.expand(self,expression,field_type)
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/adapters/base.py", line 954, in expand
    rv = op(first, **optional_args)
TypeError: EQ() takes exactly 3 arguments (2 given)

error 1: is occured when start new web2py app, add new record (e.g. auth_group in appadmin web browser)
another strange thing is all dal define table is recorded as database in couchdb, i think it should be document (pls correct me if i'm wrong)
e.g.
private/appconfig.ini
uri = couchdb://localhost:5984
where is the database name on this configuration? 

already test with 
web2py private/appconfig.ini
private/appconfig.ini
uri = couchdb://localhost:5984/testweb2py

couchdb create database
not work with web2py configuration above

while in mongodb, there is database name in configuration
e.g.
private/appconfig.ini
uri = mongodb://localhost/mutualfunds

compare couchdb and mongodb to work with web2py: (posted in another thread of this forum)
- iterselect is work in couchdb while not work in mongodb
- auth.add_permission() is work in couchdb while not work in mongodb
- db.executesql('CREATE INDEX idx_auth_user ON auth_user (id, first_name, last_name, email, username);') seems work in couchdb while not work in mongodb

best regards,
stifan
Reply all
Reply to author
Forward
0 new messages