Port sql_fn from Perl to Julia

This is a convenience function that I
started using in Perl in 2022.
I wish I was using this style in 1998.
It removes noise from DB code.
This commit is contained in:
gg1234 2023-09-26 03:54:55 -07:00
parent bf9d33da53
commit 2a7634188c
1 changed files with 18 additions and 0 deletions

View File

@ -2,6 +2,24 @@ using SQLite
using DataFrames
using Dates
"""
sql_fn(db)
Return a function that takes an SQL and optional bind parameters
and runs the query and returns the results as a DataFrame.
```julia
db = SQLite.DB("sql/wn.db")
sql = WeatherNews.DB.sql_fn(db)
res = sql("SELECT * FROM cancellation")
```
"""
function sql_fn(db)
function sql(query, params=[])
DBInterface.execute(db, query, params) |> DataFrame
end
end
"""
Find or create a caster by short name `n`.
"""