SQL queries to collections
Project description
SQC
SQL Queries to Collections
Examples
from sqc import sqc
data = [
{"a": 1, "b": 1},
{"a": 2, "b": 1},
{"a": 3, "b": 2},
]
Simple filtering
query = sqc("SELECT b WHERE a = 2")
reset = query.execute(data)
assert result == [{"b": 1}]
Roadmap:
Named data source:
query = sqc("SELECT b FROM table WHERE a < 2")
reset = query.execute(table=data)
assert result == [{"b": 1}]
Attribute access:
from typing import NamedTuple
class Row(NamedTuple):
a: int
b: int
query = sqc("SELECT b WHERE a < 2", field_getter=getattr)
assert isinstance(query, SqcQuery)
reset = query.execute(map(Row._make, data))
assert result == [{"b": 1}]
Nested data structures:
query = sqc("SELECT path(a, 'c[a].b[0]') AS q, c WHERE b > 1")
Custom output structure:
query = sqc("SELECT b WHERE a < 2", output=tuple)
reset = query.execute(data)
assert result == [(1,)]
Shortcuts:
query = sqc("SELECT b WHERE a < 2")
assert query.one(data) = (1,)
assert query.scalar(data) == 1
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sqc-0.1.0.tar.gz
(3.3 kB
view details)
Built Distribution
File details
Details for the file sqc-0.1.0.tar.gz
.
File metadata
- Download URL: sqc-0.1.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.26.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2f22aa0b06babcf322fc656b3ab195a5796cd5ceda5621a391fe27f5101afcc |
|
MD5 | ead9031ed5a74f667c6b349c4825738a |
|
BLAKE2b-256 | 068558cad4ee02044ef9a1dea1f0a1e59bf4ca3c02750710d3b61440686c145c |
Provenance
File details
Details for the file sqc-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: sqc-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.26.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca261927ece519566801ccb589e19c0eab42c60f447693b1271794facefba23d |
|
MD5 | c8efd0b78b72a3f98d587fcefeb51d14 |
|
BLAKE2b-256 | 21257a9d5cad9054017ac924dc151c07b9311efdd11fae19bcc2844bbdb83a41 |