01 July 2020

freeswitch.Dbh is the method I’ve chosen for connecting to a database via a Lua script in FreeSWITCH.

The interface is simple to use, and provides all the basics needed to communicate with a database via a configured ODBC driver.

One thing I found lacking, however, were ‘fetch’ type helper functions, that:

  • Returned a multi-row result in a table of tables
  • Returned a single-row result in a table
  • Returned a single-row, single-column result directly.

Below are the helper functions I came up with. You might also be able to extend the dbh object directly with methods – I just chose to pass the dbh object into a standalone function call.