Skip to main content

Type Hint SQL Query Builder for Python.

Project description

Type Safed SQL Query Builder for Python

test pypi package

⚠️⚠️⚠️ This library is currently under consideration and is not ready for use in actual products. ⚠️⚠️⚠️

Development Notes

DDL

There are no plans for support.

DDL is often used infrequently as its syntax varies from database to database. It is recommended that it be managed by a separate migration tool.

For Table Relation

If a PrimaryKey or a join key is included as a constraint, it can be expressed as a NewType to match the condition.

Examples

from textwrap import dedent

from tipsql.core.query.builder import QueryBuilder

from your_project.database.public import User, Address


builder = (
    query.chain()
    .from_(
        lambda c: c(User)
        .left_outer_join(
            Address,
        )
        .on(
            lambda c: c(User.id == Address.user_id)
            .and_(Address.city == "Tokyo")
        )
    )
    .select(
        User.id,
        User.name,
    )
)

assert (
    builder.build()
    == dedent(
        """
        SELECT
            users.id,
            users.name
        FROM
            users
            LEFT OUTER JOIN
                addresses
            ON
                users.id = addresses.user_id
                AND addresses.city = 'Tokyo';
        """
    ).strip()
)

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

tipsql-0.0.14.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

tipsql-0.0.14-py3-none-any.whl (1.9 kB view hashes)

Uploaded 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