Returning a row with a function


#1

Hello there, I have some trouble with something.

I work with postgresql and a database and i would like to have the last id in the table (so an int)

and i have this code :

fn counter_last_entry() -> i64 {
	let db_local_url = "postgres://postgres:mdp@127.0.0.1:5432/qds";    //Changer adresse et/ou nom de base
	let db_local = Connection::connect(db_local_url, SslMode::None)
		.expect("Unable to connect to database");

	let mut counter_receive_last_id = match db_local.query("SELECT id from astm_receive order by id desc limit 1", &[]){
		Ok(rows) => {
			let last= rows.get(0); //use unwrap because there always one row
			return last;

		}
		Err(err) => { println!("error {:?}",err );return 0},
	};
}

[dependencies]
postgres = { version = "*", features = ["chrono"] }

And i have this king of error :

   Compiling messagebus v0.1.0 (file:///home/diagast/Documents/MAS2/core/messagebus)
error[E0308]: mismatched types
  --> src/bin/main.rs:62:11
   |
62 | 			return last;
   | 			       ^^^^ expected i64, found struct `postgres::rows::Row`
   |
   = note: expected type `i64`
   = note:    found type `postgres::rows::Row<'_>`

error: aborting due to previous error

error: Could not compile `messagebus`.

To learn more, run the command again with --verbose.

Do you huys have an idea how to transform this row variable into an int or how can i return a row with this function ?

Thanks for the attention,

Cheer


#2

i think it is

let last = rows.get(0).get(0); //get first row then get first column

#3

Thank you ! <3