• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Giorgi / DuckDB.NET / 21644766496

03 Feb 2026 07:34PM UTC coverage: 89.45%. First build
21644766496

push

github

Giorgi
Merge branch 'develop'

1203 of 1395 branches covered (86.24%)

Branch coverage included in aggregate %.

125 of 154 new or added lines in 7 files covered. (81.17%)

2375 of 2605 relevant lines covered (91.17%)

377965.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.52
/DuckDB.NET.Data/Mapping/DuckDBAppenderMap.cs
1
using DuckDB.NET.Native;
2
using System;
3
using System.Collections.Generic;
4
using System.Numerics;
5

6
namespace DuckDB.NET.Data.Mapping;
7

8
/// <summary>
9
/// Base class for defining mappings between .NET classes and DuckDB table columns for appender operations.
10
/// </summary>
11
/// <typeparam name="T">The type to map</typeparam>
12
public abstract class DuckDBAppenderMap<T>
13
{
14
    /// <summary>
15
    /// Gets the property mappings defined for this class map.
16
    /// </summary>
17
    internal List<IPropertyMapping<T>> PropertyMappings { get; } = new(8);
36✔
18

19
    /// <summary>
20
    /// Maps a property to the next column in sequence.
21
    /// </summary>
22
    /// <typeparam name="TProperty">The property type</typeparam>
23
    /// <param name="getter">Function to get the property value</param>
24
    protected void Map<TProperty>(Func<T, TProperty> getter)
25
    {
26
        var mapping = new PropertyMapping<T, TProperty>
20✔
27
        {
20✔
28
            PropertyType = typeof(TProperty),
20✔
29
            Getter = getter,
20✔
30
            MappingType = PropertyMappingType.Property
20✔
31
        };
20✔
32

33
        PropertyMappings.Add(mapping);
20✔
34
    }
20✔
35

36
    /// <summary>
37
    /// Adds a default value for the next column.
38
    /// </summary>
39
    protected void DefaultValue()
40
    {
41
        var mapping = new DefaultValueMapping<T>
2✔
42
        {
2✔
43
            PropertyType = typeof(object),
2✔
44
            MappingType = PropertyMappingType.Default
2✔
45
        };
2✔
46

47
        PropertyMappings.Add(mapping);
2✔
48
    }
2✔
49

50
    /// <summary>
51
    /// Adds a null value for the next column.
52
    /// </summary>
53
    protected void NullValue()
54
    {
55
        var mapping = new NullValueMapping<T>
2✔
56
        {
2✔
57
            PropertyType = typeof(object),
2✔
58
            MappingType = PropertyMappingType.Null
2✔
59
        };
2✔
60

61
        PropertyMappings.Add(mapping);
2✔
62
    }
2✔
63
}
64

65
internal enum PropertyMappingType
66
{
67
    Property,
68
    Default,
69
    Null
70
}
71

72
internal interface IPropertyMapping<T>
73
{
74
    Type PropertyType { get; }
75
    PropertyMappingType MappingType { get; }
76
    IDuckDBAppenderRow AppendToRow(IDuckDBAppenderRow row, T record);
77
}
78

79
internal sealed class PropertyMapping<T, TProperty> : IPropertyMapping<T>
80
{
81
    public Type PropertyType { get; set; } = typeof(object);
60✔
82
    public Func<T, TProperty> Getter { get; set; } = _ => default!;
64✔
83
    public PropertyMappingType MappingType { get; set; }
38✔
84

85
    public IDuckDBAppenderRow AppendToRow(IDuckDBAppenderRow row, T record)
86
    {
87
        var value = Getter(record);
24✔
88

89
        if (value is null)
24!
90
        {
NEW
91
            return row.AppendNullValue();
×
92
        }
93

94
        return value switch
24!
95
        {
24✔
96
            // Reference types
24✔
97
            string v => row.AppendValue(v),
8✔
98

24✔
99
            // Value types
24✔
NEW
100
            bool v => row.AppendValue(v),
×
NEW
101
            sbyte v => row.AppendValue(v),
×
NEW
102
            short v => row.AppendValue(v),
×
103
            int v => row.AppendValue(v),
8✔
NEW
104
            long v => row.AppendValue(v),
×
NEW
105
            byte v => row.AppendValue(v),
×
NEW
106
            ushort v => row.AppendValue(v),
×
NEW
107
            uint v => row.AppendValue(v),
×
NEW
108
            ulong v => row.AppendValue(v),
×
109
            float v => row.AppendValue(v),
4✔
NEW
110
            double v => row.AppendValue(v),
×
NEW
111
            decimal v => row.AppendValue(v),
×
112
            DateTime v => row.AppendValue(v),
4✔
NEW
113
            DateTimeOffset v => row.AppendValue(v),
×
NEW
114
            TimeSpan v => row.AppendValue(v),
×
NEW
115
            Guid v => row.AppendValue(v),
×
NEW
116
            BigInteger v => row.AppendValue(v),
×
NEW
117
            DuckDBDateOnly v => row.AppendValue(v),
×
NEW
118
            DuckDBTimeOnly v => row.AppendValue(v),
×
119
#if NET6_0_OR_GREATER
24✔
NEW
120
            DateOnly v => row.AppendValue(v),
×
NEW
121
            TimeOnly v => row.AppendValue(v),
×
122
#endif
24✔
123

24✔
NEW
124
            _ => throw new NotSupportedException($"Type {typeof(TProperty).Name} is not supported for appending")
×
125
        };
24✔
126
    }
127
}
128

129
internal sealed class DefaultValueMapping<T> : IPropertyMapping<T>
130
{
131
    public Type PropertyType { get; set; } = typeof(object);
4✔
132
    public PropertyMappingType MappingType { get; set; }
4✔
133

134
    public IDuckDBAppenderRow AppendToRow(IDuckDBAppenderRow row, T record)
135
    {
136
        return row.AppendDefault();
4✔
137
    }
138
}
139

140
internal sealed class NullValueMapping<T> : IPropertyMapping<T>
141
{
142
    public Type PropertyType { get; set; } = typeof(object);
4✔
143
    public PropertyMappingType MappingType { get; set; }
4✔
144

145
    public IDuckDBAppenderRow AppendToRow(IDuckDBAppenderRow row, T record)
146
    {
147
        return row.AppendNullValue();
4✔
148
    }
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc