Skip to content

Commit 008dccf

Browse files
authored
Merge pull request #43 from dimitri-yatsenko/course
2 parents 9c3e71d + d240175 commit 008dccf

38 files changed

+62407
-34
lines changed

db-course/000-Connect.ipynb

Lines changed: 580 additions & 0 deletions
Large diffs are not rendered by default.

db-course/000-ConnectCursors.ipynb

Lines changed: 278 additions & 0 deletions
Large diffs are not rendered by default.

db-course/000-ConnectSQL.ipynb

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import pymysql\n",
10+
"pymysql.install_as_MySQLdb()"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 2,
16+
"metadata": {},
17+
"outputs": [],
18+
"source": [
19+
"%load_ext sql\n",
20+
"%config SqlMagic.autocommit=True"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 3,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"connection_string = \"mysql://root:[email protected]\""
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 4,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"%sql $connection_string"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 8,
44+
"metadata": {},
45+
"outputs": [
46+
{
47+
"name": "stdout",
48+
"output_type": "stream",
49+
"text": [
50+
" * mysql://root:***@127.0.0.1\n",
51+
"1 rows affected.\n"
52+
]
53+
},
54+
{
55+
"data": {
56+
"text/plain": [
57+
"[]"
58+
]
59+
},
60+
"execution_count": 8,
61+
"metadata": {},
62+
"output_type": "execute_result"
63+
}
64+
],
65+
"source": [
66+
"%%sql\n",
67+
"\n",
68+
"CREATE SCHEMA IF NOT EXISTS university"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 9,
74+
"metadata": {},
75+
"outputs": [
76+
{
77+
"name": "stdout",
78+
"output_type": "stream",
79+
"text": [
80+
" * mysql://root:***@127.0.0.1\n",
81+
"0 rows affected.\n"
82+
]
83+
},
84+
{
85+
"data": {
86+
"text/plain": [
87+
"[]"
88+
]
89+
},
90+
"execution_count": 9,
91+
"metadata": {},
92+
"output_type": "execute_result"
93+
}
94+
],
95+
"source": [
96+
"%%sql \n",
97+
"\n",
98+
"USE university "
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": 10,
104+
"metadata": {},
105+
"outputs": [
106+
{
107+
"name": "stdout",
108+
"output_type": "stream",
109+
"text": [
110+
" * mysql://root:***@127.0.0.1\n",
111+
"0 rows affected.\n"
112+
]
113+
},
114+
{
115+
"data": {
116+
"text/plain": [
117+
"[]"
118+
]
119+
},
120+
"execution_count": 10,
121+
"metadata": {},
122+
"output_type": "execute_result"
123+
}
124+
],
125+
"source": [
126+
"%%sql\n",
127+
"\n",
128+
"CREATE TABLE person (\n",
129+
" person_id int NOT NULL,\n",
130+
" first_name varchar(30) NOT NULL,\n",
131+
" last_name varchar(30) NOT NULL,\n",
132+
" PRIMARY KEY(person_id)\n",
133+
")"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": 17,
139+
"metadata": {},
140+
"outputs": [
141+
{
142+
"name": "stdout",
143+
"output_type": "stream",
144+
"text": [
145+
" * mysql://root:***@127.0.0.1\n",
146+
"2 rows affected.\n"
147+
]
148+
},
149+
{
150+
"data": {
151+
"text/plain": [
152+
"[]"
153+
]
154+
},
155+
"execution_count": 17,
156+
"metadata": {},
157+
"output_type": "execute_result"
158+
}
159+
],
160+
"source": [
161+
"%%sql\n",
162+
"\n",
163+
"INSERT INTO person VALUES (2, \"Jane\", \"Doe\"), (3, \"Alice\", \"Cooper\") "
164+
]
165+
},
166+
{
167+
"cell_type": "code",
168+
"execution_count": 18,
169+
"metadata": {},
170+
"outputs": [
171+
{
172+
"name": "stdout",
173+
"output_type": "stream",
174+
"text": [
175+
" * mysql://root:***@127.0.0.1\n",
176+
"3 rows affected.\n"
177+
]
178+
},
179+
{
180+
"data": {
181+
"text/html": [
182+
"<table>\n",
183+
" <thead>\n",
184+
" <tr>\n",
185+
" <th>person_id</th>\n",
186+
" <th>first_name</th>\n",
187+
" <th>last_name</th>\n",
188+
" </tr>\n",
189+
" </thead>\n",
190+
" <tbody>\n",
191+
" <tr>\n",
192+
" <td>1</td>\n",
193+
" <td>Alice</td>\n",
194+
" <td>Cooper</td>\n",
195+
" </tr>\n",
196+
" <tr>\n",
197+
" <td>2</td>\n",
198+
" <td>Jane</td>\n",
199+
" <td>Doe</td>\n",
200+
" </tr>\n",
201+
" <tr>\n",
202+
" <td>3</td>\n",
203+
" <td>Alice</td>\n",
204+
" <td>Cooper</td>\n",
205+
" </tr>\n",
206+
" </tbody>\n",
207+
"</table>"
208+
],
209+
"text/plain": [
210+
"[(1, 'Alice', 'Cooper'), (2, 'Jane', 'Doe'), (3, 'Alice', 'Cooper')]"
211+
]
212+
},
213+
"execution_count": 18,
214+
"metadata": {},
215+
"output_type": "execute_result"
216+
}
217+
],
218+
"source": [
219+
"%%sql\n",
220+
"\n",
221+
"SELECT * FROM person"
222+
]
223+
},
224+
{
225+
"cell_type": "code",
226+
"execution_count": null,
227+
"metadata": {},
228+
"outputs": [],
229+
"source": []
230+
}
231+
],
232+
"metadata": {
233+
"kernelspec": {
234+
"display_name": "Python 3",
235+
"language": "python",
236+
"name": "python3"
237+
},
238+
"language_info": {
239+
"codemirror_mode": {
240+
"name": "ipython",
241+
"version": 3
242+
},
243+
"file_extension": ".py",
244+
"mimetype": "text/x-python",
245+
"name": "python",
246+
"nbconvert_exporter": "python",
247+
"pygments_lexer": "ipython3",
248+
"version": "3.9.17"
249+
},
250+
"orig_nbformat": 4
251+
},
252+
"nbformat": 4,
253+
"nbformat_minor": 2
254+
}

0 commit comments

Comments
 (0)