Skip to content

Commit 9133a3b

Browse files
committed
adding appendices
1 parent 78d0c13 commit 9133a3b

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

modules/week09/hw-09-2.qmd

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ For the purposes of this assignment we will be working with an SQLite database t
1414

1515
We will also be working with the following query:
1616

17-
```
17+
```sql
1818
SELECT Nest_ID
1919
FROM Bird_nests
2020
WHERE Site = 'nome' AND
@@ -93,7 +93,7 @@ Recall that num_distinct_values = 1, the leftmost point on your scatter plot, co
9393

9494
A few tips on modifying your Bash test harness to make it more useful for this assignment. First, if you find it annoying to have to try different numbers of repetitions to get positive and more precise timings, you can automate your script to try different numbers of repetitions until it achieves something reasonable. Here's one idea:
9595

96-
```
96+
```bash
9797
num_reps=1
9898
while true; do
9999
start=$SECONDS
@@ -117,4 +117,37 @@ And third, if you make the column(s) you want to index an argument to your scrip
117117

118118
# Appendix 2: Connecting to SQLite from Python
119119

120+
```python
121+
# %pip install sqlite3
122+
123+
# Connect to the database
124+
import sqlite3
125+
conn = sqlite3.connect("/courses/EDS213/big-fat.sqlite3")
126+
cur = conn.cursor()
127+
128+
# Execute a query
129+
cur.execute("SELECT * FROM Site")
130+
cur.fetchone()
131+
```
132+
120133
# Appendix 3: Connecting to SQLite from R
134+
135+
```r
136+
library(tidyverse)
137+
library(DBI)
138+
library(RSQLite)
139+
library(dbplyr)
140+
141+
# Connect to the big database
142+
conn <- DBI::dbConnect(RSQLite::SQLite(), "/courses/EDS213/big-fat.sqlite3")
143+
144+
# List the available tables
145+
DBI::dbListTables(conn)
146+
147+
# query using DBI
148+
DBI::dbGetQuery(conn, 'SELECT * FROM Site')
149+
150+
# or using dbplyr
151+
sites <- tbl(conn, "Site")
152+
sites %>% filter(Location == 'Alaska, USA')
153+
```

0 commit comments

Comments
 (0)