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

Giorgi / DuckDB.NET / 13181745983

06 Feb 2025 02:31PM UTC coverage: 89.958% (+0.02%) from 89.937%
13181745983

push

github

Giorgi
Merge branch 'develop'

1081 of 1235 branches covered (87.53%)

Branch coverage included in aggregate %.

322 of 345 new or added lines in 20 files covered. (93.33%)

2 existing lines in 1 file now uncovered.

2108 of 2310 relevant lines covered (91.26%)

760472.2 hits per line

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

96.97
/DuckDB.NET.Data/Extensions/TypeExtensions.cs
1
using DuckDB.NET.Native;
2
using System;
3
using System.Collections.Generic;
4
using System.Diagnostics.CodeAnalysis;
5
using System.Numerics;
6

7
namespace DuckDB.NET.Data.Extensions;
8

9
internal static class TypeExtensions
10
{
11
    private static readonly HashSet<Type> FloatingNumericTypes = [typeof(decimal), typeof(float), typeof(double)];
3✔
12

13
    private static readonly HashSet<Type> IntegralNumericTypes =
3✔
14
    [
3✔
15
        typeof(byte), typeof(sbyte),
3✔
16
        typeof(short), typeof(ushort),
3✔
17
        typeof(int), typeof(uint),
3✔
18
        typeof(long), typeof(ulong),
3✔
19
        typeof(BigInteger)
3✔
20
    ];
3✔
21

22
    private static readonly Dictionary<Type, DuckDBType> ClrToDuckDBTypeMap = new()
3✔
23
    {
3✔
24
        { typeof(bool), DuckDBType.Boolean },
3✔
25
        { typeof(sbyte), DuckDBType.TinyInt },
3✔
26
        { typeof(short), DuckDBType.SmallInt },
3✔
27
        { typeof(int), DuckDBType.Integer },
3✔
28
        { typeof(long), DuckDBType.BigInt },
3✔
29
        { typeof(byte), DuckDBType.UnsignedTinyInt },
3✔
30
        { typeof(ushort), DuckDBType.UnsignedSmallInt },
3✔
31
        { typeof(uint), DuckDBType.UnsignedInteger },
3✔
32
        { typeof(ulong), DuckDBType.UnsignedBigInt },
3✔
33
        { typeof(float), DuckDBType.Float },
3✔
34
        { typeof(double), DuckDBType.Double},
3✔
35
        { typeof(Guid), DuckDBType.Uuid},
3✔
36
        { typeof(DateTime), DuckDBType.Timestamp},
3✔
37
        { typeof(TimeSpan), DuckDBType.Interval},
3✔
38
#if NET6_0_OR_GREATER
3✔
39
        { typeof(DateOnly), DuckDBType.Date},
3✔
40
        { typeof(TimeOnly), DuckDBType.Time},
3✔
41
#endif
3✔
42
        { typeof(DateTimeOffset), DuckDBType.TimestampTz},
3✔
43
        { typeof(BigInteger), DuckDBType.HugeInt},
3✔
44
        { typeof(string), DuckDBType.Varchar},
3✔
45
        { typeof(decimal), DuckDBType.Decimal},
3✔
46
        { typeof(object), DuckDBType.Any},
3✔
47
    };
3✔
48

49
    public static bool IsNull([NotNullWhen(false)] this object? value) => value is null or DBNull;
11,442✔
50

51
    public static (bool isNullableValueType, Type type) IsNullableValueType<T>()
52
    {
53
        var targetType = typeof(T);
5,628,913✔
54

55
        var isNullableValueType = default(T) is null && targetType.IsValueType;
5,628,913✔
56

57
        return (isNullableValueType, targetType);
5,628,913✔
58
    }
59

60
    public static bool IsFloatingNumericType<T>()
61
    {
62
        return FloatingNumericTypes.Contains(typeof(T));
2,789,851✔
63
    }
64

65
    public static bool IsIntegralNumericType<T>()
66
    {
67
        return IntegralNumericTypes.Contains(typeof(T));
2,789,851✔
68
    }
69

70
    public static bool IsNumeric(this Type type)
71
    {
72
        return IntegralNumericTypes.Contains(type) || FloatingNumericTypes.Contains(type);
10,600,720✔
73
    }
74

75
    public static bool AllowsNullValue(this Type type, out bool isNullableValueType, out Type? underlyingType)
76
    {
77
        underlyingType = Nullable.GetUnderlyingType(type);
1,041,304✔
78
        isNullableValueType = underlyingType != null;
1,041,304✔
79

80
        var isNullable = isNullableValueType || !type.IsValueType;
1,041,304✔
81

82
        return isNullable;
307,494✔
83
    }
84

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

87
    public static DuckDBLogicalType GetLogicalType(this Type type)
88
    {
89
        if (type == typeof(decimal))
186✔
90
        {
91
            return NativeMethods.LogicalType.DuckDBCreateDecimalType(38, 18);
3✔
92
        }
93

94
        if (ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType))
183!
95
        {
96
            return NativeMethods.LogicalType.DuckDBCreateLogicalType(duckDBType);
183✔
97
        }
98

NEW
99
        throw new InvalidOperationException($"Cannot map type {type.FullName} to DuckDBType.");
×
100
    }
101
}
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