Skip to content

Commit 31ade60

Browse files
committed
support eltype()
1 parent 719f25f commit 31ade60

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/SQLCollections.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ exists(dbc::SQLCollection) =
4848

4949
Base.collect(dbc::SQLCollection) = StructArray(dbc)
5050

51+
Base.eltype(dbc::SQLCollection) = @p dbc first(__, 0) collect eltype
52+
5153
(::Type{StructArray})(dbc::SQLCollection) = DBInterface.execute(dbc.conn, dbc.query) |> columntable |> StructArray
5254
(::Type{StructVector})(dbc::SQLCollection) = StructArray(dbc)
5355
(::Type{Array})(dbc::SQLCollection) = DBInterface.execute(dbc.conn, dbc.query) |> rowtable

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ using TestItemRunner
1313
using StructArrays
1414
using DictArrays
1515

16+
function eltype_compatible(sql_T, mem_T)
17+
sql_T == mem_T && return true
18+
if isconcretetype(sql_T) && sql_T <: NamedTuple && mem_T <: NamedTuple
19+
return fieldnames(sql_T) == fieldnames(mem_T)
20+
end
21+
@warn "" sql_T mem_T
22+
return false
23+
end
24+
1625
# using Logging; ConsoleLogger(stdout, Logging.Debug) |> global_logger
1726

1827
data = [(;i, j=i/10, s=string('a'+i-1)^i, d=Date(2000+i, i, 2i), dt=DateTime(2000+i, i, 2i, i, 3i, 4i)) for i in 1:10]
@@ -86,6 +95,7 @@ using TestItemRunner
8695
cf = collect(f(tbl))
8796
@test issetequal(cf, f(data))
8897
@test isequal(cf, f(data))
98+
@test eltype_compatible(eltype(f(tbl)), eltype(f(data)))
8999

90100
@testset for g in [
91101
Array,

0 commit comments

Comments
 (0)