Skip to content

Commit

Permalink
Add pypika
Browse files Browse the repository at this point in the history
  • Loading branch information
baniasbaabe committed Feb 4, 2024
1 parent e20bb87 commit 4d8b00e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
39 changes: 39 additions & 0 deletions book/cooltools/Chapter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,45 @@
" }\n",
" )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## SQL Query Builder in Python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can build SQL queries in Python with pypika.\n",
"\n",
"pypika provides a simple interface to build SQL queries with an easy syntax.\n",
"\n",
"It supports nearly every SQL command."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pypika import Tables, Query\n",
"\n",
"history, customers = Tables('history', 'customers')\n",
"q = Query \\\n",
" .from_(history) \\\n",
" .join(customers) \\\n",
" .on(history.customer_id == customers.id) \\\n",
" .select(history.star) \\\n",
" .where(customers.id == 5)\n",
" \n",
"q.get_sql()\n",
"# SELECT \"history\".* FROM \"history\" JOIN \"customers\" \n",
"# ON \"history\".\"customer_id\"=\"customers\".\"id\" WHERE \"customers\".\"id\"=5"
]
}
],
"metadata": {
Expand Down
10 changes: 9 additions & 1 deletion book/pythontricks/Chapter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,15 @@
{
"cell_type": "markdown",
"metadata": {},
"source": []
"source": [
"One cool feature in Python 3.12:\n",
"\n",
"The support for Type Variables.\n",
"\n",
"You can use them to parametrize generic classes and functions.\n",
"\n",
"See below for a small example where our generic class is parametrized by T which we indicate with [T]."
]
},
{
"cell_type": "code",
Expand Down

0 comments on commit 4d8b00e

Please sign in to comment.