Skip to content

Commit 7b3e06d

Browse files
author
Mattia
committed
fix missing in df2model
1 parent a6d0b85 commit 7b3e06d

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Mattia <[email protected]>
3+
Copyright (c) 2023 Mattia Careddu <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Wasabi"
22
uuid = "cec542a4-22c5-46cb-8ca4-a46a7737b387"
33
authors = ["Mattia <[email protected]>"]
4-
version = "0.2.0"
4+
version = "0.2.1"
55

66
[deps]
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

src/Wasabi.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ union_types(x::Type) = (x,)
8282
Converts the given DataFrame to the given model.
8383
"""
8484
function df2model(m::Type{T}, df::DataFrame) where {T<:Wasabi.Model}
85-
return [m(map(col -> Wasabi.from_sql_value(coltype(m, col), row[col]), Wasabi.colnames(m))...) for row in eachrow(df)]
85+
return [m(map(col -> row[col] !== missing ? Wasabi.from_sql_value(coltype(m, col), row[col]) : nothing, Wasabi.colnames(m))...) for row in eachrow(df)]
8686
end
8787

8888
"""

src/types.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ function Wasabi.to_sql_value(value::Any)
99
return value
1010
end
1111

12-
function Wasabi.to_sql_value(value::DateTime)
13-
return Dates.format(value, "yyyy-mm-ddTHH:MM:SS.s")
14-
end
15-
16-
function Wasabi.to_sql_value(value::Date)
17-
return Dates.format(value, "yyyy-mm-dd")
18-
end
19-
2012
function Wasabi.from_sql_value(t::Type{T}, value::Any) where {T}
2113
return value
2214
end
2315

16+
function Wasabi.to_sql_value(value::DateTime)
17+
return Dates.format(value, "yyyy-mm-ddTHH:MM:SS.s")
18+
end
19+
2420
function Wasabi.from_sql_value(t::Type{DateTime}, value::Any)
2521
return DateTime(value)
2622
end
2723

24+
function Wasabi.to_sql_value(value::Date)
25+
return Dates.format(value, "yyyy-mm-dd")
26+
end
27+
2828
function Wasabi.from_sql_value(t::Type{Date}, value::Any)
2929
return Date(value)
3030
end

0 commit comments

Comments
 (0)