From e1f84f5dd70bbe0c890fc327817818a5c38fcb1a Mon Sep 17 00:00:00 2001 From: serxoz Date: Fri, 23 Sep 2022 21:48:57 +0200 Subject: [PATCH] =?UTF-8?q?cambio=20de=20mysql=20a=20postgres=20para=20ter?= =?UTF-8?q?=20campos=20tipo=20array=20para=20as=20condici=C3=B3s=20dos=20o?= =?UTF-8?q?bxetos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 96 +++---------------- Cargo.toml | 2 +- .../2022-09-15-133454_create_npc/up.sql | 2 +- src/database.rs | 6 +- src/schema.rs | 14 +-- 5 files changed, 26 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5307c89..ea12f21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,9 +41,8 @@ dependencies = [ "bitflags", "byteorder", "diesel_derives", - "mysqlclient-sys", - "percent-encoding", - "url", + "itoa", + "pq-sys", ] [[package]] @@ -64,15 +63,6 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" -[[package]] -name = "form_urlencoded" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" -dependencies = [ - "percent-encoding", -] - [[package]] name = "getrandom" version = "0.2.7" @@ -94,14 +84,10 @@ dependencies = [ ] [[package]] -name = "idna" -version = "0.3.0" +name = "itoa" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "libc" @@ -146,16 +132,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "mysqlclient-sys" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f61b381528ba293005c42a409dd73d034508e273bf90481f17ec2e964a6e969b" -dependencies = [ - "pkg-config", - "vcpkg", -] - [[package]] name = "num_cpus" version = "1.13.1" @@ -195,30 +171,27 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "percent-encoding" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" - [[package]] name = "pin-project-lite" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" -[[package]] -name = "pkg-config" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" - [[package]] name = "ppv-lite86" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "pq-sys" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b845d6d8ec554f972a2c5298aad68953fd64e7441e846075450b44656a016d1" +dependencies = [ + "vcpkg", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -353,21 +326,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - [[package]] name = "tokio" version = "1.21.1" @@ -400,38 +358,12 @@ dependencies = [ "syn", ] -[[package]] -name = "unicode-bidi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" - [[package]] name = "unicode-ident" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" -[[package]] -name = "unicode-normalization" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "url" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - [[package]] name = "uuid" version = "1.1.2" diff --git a/Cargo.toml b/Cargo.toml index be88b27..b59ef5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -diesel = { version = "2.0.0", features = ["mysql"] } +diesel = { version = "2.0.0", features = ["postgres"] } dotenv = "0.15.0" rand = "0.8.5" tokio = { version = "1", features = ["full"] } diff --git a/migrations/2022-09-15-133454_create_npc/up.sql b/migrations/2022-09-15-133454_create_npc/up.sql index 0186a27..20ed03e 100644 --- a/migrations/2022-09-15-133454_create_npc/up.sql +++ b/migrations/2022-09-15-133454_create_npc/up.sql @@ -6,5 +6,5 @@ CREATE TABLE npc ( ca int NOT NULL, ba int NOT NULL, hp int NOT NULL, - CONSTRAINT PK_Player PRIMARY KEY (tag) + CONSTRAINT PK_Npc PRIMARY KEY (tag) ) diff --git a/src/database.rs b/src/database.rs index 3a4d2a6..fe4e811 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,13 +1,13 @@ +use diesel::pg::PgConnection; use diesel::prelude::*; -use diesel::mysql::MysqlConnection; use dotenv::dotenv; use std::env; -pub fn establish_connection() -> MysqlConnection { +pub fn establish_connection() -> PgConnection { dotenv().ok(); let database_url = env::var("DATABASE_URL") .expect("DATABASE_URL must be set"); - MysqlConnection::establish(&database_url) + PgConnection::establish(&database_url) .expect(&format!("Error connecting to {}", database_url)) } diff --git a/src/schema.rs b/src/schema.rs index c12ce37..2bca1e9 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -14,9 +14,9 @@ diesel::table! { nombre -> Varchar, descripcion -> Varchar, location -> Varchar, - ca -> Integer, - ba -> Integer, - hp -> Integer, + ca -> Int4, + ba -> Int4, + hp -> Int4, } } @@ -27,7 +27,7 @@ diesel::table! { nombre -> Varchar, descripcion -> Varchar, location -> Varchar, - peso -> Integer, + peso -> Int4, destino -> Nullable, } } @@ -38,9 +38,9 @@ diesel::table! { nombre -> Varchar, descripcion -> Varchar, location -> Varchar, - ca -> Integer, - ba -> Integer, - hp -> Integer, + ca -> Int4, + ba -> Int4, + hp -> Int4, } }