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

Giorgi / DuckDB.NET / 21645923868

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

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%)

566599.28 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);
54✔
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>
30✔
27
        {
30✔
28
            PropertyType = typeof(TProperty),
30✔
29
            Getter = getter,
30✔
30
            MappingType = PropertyMappingType.Property
30✔
31
        };
30✔
32

33
        PropertyMappings.Add(mapping);
30✔
34
    }
30✔
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>
3✔
42
        {
3✔
43
            PropertyType = typeof(object),
3✔
44
            MappingType = PropertyMappingType.Default
3✔
45
        };
3✔
46

47
        PropertyMappings.Add(mapping);
3✔
48
    }
3✔
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>
3✔
56
        {
3✔
57
            PropertyType = typeof(object),
3✔
58
            MappingType = PropertyMappingType.Null
3✔
59
        };
3✔
60

61
        PropertyMappings.Add(mapping);
3✔
62
    }
3✔
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);
90✔
82
    public Func<T, TProperty> Getter { get; set; } = _ => default!;
96✔
83
    public PropertyMappingType MappingType { get; set; }
57✔
84

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

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

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

36✔
99
            // Value types
36✔
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),
12✔
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),
6✔
NEW
110
            double v => row.AppendValue(v),
×
NEW
111
            decimal v => row.AppendValue(v),
×
112
            DateTime v => row.AppendValue(v),
6✔
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
36✔
NEW
120
            DateOnly v => row.AppendValue(v),
×
NEW
121
            TimeOnly v => row.AppendValue(v),
×
122
#endif
36✔
123

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

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

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

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

145
    public IDuckDBAppenderRow AppendToRow(IDuckDBAppenderRow row, T record)
146
    {
147
        return row.AppendNullValue();
6✔
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