ORM — Object Relational Mapping is a layer of type-casting between the database and the programming language. Fluent is an open-source ORM library i

Just Fluent 4.0: Manage Database Connections and Decode SQL Queries in Swift

submited by
Style Pass
2021-06-21 20:30:04

ORM — Object Relational Mapping is a layer of type-casting between the database and the programming language. Fluent is an open-source ORM library in Swift, which is a part of the Vapor project. Fluent can be used independently of Vapor to communicate with databases, though the Fluent-Vapor documentation gives an impression otherwise.

When I started my project to replace a legacy ORM with Fluent 4.0, I was worried that I would need to write a Rest or GraphQL based interface to use the Fluent library, and it would be a lot of work. Fortunately, this thread on Github gave me hope that I can survive without writing that big of bulk of code.

Both topics are not covered in the Fluent-Vapor documentation and would be handy tools when writing an Enterprise level API. Also, I’m referencing the Postgres database drivers here, but you can replace it with any other database driver.

FluentPostgresDriver allows you to connect to multiple databases at the same time. The Databases class (representation of a collection of databases and more..) enables you to connect to multiple Database (representation of a single database) objects using unique DatabaseIDs (a unique id attached to a Database). Following are the primary functions you need to implement to manage the database:

Leave a Comment