rssql
Struct-free Rust SQL tool.
Intro
sqlx
based sql tools, support mysql (mariadb)
and postgresql
.
Example
Start with the easy ones
use rssql::PostgreSQL;
async fn test_postgresql() {
let url = "postgre://user:password@docker:15432/test";
let mut postgresql = PostgreSQL::connect(url).await.unwrap();
let check = postgresql.check_connection().await;
println!("{}", check);
let rets = postgresql.execute("SELECT * FROM info").await.unwrap();
println!("{}", rets);
let rets = postgresql.execute("INSERT INTO info (name, date) VALUES ('test3', '2022-01-01')").await.unwrap();
let rets = postgresql.execute("SELECT * FROM info").await.unwrap();
println!("{}", rets);
postgresql.close().await;
}
Output
true
+----+-------+------------+
| id | name | date |
+----+-------+------------+
| 1 | test1 | 2023-06-11 |
| 2 | test2 | 2023-06-11 |
+----+-------+------------+
+----+-------+------------+
| id | name | date |
+----+-------+------------+
| 1 | test1 | 2023-06-11 |
| 2 | test2 | 2023-06-11 |
| 3 | test3 | 2022-01-01 |
+----+-------+------------+
Get data by column name
use rssql::PostgreSQL;
async fn test_postgresql_one() {
let url = "postgre://user:password@docker:15432/test";
let mut postgresql = PostgreSQL::connect(url).await.unwrap();
let check = postgresql.check_connection().await;
println!("{}", check);
let rets = postgresql.execute("SELECT * FROM info").await.unwrap();
for c in &rets.column {
println!("{}", rets.get_first_one(&c).unwrap());
}
for r in rets.get_all("id").unwrap() {
println!("{}", r);
}
postgresql.close().await;
}