diff --git a/.env b/.env index db4cadc..342e241 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ -URL=https://vk.gy/database \ No newline at end of file +URL=https://vk.gy/database +DATABASE_URL=sqlite://db.sqlite \ No newline at end of file diff --git a/.gitignore b/.gitignore index ea8c4bf..301d28b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +*.sqlite \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index d999f63..57225cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,6 +103,7 @@ dependencies = [ name = "data_extractor" version = "0.1.0" dependencies = [ + "diesel", "dotenvy", "reqwest", "scraper", @@ -121,6 +122,28 @@ dependencies = [ "syn", ] +[[package]] +name = "diesel" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68c186a7418a2aac330bb76cde82f16c36b03a66fb91db32d20214311f9f6545" +dependencies = [ + "diesel_derives", + "libsqlite3-sys", +] + +[[package]] +name = "diesel_derives" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "143b758c91dbc3fe1fdcb0dba5bd13276c6a66422f2ef5795b58488248a310aa" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dirs" version = "4.0.0" @@ -506,6 +529,16 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +[[package]] +name = "libsqlite3-sys" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29f835d03d717946d28b1d1ed632eb6f0e24a299388ee623d0c23118d3e8a7fa" +dependencies = [ + "pkg-config", + "vcpkg", +] + [[package]] name = "lock_api" version = "0.4.7" @@ -817,6 +850,30 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro-hack" version = "0.5.19" @@ -1021,9 +1078,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "scraper" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5684396b456f3eb69ceeb34d1b5cb1a2f6acf7ca4452131efa3ba0ee2c2d0a70" +checksum = "fc7cb4dae083699a22a65aa9d2699c27f525e35dffaec38b10801e958ed4cf27" dependencies = [ "cssparser", "ego-tree", @@ -1137,9 +1194,9 @@ checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" [[package]] name = "smallvec" -version = "1.8.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "socket2" @@ -1384,6 +1441,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "want" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index f27b67f..be4e684 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" [dependencies] reqwest = {version = "0.11", features = ["blocking"]} -scraper = "0.13.0" -dotenvy = "0.15.1" \ No newline at end of file +scraper = "0.14.0" +dotenvy = "0.15.1" +diesel = { version = "2.0.2", features = ["sqlite"] } \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..afb0c2a --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +cargo install diesel_cli --no-default-features --features sqlite + +~/.cargo/bin/diesel setup \ No newline at end of file diff --git a/diesel.toml b/diesel.toml new file mode 100644 index 0000000..35a12ff --- /dev/null +++ b/diesel.toml @@ -0,0 +1,8 @@ +# For documentation on how to configure this file, +# see https://diesel.rs/guides/configuring-diesel-cli + +[print_schema] +file = "src/schema.rs" + +[migrations_directory] +dir = "migrations" diff --git a/migrations/.keep b/migrations/.keep new file mode 100644 index 0000000..e69de29 diff --git a/migrations/2023-01-02-184703_create_artists/down.sql b/migrations/2023-01-02-184703_create_artists/down.sql new file mode 100644 index 0000000..fe78390 --- /dev/null +++ b/migrations/2023-01-02-184703_create_artists/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE artists \ No newline at end of file diff --git a/migrations/2023-01-02-184703_create_artists/up.sql b/migrations/2023-01-02-184703_create_artists/up.sql new file mode 100644 index 0000000..25a2cf9 --- /dev/null +++ b/migrations/2023-01-02-184703_create_artists/up.sql @@ -0,0 +1,9 @@ +-- Your SQL goes here +CREATE TABLE artists ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + artist_name VARCHAR NOT NULL, + artist_url VARCHAR NOT NULL, + date INT NOT NULL, + author VARCHAR NOT NULL, + author_url VARCHAR NOT NULL +) \ No newline at end of file diff --git a/migrations/2023-01-02-184719_create_labels/down.sql b/migrations/2023-01-02-184719_create_labels/down.sql new file mode 100644 index 0000000..225a453 --- /dev/null +++ b/migrations/2023-01-02-184719_create_labels/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE labels \ No newline at end of file diff --git a/migrations/2023-01-02-184719_create_labels/up.sql b/migrations/2023-01-02-184719_create_labels/up.sql new file mode 100644 index 0000000..0bf9ad8 --- /dev/null +++ b/migrations/2023-01-02-184719_create_labels/up.sql @@ -0,0 +1,9 @@ +-- Your SQL goes here +CREATE TABLE labels ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + artist_name VARCHAR NOT NULL, + artist_url VARCHAR NOT NULL, + date INT NOT NULL, + author VARCHAR NOT NULL, + author_url VARCHAR NOT NULL +) \ No newline at end of file diff --git a/migrations/2023-01-02-184728_create_musicians/down.sql b/migrations/2023-01-02-184728_create_musicians/down.sql new file mode 100644 index 0000000..04420bb --- /dev/null +++ b/migrations/2023-01-02-184728_create_musicians/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE musicians \ No newline at end of file diff --git a/migrations/2023-01-02-184728_create_musicians/up.sql b/migrations/2023-01-02-184728_create_musicians/up.sql new file mode 100644 index 0000000..cb57551 --- /dev/null +++ b/migrations/2023-01-02-184728_create_musicians/up.sql @@ -0,0 +1,9 @@ +-- Your SQL goes here +CREATE TABLE musicians ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + artist_name VARCHAR NOT NULL, + artist_url VARCHAR NOT NULL, + date INT NOT NULL, + author VARCHAR NOT NULL, + author_url VARCHAR NOT NULL +) \ No newline at end of file diff --git a/migrations/2023-01-02-184734_create_releases/down.sql b/migrations/2023-01-02-184734_create_releases/down.sql new file mode 100644 index 0000000..5631e11 --- /dev/null +++ b/migrations/2023-01-02-184734_create_releases/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE releases \ No newline at end of file diff --git a/migrations/2023-01-02-184734_create_releases/up.sql b/migrations/2023-01-02-184734_create_releases/up.sql new file mode 100644 index 0000000..99d681e --- /dev/null +++ b/migrations/2023-01-02-184734_create_releases/up.sql @@ -0,0 +1,11 @@ +-- Your SQL goes here +CREATE TABLE releases ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + artist_name VARCHAR NOT NULL, + artist_url VARCHAR NOT NULL, + album VARCHAR NOT NULL, + album_url VARCHAR NOT NULL, + date INT NOT NULL, + author VARCHAR NOT NULL, + author_url VARCHAR NOT NULL +) \ No newline at end of file diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 0000000..fbfc0cb --- /dev/null +++ b/src/schema.rs @@ -0,0 +1,54 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + artists (id) { + id -> Nullable, + artist_name -> Text, + artist_url -> Text, + date -> Integer, + author -> Text, + author_url -> Text, + } +} + +diesel::table! { + labels (id) { + id -> Nullable, + artist_name -> Text, + artist_url -> Text, + date -> Integer, + author -> Text, + author_url -> Text, + } +} + +diesel::table! { + musicians (id) { + id -> Nullable, + artist_name -> Text, + artist_url -> Text, + date -> Integer, + author -> Text, + author_url -> Text, + } +} + +diesel::table! { + releases (id) { + id -> Nullable, + artist_name -> Text, + artist_url -> Text, + album -> Text, + album_url -> Text, + date -> Integer, + author -> Text, + author_url -> Text, + } +} + +diesel::allow_tables_to_appear_in_same_query!( + artists, + labels, + musicians, + releases, +);