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:
parent
bf9d33da53
commit
2a7634188c
18
src/db.jl
18
src/db.jl
|
@ -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`.
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue