-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for DateTime.UtcNow and DateTime.Now
- Loading branch information
1 parent
3fa2cfb
commit 80691fa
Showing
33 changed files
with
651 additions
and
13 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/Laraue.EfCoreTriggers.Common/Converters/MemberAccess/BaseMemberAccessVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
using Laraue.EfCoreTriggers.Common.Converters.MethodCall; | ||
using Laraue.EfCoreTriggers.Common.SqlGeneration; | ||
using Laraue.EfCoreTriggers.Common.Visitors.ExpressionVisitors; | ||
|
||
namespace Laraue.EfCoreTriggers.Common.Converters.MemberAccess | ||
{ | ||
/// <summary> | ||
/// Base <see cref="IMethodCallVisitor"/>. | ||
/// </summary> | ||
public abstract class BaseMemberAccessVisitor : IMemberAccessVisitor | ||
{ | ||
/// <summary> | ||
/// Specifies a method which will be handled by this converter. | ||
/// </summary> | ||
protected abstract string PropertyName { get; } | ||
|
||
/// <summary> | ||
/// Specifies a class which methods will be handled by this converter. | ||
/// </summary> | ||
protected abstract Type ReflectedType { get; } | ||
|
||
/// <summary> | ||
/// Factory to visit expressions and generate SQL code. | ||
/// </summary> | ||
protected IExpressionVisitorFactory VisitorFactory { get; } | ||
|
||
/// <summary> | ||
/// Initialize a new instance of <see cref="BaseMethodCallVisitor"/>. | ||
/// </summary> | ||
/// <param name="visitorFactory"></param> | ||
protected BaseMemberAccessVisitor(IExpressionVisitorFactory visitorFactory) | ||
{ | ||
VisitorFactory = visitorFactory; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool IsApplicable(MemberExpression expression) | ||
{ | ||
return expression.Member.ReflectedType == ReflectedType && PropertyName == expression.Member.Name; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public abstract SqlBuilder Visit(MemberExpression expression); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Laraue.EfCoreTriggers.Common/Converters/MemberAccess/DateTime/BaseDateTimeVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using Laraue.EfCoreTriggers.Common.Visitors.ExpressionVisitors; | ||
|
||
namespace Laraue.EfCoreTriggers.Common.Converters.MemberAccess.DateTime | ||
{ | ||
/// <summary> | ||
/// Base visitor for <see cref="System.Math"/> methods. | ||
/// </summary> | ||
public abstract class BaseDateTimeVisitor : BaseMemberAccessVisitor | ||
{ | ||
/// <inheritdoc /> | ||
protected override Type ReflectedType => typeof(System.DateTime); | ||
|
||
/// <inheritdoc /> | ||
protected BaseDateTimeVisitor(IExpressionVisitorFactory visitorFactory) | ||
: base(visitorFactory) | ||
{ | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Laraue.EfCoreTriggers.Common/Converters/MemberAccess/DateTime/BaseNowVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Laraue.EfCoreTriggers.Common.Visitors.ExpressionVisitors; | ||
|
||
namespace Laraue.EfCoreTriggers.Common.Converters.MemberAccess.DateTime | ||
{ | ||
/// <summary> | ||
/// Visitor for <see cref="System.DateTime.Now"/>. | ||
/// </summary> | ||
public abstract class BaseNowVisitor : BaseDateTimeVisitor | ||
{ | ||
/// <inheritdoc /> | ||
protected override string PropertyName => nameof(System.DateTime.Now); | ||
|
||
/// <inheritdoc /> | ||
protected BaseNowVisitor(IExpressionVisitorFactory visitorFactory) | ||
: base(visitorFactory) | ||
{ | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Laraue.EfCoreTriggers.Common/Converters/MemberAccess/DateTime/BaseUtcNowVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Laraue.EfCoreTriggers.Common.Visitors.ExpressionVisitors; | ||
|
||
namespace Laraue.EfCoreTriggers.Common.Converters.MemberAccess.DateTime | ||
{ | ||
/// <summary> | ||
/// Visitor for <see cref="System.DateTime.UtcNow"/>, | ||
/// </summary> | ||
public abstract class BaseUtcNowVisitor : BaseDateTimeVisitor | ||
{ | ||
/// <inheritdoc /> | ||
protected override string PropertyName => nameof(System.DateTime.UtcNow); | ||
|
||
/// <inheritdoc /> | ||
protected BaseUtcNowVisitor(IExpressionVisitorFactory visitorFactory) | ||
: base(visitorFactory) | ||
{ | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Laraue.EfCoreTriggers.Common/Converters/MemberAccess/IMemberAccessVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Linq.Expressions; | ||
using Laraue.EfCoreTriggers.Common.SqlGeneration; | ||
|
||
namespace Laraue.EfCoreTriggers.Common.Converters.MemberAccess | ||
{ | ||
/// <summary> | ||
/// Converter for <see cref="MethodCallExpression"/>. | ||
/// </summary> | ||
public interface IMemberAccessVisitor | ||
{ | ||
/// <summary> | ||
/// Should this converter be used to translate a <see cref="MemberExpression"/> to a SQL. | ||
/// </summary> | ||
/// <param name="expression"></param> | ||
/// <returns></returns> | ||
bool IsApplicable(MemberExpression expression); | ||
|
||
/// <summary> | ||
/// Build a SQL for passed <see cref="MethodCallExpression"/>. | ||
/// </summary> | ||
/// <param name="expression">Expression to parse.</param> | ||
/// <returns></returns> | ||
SqlBuilder Visit(MemberExpression expression); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Laraue.EfCoreTriggers.MySql/Converters/MemberAccess/DateTime/NowVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Linq.Expressions; | ||
using Laraue.EfCoreTriggers.Common.Converters.MemberAccess.DateTime; | ||
using Laraue.EfCoreTriggers.Common.SqlGeneration; | ||
using Laraue.EfCoreTriggers.Common.Visitors.ExpressionVisitors; | ||
|
||
namespace Laraue.EfCoreTriggers.MySql.Converters.MemberAccess.DateTime | ||
{ | ||
/// <inheritdoc /> | ||
public class NowVisitor : BaseNowVisitor | ||
{ | ||
/// <inheritdoc /> | ||
public NowVisitor(IExpressionVisitorFactory visitorFactory) | ||
: base(visitorFactory) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override SqlBuilder Visit(MemberExpression expression) | ||
{ | ||
return SqlBuilder.FromString("LOCALTIME()"); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Laraue.EfCoreTriggers.MySql/Converters/MemberAccess/DateTime/UtcNowVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Linq.Expressions; | ||
using Laraue.EfCoreTriggers.Common.Converters.MemberAccess.DateTime; | ||
using Laraue.EfCoreTriggers.Common.SqlGeneration; | ||
using Laraue.EfCoreTriggers.Common.Visitors.ExpressionVisitors; | ||
|
||
namespace Laraue.EfCoreTriggers.MySql.Converters.MemberAccess.DateTime | ||
{ | ||
/// <inheritdoc /> | ||
public class UtcNowVisitor : BaseUtcNowVisitor | ||
{ | ||
/// <inheritdoc /> | ||
public UtcNowVisitor(IExpressionVisitorFactory visitorFactory) | ||
: base(visitorFactory) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override SqlBuilder Visit(MemberExpression expression) | ||
{ | ||
return SqlBuilder.FromString("UTC_TIMESTAMP()"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Laraue.EfCoreTriggers.PostgreSql/Converters/MemberAccess/DateTime/NowVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Linq.Expressions; | ||
using Laraue.EfCoreTriggers.Common.Converters.MemberAccess.DateTime; | ||
using Laraue.EfCoreTriggers.Common.SqlGeneration; | ||
using Laraue.EfCoreTriggers.Common.Visitors.ExpressionVisitors; | ||
|
||
namespace Laraue.EfCoreTriggers.PostgreSql.Converters.MemberAccess.DateTime | ||
{ | ||
/// <inheritdoc /> | ||
public class NowVisitor : BaseNowVisitor | ||
{ | ||
/// <inheritdoc /> | ||
public NowVisitor(IExpressionVisitorFactory visitorFactory) | ||
: base(visitorFactory) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override SqlBuilder Visit(MemberExpression expression) | ||
{ | ||
return SqlBuilder.FromString("NOW()"); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Laraue.EfCoreTriggers.PostgreSql/Converters/MemberAccess/DateTime/UtcNowVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Linq.Expressions; | ||
using Laraue.EfCoreTriggers.Common.Converters.MemberAccess.DateTime; | ||
using Laraue.EfCoreTriggers.Common.SqlGeneration; | ||
using Laraue.EfCoreTriggers.Common.Visitors.ExpressionVisitors; | ||
|
||
namespace Laraue.EfCoreTriggers.PostgreSql.Converters.MemberAccess.DateTime | ||
{ | ||
/// <inheritdoc /> | ||
public class UtcNowVisitor : BaseUtcNowVisitor | ||
{ | ||
/// <inheritdoc /> | ||
public UtcNowVisitor(IExpressionVisitorFactory visitorFactory) | ||
: base(visitorFactory) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override SqlBuilder Visit(MemberExpression expression) | ||
{ | ||
return SqlBuilder.FromString("CURRENT_TIMESTAMP"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Laraue.EfCoreTriggers.SqlLite/Converters/MemberAccess/DateTime/NowVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Linq.Expressions; | ||
using Laraue.EfCoreTriggers.Common.Converters.MemberAccess.DateTime; | ||
using Laraue.EfCoreTriggers.Common.SqlGeneration; | ||
using Laraue.EfCoreTriggers.Common.Visitors.ExpressionVisitors; | ||
|
||
namespace Laraue.EfCoreTriggers.SqlLite.Converters.MemberAccess.DateTime | ||
{ | ||
/// <inheritdoc /> | ||
public class NowVisitor : BaseNowVisitor | ||
{ | ||
/// <inheritdoc /> | ||
public NowVisitor(IExpressionVisitorFactory visitorFactory) | ||
: base(visitorFactory) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override SqlBuilder Visit(MemberExpression expression) | ||
{ | ||
return SqlBuilder.FromString("DATETIME('now', 'localtime')"); | ||
} | ||
} | ||
} |
Oops, something went wrong.