Skip to content

Commit

Permalink
Merge pull request #43 from dimitri-yatsenko/course
Browse files Browse the repository at this point in the history
  • Loading branch information
ttngu207 authored Apr 16, 2024
2 parents 9c3e71d + d240175 commit 008dccf
Show file tree
Hide file tree
Showing 38 changed files with 62,407 additions and 34 deletions.
580 changes: 580 additions & 0 deletions db-course/000-Connect.ipynb

Large diffs are not rendered by default.

278 changes: 278 additions & 0 deletions db-course/000-ConnectCursors.ipynb

Large diffs are not rendered by default.

254 changes: 254 additions & 0 deletions db-course/000-ConnectSQL.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pymysql\n",
"pymysql.install_as_MySQLdb()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"%load_ext sql\n",
"%config SqlMagic.autocommit=True"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"connection_string = \"mysql://root:[email protected]\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"%sql $connection_string"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * mysql://root:***@127.0.0.1\n",
"1 rows affected.\n"
]
},
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"\n",
"CREATE SCHEMA IF NOT EXISTS university"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * mysql://root:***@127.0.0.1\n",
"0 rows affected.\n"
]
},
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql \n",
"\n",
"USE university "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * mysql://root:***@127.0.0.1\n",
"0 rows affected.\n"
]
},
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"\n",
"CREATE TABLE person (\n",
" person_id int NOT NULL,\n",
" first_name varchar(30) NOT NULL,\n",
" last_name varchar(30) NOT NULL,\n",
" PRIMARY KEY(person_id)\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * mysql://root:***@127.0.0.1\n",
"2 rows affected.\n"
]
},
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"\n",
"INSERT INTO person VALUES (2, \"Jane\", \"Doe\"), (3, \"Alice\", \"Cooper\") "
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" * mysql://root:***@127.0.0.1\n",
"3 rows affected.\n"
]
},
{
"data": {
"text/html": [
"<table>\n",
" <thead>\n",
" <tr>\n",
" <th>person_id</th>\n",
" <th>first_name</th>\n",
" <th>last_name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>Alice</td>\n",
" <td>Cooper</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>Jane</td>\n",
" <td>Doe</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>Alice</td>\n",
" <td>Cooper</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"[(1, 'Alice', 'Cooper'), (2, 'Jane', 'Doe'), (3, 'Alice', 'Cooper')]"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%sql\n",
"\n",
"SELECT * FROM person"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.17"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 008dccf

Please sign in to comment.