#2: Learning Rust — Conspiracies, Databases, and Diesel.rs

Re-organizing the Code

▶ tree src 
├── db_loader
│ └── main.rs
├── lib.rs
└── wiki.rs
name = "db_loader"
path = "src/db_loader/main.rs"
importing the the wiki module’s WikiRepo
the WikePage ‘constructor’

Using Diesel.rs to Interact with a Database

cargo install diesel_cli --no-default-features --features sqlite
▶ diesel migration generate create_conspiracies Creating migrations/2018-05-01-002930_create_conspiracies/up.sql Creating migrations/2018-05-01-002930_create_conspiracies/down.sql
▶ sqlite3 database/conspiracies.sqlite3
-- Loading resources from /Users/robertrowe/.sqliterc
SQLite version 3.19.3 2017-06-27 16:48:08
Enter ".help" for usage hints.
sqlite> .tables
__diesel_schema_migrations conspiracies
diesel’s generated schema.rs file
clap = "2.31.2"
wikipedia = "0.3.1"
diesel = { version = "1.0.0", features = ["sqlite"] }
dotenv = "0.9.0"

The db module

added database related attributes

Updating db_loader/main.rs

Loading the Database

▶ cargo run --bin db_loader -- --get-links --title Conspiracy_theories
Compiling conspiracies v0.0.1 (file:///<path to code>/conspiracies_api)
Finished dev [unoptimized + debuginfo] target(s) in 5.89 secs
Running `target/debug/db_loader --get-links --title Conspiracy_theories`
Added: Conspiracy_theory 5530
Added: 1980 Camarate air crash 40839521
Added: 1986 Mozambican Tupolev Tu-134 crash 7631057
Added: 2006 O'Hare International Airport UFO sighting 8790044
Added: 2012 phenomenon 21538638
Added: 2013 Lahad Datu standoff 38554050
Added: 9/11 5058690
Added: 9/11 Truth movement 2658444
Added: 9/11 conspiracy theories 1077137
Added: A Culture of Conspiracy 24772931
sleeping for 189 seconds starting at 2018-05-08 20:53:23.299697 -04:00

Diesel update




Crates of Interest

Data Source





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Object Relational Impedance Mismatch

NEWS:Global PC as a Service market is projected to reach a value of over USD 330.5 Billion by 2027

So how do Kubernetes Services work?

Configure JMeter with Jenkins

2D Galaxy Shooter — Lives System

Bigdata Hadoop Training in Hyderabad

Every Python developer should read it once- “The Zen of Python”

Why Use the Go Language for Your Project?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rob Rowe

Rob Rowe

More from Medium

Using std::optional for potentially invalid value

WASM and SIMD with a sample (C++, TFLite)

Matter: Device-to-Device Automations

HasCal — A promising embedding of pluscal in haskell.