Skip to main content

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


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 hashes)

Uploaded Source

Built Distribution

sqc-0.1.0-py2.py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page