Skip to content

Commit 0d16b47

Browse files
feat: add text_search (#215)
* feat: add text_search * fix: run pre-commit hooks * test: add tests for text search * fix: run black * fix: update poetry deps --------- Co-authored-by: [email protected] <[email protected]>
1 parent 29cb042 commit 0d16b47

File tree

5 files changed

+165
-62
lines changed

5 files changed

+165
-62
lines changed

poetry.lock

+83-62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

postgrest/_async/request_builder.py

+26
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,29 @@ def maybe_single(self) -> AsyncMaybeSingleRequestBuilder:
208208
session=self.session, # type: ignore
209209
)
210210

211+
def text_search(
212+
self, column: str, query: str, options: Dict[str, any] = {}
213+
) -> AsyncFilterRequestBuilder:
214+
type_ = options.get("type")
215+
type_part = ""
216+
if type_ == "plain":
217+
type_part = "pl"
218+
elif type_ == "phrase":
219+
type_part = "ph"
220+
elif type_ == "web_search":
221+
type_part = "w"
222+
config_part = f"({options.get('config')})" if options.get("config") else ""
223+
self.params = self.params.add(column, f"{type_part}fts{config_part}.{query}")
224+
225+
return AsyncQueryRequestBuilder(
226+
headers=self.headers,
227+
http_method=self.http_method,
228+
json=self.json,
229+
params=self.params,
230+
path=self.path,
231+
session=self.session, # type: ignore
232+
)
233+
211234

212235
class AsyncRequestBuilder:
213236
def __init__(self, session: AsyncClient, path: str) -> None:
@@ -337,3 +360,6 @@ def delete(
337360
return AsyncFilterRequestBuilder(
338361
self.session, self.path, method, headers, params, json
339362
)
363+
364+
def stub(self):
365+
return None

postgrest/_sync/request_builder.py

+26
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,29 @@ def maybe_single(self) -> SyncMaybeSingleRequestBuilder:
208208
session=self.session, # type: ignore
209209
)
210210

211+
def text_search(
212+
self, column: str, query: str, options: Dict[str, any] = {}
213+
) -> SyncFilterRequestBuilder:
214+
type_ = options.get("type")
215+
type_part = ""
216+
if type_ == "plain":
217+
type_part = "pl"
218+
elif type_ == "phrase":
219+
type_part = "ph"
220+
elif type_ == "web_search":
221+
type_part = "w"
222+
config_part = f"({options.get('config')})" if options.get("config") else ""
223+
self.params = self.params.add(column, f"{type_part}fts{config_part}.{query}")
224+
225+
return SyncQueryRequestBuilder(
226+
headers=self.headers,
227+
http_method=self.http_method,
228+
json=self.json,
229+
params=self.params,
230+
path=self.path,
231+
session=self.session, # type: ignore
232+
)
233+
211234

212235
class SyncRequestBuilder:
213236
def __init__(self, session: SyncClient, path: str) -> None:
@@ -337,3 +360,6 @@ def delete(
337360
return SyncFilterRequestBuilder(
338361
self.session, self.path, method, headers, params, json
339362
)
363+
364+
def stub(self):
365+
return None

0 commit comments

Comments
 (0)