Calling database functions when using Octo.jl

suvayu
Thu, 09 May 2024 08:35:33 +0000
General Usage

I’m trying out Octo.jl with DuckDB. I managed to connect to an existing file and query a table there.

julia> import DataFrames as DF;

julia> using Octo.Adapters.DuckDB

julia> con = Repo.connect(adapter=Octo.Adapters.DuckDB, file="test/data/norse.duckdb")
Octo.Repo.Connection(false, "DuckDB", Main.DuckDBLoader, Octo.Adapters.DuckDB, DuckDB.DB("test/data/norse.duckdb"))

julia> struct Assets end

julia> Schema.model(Assets, table_name="alt_assets", primary_key="name")
| primary_key   | table_name   |
| ------------- | ------------ |
| name          | alt_assets   |

julia> assets = from(Assets)
FromItem alt_assets

julia> [SELECT * FROM assets LIMIT 5]
SELECT * FROM alt_assets LIMIT 5

julia> Repo.query([SELECT * FROM assets LIMIT 5]) |> DF.DataFrame
5×21 DataFrame
 Row │ name             type        active  investable  investment_integer  variable_cost  inv ⋯
     │ String?          String?     Bool?   Bool?       Bool?               Float64?       Flo ⋯
─────┼──────────────────────────────────────────────────────────────────────────────────────────
   1 │ Asgard_Battery   storage       true        true                true         0.003       ⋯
   2 │ Asgard_Solar     producer      true        true                true         0.001
   3 │ Asgard_E_demand  consumer      true       false               false         0.0
   4 │ Asgard_CCGT      conversion    true       false                true         0.0015
   5 │ G_imports        producer      true       false               false         0.08        ⋯

However now I want to query CSV files (the reason for using DuckDB), but I’m unsure how to call database functions like read_csv_auto.

Hoping to get some hints on how to proceed.

6 posts - 4 participants