Skip to content

Latest commit

 

History

History
100 lines (74 loc) · 1.83 KB

syntax.md

File metadata and controls

100 lines (74 loc) · 1.83 KB

querymaker

Querymaker is a lightweight query builder for turning python functions into SQL queries.

It is not an ORM. It outputs strings which can be used as sql queries by other programs.

The primary design principle in querymaker syntax is to avoid creating specialized methods but rather to use the primitives inherent in python syntax to build sql queries.


select star from

SELECT * FROM table_name;

option 1: all (built in) good fit with English syntax - bad if you're thinking of the boolean meaning of all

def my_func(table_name):
    return all(table_name)

option 2: all (not built in)

def my_func(table_name, all):
    return table_name.all()

option 3: star

def my_func(table_name, star):
    return star(table_name)

select where

SELECT column_name FROM table_name WHERE condition;

option 1: with statement

def my_func(condition, table_name):
    with table_name:
        if condition:
            return column_name

option 2: dot syntax

def my_func(condition, table_name):
    if condition:
        return table_name.column_name

delete from

DELETE FROM table_name WHERE condition;

Option: where

def my_func(a, b, table_name, condition):
    with table_name as table:
        if condition:
            del table_name

alter table + drop

ALTER TABLE table_name DROP COLUMN column_name;

should alter table be a function? automatically added?

problem - how do I know that it's drop and not del

def my_func(table_name, column_name):
    with customers as table:
        with column_name as column:
            del column_name

Option 2:

def my_func(table_name, column_name, drop):
    with customers as table:
            drop(column_name)