ну чёто из базы данных уже тянется. но пока только постоянно. надо менять
parent
7e1fd4f5df
commit
ead266377f
|
|
@ -750,6 +750,7 @@ dependencies = [
|
|||
"egui_extras",
|
||||
"rust_decimal",
|
||||
"sqlx",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3749,7 +3750,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -4174,18 +4175,32 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.52.1"
|
||||
version = "1.52.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6"
|
||||
checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"libc",
|
||||
"mio",
|
||||
"parking_lot",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-stream"
|
||||
version = "0.1.18"
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ egui_dock = "0.19.1"
|
|||
egui_extras = "0.34.2"
|
||||
rust_decimal = {version = "1.42.0", features = ["macros"]}
|
||||
sqlx = {version="0.8.6", features = ["runtime-tokio", "mysql","bigdecimal"]}
|
||||
tokio={version = "1.52.3", features = ["full"]}
|
||||
|
||||
[target.'cfg(target_os="windows")'.dependencies]
|
||||
eframe = {version ="0.34.2",default-features=false, features=["glow"]}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use egui_dock::{DockArea, Style};
|
||||
|
||||
use crate::database::DBOperator;
|
||||
|
||||
static TABS_CAN_BE_WINDOWS: bool = false;
|
||||
|
||||
enum TabTypes{
|
||||
|
|
@ -104,7 +106,22 @@ impl MainTabViewer{
|
|||
|
||||
}
|
||||
fn show_worker(&mut self, ui: &mut egui::Ui){
|
||||
ui.label("Worker");
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async{
|
||||
let dbd = DBOperator::new();
|
||||
let positions = dbd.get_position().await.unwrap();
|
||||
for eq in positions{
|
||||
println!("{}",&eq.name);
|
||||
ui.push_id(&eq.name, |ui|{
|
||||
egui::CollapsingHeader::new(&eq.name)
|
||||
.default_open(false)
|
||||
.show(ui, |ui|{
|
||||
ui.label(eq.wage.to_string());
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
fn show_salary(&mut self, ui: &mut egui::Ui){
|
||||
ui.label("Salary");
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use dotenv::dotenv;
|
|||
// use crate::schema::worker::dsl::*;
|
||||
use crate::models::*;
|
||||
|
||||
struct DBOperator{
|
||||
pub struct DBOperator{
|
||||
connection_string: String,
|
||||
}
|
||||
impl DBOperator{
|
||||
|
|
@ -18,17 +18,17 @@ impl DBOperator{
|
|||
Self{connection_string:db_url}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async fn get_position(pool: &MySqlPool) -> Result<Vec<Position>, sqlx::Error>{
|
||||
let rets: Vec<Position> = sqlx::query_as:: <_, Position>("SELECT * FROM `position`").fetch_all(pool).await?;
|
||||
pub async fn get_position(&self) -> Result<Vec<Position>, sqlx::Error>{
|
||||
let pool = MySqlPool::connect(&self.connection_string).await?;
|
||||
let rets: Vec<Position> = sqlx::query_as:: <_, Position>("SELECT * FROM `position`").fetch_all(&pool).await?;
|
||||
Ok(rets)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pub async fn estabilish_connection() -> Result<(), sqlx::Error>{
|
||||
dotenv().ok();
|
||||
let db_url = dotenv::var("DATABASE_URL").expect("DATABASE_URL установи!");
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use crate::database::DBOperator;
|
||||
mod app;
|
||||
mod models;
|
||||
mod database;
|
||||
// mod schema;
|
||||
fn main() -> eframe::Result{
|
||||
// database::estabilish_connection();
|
||||
database::estabilish_connection();
|
||||
let native_opts = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default()
|
||||
.with_inner_size([400.0,300.0])
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ use sqlx::types::BigDecimal;
|
|||
|
||||
#[derive(Default, Clone, Hash, sqlx::FromRow)]
|
||||
pub struct Position{
|
||||
id: i32,
|
||||
name: String,
|
||||
wage: BigDecimal,
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub wage: BigDecimal,
|
||||
}
|
||||
#[derive(Default, Clone, Hash)]
|
||||
pub struct Worker{
|
||||
|
|
|
|||
Loading…
Reference in New Issue