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

Giorgi / DuckDB.NET / 42059113838

05 Nov 2026 03:50PM UTC coverage: 93.39% (+0.6%) from 92.771%
42059113838

Pull #387

github

web-flow
Merge d647f8ecd into 80a438a22
Pull Request #387: feat(data): support writing TIME_NS values

2773 of 3019 branches covered (91.85%)

Branch coverage included in aggregate %.

13 of 13 new or added lines in 5 files covered. (100.0%)

52 existing lines in 14 files now uncovered.

4319 of 4575 relevant lines covered (94.4%)

1059905.08 hits per line

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

98.1
/DuckDB.NET.Data/Extensions/TypeExtensions.cs
1
using System.Diagnostics.CodeAnalysis;
2
using System.Runtime.CompilerServices;
3

4
namespace DuckDB.NET.Data.Extensions;
5

6
internal static class TypeExtensions
7
{
8
    private static readonly Dictionary<Type, DuckDBType> ClrToDuckDBTypeMap = new()
3 ✔
9
    {
3 ✔
10
        { typeof(bool), DuckDBType.Boolean },
3 ✔
11
        { typeof(sbyte), DuckDBType.TinyInt },
3 ✔
12
        { typeof(short), DuckDBType.SmallInt },
3 ✔
13
        { typeof(int), DuckDBType.Integer },
3 ✔
14
        { typeof(long), DuckDBType.BigInt },
3 ✔
15
        { typeof(byte), DuckDBType.UnsignedTinyInt },
3 ✔
16
        { typeof(ushort), DuckDBType.UnsignedSmallInt },
3 ✔
17
        { typeof(uint), DuckDBType.UnsignedInteger },
3 ✔
18
        { typeof(ulong), DuckDBType.UnsignedBigInt },
3 ✔
19
        { typeof(float), DuckDBType.Float },
3 ✔
20
        { typeof(double), DuckDBType.Double},
3 ✔
21
        { typeof(Guid), DuckDBType.Uuid},
3 ✔
22
        { typeof(DateTime), DuckDBType.Timestamp},
3 ✔
23
        { typeof(TimeSpan), DuckDBType.Interval},
3 ✔
24
        { typeof(DateOnly), DuckDBType.Date},
3 ✔
25
        { typeof(TimeOnly), DuckDBType.Time},
3 ✔
26
        { typeof(DuckDBDateOnly), DuckDBType.Date},
3 ✔
27
        { typeof(DuckDBTimeOnly), DuckDBType.Time},
3 ✔
28
        { typeof(DateTimeOffset), DuckDBType.TimestampTz},
3 ✔
29
        { typeof(BigInteger), DuckDBType.HugeInt},
3 ✔
30
        { typeof(Int128), DuckDBType.HugeInt},
3 ✔
31
        { typeof(UInt128), DuckDBType.UnsignedHugeInt},
3 ✔
32
        { typeof(string), DuckDBType.Varchar},
3 ✔
33
        { typeof(byte[]), DuckDBType.Blob},
3 ✔
34
        { typeof(decimal), DuckDBType.Decimal},
3 ✔
35
        { typeof(object), DuckDBType.Any},
3 ✔
36
    };
3 ✔
37

38
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
39
    public static bool IsNull([NotNullWhen(false)] this object? value) => value is null or DBNull;
79,431 ✔
40

41
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
42
    public static Type UnderlyingTypeOrSelf(this Type type) => Nullable.GetUnderlyingType(type) ?? type;
3,372 ✔
43

44
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
45
    public static bool IsFloatingNumericType<T>()
46
    {
47
        return typeof(T) == typeof(decimal) || typeof(T) == typeof(float) || typeof(T) == typeof(double);
517,749 ✔
48
    }
49

50
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
51
    public static bool IsIntegralNumericType<T>()
52
    {
53
        return typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte) ||
4,279,146 ✔
54
               typeof(T) == typeof(short) || typeof(T) == typeof(ushort) ||
4,279,146 ✔
55
               typeof(T) == typeof(int) || typeof(T) == typeof(uint) ||
4,279,146 ✔
56
               typeof(T) == typeof(long) || typeof(T) == typeof(ulong) ||
4,279,146 ✔
57
               typeof(T) == typeof(Int128) || typeof(T) == typeof(UInt128) ||
4,279,146 ✔
58
               typeof(T) == typeof(BigInteger);
4,279,146 ✔
59
    }
60

61
    public static bool AllowsNullValue(this Type type, out bool isNullableValueType, out Type? underlyingType)
62
    {
63
        underlyingType = Nullable.GetUnderlyingType(type);
3,124,068 ✔
64
        isNullableValueType = underlyingType != null;
3,124,068 ✔
65

66
        var isNullable = isNullableValueType || !type.IsValueType;
3,124,068 ✔
67

68
        return isNullable;
849,810 ✔
69
    }
70

71
    // The constructed type of genericDefinition (List<>, Dictionary<,>) that the type is or derives from, or null.
72
    public static Type? FindGenericBase(this Type type, Type genericDefinition)
73
    {
74
        for (var current = type; current != null; current = current.BaseType)
6,290,112 ✔
75
        {
76
            if (current.IsGenericType && current.GetGenericTypeDefinition() == genericDefinition)
3,105,867 ✔
77
            {
78
                return current;
2,892,459 ✔
79
            }
80
        }
81

82
        return null;
39,189 ✔
83
    }
84

85
    public static DuckDBLogicalType GetLogicalType<T>() => typeof(T).GetLogicalType();
762 ✔
86

87
    public static DuckDBLogicalType GetLogicalType(this Type type)
88
    {
89
        type = type.UnderlyingTypeOrSelf();
3,132 ✔
90

91
        if (type == typeof(decimal))
3,132 ✔
92
        {
93
            return NativeMethods.LogicalType.DuckDBCreateDecimalType(38, 18);
138 ✔
94
        }
95

96
        if (type.IsAssignableTo(typeof(IList)) && type.IsGenericType)
2,994 ✔
97
        {
98
            var genericTypeParameter = type.GetGenericArguments()[0];
51 ✔
99
            using var nestedType = genericTypeParameter.GetLogicalType();
51 ✔
100
            return NativeMethods.LogicalType.DuckDBCreateListType(nestedType);
51 ✔
101
        }
102

103
        if (ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType))
2,943 !
104
        {
105
            return NativeMethods.LogicalType.DuckDBCreateLogicalType(duckDBType);
2,943 ✔
106
        }
107

UNCOV
108
        throw new InvalidOperationException($"Cannot map type {type.FullName} to DuckDBType.");
×
109
    }
51 ✔
110

111
    public static DuckDBType GetDuckDBType(this Type type) => ClrToDuckDBTypeMap.GetValueOrDefault(type, DuckDBType.Invalid);
183 ✔
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc