feat: add sqlx
This commit is contained in:
1505
__database/sqlx/Cargo.lock
generated
Normal file
1505
__database/sqlx/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
__database/sqlx/Cargo.toml
Normal file
12
__database/sqlx/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "sqlx"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
sqlx = { version = "0.4.1", features = [ "sqlite", "runtime-async-std-rustls" ] }
|
||||
async-std = { version = "1.6", features = [ "attributes" ] }
|
||||
|
||||
19
__database/sqlx/src/main.rs
Normal file
19
__database/sqlx/src/main.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use sqlx::sqlite::SqlitePoolOptions;
|
||||
|
||||
#[async_std::main]
|
||||
// or #[tokio::main]
|
||||
async fn main() -> Result<(), sqlx::Error> {
|
||||
let pool = SqlitePoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect("sqlite::memory:")
|
||||
.await?;
|
||||
|
||||
println!("{:#?}", pool);
|
||||
|
||||
let row: (i64,) = sqlx::query_as("SELECT $1")
|
||||
.bind(150_i64)
|
||||
.fetch_one(&pool).await?;
|
||||
println!("{:#?}", row);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user