### Running Example Scripts Source: https://github.com/grayjou/expressql/blob/main/README.md Instructions on how to execute the provided example Python scripts to see expressQL in action, demonstrating various features. ```bash python simple_examples.py python complex_examples.py ``` -------------------------------- ### Quick Example: Building SQL Expressions Source: https://github.com/grayjou/expressql/blob/main/README.md Demonstrates building a complex SQL condition using expressQL's Pythonic syntax. It combines arithmetic and logical operations, translating them into a SQL-safe placeholder pair. ```python from expressql import col, cols, Func age, salary, department = cols("age", "salary", "department") condition = ((age > 30) * (department == "HR")) + (salary > 50000) print(condition.placeholder_pair()) # ('((age > ?) AND (department = ?)) OR (salary > ?)', [30, 'HR', 50000]) ``` -------------------------------- ### Expressions & Comparisons in expressQL Source: https://github.com/grayjou/expressql/blob/main/README.md Illustrates basic expression building and comparison using expressQL. It shows how arithmetic operations on columns are translated into SQL. ```python from expressql import col age = col("age") condition = (age + 10) > 50 ``` ```sql -- SQL Equivalent: (age + 10) > 50 ``` -------------------------------- ### Using SQL Functions in expressQL Source: https://github.com/grayjou/expressql/blob/main/README.md Illustrates how to apply SQL functions to expressions, including built-in functions and custom user-defined functions, directly within the Python DSL. ```python from expressql import col total = col("salary") + col("bonus") cond = total.LOG() > 10 ``` ```sql -- SQL Equivalent: LOG((salary + bonus)) > 10 ``` ```python from expressql import functions as f, cols salary, bonus, passive_incomes = cols("salary", "bonus", "passive_incomes") func_expr = f.CUSTOM_FUNC_FOO(salary, bonus, passive_incomes, inverted=True) ``` ```sql -- SQL Equivalent: 1/CUSTOM_FUNC_FOO(salary, bonus, passive_incomes) ``` -------------------------------- ### Chained Conditions in expressQL Source: https://github.com/grayjou/expressql/blob/main/README.md Demonstrates how expressQL supports chained comparisons, translating them into SQL AND clauses for concise condition building. ```python from expressql import col score = col("score") cond = (50 < score) < 80 # Equivalent to 50 < score < 80 ``` ```sql -- SQL Equivalent: (score > 50 AND score < 80) ``` -------------------------------- ### Logical Composition (AND, OR, NOT) in expressQL Source: https://github.com/grayjou/expressql/blob/main/README.md Shows how to use Python's arithmetic operators (`*` for AND, `+` for OR, `~` for NOT) to build complex logical conditions in expressQL. ```python from expressql import col salary = col("salary") dept = col("department") cond = (salary > 40000) * (dept == "IT") ``` ```sql -- SQL Equivalent: (salary > 40000 AND department = 'IT') ``` -------------------------------- ### NULL and Set Operations in expressQL Source: https://github.com/grayjou/expressql/blob/main/README.md Demonstrates null-safe operations (`is_null`) and set membership checks (`isin`) using expressQL, translating them into standard SQL `IS NULL` and `IN` clauses. ```python from expressql import col city = col("city") region = col("region") cond = city.is_null + region.isin(["North", "South"]) ``` ```sql -- SQL Equivalent: (city IS NULL OR region IN ('North', 'South')) ``` -------------------------------- ### Parsing SQL-Like Strings into Expressions Source: https://github.com/grayjou/expressql/blob/main/README.md Shows how to parse raw SQL-like strings into expressQL expressions, including custom functions and arithmetic. The output is a SQL-safe placeholder pair. ```python from expressql.parsers import parse_expression expr = parse_expression("LOG(age, 10) + CUSTOM_FUNC(salary, bonus + 10) + 15") print(expr.placeholder_pair()) # ('(? + LOG(age, ?) + CUSTOM_FUNC(salary, (bonus + ?)))', [15, 10, 10]) ``` -------------------------------- ### Parsing SQL Conditions with BETWEEN Source: https://github.com/grayjou/expressql/blob/main/README.md Demonstrates parsing high-level SQL condition strings, specifically handling the BETWEEN clause by transforming it into composite comparisons. ```python from expressql.parsers import parse_condition cond = parse_condition("age BETWEEN 30 AND 50 AND department = 'IT'") print(cond.placeholder_pair()) # ('(age >= ? AND age <= ?) AND (department = ?)', [30, 50, 'IT']) ``` -------------------------------- ### Transforming BETWEEN Clauses in Strings Source: https://github.com/grayjou/expressql/blob/main/README.md A utility function to automatically convert BETWEEN clauses within a SQL string into equivalent greater-than-or-equal-to and less-than-or-equal-to comparisons. ```python from expressql.parsers import transform_betweens s = "weight/POWER(height, 2) BETWEEN 18.5 AND 24.9 AND age >= 18" print(transform_betweens(s)) # '(weight / POWER(height, 2) >= 18.5 AND weight / POWER(height, 2) <= 24.9 AND age >= 18)' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.