Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ clean_infra:
docker-compose down --remove-orphans &&\
docker system prune -a --volumes -f

run_tests: tests
stop_infra:
cd infra &&\
docker-compose down --remove-orphans

run_tests: run_infra sleep tests

run_unasync:
poetry run unasync postgrest tests
Expand All @@ -31,3 +35,6 @@ build_sync: run_unasync remove_pytest_asyncio_from_sync

remove_pytest_asyncio_from_sync:
sed -i 's/@pytest.mark.asyncio//g' tests/_sync/test_client.py

sleep:
sleep 5
6 changes: 3 additions & 3 deletions infra/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ services:
POSTGRES_USER: app_user
POSTGRES_PASSWORD: password
# Uncomment this if you want to persist the data. Create your boostrap SQL file in the project root
# volumes:
# - "./pgdata:/var/lib/postgresql/data"
# - "./init.sql:/docker-entrypoint-initdb.d/init.sql"
volumes:
# - "./pgdata:/var/lib/postgresql/data"
- "./init.sql:/docker-entrypoint-initdb.d/init.sql"
71 changes: 71 additions & 0 deletions infra/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
CREATE TABLE public.countries (
id int8 PRIMARY KEY,
iso CHAR (2) NOT NULL,
country_name VARCHAR (80) NOT NULL,
nicename VARCHAR (80) NOT NULL,
iso3 CHAR (3) DEFAULT NULL,
numcode SMALLINT DEFAULT NULL,
phonecode INT NOT NULL
);

INSERT INTO public.countries (id, iso, country_name, nicename, iso3, numcode, phonecode) VALUES
(1, 'AF', 'AFGHANISTAN', 'Afghanistan', 'AFG', 4, 93),
(2, 'AL', 'ALBANIA', 'Albania', 'ALB', 8, 355),
(3, 'DZ', 'ALGERIA', 'Algeria', 'DZA', 12, 213),
(4, 'AQ', 'ANTARCTICA', 'Antarctica', NULL, NULL, 0),
(5, 'CR', 'COSTA RICA', 'Costa Rica', 'CRI', 188, 506),
(6, 'ES', 'SPAIN', 'Spain', 'ESP', 724, 34),
(7, 'TH', 'THAILAND', 'Thailand', 'THA', 764, 66),
(8, 'TG', 'TOGO', 'Togo', 'TGO', 768, 228),
(9, 'TT', 'TRINIDAD AND TOBAGO', 'Trinidad and Tobago', 'TTO', 780, 1868),
(10, 'GB', 'UNITED KINGDOM', 'United Kingdom', 'GBR', 826, 44),
(11, 'US', 'UNITED STATES', 'United States', 'USA', 840, 1),
(12, 'ZW', 'ZIMBABWE', 'Zimbabwe', 'ZWE', 716, 263);

create table public.cities (
id int8 primary key,
country_id int8 not null references public.countries,
name text
);

insert into public.cities (id, name, country_id) values
(1, 'London', 10),
(2, 'Manchester', 10),
(3, 'Liverpool', 10),
(4, 'Bristol', 10),
(5, 'Miami', 11),
(6, 'Huston', 11),
(7, 'Atlanta', 11);

create table public.users (
id int8 primary key,
name text,
address jsonb
);

insert into public.users (id, name, address) values
(1, 'Michael', '{ "postcode": 90210, "street": "Melrose Place" }'),
(2, 'Jane', '{}');

create table public.reservations (
id int8 primary key,
room_name text,
during tsrange
);

insert into public.reservations (id, room_name, during) values
(1, 'Emerald', '[2000-01-01 13:00, 2000-01-01 15:00)'),
(2, 'Topaz', '[2000-01-02 09:00, 2000-01-02 10:00)');


create table public.issues (
id int8 primary key,
title text,
tags text[]
);

insert into public.issues (id, title, tags) values
(1, 'Cache invalidation is not working', array['is:open', 'severity:high', 'priority:low']),
(2, 'Use better names', array['is:open', 'severity:low', 'priority:medium']),
(3, 'Add missing postgrest filters', array['is:open', 'severity:low', 'priority:high']),
(4, 'Add alias to filters', array['is:closed', 'severity:low', 'priority:medium']);
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions postgrest/base_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,17 @@ def ilike(self: Self, column: str, pattern: str) -> Self:
"""
return self.filter(column, Filters.ILIKE, pattern)

def or_(self: Self, filters: str, reference_table: Union[str, None] = None) -> Self:
"""An 'or' filter

Args:
filters: The filters to use, following PostgREST syntax
reference_table: Set this to filter on referenced tables instead of the parent table
"""
key = f"{sanitize_param(reference_table)}.or" if reference_table else "or"
self.params = self.params.add(key, f"({filters})")
return self

def fts(self: Self, column: str, query: Any) -> Self:
return self.filter(column, Filters.FTS, query)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "postgrest"
version = "0.13.2"
description = "PostgREST client for Python. This library provides an ORM interface to PostgREST."
authors = ["Lương Quang Mạnh <[email protected]>", "Joel Lee <[email protected]>", "Anand", "Oliver Rice"]
authors = ["Lương Quang Mạnh <[email protected]>", "Joel Lee <[email protected]>", "Anand", "Oliver Rice", "Andrew Smith <[email protected]>"]
homepage = "https://github.com/supabase-community/postgrest-py"
repository = "https://github.com/supabase-community/postgrest-py"
documentation = "https://postgrest-py.rtfd.io"
Expand Down
9 changes: 9 additions & 0 deletions tests/_async/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from postgrest import AsyncPostgrestClient

REST_URL = "http://127.0.0.1:3000"


def rest_client():
return AsyncPostgrestClient(
base_url=REST_URL,
)
15 changes: 15 additions & 0 deletions tests/_async/test_filter_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,18 @@ def test_in_(filter_request_builder):
builder = filter_request_builder.in_("x", ["a", "b"])

assert str(builder.params) == "x=in.%28a%2Cb%29"


def test_or_(filter_request_builder):
builder = filter_request_builder.or_("x.eq.1")

assert str(builder.params) == "or=%28x.eq.1%29"


def test_or_in_contain(filter_request_builder):
builder = filter_request_builder.or_("id.in.(5,6,7), arraycol.cs.{'a','b'}")

assert (
str(builder.params)
== "or=%28id.in.%285%2C6%2C7%29%2C%20arraycol.cs.%7B%27a%27%2C%27b%27%7D%29"
)
Loading