# Database Integration (Rust) > SQLx, Diesel, การเข้าถึงฐานข้อมูลแบบ async, connection pooling, migration, query builder, รูปแบบ ORM - 20 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: Rust](https://sharpskill.dev/th/technologies/rust/interview-questions.md) ## 1. ความแตกต่างหลักระหว่าง SQLx และ Diesel ในด้านการตรวจสอบ query คืออะไร? **คำตอบ** SQLx ทำการตรวจสอบ query ในเวลาคอมไพล์โดยเชื่อมต่อกับฐานข้อมูลจริงระหว่างกระบวนการ build ส่วน Diesel ใช้ DSL (Domain-Specific Language) ของ Rust เพื่อสร้าง query ที่ type-safe โดยไม่ต้องเชื่อมต่อฐานข้อมูลในเวลาคอมไพล์ ทั้งสองแนวทางรับประกันความปลอดภัยของชนิดข้อมูล แต่ SQLx อนุญาตให้เขียน raw SQL ที่ผ่านการตรวจสอบแล้ว ในขณะที่ Diesel บังคับให้ใช้ Rust API ของมัน ## 2. ใน SQLx มาโครใดที่อนุญาตให้รัน query และแมปผลลัพธ์ไปยัง struct ของ Rust โดยอัตโนมัติ? **คำตอบ** มาโคร query_as! ของ SQLx รัน query SQL และแมปผลลัพธ์ไปยัง struct ของ Rust ที่ระบุโดยอัตโนมัติ มาโครนี้ตรวจสอบในเวลาคอมไพล์ว่าคอลัมน์ที่ส่งกลับตรงกับฟิลด์ของ struct เพื่อรับประกันความปลอดภัยของชนิดข้อมูล มาโคร query! ส่งคืนชนิดแบบนิรนาม ในขณะที่ query_scalar! ใช้สำหรับดึงค่าเดี่ยว ## 3. จะกำหนดค่า connection pool ด้วย SQLx สำหรับแอปพลิเคชัน PostgreSQL แบบ async ได้อย่างไร? **คำตอบ** SQLx ใช้ PgPoolOptions เพื่อกำหนดค่า connection pool ของ PostgreSQL แบบ async เมธอด max_connections กำหนดจำนวนการเชื่อมต่อสูงสุด และ connect สร้าง pool จาก URL ของฐานข้อมูล pool จะจัดการการขอและคืนการเชื่อมต่อโดยอัตโนมัติ และรองรับ timeout และ retry ที่กำหนดค่าได้ ## มีอีก 17 คำถาม - ใน Diesel จะกำหนด schema ของตารางเพื่อเปิดใช้งานการดำเนินการ CRUD แบบ type-safe ได้อย่างไร? - struct ต้อง implement Diesel trait ใดเพื่อแทรกข้อมูลลงในตาราง? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Rust อื่นๆ - [พื้นฐาน Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/rust-basics.md): 25 คำถาม, Junior - [Ownership & Borrowing](https://sharpskill.dev/th/technologies/rust/interview-questions/ownership-borrowing.md): 22 คำถาม, Junior - [Structs & Enums](https://sharpskill.dev/th/technologies/rust/interview-questions/structs-enums.md): 20 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/rust/interview-questions/error-handling.md): 18 คำถาม, Junior - [คอลเลกชัน](https://sharpskill.dev/th/technologies/rust/interview-questions/collections.md): 20 คำถาม, Junior - [โมดูลและแพ็กเกจ](https://sharpskill.dev/th/technologies/rust/interview-questions/modules-packages.md): 18 คำถาม, Junior - [Traits](https://sharpskill.dev/th/technologies/rust/interview-questions/traits.md): 22 คำถาม, Mid-Level - [Generics](https://sharpskill.dev/th/technologies/rust/interview-questions/generics.md): 20 คำถาม, Mid-Level - [Lifetimes](https://sharpskill.dev/th/technologies/rust/interview-questions/lifetimes.md): 20 คำถาม, Mid-Level - [Iterators & Closures](https://sharpskill.dev/th/technologies/rust/interview-questions/iterators-closures.md): 22 คำถาม, Mid-Level - [Smart Pointers](https://sharpskill.dev/th/technologies/rust/interview-questions/smart-pointers.md): 22 คำถาม, Mid-Level - [Concurrency Basics](https://sharpskill.dev/th/technologies/rust/interview-questions/concurrency-basics.md): 20 คำถาม, Mid-Level - [async/await](https://sharpskill.dev/th/technologies/rust/interview-questions/async-await.md): 22 คำถาม, Mid-Level - [Testing](https://sharpskill.dev/th/technologies/rust/interview-questions/testing.md): 18 คำถาม, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/th/technologies/rust/interview-questions/cargo-ecosystem.md): 18 คำถาม, Mid-Level - [Pattern Matching](https://sharpskill.dev/th/technologies/rust/interview-questions/pattern-matching.md): 18 คำถาม, Mid-Level - [มาโคร](https://sharpskill.dev/th/technologies/rust/interview-questions/macros.md): 20 คำถาม, Mid-Level - [Serde และการ Serialization](https://sharpskill.dev/th/technologies/rust/interview-questions/serde-serialization.md): 20 คำถาม, Mid-Level - [Unsafe Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/unsafe-rust.md): 20 คำถาม, Senior - [Trait ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-traits.md): 22 คำถาม, Senior - [Lifetime ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-lifetimes.md): 20 คำถาม, Senior - [Type System](https://sharpskill.dev/th/technologies/rust/interview-questions/type-system.md): 20 คำถาม, Senior - [Tokio & Async I/O](https://sharpskill.dev/th/technologies/rust/interview-questions/tokio-async.md): 22 คำถาม, Senior - [การเพิ่มประสิทธิภาพ](https://sharpskill.dev/th/technologies/rust/interview-questions/performance-optimization.md): 20 คำถาม, Senior - [Memory Management](https://sharpskill.dev/th/technologies/rust/interview-questions/memory-management.md): 20 คำถาม, Senior - [Web Frameworks](https://sharpskill.dev/th/technologies/rust/interview-questions/web-frameworks.md): 22 คำถาม, Senior - [Design Pattern ของ Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/design-patterns.md): 20 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/rust/interview-questions/database-integration