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

Giorgi / DuckDB.NET / 11718008762

07 Nov 2024 06:48AM UTC coverage: 89.937% (+0.09%) from 89.848%
11718008762

push

github

Giorgi
Merge branch 'develop'

1063 of 1216 branches covered (87.42%)

Branch coverage included in aggregate %.

256 of 275 new or added lines in 15 files covered. (93.09%)

1 existing line in 1 file now uncovered.

2083 of 2282 relevant lines covered (91.28%)

833197.35 hits per line

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

97.22
/DuckDB.NET.Data/Internal/DuckDBTypeMap.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Data;
4
using System.Numerics;
5
using DuckDB.NET.Data.Extensions;
6
using DuckDB.NET.Native;
7

8
namespace DuckDB.NET.Data.Internal;
9

10
internal static class DuckDBTypeMap
11
{
12
    private static readonly Dictionary<Type, DbType> ClrToDbTypeMap = new()
3✔
13
    {
3✔
14
        {typeof(bool), DbType.Boolean},
3✔
15
        {typeof(sbyte), DbType.SByte},
3✔
16
        {typeof(short), DbType.Int16},
3✔
17
        {typeof(int), DbType.Int32},
3✔
18
        {typeof(long), DbType.Int64},
3✔
19
        {typeof(float), DbType.Single},
3✔
20
        {typeof(double), DbType.Double},
3✔
21
        {typeof(string), DbType.String},
3✔
22
        {typeof(Guid), DbType.Guid},
3✔
23
        {typeof(decimal), DbType.Currency},
3✔
24
        {typeof(byte), DbType.Byte},
3✔
25
        {typeof(ushort), DbType.UInt16},
3✔
26
        {typeof(uint), DbType.UInt32},
3✔
27
        {typeof(ulong), DbType.UInt64},
3✔
28
        {typeof(BigInteger), DbType.VarNumeric},
3✔
29
        {typeof(byte[]), DbType.Binary},
3✔
30
        {typeof(DateTime), DbType.DateTime},
3✔
31
        {typeof(DuckDBDateOnly), DbType.Date},
3✔
32
        {typeof(DuckDBTimeOnly), DbType.Time},
3✔
33
#if NET6_0_OR_GREATER
3✔
34
        {typeof(DateOnly), DbType.Date},
3✔
35
        {typeof(TimeOnly), DbType.Time},
3✔
36
#endif
3✔
37
    };
3✔
38

39
    private static readonly Dictionary<Type, DuckDBType> ClrToDuckDBTypeMap = new()
3✔
40
    {
3✔
41
        { typeof(bool), DuckDBType.Boolean },
3✔
42
        { typeof(sbyte), DuckDBType.TinyInt },
3✔
43
        { typeof(short), DuckDBType.SmallInt },
3✔
44
        { typeof(int), DuckDBType.Integer },
3✔
45
        { typeof(long), DuckDBType.BigInt },
3✔
46
        { typeof(byte), DuckDBType.UnsignedTinyInt },
3✔
47
        { typeof(ushort), DuckDBType.UnsignedSmallInt },
3✔
48
        { typeof(uint), DuckDBType.UnsignedInteger },
3✔
49
        { typeof(ulong), DuckDBType.UnsignedBigInt },
3✔
50
        { typeof(float), DuckDBType.Float },
3✔
51
        { typeof(double), DuckDBType.Double},
3✔
52
        { typeof(Guid), DuckDBType.Uuid},
3✔
53
        { typeof(DateTime), DuckDBType.Timestamp},
3✔
54
        { typeof(TimeSpan), DuckDBType.Interval},
3✔
55
#if NET6_0_OR_GREATER
3✔
56
        { typeof(DateOnly), DuckDBType.Date},
3✔
57
        { typeof(TimeOnly), DuckDBType.Time},
3✔
58
#endif
3✔
59
        { typeof(DateTimeOffset), DuckDBType.TimeTz},
3✔
60
        { typeof(BigInteger), DuckDBType.HugeInt},
3✔
61
        { typeof(string), DuckDBType.Varchar},
3✔
62
        { typeof(decimal), DuckDBType.Decimal},
3✔
63
        { typeof(object), DuckDBType.Any},
3✔
64
    };
3✔
65

66
    public static DbType GetDbTypeForValue(object? value)
67
    {
68
        if (value.IsNull())
663✔
69
        {
70
            return DbType.Object;
18✔
71
        }
72

73
        var type = value!.GetType();
645✔
74

75
        if (ClrToDbTypeMap.TryGetValue(type, out var dbType))
645✔
76
        {
77
            return dbType;
495✔
78
        }
79

80
        return DbType.Object;
150✔
81
    }
82

83
    public static DuckDBLogicalType GetLogicalType<T>() => GetLogicalType(typeof(T));
39✔
84

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

92
        if (ClrToDuckDBTypeMap.TryGetValue(type, out var duckDBType))
132!
93
        {
94
            return NativeMethods.LogicalType.DuckDBCreateLogicalType(duckDBType);
132✔
95
        }
96

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