Fusing Rust with data access
In web applications, accessing a database is a big part of the process. We could import the dal
object that we created in the src/data_access.py
file and pass it into our Rust function, executing database operations through Python. While this will technically work, it is not ideal as we will have to waste time and effort extracting objects from the database queries, inspecting them, and converting them into Rust structs. We would then have to convert the Rust structs into Python objects before inserting them into the database. This is a lot of excess code that has a lot of interaction with Python, reducing its speed gain.
Because a database is external from the Python web application, and it contains information about its schema, we can completely bypass Python's implementations by using the diesel
Rust crate to automatically write our schema and database models in Rust based on the live database. We can also use diesel
to manage the connection...