Created
December 17, 2021 17:49
-
-
Save oscartbeaumont/2bf6283bcf93cb7a445d28253b79c4b9 to your computer and use it in GitHub Desktop.
SeaORM Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "sea-orm-test" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
sea-orm = { version = "0.4.2", features = [ "sqlx-sqlite", "runtime-tokio-native-tls", "macros" ], default-features = false } | |
tokio = { version = "1", features = ["full"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use sea_orm::{ConnectOptions, ConnectionTrait, Database, DbErr, QueryResult, Statement}; | |
#[tokio::main] | |
async fn main() { | |
let opt = ConnectOptions::new("sqlite::memory:".to_string()); | |
let db = Database::connect(opt).await.unwrap(); | |
db.execute(Statement::from_string( | |
db.get_database_backend(), | |
"CREATE TABLE Persons (PersonID int);".to_owned(), | |
)) | |
.await | |
.unwrap(); | |
// db.execute(Statement::from_string( | |
// db.get_database_backend(), | |
// "INSERT INTO Persons(PersonID) VALUES (5);".to_owned(), | |
// )) | |
// .await | |
// .unwrap(); | |
let query: Option<QueryResult> = db | |
.query_one(Statement::from_string( | |
db.get_database_backend(), | |
"SELECT 1 AS 'a' FROM 'Persons';".to_owned(), | |
)) | |
.await | |
.unwrap(); | |
assert!(query.is_some()); // This should always be true but isn't | |
let result: Result<u32, DbErr> = query.unwrap().try_get("", "a"); | |
assert!(result == Ok(1 as u32)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment