Skip to content

Commit e6e7976

Browse files
authored
Support for interval and fix unwanted lowercasing on enum values (#41)
1 parent c042b4a commit e6e7976

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PostgresORM"
22
uuid = "748b5efa-ed57-4836-b183-a38105a77fdd"
33
authors = ["Vincent Laugier <vincent.laugier@gmail.com>"]
4-
version = "0.6.1"
4+
version = "0.7.0"
55

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

src/Tool/Tool.jl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ function build_enum_name_w_module(str::String)
3535
end
3636

3737
function build_enum_value(str::String)
38-
StringCases.snakecase(str)
38+
# StringCases.snakecase returns a lowercase string, we need to uppercase the result if
39+
# the original string was in uppercase.
40+
# NOTE: Base.Unicode.isuppercase returns false on non-letter characters
41+
StringCases.snakecase(str) |>
42+
n -> all(c -> !isletter(c) || Base.Unicode.isuppercase(c),str) ? uppercase(n) : n
3943
end
4044

4145
function build_struct_name(str::String)
@@ -95,11 +99,17 @@ function is_vector_of_enum(coltype::String,
9599
customtypes_names)
96100
end
97101

98-
function get_fieldtype_from_coltype(coltype::String,
99-
elttype::String,
100-
customtypes::Dict,
101-
;tablename::String = "",
102-
colname::String = "")
102+
function get_fieldtype_from_coltype(
103+
coltype::String,
104+
elttype::String,
105+
customtypes::Dict,
106+
;tablename::String = "",
107+
colname::String = ""
108+
)
109+
110+
if (colname == "duration")
111+
@info "duration coltype[$coltype]"
112+
end
103113

104114
attrtype = missing
105115
customtypes_names = keys(customtypes) |> collect |> n -> string.(n)
@@ -113,7 +123,7 @@ function get_fieldtype_from_coltype(coltype::String,
113123
attrtype = "Bool"
114124
elseif (coltype == "smallint")
115125
attrtype = "Int16"
116-
elseif (coltype == "integer" || coltype == "interval")
126+
elseif (coltype == "integer")
117127
attrtype = "Int32"
118128
elseif (coltype == "bigint")
119129
attrtype = "Int64"
@@ -129,6 +139,8 @@ function get_fieldtype_from_coltype(coltype::String,
129139
attrtype = "DateTime"
130140
elseif (coltype == "timestamp with time zone")
131141
attrtype = "ZonedDateTime"
142+
elseif coltype == "interval"
143+
attrtype = "Dates.CompoundPeriod"
132144
elseif (coltype == "ARRAY")
133145
if (elttype == "_text" || elttype == "_varchar")
134146
attrtype = "Vector{String}"

0 commit comments

Comments
 (0)