-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
13 changed files
with
457 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 +1,32 @@ | ||
# excavator | ||
 | ||
|
||
|
||
#### Diesel with SQLite setup | ||
|
||
* Diesel-cli install | ||
|
||
``` | ||
cargo install diesel_cli | ||
``` | ||
|
||
* Create SQLite Database file | ||
|
||
``` | ||
diesel setup --database-url=ichneos.db | ||
``` | ||
|
||
* Create Migration scripts | ||
|
||
``` | ||
diesel migration generate google_my_activity | ||
``` | ||
|
||
* Populate the migration scripts | ||
|
||
|
||
* Run the migration | ||
|
||
``` | ||
diesel --database-url=ichneos.db migration run | ||
``` |
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,5 @@ | ||
# For documentation on how to configure this file, | ||
# see diesel.rs/guides/configuring-diesel-cli | ||
|
||
[print_schema] | ||
file = "src/db/schema.rs" |
Binary file not shown.
Empty file.
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,8 @@ | ||
-- | ||
-- Tables for Google derrived data | ||
-- | ||
drop table google_my_activity; | ||
drop table activity_location_info; | ||
drop table activity_sub_title; | ||
drop table activity_details; | ||
drop table activity_products; |
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,46 @@ | ||
-- | ||
-- Tables for Google derrived data | ||
-- | ||
CREATE TABLE google_my_activity ( | ||
uuid TEXT NOT NULL PRIMARY KEY, | ||
header TEXT NOT NULL, | ||
title TEXT NOT NULL, | ||
title_url TEXT, | ||
time TEXT NOT NULL, | ||
UNIQUE(header,title,time) | ||
); | ||
|
||
CREATE TABLE activity_location_info ( | ||
id INTEGER PRIMARY KEY, | ||
a_uuid TEXT NOT NULL , | ||
name TEXT, | ||
url TEXT, | ||
source TEXT, | ||
FOREIGN KEY (a_uuid) REFERENCES google_my_activity(uuid) ON DELETE CASCADE | ||
); | ||
CREATE INDEX gact1 on activity_location_info(a_uuid); | ||
|
||
CREATE TABLE activity_sub_title ( | ||
id INTEGER PRIMARY KEY, | ||
a_uuid TEXT NOT NULL, | ||
name TEXT, | ||
url TEXT, | ||
FOREIGN KEY (a_uuid) REFERENCES google_my_activity(uuid) ON DELETE CASCADE | ||
); | ||
CREATE INDEX gact2 on activity_sub_title(a_uuid); | ||
|
||
CREATE TABLE activity_details ( | ||
id INTEGER PRIMARY KEY, | ||
a_uuid TEXT NOT NULL, | ||
name TEXT, | ||
FOREIGN KEY (a_uuid) REFERENCES google_my_activity(uuid) ON DELETE CASCADE | ||
); | ||
CREATE INDEX gact3 on activity_details(a_uuid); | ||
|
||
CREATE TABLE activity_products ( | ||
id INTEGER PRIMARY KEY, | ||
a_uuid TEXT NOT NULL, | ||
name TEXT, | ||
FOREIGN KEY (a_uuid) REFERENCES google_my_activity(uuid) ON DELETE CASCADE | ||
); | ||
CREATE INDEX gact4 on activity_products(a_uuid); |
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,43 @@ | ||
use diesel::{prelude::*, sqlite::SqliteConnection}; | ||
|
||
pub mod models; | ||
pub mod schema; | ||
|
||
pub fn establish_connection() -> SqliteConnection { | ||
let db = "./ichneos.db"; | ||
SqliteConnection::establish(db) | ||
.unwrap_or_else(|_| panic!("Error connecting to {}", db)) | ||
} | ||
|
||
pub fn save_activity(connection: &SqliteConnection, | ||
uuid: &str, header: &str, title: &str, | ||
title_url: &str, time: &str) { | ||
|
||
let task = models::MyActivityEntity { | ||
uuid : uuid.to_string(), | ||
header : header.to_string(), | ||
title : title.to_string(), | ||
title_url : title_url.to_string(), | ||
time : time.to_string() | ||
}; | ||
|
||
diesel::insert_into(schema::google_my_activity::table) | ||
.values(&task) | ||
.execute(connection) | ||
.expect("Error inserting new task"); | ||
} | ||
|
||
pub fn save_sub_title(connection: &SqliteConnection, | ||
a_uuid: &str, name: &str, url: &str ) { | ||
|
||
let task = models::SubTitlesEntity { | ||
a_uuid : a_uuid.to_string(), | ||
name : name.to_string(), | ||
url : url.to_string() | ||
}; | ||
|
||
diesel::insert_into(schema::activity_sub_title::table) | ||
.values(&task) | ||
.execute(connection) | ||
.expect("Error inserting new task"); | ||
} |
Oops, something went wrong.