Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 85120 invoked from network); 13 Apr 2008 21:12:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Apr 2008 21:12:34 -0000 Received: (qmail 66956 invoked by uid 500); 13 Apr 2008 21:12:34 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 66923 invoked by uid 500); 13 Apr 2008 21:12:34 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 66914 invoked by uid 99); 13 Apr 2008 21:12:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Apr 2008 14:12:34 -0700 X-ASF-Spam-Status: No, hits=1.5 required=10.0 tests=SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of yoan.blanc@gmail.com designates 209.85.146.179 as permitted sender) Received: from [209.85.146.179] (HELO wa-out-1112.google.com) (209.85.146.179) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Apr 2008 21:11:50 +0000 Received: by wa-out-1112.google.com with SMTP id n4so1827175wag.6 for ; Sun, 13 Apr 2008 14:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=6MzkCLdgyGY1ADvzCeMqfdtJe3Sm57FMX3h3PNq4m5o=; b=PL0rmde8kTnamMN238x5/y36geAf34G/q3Ikko+69vSdCNptXk43pr0HB4HeUmGx/qQQuiUMt9jjGInrs5TNUH+lESJUIFbglqkXQ5c27fbaCZ55PA99nwD/lDu/wlb33T+EPMuAMf1NL3eu4RGNpwGe5oMsoJm8tQbMVAlcrfs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ci12N6aqKtBNAsr1GfhvHDsqLp1bzqYAlEWYCKCB2FOmsbBUP7PUj2zMFGzrF4wfg/Nv/amZzeiU1vehltp+oNtqOXQeoc0AK7KPY8jZ5f++oxGXkjdlUbgM6bPOsDiioJ66BviAeUsNhQuBRXQA9Coq3/cXWMzfnYkKWXORbPg= Received: by 10.114.144.1 with SMTP id r1mr6072110wad.135.1208121120971; Sun, 13 Apr 2008 14:12:00 -0700 (PDT) Received: by 10.114.190.1 with HTTP; Sun, 13 Apr 2008 14:12:00 -0700 (PDT) Message-ID: Date: Sun, 13 Apr 2008 23:12:00 +0200 From: "Yoan Blanc" To: couchdb-user@incubator.apache.org Subject: Re: couchdb-python: looking for the equivalent of Database.exists() In-Reply-To: <30292b940804131407naaa9ec1t8730920be93aa586@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <30292b940804131407naaa9ec1t8730920be93aa586@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org Do this work for you? if dbname in couch: db = couch[dbname] else: db = couch.create(dbname) Cheers, -- Yoan On Sun, Apr 13, 2008 at 11:07 PM, Jay Luker wrote: > Hi, > > I'm basically wondering if there's a better way to implement this: > > def get_or_make_db(dbname): > couch = Server('http://localhost:5984') > db = None > try: > db = couch.create(dbname) > except ResourceConflict,e: > logger.debug("db %s already existed: %s" % (dbname,e)) > db = couch[dbname] > return db > > Having to catch the ResourceConflict exception seems backwards to me. > I came to this solution after my natural inclination didn't seem to > behave like I expected. I initially tried this: > > def get_or_make_db(dbname): > couch = Server('http://localhost:5984') > db = None > try: > db = couch[dbname] > except ResourceNotFound,e: > logger.debug("db %s already existed: %s" % (dbname,e)) > db = couch.create(dbname) > return db > > The problem with that is that "db = couch[dbname]" won't throw a > ResourceNotFound exception if the database doesn't exist. > > --jay >