etchdb 0.7.0__tar.gz → 0.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. {etchdb-0.7.0 → etchdb-0.8.0}/PKG-INFO +46 -6
  2. {etchdb-0.7.0 → etchdb-0.8.0}/README.md +45 -5
  3. {etchdb-0.7.0 → etchdb-0.8.0}/pyproject.toml +1 -1
  4. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/__init__.py +25 -2
  5. etchdb-0.8.0/src/etchdb/expr.py +447 -0
  6. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/sql/__init__.py +71 -24
  7. etchdb-0.8.0/tests/integration/test_filter_operators.py +265 -0
  8. etchdb-0.8.0/tests/unit/test_filter_operators.py +289 -0
  9. etchdb-0.7.0/src/etchdb/expr.py +0 -102
  10. {etchdb-0.7.0 → etchdb-0.8.0}/.github/workflows/ci.yml +0 -0
  11. {etchdb-0.7.0 → etchdb-0.8.0}/.github/workflows/release.yml +0 -0
  12. {etchdb-0.7.0 → etchdb-0.8.0}/.gitignore +0 -0
  13. {etchdb-0.7.0 → etchdb-0.8.0}/.python-version +0 -0
  14. {etchdb-0.7.0 → etchdb-0.8.0}/LICENSE +0 -0
  15. {etchdb-0.7.0 → etchdb-0.8.0}/Makefile +0 -0
  16. {etchdb-0.7.0 → etchdb-0.8.0}/docker-compose.yml +0 -0
  17. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/__main__.py +0 -0
  18. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/adapter.py +0 -0
  19. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/aiosqlite/__init__.py +0 -0
  20. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/aiosqlite/adapter.py +0 -0
  21. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/asyncpg/__init__.py +0 -0
  22. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/asyncpg/adapter.py +0 -0
  23. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/cli.py +0 -0
  24. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/codecs.py +0 -0
  25. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/db.py +0 -0
  26. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/errors.py +0 -0
  27. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/migrations.py +0 -0
  28. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/psycopg/__init__.py +0 -0
  29. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/psycopg/adapter.py +0 -0
  30. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/py.typed +0 -0
  31. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/query.py +0 -0
  32. {etchdb-0.7.0 → etchdb-0.8.0}/src/etchdb/row.py +0 -0
  33. {etchdb-0.7.0 → etchdb-0.8.0}/tests/__init__.py +0 -0
  34. {etchdb-0.7.0 → etchdb-0.8.0}/tests/_models.py +0 -0
  35. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/__init__.py +0 -0
  36. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/conftest.py +0 -0
  37. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_batch.py +0 -0
  38. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_cli.py +0 -0
  39. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_codecs.py +0 -0
  40. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_errors.py +0 -0
  41. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_execute_rowcount.py +0 -0
  42. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_expressions.py +0 -0
  43. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_facade.py +0 -0
  44. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_fields_not_in_db.py +0 -0
  45. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_in_filter.py +0 -0
  46. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_is_null.py +0 -0
  47. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_iter_rows.py +0 -0
  48. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_iter_rows_keyset.py +0 -0
  49. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_migrations.py +0 -0
  50. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_ping_and_aclose.py +0 -0
  51. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_pool_kwargs.py +0 -0
  52. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_readme_example.py +0 -0
  53. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_sqlite_transactions.py +0 -0
  54. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_typed_crud.py +0 -0
  55. {etchdb-0.7.0 → etchdb-0.8.0}/tests/integration/test_update_where.py +0 -0
  56. {etchdb-0.7.0 → etchdb-0.8.0}/tests/typing/crud_types.py +0 -0
  57. {etchdb-0.7.0 → etchdb-0.8.0}/tests/unit/__init__.py +0 -0
  58. {etchdb-0.7.0 → etchdb-0.8.0}/tests/unit/test_adapters.py +0 -0
  59. {etchdb-0.7.0 → etchdb-0.8.0}/tests/unit/test_cli.py +0 -0
  60. {etchdb-0.7.0 → etchdb-0.8.0}/tests/unit/test_connection_hooks.py +0 -0
  61. {etchdb-0.7.0 → etchdb-0.8.0}/tests/unit/test_db_dispatch.py +0 -0
  62. {etchdb-0.7.0 → etchdb-0.8.0}/tests/unit/test_migrations.py +0 -0
  63. {etchdb-0.7.0 → etchdb-0.8.0}/tests/unit/test_sql_emitter.py +0 -0
  64. {etchdb-0.7.0 → etchdb-0.8.0}/tests/unit/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: etchdb
3
- Version: 0.7.0
3
+ Version: 0.8.0
4
4
  Summary: Minimal async DB layer for Python. Typed CRUD over Pydantic, raw SQL when you need it
5
5
  Project-URL: Homepage, https://github.com/varjoranta/etchdb
6
6
  Project-URL: Repository, https://github.com/varjoranta/etchdb
@@ -157,10 +157,17 @@ user = await db.get(User, id=alice.id) # one row or None
157
157
  users = await db.query(User) # list of rows
158
158
  no_email = await db.query(User, email=None) # IS NULL, not = NULL
159
159
  recent = await db.query(User, id=[1, 5, 7]) # IN ($1, $2, $3)
160
+
161
+ # Filter operators for the common conditions beyond equality.
162
+ from etchdb import Contains, Ge, Not, Range
163
+ adults = await db.query(User, age=Ge(18), email=Not(None))
164
+ window = await db.query(Event, created_at=Range(ge=start, lt=end))
165
+ found = await db.query(User, name=Contains(term, ignore_case=True))
166
+
160
167
  await db.update(User(id=alice.id, name="Alice B")) # partial: email is preserved
161
168
  await db.delete(alice)
162
169
 
163
- # Add `where=` to AND extra equality filters onto the PK. Atomic, so
170
+ # Add `where=` to AND extra filters onto the PK. Atomic, so
164
171
  # the scope check runs in the same statement as the update.
165
172
  await db.update(User(id=alice.id, name="Alice B"),
166
173
  where={"email": "alice@example.com"})
@@ -253,12 +260,47 @@ q = sql.compose("get", User, id=1, placeholder=lambda i: f"${i + 1}")
253
260
 
254
261
  `insert` only emits the columns you actually set, so an unset `id` lets the database allocate one (SERIAL or INTEGER PRIMARY KEY); the returned Row reflects the DB's view (`RETURNING *`), so server-defaults like `id` and `created_at` are populated in place. `update` does the same: a column you didn't touch keeps its current value rather than being clobbered. An explicit `None` counts as set in both cases.
255
262
 
256
- `update` and `delete` use the value of every column in `__pk__` (default: `("id",)`) as the WHERE clause; override the class attribute for a composite or differently-named primary key. Add extra equality filters with `where={...}` for guarded updates: multi-tenant scoping like `where={"user_id": current_user}` is the canonical use case. Filter values are always bound as parameters. Filter names go into the statement as column names, so they must be plain identifiers (letters, digits, underscore) and anything else raises `ValueError`; keep them in your code rather than taking them from request input. Raw SQL is still the right tool when you need anything richer than equality.
263
+ `update` and `delete` use the value of every column in `__pk__` (default: `("id",)`) as the WHERE clause; override the class attribute for a composite or differently-named primary key. Add extra filters with `where={...}` for guarded updates: multi-tenant scoping like `where={"user_id": current_user}` is the canonical use case. Filter values are always bound as parameters. Filter names go into the statement as column names, so they must be plain identifiers (letters, digits, underscore) and anything else raises `ValueError`; keep them in your code rather than taking them from request input. Raw SQL is still the right tool when you need anything richer than a per-column condition.
257
264
 
258
265
  Use `Row.patch(**fields)` to build a partial Row that satisfies neither validation nor missing-required-field checks. It's the right shape when you want partial updates against a model with NOT NULL columns. A name that is not a field of the model raises `ValueError`.
259
266
 
260
267
  Set `__fields_not_in_db__ = ("computed_label",)` on a Row class to carry computed or transient fields alongside DB-backed ones without etchdb sending them to or reading them from the database. The fields stay on the Pydantic model (validation, attribute access, type checking all work as normal); they're just dropped from INSERT, UPDATE, and SELECT column lists. Give such fields a default value -- read paths hydrate from the SELECT result, which never carries the column, so Pydantic uses the default.
261
268
 
269
+ ## Filter operators
270
+
271
+ A filter value, in `query`, `iter_rows`, `iter_rows_keyset` and the `where=` of `update`, `update_where` and `delete`, is one of four things: a plain value (`=`), `None` (`IS NULL`), a list (`IN`), or one of the operators below.
272
+
273
+ | Operator | SQL |
274
+ |---|---|
275
+ | `Gt(x)`, `Ge(x)`, `Lt(x)`, `Le(x)` | `col > x`, `col >= x`, `col < x`, `col <= x` |
276
+ | `Range(ge=a, lt=b)` | `col >= a AND col < b`; any of `gt`, `ge`, `lt`, `le`, one per side |
277
+ | `Not(x)` | `col <> x`; `Not(None)` is `IS NOT NULL`; `Not([a, b])` is `NOT IN (a, b)` |
278
+ | `Like(p)`, `ILike(p)` | `col LIKE p`, case-insensitive for `ILike`; `%` and `_` are wildcards, `\` escapes |
279
+ | `StartsWith(s)`, `Contains(s)` | `s` matched literally, its wildcards escaped; `ignore_case=True` to fold case |
280
+
281
+ ```python
282
+ from etchdb import Gt, Lt, Not, Now, Range, StartsWith
283
+
284
+ await db.query(Order, total=Gt(100), state=Not(["CANCELLED", "REFUNDED"]))
285
+ await db.query(Session, expires_at=Lt(Now())) # expires_at < CURRENT_TIMESTAMP
286
+ await db.query(Event, at=Range(ge=day, lt=day + timedelta(days=1)), order_by="at")
287
+ await db.update_where(Job.patch(state="STALE"), where={"heartbeat_at": Lt(cutoff)})
288
+ await db.query(File, path=StartsWith(user_input)) # % and _ in the input match themselves
289
+ ```
290
+
291
+ Things to know:
292
+
293
+ - **One condition per column.** Filters are keyword arguments joined with `AND`; `Range` is the way to put two bounds on one column. `OR`, comparisons between two columns, functions and joins stay in raw SQL.
294
+ - **The primary key of `update` and `delete` is a value.** Those address one row, so an operator in the row's key raises; operators go in `where=`. `iter_rows_keyset` does not accept a filter on its `by` column, which the cursor already constrains.
295
+ - **`get` takes equality only.** An operator with `LIMIT 1` would return an arbitrary match, so `db.get` rejects it; use `db.query(..., order_by=..., limit=1)`.
296
+ - **`Not` follows SQL for NULL.** `Not("x")` and `Not([...])` leave out rows where the column is NULL, because `<>` and `NOT IN` are not true for NULL. `Not([])` raises, since an empty exclusion list is usually a caller bug; drop the filter for that case.
297
+ - **`Range` skips a bound that is `None`**, so one optional end of a window passes straight through. With every bound `None` there is nothing to filter on and `Range` raises; leave the filter out in that case. `Gt(None)` and the other comparisons raise, since a comparison with NULL never matches.
298
+ - **`Now()` works as the compared value** in `Gt`, `Ge`, `Lt`, `Le` and `Range`. On SQLite `CURRENT_TIMESTAMP` is the text `YYYY-MM-DD HH:MM:SS` in UTC, so the column has to hold the same format for the comparison to mean anything.
299
+ - **Case sensitivity.** `StartsWith` and `Contains` are case-sensitive on every backend (SQLite uses `GLOB` for this) unless `ignore_case=True`. A raw `Like` is case-sensitive on Postgres but not on SQLite, whose `LIKE` ignores case for ASCII letters. `ILike` and `ignore_case=True` fold ASCII only on SQLite and follow the database locale on Postgres. SQLite's `PRAGMA case_sensitive_like = ON` makes every `LIKE` case-sensitive, `ILike` and `ignore_case=True` included.
300
+ - **Text ordering follows the column's collation.** `Lt("b")` or `Range(ge="a", lt="c")` on a text column can return different rows on Postgres (the database's locale, where `B` usually sorts next to `b`) and SQLite (byte order, where every uppercase ASCII letter sorts before lowercase). Numbers and timestamps compare the same everywhere.
301
+ - **`Like` patterns are yours to escape.** The pattern is a bound parameter, so it cannot inject SQL, but a `%` from user input is still a wildcard. Use `StartsWith` or `Contains` for user text. A pattern that ends in a lone `\` raises `ValueError`.
302
+ - **Operators compare by type and arguments** (`Gt(5) == Gt(5)`) and print as the call that made them, so they work in test assertions and logs.
303
+
262
304
  ## Typed errors
263
305
 
264
306
  Driver exceptions are mapped onto a small etchdb family so application code catches the same type regardless of the backend. The original driver exception is preserved as `__cause__`.
@@ -505,9 +547,7 @@ Migration status (./migrations):
505
547
 
506
548
  ## Under consideration
507
549
 
508
- Comparison sentinels for `where=` filters (`Gt`, `Gte`, `Lt`, `Lte`, accepting either a scalar or the existing `Now()` sentinel) are on the table for a later release. Scope would stay narrow: single-column inequality only; compound predicates, `LIKE`, and `BETWEEN` would still go through raw SQL. Holding the API for more real use cases before committing. Until then, raw SQL via `db.fetch_models(User, "SELECT * FROM users WHERE expires_at > NOW()")` is the canonical answer; that's what etchdb's first-class raw-SQL escape valve is for.
509
-
510
- `Inc` / `Now` composing with `on_conflict="upsert"` is a related deferred shape: the create-or-increment pattern would let `db.insert(RateCounter(...), on_conflict="upsert")` carry an `Inc(by=N)` for the conflict SET, but the INSERT branch still needs a literal initial value, so the row would have to express two values per column. Today the sentinels are rejected by `db.insert` / `db.insert_many` outright; raw SQL with `INSERT ... ON CONFLICT (key) DO UPDATE SET count = table.count + 1` covers the case in one statement.
550
+ `Inc` / `Now` composing with `on_conflict="upsert"` is a deferred shape: the create-or-increment pattern would let `db.insert(RateCounter(...), on_conflict="upsert")` carry an `Inc(by=N)` for the conflict SET, but the INSERT branch still needs a literal initial value, so the row would have to express two values per column. Today the sentinels are rejected by `db.insert` / `db.insert_many` outright; raw SQL with `INSERT ... ON CONFLICT (key) DO UPDATE SET count = table.count + 1` covers the case in one statement.
511
551
 
512
552
  ## Built with AI assistance
513
553
 
@@ -93,10 +93,17 @@ user = await db.get(User, id=alice.id) # one row or None
93
93
  users = await db.query(User) # list of rows
94
94
  no_email = await db.query(User, email=None) # IS NULL, not = NULL
95
95
  recent = await db.query(User, id=[1, 5, 7]) # IN ($1, $2, $3)
96
+
97
+ # Filter operators for the common conditions beyond equality.
98
+ from etchdb import Contains, Ge, Not, Range
99
+ adults = await db.query(User, age=Ge(18), email=Not(None))
100
+ window = await db.query(Event, created_at=Range(ge=start, lt=end))
101
+ found = await db.query(User, name=Contains(term, ignore_case=True))
102
+
96
103
  await db.update(User(id=alice.id, name="Alice B")) # partial: email is preserved
97
104
  await db.delete(alice)
98
105
 
99
- # Add `where=` to AND extra equality filters onto the PK. Atomic, so
106
+ # Add `where=` to AND extra filters onto the PK. Atomic, so
100
107
  # the scope check runs in the same statement as the update.
101
108
  await db.update(User(id=alice.id, name="Alice B"),
102
109
  where={"email": "alice@example.com"})
@@ -189,12 +196,47 @@ q = sql.compose("get", User, id=1, placeholder=lambda i: f"${i + 1}")
189
196
 
190
197
  `insert` only emits the columns you actually set, so an unset `id` lets the database allocate one (SERIAL or INTEGER PRIMARY KEY); the returned Row reflects the DB's view (`RETURNING *`), so server-defaults like `id` and `created_at` are populated in place. `update` does the same: a column you didn't touch keeps its current value rather than being clobbered. An explicit `None` counts as set in both cases.
191
198
 
192
- `update` and `delete` use the value of every column in `__pk__` (default: `("id",)`) as the WHERE clause; override the class attribute for a composite or differently-named primary key. Add extra equality filters with `where={...}` for guarded updates: multi-tenant scoping like `where={"user_id": current_user}` is the canonical use case. Filter values are always bound as parameters. Filter names go into the statement as column names, so they must be plain identifiers (letters, digits, underscore) and anything else raises `ValueError`; keep them in your code rather than taking them from request input. Raw SQL is still the right tool when you need anything richer than equality.
199
+ `update` and `delete` use the value of every column in `__pk__` (default: `("id",)`) as the WHERE clause; override the class attribute for a composite or differently-named primary key. Add extra filters with `where={...}` for guarded updates: multi-tenant scoping like `where={"user_id": current_user}` is the canonical use case. Filter values are always bound as parameters. Filter names go into the statement as column names, so they must be plain identifiers (letters, digits, underscore) and anything else raises `ValueError`; keep them in your code rather than taking them from request input. Raw SQL is still the right tool when you need anything richer than a per-column condition.
193
200
 
194
201
  Use `Row.patch(**fields)` to build a partial Row that satisfies neither validation nor missing-required-field checks. It's the right shape when you want partial updates against a model with NOT NULL columns. A name that is not a field of the model raises `ValueError`.
195
202
 
196
203
  Set `__fields_not_in_db__ = ("computed_label",)` on a Row class to carry computed or transient fields alongside DB-backed ones without etchdb sending them to or reading them from the database. The fields stay on the Pydantic model (validation, attribute access, type checking all work as normal); they're just dropped from INSERT, UPDATE, and SELECT column lists. Give such fields a default value -- read paths hydrate from the SELECT result, which never carries the column, so Pydantic uses the default.
197
204
 
205
+ ## Filter operators
206
+
207
+ A filter value, in `query`, `iter_rows`, `iter_rows_keyset` and the `where=` of `update`, `update_where` and `delete`, is one of four things: a plain value (`=`), `None` (`IS NULL`), a list (`IN`), or one of the operators below.
208
+
209
+ | Operator | SQL |
210
+ |---|---|
211
+ | `Gt(x)`, `Ge(x)`, `Lt(x)`, `Le(x)` | `col > x`, `col >= x`, `col < x`, `col <= x` |
212
+ | `Range(ge=a, lt=b)` | `col >= a AND col < b`; any of `gt`, `ge`, `lt`, `le`, one per side |
213
+ | `Not(x)` | `col <> x`; `Not(None)` is `IS NOT NULL`; `Not([a, b])` is `NOT IN (a, b)` |
214
+ | `Like(p)`, `ILike(p)` | `col LIKE p`, case-insensitive for `ILike`; `%` and `_` are wildcards, `\` escapes |
215
+ | `StartsWith(s)`, `Contains(s)` | `s` matched literally, its wildcards escaped; `ignore_case=True` to fold case |
216
+
217
+ ```python
218
+ from etchdb import Gt, Lt, Not, Now, Range, StartsWith
219
+
220
+ await db.query(Order, total=Gt(100), state=Not(["CANCELLED", "REFUNDED"]))
221
+ await db.query(Session, expires_at=Lt(Now())) # expires_at < CURRENT_TIMESTAMP
222
+ await db.query(Event, at=Range(ge=day, lt=day + timedelta(days=1)), order_by="at")
223
+ await db.update_where(Job.patch(state="STALE"), where={"heartbeat_at": Lt(cutoff)})
224
+ await db.query(File, path=StartsWith(user_input)) # % and _ in the input match themselves
225
+ ```
226
+
227
+ Things to know:
228
+
229
+ - **One condition per column.** Filters are keyword arguments joined with `AND`; `Range` is the way to put two bounds on one column. `OR`, comparisons between two columns, functions and joins stay in raw SQL.
230
+ - **The primary key of `update` and `delete` is a value.** Those address one row, so an operator in the row's key raises; operators go in `where=`. `iter_rows_keyset` does not accept a filter on its `by` column, which the cursor already constrains.
231
+ - **`get` takes equality only.** An operator with `LIMIT 1` would return an arbitrary match, so `db.get` rejects it; use `db.query(..., order_by=..., limit=1)`.
232
+ - **`Not` follows SQL for NULL.** `Not("x")` and `Not([...])` leave out rows where the column is NULL, because `<>` and `NOT IN` are not true for NULL. `Not([])` raises, since an empty exclusion list is usually a caller bug; drop the filter for that case.
233
+ - **`Range` skips a bound that is `None`**, so one optional end of a window passes straight through. With every bound `None` there is nothing to filter on and `Range` raises; leave the filter out in that case. `Gt(None)` and the other comparisons raise, since a comparison with NULL never matches.
234
+ - **`Now()` works as the compared value** in `Gt`, `Ge`, `Lt`, `Le` and `Range`. On SQLite `CURRENT_TIMESTAMP` is the text `YYYY-MM-DD HH:MM:SS` in UTC, so the column has to hold the same format for the comparison to mean anything.
235
+ - **Case sensitivity.** `StartsWith` and `Contains` are case-sensitive on every backend (SQLite uses `GLOB` for this) unless `ignore_case=True`. A raw `Like` is case-sensitive on Postgres but not on SQLite, whose `LIKE` ignores case for ASCII letters. `ILike` and `ignore_case=True` fold ASCII only on SQLite and follow the database locale on Postgres. SQLite's `PRAGMA case_sensitive_like = ON` makes every `LIKE` case-sensitive, `ILike` and `ignore_case=True` included.
236
+ - **Text ordering follows the column's collation.** `Lt("b")` or `Range(ge="a", lt="c")` on a text column can return different rows on Postgres (the database's locale, where `B` usually sorts next to `b`) and SQLite (byte order, where every uppercase ASCII letter sorts before lowercase). Numbers and timestamps compare the same everywhere.
237
+ - **`Like` patterns are yours to escape.** The pattern is a bound parameter, so it cannot inject SQL, but a `%` from user input is still a wildcard. Use `StartsWith` or `Contains` for user text. A pattern that ends in a lone `\` raises `ValueError`.
238
+ - **Operators compare by type and arguments** (`Gt(5) == Gt(5)`) and print as the call that made them, so they work in test assertions and logs.
239
+
198
240
  ## Typed errors
199
241
 
200
242
  Driver exceptions are mapped onto a small etchdb family so application code catches the same type regardless of the backend. The original driver exception is preserved as `__cause__`.
@@ -441,9 +483,7 @@ Migration status (./migrations):
441
483
 
442
484
  ## Under consideration
443
485
 
444
- Comparison sentinels for `where=` filters (`Gt`, `Gte`, `Lt`, `Lte`, accepting either a scalar or the existing `Now()` sentinel) are on the table for a later release. Scope would stay narrow: single-column inequality only; compound predicates, `LIKE`, and `BETWEEN` would still go through raw SQL. Holding the API for more real use cases before committing. Until then, raw SQL via `db.fetch_models(User, "SELECT * FROM users WHERE expires_at > NOW()")` is the canonical answer; that's what etchdb's first-class raw-SQL escape valve is for.
445
-
446
- `Inc` / `Now` composing with `on_conflict="upsert"` is a related deferred shape: the create-or-increment pattern would let `db.insert(RateCounter(...), on_conflict="upsert")` carry an `Inc(by=N)` for the conflict SET, but the INSERT branch still needs a literal initial value, so the row would have to express two values per column. Today the sentinels are rejected by `db.insert` / `db.insert_many` outright; raw SQL with `INSERT ... ON CONFLICT (key) DO UPDATE SET count = table.count + 1` covers the case in one statement.
486
+ `Inc` / `Now` composing with `on_conflict="upsert"` is a deferred shape: the create-or-increment pattern would let `db.insert(RateCounter(...), on_conflict="upsert")` carry an `Inc(by=N)` for the conflict SET, but the INSERT branch still needs a literal initial value, so the row would have to express two values per column. Today the sentinels are rejected by `db.insert` / `db.insert_many` outright; raw SQL with `INSERT ... ON CONFLICT (key) DO UPDATE SET count = table.count + 1` covers the case in one statement.
447
487
 
448
488
  ## Built with AI assistance
449
489
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "etchdb"
3
- version = "0.7.0"
3
+ version = "0.8.0"
4
4
  description = "Minimal async DB layer for Python. Typed CRUD over Pydantic, raw SQL when you need it"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -8,23 +8,46 @@ from etchdb.errors import (
8
8
  UndefinedColumnError,
9
9
  UndefinedTableError,
10
10
  )
11
- from etchdb.expr import Inc, Now
11
+ from etchdb.expr import (
12
+ Contains,
13
+ Ge,
14
+ Gt,
15
+ ILike,
16
+ Inc,
17
+ Le,
18
+ Like,
19
+ Lt,
20
+ Not,
21
+ Now,
22
+ Range,
23
+ StartsWith,
24
+ )
12
25
  from etchdb.migrations import MigrationStatus
13
26
  from etchdb.query import SqlQuery
14
27
  from etchdb.row import Row
15
28
 
16
- __version__ = "0.7.0"
29
+ __version__ = "0.8.0"
17
30
 
18
31
  __all__ = [
19
32
  "DB",
33
+ "Contains",
20
34
  "EtchdbError",
35
+ "Ge",
36
+ "Gt",
37
+ "ILike",
21
38
  "Inc",
22
39
  "IntegrityError",
40
+ "Le",
41
+ "Like",
42
+ "Lt",
23
43
  "MigrationStatus",
44
+ "Not",
24
45
  "Now",
25
46
  "OperationalError",
47
+ "Range",
26
48
  "Row",
27
49
  "SqlQuery",
50
+ "StartsWith",
28
51
  "UndefinedColumnError",
29
52
  "UndefinedTableError",
30
53
  "__version__",