Skip to content
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: 7 additions & 2 deletions arbalister/adbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ def to_arrow_table(self) -> pa.Table:
if self._limit is not None and self._offset is not None
else ""
)
columns = self._select if self._select is not None else ["*"]

# Escape column names or default to wildcard
if self._select is not None:
columns = ",".join(f'"{c}"' for c in self._select)
else:
columns = "*"

with adbc_sqlite.connect(self._path) as connection:
with connection.cursor() as cursor:
cursor.execute(f'SELECT {",".join(columns)} FROM "{self._table_name}" {limit}')
cursor.execute(f'SELECT {columns} FROM "{self._table_name}" {limit}')
return cursor.fetch_arrow_table()
2 changes: 1 addition & 1 deletion arbalister/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _parse_value(value: Any, annotation: Any) -> Any:


def build_dataclass[T](dataclass_type: type[T], callback: Callable[[str, Any], Any]) -> T:
"""Build a dtaclass from its definition and a value-p[rovising callback."""
"""Build a dataclass from its definition and a value-provising callback."""
values: dict[str, Any] = {}
for field in dataclasses.fields(cast(type[Any], dataclass_type)):
default = (
Expand Down
8 changes: 4 additions & 4 deletions arbalister/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def dummy_table_1(num_rows: int = 10) -> pa.Table:
def dummy_table_2(num_rows: int = 13) -> pa.Table:
"""Generate a table with different fake data."""
data = {
"id": list(range(num_rows)),
"flag": [random.choice([True, False]) for _ in range(num_rows)],
"letter": random.choices(string.ascii_letters, k=num_rows),
"score": [random.randint(0, 100) for _ in range(num_rows)],
"__id": list(range(num_rows)),
"Flag": [random.choice([True, False]) for _ in range(num_rows)],
"ASCII letter": random.choices(string.ascii_letters, k=num_rows),
"score 🏆": [random.randint(0, 100) for _ in range(num_rows)],
"timestamp": [random.randint(1_600_000_000, 1_700_000_000) for _ in range(num_rows)],
}
table = pa.table(data)
Expand Down
Loading