Skip to content

Commit 1230b5c

Browse files
committed
support mapinsert⁻
1 parent 73bbade commit 1230b5c

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

ext/FlexiMapsExt.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module FlexiMapsExt
22

33
using FlexiMaps
4-
using SQLCollections: SQLCollection, func_to_funsql, colnames, Select, @modify, AccessorsExtra
4+
using SQLCollections: SQLCollection, func_to_funsql, colnames, Select, @modify, AccessorsExtra, @p
55

66

77
FlexiMaps.mapset(dbc::SQLCollection; kwargs...) = @modify(dbc.query) do q
@@ -30,4 +30,11 @@ FlexiMaps.mapinsert(dbc::SQLCollection; kwargs...) = @modify(dbc.query) do q
3030
end...)
3131
end
3232

33+
FlexiMaps.mapinsert⁻(dbc::SQLCollection; kwargs...) = @modify(dbc.query) do q
34+
keys_to_drop = @p values(kwargs) flatmap(keys(AccessorsExtra.propspec(_))) unique
35+
q |> Select(setdiff(collect(colnames(dbc)), keys_to_drop)..., map(keys(kwargs), values(kwargs)) do k, o
36+
k => func_to_funsql(o)
37+
end...)
38+
end
39+
3340
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ using TestItemRunner
8787
(@f map(@o _[sr"i", sr"d(.*)" => ss"ddd\1"])),
8888
# (@f map(@o (;_[(:j, :i)]...))),
8989
(@f mapinsert(a=@o Float64(_.i) / 2)),
90+
(@f mapinsert⁻(a=@o Float64(_.i) / 2)),
91+
(@f mapinsert⁻(a=@o _.i + _.j)),
9092
(@f mapset(i=@o round(2*_.j))),
9193
(@f filter(@o _.i != 2) map(@o (a=ifelse(_.i > 6, 1, 0),)) filter(@o _.a == 1)),
9294
(@f map(@o (a=ifelse(_.i > 6, 1, 0),)) unique()),
@@ -126,6 +128,7 @@ using TestItemRunner
126128
gf = g(f(tbl))
127129
gd = g(f(data))
128130
@test nameof(typeof(gf)) == nameof(typeof(gd))
131+
# @test issetequal(gf, gd)
129132
@test isequal(gf, gd)
130133
end
131134
end

0 commit comments

Comments
 (0)