Skip to content

Commit 4cbc310

Browse files
committed
Issue-2: added support for bool, int, uint, byte, sbyte, short, ushort, long, ulong, fload, double, string
1 parent b05d9f7 commit 4cbc310

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.EntityFrameworkCore.Storage;
2+
3+
namespace EfCore.Ydb.Storage.Internal.Mapping;
4+
5+
public class YdbBoolTypeMapping : BoolTypeMapping
6+
{
7+
public new static YdbBoolTypeMapping Default { get; } = new();
8+
9+
public YdbBoolTypeMapping() : base("BOOL")
10+
{
11+
}
12+
13+
protected YdbBoolTypeMapping(RelationalTypeMappingParameters parameters)
14+
: base(parameters)
15+
{
16+
}
17+
18+
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
19+
=> new YdbBoolTypeMapping(parameters);
20+
21+
protected override string GenerateNonNullSqlLiteral(object value)
22+
=> (bool)value ? "true" : "false";
23+
}

src/EfCore.Ydb/src/Storage/Internal/YdbTypeMappingSource.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Data;
5+
using EfCore.Ydb.Storage.Internal.Mapping;
56
using Microsoft.EntityFrameworkCore.Storage;
67

78
namespace EfCore.Ydb.Storage.Internal;
@@ -13,7 +14,22 @@ public class YdbTypeMappingSource : RelationalTypeMappingSource
1314

1415
#region Mappings
1516

17+
private readonly YdbBoolTypeMapping _bool = YdbBoolTypeMapping.Default;
18+
19+
private readonly SByteTypeMapping _int8 = new("INT8", DbType.Byte);
20+
private readonly ShortTypeMapping _int16 = new("INT16", DbType.Int16);
1621
private readonly IntTypeMapping _int32 = new("INT32", DbType.Int32);
22+
private readonly LongTypeMapping _int64 = new("INT64", DbType.Int64);
23+
24+
private readonly ByteTypeMapping _uint8 = new("UINT8", DbType.SByte);
25+
private readonly UShortTypeMapping _uint16 = new("UINT16", DbType.UInt16);
26+
private readonly UIntTypeMapping _uint32 = new("UINT32", DbType.UInt32);
27+
private readonly ULongTypeMapping _uint64 = new("UINT64", DbType.UInt64);
28+
29+
private readonly FloatTypeMapping _float = new("FLOAT", DbType.Single);
30+
private readonly DoubleTypeMapping _double = new("DOUBLE", DbType.Double);
31+
32+
private readonly StringTypeMapping _string = new("STRING", DbType.String);
1733

1834
#endregion
1935

@@ -24,11 +40,41 @@ RelationalTypeMappingSourceDependencies relationalDependencies
2440
{
2541
var storeTypeMappings = new Dictionary<string, RelationalTypeMapping[]>(StringComparer.OrdinalIgnoreCase)
2642
{
27-
{ "integer", [_int32] }
43+
{ "bool", [_bool] },
44+
45+
{ "int8", [_int8] },
46+
{ "int16", [_int16] },
47+
{ "int32", [_int32] },
48+
{ "int64", [_int64] },
49+
50+
{ "uint8", [_uint8] },
51+
{ "uint16", [_uint16] },
52+
{ "uint32", [_uint32] },
53+
{ "uint64", [_uint64] },
54+
55+
{ "float", [_float] },
56+
{ "double", [_double] },
57+
58+
{ "string", [_string] }
2859
};
2960
var clrTypeMappings = new Dictionary<Type, RelationalTypeMapping>
3061
{
31-
{ typeof(int), _int32 }
62+
{ typeof(bool), _bool },
63+
64+
{ typeof(sbyte), _int8 },
65+
{ typeof(short), _int16 },
66+
{ typeof(int), _int32 },
67+
{ typeof(long), _int64 },
68+
69+
{ typeof(byte), _uint8 },
70+
{ typeof(ushort), _uint16 },
71+
{ typeof(uint), _uint32 },
72+
{ typeof(ulong), _uint64 },
73+
74+
{ typeof(float), _float },
75+
{ typeof(double), _double },
76+
77+
{ typeof(string), _string }
3278
};
3379

3480
StoreTypeMapping = new ConcurrentDictionary<string, RelationalTypeMapping[]>(storeTypeMappings);
@@ -66,7 +112,6 @@ RelationalTypeMappingSourceDependencies relationalDependencies
66112
return mapping;
67113
}
68114
}
69-
70115
return null;
71116
}
72117
}

0 commit comments

Comments
 (0)