Skip to content

Commit

Permalink
Merge pull request #12 from sociallydistant/FEAT-enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
llunn authored Mar 22, 2023
2 parents 7385ecd + 594eaea commit 2de7d3f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
18 changes: 14 additions & 4 deletions couchapy/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def replace_with_segment(matches):
else:
return segments[matches.group(1)]

return sub(':([\w_]+):', replace_with_segment, template)
return sub(r':([\w_]+):', replace_with_segment, template)


def endpoint(*args, **kwargs):
Expand Down Expand Up @@ -62,7 +62,7 @@ def wrapper(self, *query_params, **kwargs):
if ('params' in kwargs):
_process_filter_format(allowed_query_parameter_keys, kwargs.get('params'))

if (request_method == 'post'or request_method == 'put'):
if (request_method == 'post' or request_method == 'put'):
if headers.get('Content-type', None) == 'application/json':
response = request_action(uri,
headers=headers,
Expand Down Expand Up @@ -141,8 +141,9 @@ class AllowedKeys():

SERVER__DB_UPDATES__PARAMS = {'feed': str, 'timeout': int, 'heartbeat': int, 'since': str}
SERVER__REPLICATE__DATA = {'cancel': bool, 'continuous': bool,
'create_target': bool, 'doc_ids': [],
'filter': str, 'proxy': str,
'create_target': bool, 'create_target_params': {},
'doc_ids': [], 'filter': str, 'selector': {},
'source_proxy': str, 'target_proxy': str,
'source': {}, 'target': {}}
SERVER__SCHEDULER_JOBS__PARAMS = {'limit': int, 'skip': int}
SERVER__SCHEDULER_DOCS__PARAMS = {'limit': int, 'skip': int}
Expand All @@ -163,6 +164,15 @@ class AllowedKeys():
'limit': int, 'skip': int, 'reduce': bool, 'sorted': bool,
'stable': bool, 'stale': str,
'update': str, 'update_seq': bool}
SEARCH__PARAMS = {'bookmark': str, 'counts': {},
'drilldown': {}, 'group_field': str,
'group_sort': {}, 'highlight_fields': {},
'highlight_pre_tag': str, 'highlight_post_tag': str,
'highlight_number': int, 'highlight_size': int,
'include_docs': bool, 'include_fields': {},
'limit': int, 'q': str,
'query': str, 'ranges': {},
'sort': {}, 'stale': str}
DATABASE__ALL_DOCS__DATA = {'keys': []}
DATABASE__ALL_DOCS_QUERIES__DATA = {'queries': []}
DATABASE__DESIGN_DOCS_QUERIES__DATA = {'queries': []}
Expand Down
2 changes: 2 additions & 0 deletions couchapy/private/design.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import couchapy.decorators as couch
import couchapy.private.attachment as _attachment
import couchapy.private.view as _view
import couchapy.private.search as _search


class _DesignDocument():
Expand All @@ -16,6 +17,7 @@ def __init__(self, parent, **kwargs):
self._predefined_segments = parent._predefined_segments
self.attachment = _attachment._DesignDocAttachment(self)
self.view = _view._View(self)
self.search = _search._Search(self)

@couch.endpoint('/:db:/_design_docs', method='post', data_keys=couch.AllowedKeys.DATABASE__DESIGN_DOCS__DATA)
def get_by_post(self, couch_data, **kwargs):
Expand Down
28 changes: 28 additions & 0 deletions couchapy/private/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import couchapy.decorators as couch


class _Search():
"""
Namespace class for search index related endpoints.
This class is not intended for direct use and should be accessed through the database attribute of a CouchDB instance.
"""
def __init__(self, parent, **kwargs):
# TODO: rename this to reference the host couch instance
self.parent = parent.parent
self._db = parent._db
self._predefined_segments = parent._predefined_segments

@couch.endpoint('/:db:/_design/:docid:/_search/:index:', query_keys=couch.AllowedKeys.SEARCH__PARAMS)
def get(self, couch_data, **kwargs):
"""
See https://docs.couchdb.org/en/stable/api/ddoc/search.html#get--db-_design-ddoc-_search-index
"""
return couch_data

@couch.endpoint('/:db:/_design/:docid:/_search_info/:index:')
def info(self, couch_data, **kwargs):
"""
See https://docs.couchdb.org/en/stable/api/ddoc/search.html#get--db-_design-ddoc-_search_info-index
"""
return couch_data

0 comments on commit 2de7d3f

Please sign in to comment.