-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Database] Query generator improvements: bulk insert, 'try' operations
- Loading branch information
Showing
62 changed files
with
1,738 additions
and
292 deletions.
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
Modules/WDE.QueryGenerators/Base/BaseInsertQueryProvider.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 WDE.SqlQueryGenerator; | ||
|
||
namespace WDE.QueryGenerators.Base; | ||
|
||
public abstract class BaseInsertQueryProvider<T> : IInsertQueryProvider<T> | ||
{ | ||
public IQuery Insert(T t) | ||
{ | ||
return Queries.Table(TableName).Insert(Convert(t)); | ||
} | ||
|
||
public IQuery BulkInsert(IReadOnlyCollection<T> collection) | ||
{ | ||
return Queries.Table(TableName).BulkInsert(collection.Select(Convert)); | ||
} | ||
|
||
protected abstract object Convert(T obj); | ||
|
||
public abstract string TableName { get; } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
using WDE.SqlQueryGenerator; | ||
using Extensions = AvaloniaStyles.Controls.Extensions; | ||
|
||
namespace WDE.QueryGenerators.Base; | ||
|
||
public interface IQueryGenerator<R> | ||
public interface IQueryGenerator<T> | ||
{ | ||
IQuery? Insert(R element); | ||
IQuery? Delete(R element); | ||
IQuery? Update(R element); | ||
IQuery? TryInsert(T element); | ||
IQuery? TryBulkInsert(IReadOnlyCollection<T> elements); | ||
IQuery? TryDelete(T element); | ||
IQuery? TryUpdate(T element); | ||
string? TableName { get; } | ||
} |
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
29 changes: 29 additions & 0 deletions
29
Modules/WDE.QueryGenerators/Base/NotSupportedQueryProvider.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,29 @@ | ||
using WDE.Module.Attributes; | ||
using WDE.SqlQueryGenerator; | ||
|
||
namespace WDE.QueryGenerators.Base; | ||
|
||
[AutoRegister] | ||
[SingleInstance] | ||
public abstract class NotSupportedQueryProvider<T> : IInsertQueryProvider<T>, IDeleteQueryProvider<T>, IUpdateQueryProvider<T> | ||
{ | ||
public abstract string TableName { get; } | ||
|
||
public IQuery Insert(T t) => throw new TableNotSupportedException(TableName); | ||
|
||
public IQuery BulkInsert(IReadOnlyCollection<T> collection) => throw new TableNotSupportedException(TableName); | ||
|
||
public IQuery Delete(T t) => throw new TableNotSupportedException(TableName); | ||
|
||
public IQuery Update(T diff) => throw new TableNotSupportedException(TableName); | ||
} | ||
|
||
public class TableNotSupportedException : Exception | ||
{ | ||
public string TableName { get; } | ||
|
||
public TableNotSupportedException(string tableName) : base("Currently selected database doesn't support table " + tableName) | ||
{ | ||
TableName = tableName; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace WDE.QueryGenerators.Base; | ||
|
||
public class QueryGeneratorException<T> : Exception | ||
{ | ||
public QueryGeneratorException(string updateName) : base($"{updateName} query generator for " + typeof(T).Name + " not found for selected core version") { } | ||
} |
Oops, something went wrong.