当前位置: 首页>>代码示例>>Python>>正文


Python Server.delete方法代码示例

本文整理汇总了Python中couchdb.client.Server.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Server.delete方法的具体用法?Python Server.delete怎么用?Python Server.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在couchdb.client.Server的用法示例。


在下文中一共展示了Server.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import delete [as 别名]
class Model:
    def __init__(self):
        try:
            self.__server = Server()
        except:
            print 'can not connect to Couchdb:%s'%(settings.c['db_url'])

        self.__db = {} 
        self.__db_name = settings.c['db_name']
        DEBUG.p(self.__db_name.items())
        for (k, v) in self.__db_name.items():
            try:
                self.__db[v] = self.__server.create(v)
            except:
                self.__db[v] = self.__server[v]

    def create(self, dbname):
        return self.__server.create(dbname) 

    def delete(self, dbname):
        try:
           self.__server.delete(dbname)
        except:
           print 'database %s doeso not exist!!!'%(dbname)
        
    def clearDB(self, dbname):
        try:
           self.__server.delete(dbname)
        except:
           print 'database %s doeso not exist!!!'%(dbname)

        self.__db[v] = self.__server.create(dbname)

    def getAllDoc(self):
        return self.__db[self.__db_name['cover']] 
        
    def addOneDoc(self, doc):
        keyStr = '%s:%s'%(doc['artist'], doc['album_name']) 
        doc['_id'] = hashlib.md5(keyStr.encode('ascii', 'ignore')).hexdigest()
        print '_id:%s'%(doc['_id'])
        doc_id, doc_rev = self.__db[self.__db_name['cover']].save(doc)
        print 'addOneDoc done'

    def delOneDoc(self, doc):
        self.__db[self.__db_name['cover']].delete(doc)
    
    def getById(self, artist, albumName):
        keyStr = '%s:%s'%(artist, albumName) 
        _id = hashlib.md5(keyStr.encode('ascii', 'ignore')).hexdigest()
        print _id
        album = self.__db[self.__db_name['cover']].get(_id)
        if album:
           return dict(album)
        return album
        #map_fun = '''function(doc) {
        #     if (doc._id == '%s')
        #         emit(doc, null);
        #         }''' % (_id)
        #albums = self.__db[self.__db_name['cover']].query(map_fun)
        #for album in albums: 
        #    return album.key 
        #return None

    def getById2(self, id):
        print id
        album = self.__db[self.__db_name['cover']].get(id)
        if album:
           return dict(album)
        return album

    def getByKeyValue(self, key, value):
        map_fun = '''function(doc) {
             if (doc.%s == '%s')
                 emit(doc, null);
                 }''' % (key, value)
        albums = self.__db[self.__db_name['cover']].query(map_fun)
        for album in albums: 
            return album.key 
        return None

    def getByArtist(self, artist):
        map_fun = '''function(doc) {
             if (doc.artist == '%s')
                 emit(doc, null);
                 }''' % (artist)
        albums = self.__db[self.__db_name['cover']].query(map_fun)
        for album in albums: 
            return album.key 
        return None

    def getByAbbumName(self, albumName):
        map_fun = '''function(doc) {
             if (doc.album_name == '%s')
                 emit(doc, null);
                 }''' % (albumName)
        albums = self.__db[self.__db_name['cover']].query(map_fun)
        for album in albums: 
            return album.key 
        return None

#.........这里部分代码省略.........
开发者ID:lewislone,项目名称:albumCovers,代码行数:103,代码来源:model.py

示例2: Server

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import delete [as 别名]
from couchdb.client import Server
from glob import glob
from os import path
import json
import re

DB_SERVER = 'http://ben:[email protected]:5984'
DB_NAME = 'einfachjabber'
DB_REMOTE = 'http://ben:[email protected]:5984/einfachjabber'

server = Server(url=DB_SERVER)
server.delete(DB_NAME)
db = server.create(DB_NAME)

def defclient(osystem):
    """
    Maps the OS short-names to their long pendants
    and their default client
    """

    system = ''
    if osystem == 'android':
        system = ['Android', 'beem']
    if osystem == 'blackberry':
        system = ['Blackberry', 'None']
    if osystem == 'debian':
        system = ['Debian', 'pidgin']
    if osystem == 'iphone':
        system = ['iPhone', 'None']
    if osystem == 'macosx':
        system = ['Mac OS X', 'ichat']
开发者ID:einfachjabber,项目名称:einfachjabber.de,代码行数:33,代码来源:json2couch.py

示例3: delete_dbs

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import delete [as 别名]
def delete_dbs():
    s1 = Server(DEFAULT_STORE_ADMIN_URI)
    s2 = Server(other_node)
    s1.delete('testdb')
    s2.delete('testdb')
开发者ID:grameh,项目名称:ers-node,代码行数:7,代码来源:couchdb_repl_test.py

示例4: Server

# 需要导入模块: from couchdb.client import Server [as 别名]
# 或者: from couchdb.client.Server import delete [as 别名]
from couchdb.client import Server

server = Server('http://localhost:5984')
try:
	db = server.create('animals')
except:
	db = server['animals']

print db.name

server.delete(db.name)
开发者ID:vinod85,项目名称:segfault,代码行数:13,代码来源:2.py


注:本文中的couchdb.client.Server.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。