v+ K9 _% P7 ]4 Yimport std.stdio; 6 Y: j) B8 m+ l% s8 J1 | 1 [( ~) S- p+ Uimport hunt.database; * n# w/ f4 g+ ` Z+ B g X' l" {$ [6 Ivoid main()* \% S$ s. z' r4 ^ S' ~% [- c
" @; E) O, ]7 b$ p7 f1 ~{6 E5 f- b, F) B( T
|' p6 P7 b: @9 B5 {5 Fauto db = new Database("mysql://root:123456@localhost:3306/test?charset=utf8mb4"); # D4 h+ `1 K- j0 ~. \# h/ {& E, L) m$ B
int result = db.execute(`INSERT INTO user(username) VALUES("test")`); & F. z% w: M, }1 ^& [/ ?) ~ k. ?0 j1 d$ H1 b
// 打印插入数量- J, b' l" _5 q5 M& e: Q
}, K0 U k4 [' A3 ?writeln(result);9 @' A* _0 N$ r6 `$ d% m
. ~ H- w5 x1 Qdb.close(); & O* R, z6 v& Y: ^* V" V3 G% t 9 u! {9 n! x& Q/ ?. y}9 M1 _3 m. ?/ [. g: F+ B
1 a, J" c* A" W+ K1 j
1.2 : Rust 插入数据 . p' k) A% X j- ^7 n 4 J. }* }$ ]( V8 Pextern crate postgres;# z" R; g1 S5 f
+ w! Y; y$ {4 b
use postgres::{Connection, SslMode}; 4 U# v: i% k: p! B% V+ v( _6 Y! M! F# U+ Z: a l+ y! N
fn main() { * f$ Y$ N- X4 N9 V" `+ K! `6 G) j
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap(); 1 T% i/ Q+ y& Z3 C 5 `6 \( j9 _2 Z$ m, c3 ^conn.execute("INSERT INTO user (username) VALUES (\"test\")", &[]).unwrap();0 C$ C7 C0 U0 ]. i
/ U$ d6 s1 M; Q8 v! |
}4 V* q! J9 q/ t