-
Notifications
You must be signed in to change notification settings - Fork 380
/
MySqlDefaultDataTypeMappings.cs
189 lines (160 loc) · 5.47 KB
/
MySqlDefaultDataTypeMappings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright (c) Pomelo Foundation. All rights reserved.
// Licensed under the MIT. See LICENSE in the project root for license information.
using System;
namespace Pomelo.EntityFrameworkCore.MySql.Infrastructure
{
public class MySqlDefaultDataTypeMappings
{
public MySqlDefaultDataTypeMappings()
{
}
protected MySqlDefaultDataTypeMappings(MySqlDefaultDataTypeMappings copyFrom)
{
ClrBoolean = copyFrom.ClrBoolean;
ClrDateTime = copyFrom.ClrDateTime;
ClrDateTimeOffset = copyFrom.ClrDateTimeOffset;
ClrTimeSpan = copyFrom.ClrTimeSpan;
ClrTimeOnlyPrecision = copyFrom.ClrTimeOnlyPrecision;
}
public virtual MySqlBooleanType ClrBoolean { get; private set; }
public virtual MySqlDateTimeType ClrDateTime { get; private set; }
public virtual MySqlDateTimeType ClrDateTimeOffset { get; private set; }
public virtual MySqlTimeSpanType ClrTimeSpan { get; private set; }
public virtual int ClrTimeOnlyPrecision { get; private set; } = -1;
public virtual MySqlDefaultDataTypeMappings WithClrBoolean(MySqlBooleanType mysqlBooleanType)
{
var clone = Clone();
clone.ClrBoolean = mysqlBooleanType;
return clone;
}
public virtual MySqlDefaultDataTypeMappings WithClrDateTime(MySqlDateTimeType mysqlDateTimeType)
{
var clone = Clone();
clone.ClrDateTime = mysqlDateTimeType;
return clone;
}
public virtual MySqlDefaultDataTypeMappings WithClrDateTimeOffset(MySqlDateTimeType mysqlDateTimeType)
{
var clone = Clone();
clone.ClrDateTimeOffset = mysqlDateTimeType;
return clone;
}
// TODO: Remove Time6, add optional precision parameter for Time types.
public virtual MySqlDefaultDataTypeMappings WithClrTimeSpan(MySqlTimeSpanType mysqlTimeSpanType)
{
var clone = Clone();
clone.ClrTimeSpan = mysqlTimeSpanType;
return clone;
}
/// <summary>
/// Set the default precision for `TimeOnly` CLR type mapping to a MySQL TIME type.
/// Set <paramref name="precision"/> to <see langword="null"/>, to use the highest supported precision.
/// Otherwise, set <paramref name="precision"/> to a valid value between `0` and `6`.
/// </summary>
/// <param name="precision">The precision used for the MySQL TIME type.</param>
/// <returns>The same instance, to allow chained method calls.</returns>
public virtual MySqlDefaultDataTypeMappings WithClrTimeOnly(int? precision = null)
{
if (precision is < 0 or > 6)
{
throw new ArgumentOutOfRangeException(nameof(precision));
}
var clone = Clone();
clone.ClrTimeOnlyPrecision = precision ?? -1;
return clone;
}
protected virtual MySqlDefaultDataTypeMappings Clone() => new MySqlDefaultDataTypeMappings(this);
protected virtual bool Equals(MySqlDefaultDataTypeMappings other)
{
return ClrBoolean == other.ClrBoolean &&
ClrDateTime == other.ClrDateTime &&
ClrDateTimeOffset == other.ClrDateTimeOffset &&
ClrTimeSpan == other.ClrTimeSpan &&
ClrTimeOnlyPrecision == other.ClrTimeOnlyPrecision;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != this.GetType())
{
return false;
}
return Equals((MySqlDefaultDataTypeMappings)obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (int)ClrBoolean;
hashCode = (hashCode * 397) ^ (int)ClrDateTime;
hashCode = (hashCode * 397) ^ (int)ClrDateTimeOffset;
hashCode = (hashCode * 397) ^ (int)ClrTimeSpan;
return hashCode;
}
}
}
public enum MySqlBooleanType
{
/// <summary>
/// TODO
/// </summary>
None = -1, // TODO: Remove in EF Core 5; see MySqlTypeMappingTest.Bool_with_MySqlBooleanType_None_maps_to_null()
/// <summary>
/// TODO
/// </summary>
Default = 0,
/// <summary>
/// TODO
/// </summary>
TinyInt1 = 1,
/// <summary>
/// TODO
/// </summary>
Bit1 = 2
}
public enum MySqlDateTimeType
{
/// <summary>
/// TODO
/// </summary>
Default = 0,
/// <summary>
/// TODO
/// </summary>
DateTime = 1,
/// <summary>
/// TODO
/// </summary>
DateTime6 = 2,
/// <summary>
/// TODO
/// </summary>
Timestamp6 = 3,
/// <summary>
/// TODO
/// </summary>
Timestamp = 4,
}
public enum MySqlTimeSpanType
{
/// <summary>
/// TODO
/// </summary>
Default = 0,
/// <summary>
/// TODO
/// </summary>
Time = 1,
/// <summary>
/// TODO
/// </summary>
Time6 = 2,
}
}