-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b727907
commit 21b6739
Showing
6 changed files
with
48 additions
and
10 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""ETL Helper script to load records to a database table.""" | ||
import sqlite3 | ||
import etlhelper as etl | ||
|
||
db_file = "igneous_rocks.db" | ||
create_sql = """ | ||
CREATE TABLE IF NOT EXISTS igneous_rock ( | ||
id INTEGER PRIMARY KEY, | ||
name TEXT UNIQUE, | ||
grain_size TEXT | ||
)""" | ||
insert_sql = """ | ||
INSERT INTO igneous_rock (id, name, grain_size) | ||
VALUES (:id, :name, :grain_size) | ||
ON CONFLICT DO NOTHING | ||
""" | ||
|
||
igneous_rocks = [ | ||
{"id": 1, "name": "basalt", "grain_size": "fine"}, | ||
{"id": 1, "name": "basalt", "grain_size": "fine"} # duplicate row | ||
] | ||
|
||
|
||
with sqlite3.connect(db_file) as conn: | ||
# Create table | ||
etl.execute(create_sql, conn) | ||
|
||
# Insert rows | ||
etl.executemany(insert_sql, conn, rows=igneous_rocks) | ||
|
||
# Confirm selection | ||
for row in etl.fetchall('SELECT * FROM igneous_rock', conn): | ||
print(row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
""" | ||
ETL Helper Exception classes | ||
ETLHelper exceptions are derived from the ETLHelperError base class. | ||
""" | ||
|
||
|
||
|