Using FunSQL.jl with Postgres.jl

I am testing Postgres.jl with my package that currently uses LibPQ and FunSQL.

The testing so far which did not include FunSQL worked well. I am getting stuck on the FunSQL integration. LibPQ.jl does not support the DBInterface.jl package, so there was a workaround explained in the FunSQL documentation. I expect that this is not required with Postgres.jl since it does support DBInterface.

The FunSQL documentation, gives the example:

using FunSQL
using SQLite
conn = DBInterface.connect(FunSQL.DB{SQLite.DB}, DATABASE)

When I try to duplicate this for Postgres, Postgres.DB is not recognized. My current question is what should go into the curly braces in the command below:

using Postgres, DBInterface, FunSQL

conn = DBInterface.connect(FunSQL.DB{Postgres.DB},
"host=$dbhost port=$dbport dbname=$dbread user=$DATABASE_USER password=$DATABASE_PASSWORD")

Postgres.jl’s connection type is Postgres.Connection (there’s no Postgres.DB), and it implements DBInterface directly, so you don’t need the LibPQ bridging code from the FunSQL docs.

One catch: FunSQL detects the SQL dialect from the connection type, and it doesn’t know about Postgres.Connectionyet. Without a dialect you’ll get cannot infer SQLDialect from the connection type. For now, pass the dialect yourself:

using Postgres, DBInterface, FunSQL

conn = DBInterface.connect(FunSQL.DB{Postgres.Connection},
    "host=$dbhost port=$dbport dbname=$dbread user=$DATABASE_USER password=$DATABASE_PASSWORD";
    dialect = :postgresql)

After that, DBInterface.execute(conn, q; params...) works as usual.

I can probably open a small PR to FunSQL to add Postgres.Connection, so dialect = :postgresql won’t be needed.