use ormer::Model;
#[derive(Debug, Model)]
#[table = "test_users"]
struct TestUser {
#[primary(auto)]
id: i32,
name: String,
}
#[derive(Debug, Model)]
#[table = "test_roles"]
struct TestRole {
#[primary]
id: i32,
#[foreign(TestUser.id)]
user_id: i32,
role_name: String,
}
#[tokio::test]
async fn test_foreign_key_creation() {
let db = ormer::Database::connect(ormer::DbType::Turso, ":memory:")
.await
.unwrap();
db.create_table::<TestUser>().await.unwrap();
db.create_table::<TestRole>().await.unwrap();
println!("Tables created successfully with foreign key constraints");
db.insert(&TestUser {
id: 1,
name: "Alice".to_string(),
})
.await
.unwrap();
db.insert(&TestRole {
id: 1,
user_id: 1,
role_name: "admin".to_string(),
})
.await
.unwrap();
println!("Foreign key test passed!");
}