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

Giorgi / DuckDB.NET / 20383681089

19 Dec 2025 10:02PM UTC coverage: 89.294% (+0.03%) from 89.262%
20383681089

push

github

Giorgi
Drop .Net Standard support

1183 of 1379 branches covered (85.79%)

Branch coverage included in aggregate %.

19 of 22 new or added lines in 13 files covered. (86.36%)

16 existing lines in 9 files now uncovered.

2295 of 2516 relevant lines covered (91.22%)

567948.85 hits per line

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

56.76
/DuckDB.NET.Data/Mapping/DuckDBClassMap.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.
10
/// </summary>
11
/// <typeparam name="T">The type to map</typeparam>
12
public abstract class DuckDBClassMap<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
        {
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✔
100
            bool v => row.AppendValue(v),
×
101
            sbyte v => row.AppendValue(v),
×
102
            short v => row.AppendValue(v),
×
103
            int v => row.AppendValue(v),
12✔
104
            long v => row.AppendValue(v),
×
105
            byte v => row.AppendValue(v),
×
106
            ushort v => row.AppendValue(v),
×
107
            uint v => row.AppendValue(v),
×
108
            ulong v => row.AppendValue(v),
×
109
            float v => row.AppendValue(v),
6✔
110
            double v => row.AppendValue(v),
×
111
            decimal v => row.AppendValue(v),
×
112
            DateTime v => row.AppendValue(v),
6✔
113
            DateTimeOffset v => row.AppendValue(v),
×
114
            TimeSpan v => row.AppendValue(v),
×
115
            Guid v => row.AppendValue(v),
×
116
            BigInteger v => row.AppendValue(v),
×
117
            DuckDBDateOnly v => row.AppendValue(v),
×
118
            DuckDBTimeOnly v => row.AppendValue(v),
×
UNCOV
119
            DateOnly v => row.AppendValue(v),
×
120
            TimeOnly v => row.AppendValue(v),
×
121

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

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

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

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

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

© 2025 Coveralls, Inc