def configure(val): from couchbase_core.client import Client import couchbase_core._libcouchbase if val: couchbase_core._libcouchbase.lcb_logging(pylog_log_handler) initmsg = 'Initializing Couchbase logging. lcb_version={0}'.format( Client.lcb_version()) logging.getLogger('couchbase').info(initmsg) else: couchbase_core._libcouchbase.lcb_logging(None)
def view_query( self, design_doc, # type: str view_name, # type: str *view_options, # type: ViewOptions **kwargs): # type: (...) -> ViewResult """ Run a View Query :param str design_doc: design document :param str view_name: view name :param ViewOptions view_options: Options to use when querying a view index. :param kwargs: Override corresponding option in options. :return: A :class:`ViewResult` containing the view results """ final_kwargs = {'itercls': ViewResult} final_kwargs.update(kwargs) res = CoreClient.view_query( self, design_doc, view_name, **forward_args(final_kwargs, *view_options)) return res
def design_get(self, name, use_devmode=True): """ Retrieve a design document :param string name: The name of the design document :param bool use_devmode: Whether this design document is still in "development" mode :return: A :class:`~couchbase_core.result.HttpResult` containing a dict representing the format of the design document :raise: :exc:`couchbase.exceptions.HTTPException` if the design does not exist. .. seealso:: :meth:`design_create`, :meth:`design_list` """ name = Client._mk_devmode(name, use_devmode) existing = self._http_request(type=_LCB.LCB_HTTP_TYPE_VIEW, path="_design/" + name, method=_LCB.LCB_HTTP_METHOD_GET, content_type="application/json") return existing
def prefix(self, ddocname): return Client._mk_devmode(ddocname, self.value)
def design_create(self, name, ddoc, use_devmode=True, syncwait=0): """ Store a design document :param string name: The name of the design :param ddoc: The actual contents of the design document :type ddoc: string or dict If ``ddoc`` is a string, it is passed, as-is, to the server. Otherwise it is serialized as JSON, and its ``_id`` field is set to ``_design/{name}``. :param bool use_devmode: Whether a *development* mode view should be used. Development-mode views are less resource demanding with the caveat that by default they only operate on a subset of the data. Normally a view will initially be created in 'development mode', and then published using :meth:`design_publish` :param float syncwait: How long to poll for the action to complete. Server side design operations are scheduled and thus this function may return before the operation is actually completed. Specifying the timeout here ensures the client polls during this interval to ensure the operation has completed. :raise: :exc:`couchbase.exceptions.TimeoutException` if ``syncwait`` was specified and the operation could not be verified within the interval specified. :return: An :class:`~couchbase_core.result.HttpResult` object. .. seealso:: :meth:`design_get`, :meth:`design_delete`, :meth:`design_publish` """ client = self._cb name = Client._mk_devmode(name, use_devmode) fqname = "_design/{0}".format(name) if not isinstance(ddoc, dict): ddoc = json.loads(ddoc) ddoc = ddoc.copy() ddoc['_id'] = fqname ddoc = json.dumps(ddoc) existing = None if syncwait: try: existing = self.design_get(name, use_devmode=False) except CouchbaseException: pass ret = client._http_request(type=_LCB.LCB_HTTP_TYPE_VIEW, path=fqname, method=_LCB.LCB_HTTP_METHOD_PUT, post_data=ddoc, content_type="application/json") self._design_poll(name, 'add', existing, syncwait, use_devmode=use_devmode) return ret