Developing Your ORM Library in Rust: Optimization and Simplicity

Developing Your ORM Library in Rust: Optimization and Simplicity

Why did I decide to develop my own ORM library?

My first steps into the ORM world were made with the Diesel library. At that time it was one of the few options for working with Rust databases, and, of course, its popularity did not leave me indifferent. Soon, however, I noticed SeaORM, another promising ORM library for Rust, which was also gaining momentum. But I had some problems with them.

First, I believe that despite their popularity and functionality, both libraries, in my opinion, have some drawbacks. The main problem is redundant code. Both libraries require many additional lines of code to get started. Yes, this may be part of the price for a high level of abstraction, but it often feels like overkill.

Another issue is the difficulty of mapping data from a database to Rust objects. In Diesel and SeaORM, this often requires not only the description of data structures, but also the creation of schemas or the use of code generators.

Secondly, I don’t like that these libraries are trying to get rid of writing SQL queries. As a result, to get some simple request, you have to write long chains of function calls.

The main idea that I put into my ORM library is a minimum of stupid code and easy use of the library. I wanted users not to have to write long chains of function calls to construct a simple SQL query.

In order to simplify access to the names of the structure fields and avoid the routine work associated with serialization and deserialization, I implemented my own derive macro. This macro generates the necessary methods for accessing the structure’s fields.

https://medium.com/@igumnovnsk/developing-your-orm-library-in-rust-optimization-and-simplicity-37bfab8fa536


要查看或添加评论,请登录

Evgeny Igumnov的更多文章

社区洞察

其他会员也浏览了