rust增刪改查 v1 0 1

2021-10-14 07:58:29 字數 3052 閱讀 2389

檔名稱

版本號作者

qq元件版本

rust增刪改查

v1.0.1

學生宮布

8416837

rust 1.44.1

mysql_async = "0.22.2"等步驟

依賴

[dependencies]

rand =

"0.3.17"

mysql =

"*"

code

extern crate rand;

use mysql::*

;use mysql:

:prelude:

:queryable;

use rand:

:rng;

#[derive

(debug, partialeq, eq)

]struct payment

fn gen_db_conn

(conn: pooledconn)

fn main()

; let mut conn = match pool.

get_conn()

; let mut rng = rand:

:thread_rng()

;// let's create a table for payments.

let mut ret = conn.

query_drop

( r"create temporary table payment (

customer_id int not null,

amount int not null,

account_name text

)");// 建立臨時表,釋放連線時刪除或自定義刪除時機

// )")?;

println!

("建立臨時表:"

, ret)

; let payments = vec!

[ payment

, payment

, payment

, payment

, payment ,]

;// now let's insert payments to the database

ret = conn.

exec_batch

( r"insert into payment (customer_id, amount, account_name)

values (

:customer_id,

:amount,

:account_name)",

payments.

iter()

.map

(|p| params!))

;// )?;

println!

("插入資料:"

, ret)

;// let's select payments from database. type inference should do the trick here.

let selected_payments = conn

.query_map

("select customer_id, amount, account_name from payment",|

(customer_id, amount, account_name)|}

,);// )?;

// let's make sure, that `payments` equals to `selected_payments`.

// mysql gives no guaranties on order of returned rows 不保證返回順序

// without `order by`, so assume we are lucky. 如果不排序,那就看看運氣

// assert_eq!(payments, selected_payments); // 報錯:can't compare `std::vec::vec` with `std::result::result, mysql::error::error>`

println!

("查詢:"

, selected_payments)

; println!

("~~~完成~~~");

}

output

建立臨時表:ok((),

)插入資料:ok((),

)查詢:ok(

[ payment ,

payment ,

payment ,

payment ,

payment ,

],)~~~完成~~~

code

use mysql::*

;use mysql:

:prelude:

:queryable;

#[derive

(debug, partialeq, eq)

]struct user

fn main()

; let mut conn = match pool.

get_conn()

;// println!("", conn)

let selected_users = conn

.query_map

("select username,password, name from sys_user order by gmt_modified asc limit 1",|

(username, password, name)|}

,); println!

("查詢結果:"

, selected_users)

;}

output

查詢結果:ok([

user ,]

,)

PESCMS DOC文件管理系統 v1 0 1

pescms doc是一款基於pescms2.5開發的文件系統 管理文件原來可以做到如此便捷!本程式基於gplv2協議進行開源發布,個人 商業使用者在不進行閉源銷售情況下,沒有任何使用限制!日常工作經常需要涉及到文件的編寫。文件如何儲存成為乙個讓人頭疼的事情。而文件如何便於查閱又是乙個讓人頭疼的事情...

mysql增刪改查效果 mysql增刪改查

檢視所有資料庫 mysql show databases 建立乙個庫ghd並指定字符集為utp8 mysql create database ghd charset utf8 檢視mysql支援的字符集 mysql show char set 建立乙個表,並設定id為主鍵 create table ...

mysql增刪改查擴充套件 MySQL增刪改查

1 插入 insert 1 insert into 表名 values 值1 值2 例子 insert into t1 values zengsf 23 fengshao 22 2 insert into 表名 欄位1,values 值1 例子 insert into t1 name values ...