GithubHelp home page GithubHelp logo

squeak's Introduction

Squeak: quickly manipulate string SQL queries

String is King when it comes to SQL - no one wants to mess around constructing ad-hoc analytics queries as complicated Python objects. squeak is for speaking SQL: for when you want to make simple changes to string SQL queries in Python without complicated string formatting, copy pasting queries around, or writing " AND ".join(where_clauses)-style logic for the 300th time.

>>> query = """
... WITH subquery_1 AS (
...   SELECT DISTINCT ON (id) *
...   FROM y
...   ORDER BY id, created_at DESC
... )
...
... SELECT * FROM subquery_1
... WHERE col_1 = 3
... """
>>> with_added_filter = squeak.where(query, "col_2 = 'hey'")
>>> print(with_added_filter)

WITH subquery_1 AS (
  SELECT DISTINCT ON (id) *
  FROM y
  ORDER BY id, created_at DESC
)

SELECT * FROM subquery_1
 WHERE col_1 = 3
 AND col_2 = 'hey'

>>> with_replaced_filter = squeak.where(query, "col_2 = 'hey'", kind="replace")
>>> print(with_replaced_filter)

WITH subquery_1 AS (
  SELECT DISTINCT ON (id) *
  FROM y
  ORDER BY id, created_at DESC
)

SELECT * FROM subquery_1
 WHERE col_2 = 'hey'

>>> with_filter_on_subquery = squeak.where(query, "col_2 = 'hey'", cte="subquery_1")
>>> print(with_filter_on_subquery)

WITH subquery_1 AS (
  SELECT DISTINCT ON (id) *
  FROM y
  WHERE col_2 = 'hey'  ORDER BY id, created_at DESC
)

SELECT * FROM subquery_1
WHERE col_1 = 3

squeak's People

Contributors

ali-tny avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.