Skip to content

Commit

Permalink
Merge pull request #16 from baluyotraf/release/0.0.6
Browse files Browse the repository at this point in the history
Add docs and other updates for 0.0.6
  • Loading branch information
baluyotraf authored May 21, 2024
2 parents 3b022c2 + f2e6e83 commit b046fc7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.0.6

- Fix `altqq.Calculated` not being providing new a descriptor for each attribute
([#14])
- Add `altqq.ListParameter` for providing list of values as parameters ([#15])

[#14]: https://github.com/baluyotraf/altqq/pull/14
[#15]: https://github.com/baluyotraf/altqq/pull/15

## 0.0.5

- Nested `altqq.Query` are now checked by instance ([#13])
Expand Down
12 changes: 12 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ These are used for defining queries.

### ::: altqq.Query

### `altqq.NonParameter`

Non-parameter type hint.

### `altqq.ListParameter`

List parameter type hint.

### `altqq.Calculated`

Calculated value assignment.

## PyODBC

These are used for working with PyODBC.
Expand Down
25 changes: 24 additions & 1 deletion docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ There are cases in which one would prefer to compute the value of a parameter.
For example, defining the columns to fetch inside a `SELECT` query.

```python
import altqq

class Select(altqq.Query):
__query__ = """
SELECT {_columns} FROM "{table}"
Expand All @@ -96,14 +98,35 @@ print(res.query) # SELECT "id","first_name","last_name" FROM "Users"
```

Assigning a value as `altqq.Calculated` means that the value will not be
provided by the user. Internally, `altqq.Calculated` is just an alias to
provided by the user. Internally, `altqq.Calculated` is just replaced with
`dataclasses.field(init=False)`. Given that all `altqq.Query` objects are
`Pydantic` `dataclass`, the calculated values can be assigned inside the
`__post_init__` method.

As defined by the `Pydantic` `dataclass` behavior, the types for the assignment
inside the `__post_init__` method are not checked.

## List Parameters

For list that are used as parameters, a special `altqq.ListParameter` typing can
be used to denote that `altqq` should expand the list as a parameter.

```python
import altqq

class SelectUser(altqq.Query):
__query__ = """
SELECT * FROM Users WHERE user_id in {user_id}
"""

user_id: altqq.ListParameter[int]


query = SelectUser(user_id=[1,2,3])
res = altqq.to_pyodbc(query)
print(res.query) # SELECT * FROM Users WHERE user_id in (?,?,?)
```

## Additional Validation

As `altqq.Query` objects are `Pydantic` `dataclass` internally, one can also
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ convention = "google"

[tool.poetry]
name = "altqq"
version = "0.0.5"
version = "0.0.6"
description = "Alternative Queries: Typed and Reusable Handcrafted SQL"
authors = ["baluyotraf <baluyotraf@outlook.com>"]
maintainers = ["baluyotraf <baluyotraf@outlook.com>"]
Expand Down

0 comments on commit b046fc7

Please sign in to comment.