swiftpostgresqlormfluentvapor

How to execute postgresql or sql directly using fluent orm


I am writing a vapor application, and I am having trouble because I need to index a geohash, but it isn't easily available, now i'd like to use SQL or postgres directly however, I'm at a loss for how for that as well.

I've Google searched for how, asked gpt, and I am not seeing a way in the framework.


Solution

  • Vapor Docs gives you the answer here

    import FluentPostgresDriver
    
    if let postgres = req.db as? PostgresDatabase {
        // The underlying database driver is PostgreSQL.
        postgres.simpleQuery("SELECT * FROM planets").all()
    } else {
        // The underlying database is _not_ PostgreSQL.
    }