GithubHelp home page GithubHelp logo

blackhacked / sqlitis Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pglass/sqlitis

0.0 0.0 0.0 139 KB

Convert sql to sqlalchemy expressions

License: MIT License

Python 97.27% Makefile 2.73%

sqlitis's Introduction

Tests PyPI PyPI - Python Version

Overview

Sqlitis is a tool to convert plain SQL queries to SQLAlchemy expressions. It is usable from the command line or as a library.

Sqlitis converts to the SQLAlchemy expression language. It does not support the SQLAlchemy ORM.

$ pip install sqlitis

Examples

Turning a select query into a sqlachemy expression:

$ sqlitis "select foo.name, bar.value from foo join bar"
select([foo.c.name, bar.c.value]).select_from(foo.join(bar))

Converting a join:

$ sqlitis "foo join bar on foo.id = bar.foo_id and (foo.val < 100 or bar.val < 100)"
foo.join(bar, and_(foo.c.id == bar.c.foo_id, or_(foo.c.val < 100, bar.c.val < 100)))

Running tests

Use tox to run the tests.

$ pip install tox

### Run everything
$ tox

### Run the unit/functional tests
$ tox -e py36

### Run style checks
$ tox -e flake8 black

The code is formatted using black.

### Reformat the code with black
$ make format

### Check if black needs to be run. This does not reformat.
$ tox -e black

There are three types of tests:

  • Unit tests of the internal model classes
  • Unit tests of the core to_sqla function
  • Functional tests that execute the generated SQLAlchemy expressions against a sqlite database
  • Functional tests of the CLI

These tests are parameterized (data driven) using data from test/*.yaml

SQL Support Checklist

  • Select

    • Star: SELECT * FROM foo

    • Multiple columns: SELECT a, b, c FROM foo

    • Qualified column names: SELECT foo.a, foo.b FROM foo

    • Column aliases: SELECT foo.id AS foo_id, foo.name AS foo_name from FOO

    • Joins

      • Inner Join:

        • SELECT * FROM foo JOIN bar
        • SELECT * FROM foo INNER JOIN bar
      • Cross Joins

        • SELECT * FROM foo, bar
        • SELECT * FROM foo CROSS JOIN bar
      • Left/Right Joins

      • Outer Joins

    • On Clauses: SELECT foo.a, bar.b FROM foo JOIN bar ON foo.id = bar.foo_id

    • Conjuctions (AND/OR): SELECT foo.a, bar.b FROM foo join bar ON foo.id = bar.foo_id AND foo.val > 1

    • Select from subquery: SELECT id FROM (SELECT * FROM foo)

    • Where: SELECT id FROM foo WHERE id = 123

    • Between: SELECT a FROM foo WHERE foo.val BETWEEN 1 AND 20

    • Select distinct: SELECT DISTINCT a FROM foo

    • Aggregate functions (SUM, AVG, COUNT, MIN, MAX): SELECT COUNT(*) FROM foo

    • Group by: SELECT COUNT(*) FROM foo GROUP BY column

    • Like

    • Limit/offset

    • Order by

  • Insert

  • Update

  • Delete

sqlitis's People

Contributors

pglass 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.