From commits-return-5326-apmail-couchdb-commits-archive=couchdb.apache.org@couchdb.apache.org Thu Oct 21 12:07:47 2010 Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 53131 invoked from network); 21 Oct 2010 12:07:46 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 Oct 2010 12:07:46 -0000 Received: (qmail 283 invoked by uid 500); 21 Oct 2010 12:07:46 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 161 invoked by uid 500); 21 Oct 2010 12:07:44 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 151 invoked by uid 500); 21 Oct 2010 12:07:43 -0000 Delivered-To: apmail-incubator-couchdb-commits@incubator.apache.org Received: (qmail 148 invoked by uid 99); 21 Oct 2010 12:07:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Oct 2010 12:07:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.131] (HELO eos.apache.org) (140.211.11.131) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Oct 2010 12:07:42 +0000 Received: from eosnew.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id A10E6A7B; Thu, 21 Oct 2010 12:07:11 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Apache Wiki To: Apache Wiki Date: Thu, 21 Oct 2010 12:07:11 -0000 Message-ID: <20101021120711.84290.57260@eosnew.apache.org> Subject: =?utf-8?q?=5BCouchdb_Wiki=5D_Update_of_=22Getting=5Fstarted=5Fwith=5FPL/S?= =?utf-8?q?QL=22_by_ZekeriyaKoc?= Dear Wiki user, You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for c= hange notification. The "Getting_started_with_PL/SQL" page has been changed by ZekeriyaKoc. http://wiki.apache.org/couchdb/Getting_started_with_PL/SQL?action=3Ddiff&re= v1=3D18&rev2=3D19 -------------------------------------------------- - ## page was copied from Getting_started_with_Python - Getting started with Python and the CouchDB API. + Getting started with Oracle PL/SQL and the CouchDB API. = =3D=3D Library =3D=3D - =3D=3D=3D couchdbkit =3D=3D=3D - . http://couchdbkit.org/ + =3D=3D=3D couch_orcl =3D=3D=3D + . [[http://couchdbkit.org/|http://http://projects.zekzekus.com/projects/= couch-orcl]] = - Start using Couchdbkit by reading the [[http://couchdbkit.org/docs/gettin= gstarted.html|Getting Started tutorial]]. - = - For django use the [[http://www.couchdbkit.org/docs/django-extension.html= |django extension]] of couchdbkit. Other extension exists for [[http://docs= .formalchemy.org/ext/couchdb.html|formalchemy]]. - = - =3D=3D=3D couchdb-python =3D=3D=3D - The code for the Python library can be obtained from: - = - . http://code.google.com/p/couchdb-python - = - From a terminal window: - = - {{{ - $ wget http://peak.telecommunity.com/dist/ez_setup.py - $ sudo python ez_setup.py - $ wget http://pypi.python.org/packages/2.6/C/CouchDB/CouchDB-0.8-py2.6.egg - $ sudo easy_install CouchDB-0.8-py2.6.egg - }}} - This first downloads and installs the ''ez_setup.py'' script which runs p= ython ''.egg'' files. The second part downloads the ''.egg'' file for Couch= DB and installs it along with its dependencies. - = - You can find the documentation [[http://packages.python.org/CouchDB/getti= ng-started.html|here]], although make sure you use the latest version. - = - =3D=3D=3D couchquery =3D=3D=3D - . http://mikeal.github.com/couchquery/ - = - An implementation of the python 'shelve' API using couchquery as a backend - = - . http://www.randomwalking.com/snippets/couchshelve.text - = - =3D=3D Tutorial on using couchdb-python with Django =3D=3D - A tutorial on using Django (a Python framework) with CouchDb can be found= at - = - . http://lethain.com/entry/2008/aug/18/an-introduction-to-using-couchdb-= with-django/ http://www.eflorenzano.com/blog/post/using-couchdb-django/ - = - Alternatively you can view just the source for that example at - = - . http://github.com/lethain/comfy-django-example/tree/master - = - =3D=3D Example Wrapper Class =3D=3D - Demonstration of basic API-interaction using Python. (note: as of python = 2.6, one can use "import json" for the same functionality in this script.) - = - {{{#!python - #! /usr/bin/python2.4 - = - import httplib, simplejson # http://cheeseshop.python.org/pypi/simplejson - # Here only used for prettyprinting - = - def prettyPrint(s): - """Prettyprints the json response of an HTTPResponse object""" - = - # HTTPResponse instance -> Python object -> str - print simplejson.dumps(simplejson.loads(s.read()), sort_keys=3DTrue, = indent=3D4) - = - class Couch: - """Basic wrapper class for operations on a couchDB""" - = - def __init__(self, host, port=3D5984, options=3DNone): - self.host =3D host - self.port =3D port - = - def connect(self): - return httplib.HTTPConnection(self.host, self.port) # No close() - = - # Database operations - = - def createDb(self, dbName): - """Creates a new database on the server""" - = - r =3D self.put(''.join(['/',dbName,'/']), "") - prettyPrint(r) - = - def deleteDb(self, dbName): - """Deletes the database on the server""" - = - r =3D self.delete(''.join(['/',dbName,'/'])) - prettyPrint(r) - = - def listDb(self): - """List the databases on the server""" - = - prettyPrint(self.get('/_all_dbs')) - = - def infoDb(self, dbName): - """Returns info about the couchDB""" - r =3D self.get(''.join(['/', dbName, '/'])) - prettyPrint(r) - = - # Document operations - = - def listDoc(self, dbName): - """List all documents in a given database""" - = - r =3D self.get(''.join(['/', dbName, '/', '_all_docs'])) - prettyPrint(r) - = - def openDoc(self, dbName, docId): - """Open a document in a given database""" - r =3D self.get(''.join(['/', dbName, '/', docId,])) - prettyPrint(r) - = - def saveDoc(self, dbName, body, docId=3DNone): - """Save/create a document to/in a given database""" - if docId: - r =3D self.put(''.join(['/', dbName, '/', docId]), body) - else: - r =3D self.post(''.join(['/', dbName, '/']), body) - prettyPrint(r) - = - def deleteDoc(self, dbName, docId): - # XXX Crashed if resource is non-existent; not so for DELETE on d= b. Bug? - # XXX Does not work any more, on has to specify an revid - # Either do html head to get the recten revid or provide it a= s parameter - r =3D self.delete(''.join(['/', dbName, '/', docId])) - prettyPrint(r) - = - # Basic http methods - = - def get(self, uri): - c =3D self.connect() - headers =3D {"Accept": "application/json"} - c.request("GET", uri, None, headers) - return c.getresponse() - = - def post(self, uri, body): - c =3D self.connect() - headers =3D {"Content-type": "application/json"} - c.request('POST', uri, body, headers) - return c.getresponse() - = - def put(self, uri, body): - c =3D self.connect() - if len(body) > 0: - headers =3D {"Content-type": "application/json"} - c.request("PUT", uri, body, headers) - else: - c.request("PUT", uri, body) - return c.getresponse() - = - def delete(self, uri): - c =3D self.connect() - c.request("DELETE", uri) - return c.getresponse() - }}} - =3D=3D Usage Example =3D=3D - {{{#!python - def test(): - foo =3D Couch('localhost', '5984') - = - print "\nCreate database 'mydb':" - foo.createDb('mydb') - = - print "\nList databases on server:" - foo.listDb() - = - print "\nCreate a document 'mydoc' in database 'mydb':" - doc =3D """ - { - "value": - { - "Subject":"I like Planktion", - "Author":"Rusty", - "PostedDate":"2006-08-15T17:30:12-04:00", - "Tags":["plankton", "baseball", "decisions"], - "Body":"I decided today that I don't like baseball. I like pl= ankton." - } - } - """ - foo.saveDoc('mydb', doc, 'mydoc') - = - print "\nCreate a document, using an assigned docId:" - foo.saveDoc('mydb', doc) - = - print "\nList all documents in database 'mydb'" - foo.listDoc('mydb') - = - print "\nRetrieve document 'mydoc' in database 'mydb':" - foo.openDoc('mydb', 'mydoc') - = - print "\nDelete document 'mydoc' in database 'mydb':" - foo.deleteDoc('mydb', 'mydoc') - = - print "\nList all documents in database 'mydb'" - foo.listDoc('mydb') - = - print "\nList info about database 'mydb':" - foo.infoDb('mydb') - = - print "\nDelete database 'mydb':" - foo.deleteDb('mydb') - = - print "\nList databases on server:" - foo.listDb() - = - if __name__ =3D=3D "__main__": - test() - }}} - =3D=3D Sample Output =3D=3D - {{{#!java - Create database 'mydb': - { - "ok": true - } - = - List databases on server: - [ - "mydb" - ] - = - Create a document 'mydoc' in database 'mydb': - { - "_id": "mydoc", - "_rev": 362213977, - "ok": true - } - = - Create a document, using an assigned docId: - { - "_id": "CF29360495B2AAB44C7E43E5752A5123", - "_rev": 627930386, - "ok": true - } - = - List all documents in database 'mydb' - { - "rows": [ - { - "_id": "CF29360495B2AAB44C7E43E5752A5123", - "_rev": 627930386 - }, - { - "_id": "mydoc", - "_rev": 362213977 - } - ], - "view": "_all_docs" - } - = - Retrieve document 'mydoc' in database 'mydb': - { - "_id": "mydoc", - "_rev": 362213977, - "value": { - "Author": "Rusty", - "Body": "I decided today that I don't like baseball. I like plank= ton.", - "PostedDate": "2006-08-15T17:30:12-04:00", - "Subject": "I like Planktion", - "Tags": [ - "plankton", - "baseball", - "decisions" - ] - } - } - = - Delete document 'mydoc' in database 'mydb': - { - "_rev": 3811288472, - "ok": true - } - = - List all documents in database 'mydb' - { - "rows": [ - { - "_id": "CF29360495B2AAB44C7E43E5752A5123", - "_rev": 627930386 - } - ], - "view": "_all_docs" - } - = - List info about database 'mydb': - { - "db_name": "mydb", - "doc_count": 1, - "update_seq": 3 - } - = - Delete database 'mydb': - { - "ok": true - } - = - List databases on server: - [] - }}} -=20