Skip to content

Commit

Permalink
#15 - DynamoDB Query should use unmodified values rather than convert…
Browse files Browse the repository at this point in the history
…ing to string (closes #15) (#16)
  • Loading branch information
Yuck committed Aug 3, 2023
1 parent b16f057 commit f2d2a77
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;
using YuckQi.Data.Filtering;

Expand All @@ -14,15 +13,53 @@ public static QueryFilter ToQueryFilter(this IReadOnlyCollection<FilterCriteria>
foreach (var parameter in parameters)
{
var attribute = parameter.FieldName;
var comparison = parameter.Operation.ToComparisonOperator();
var value = new AttributeValue(parameter.Value?.ToString());
var condition = new Condition
{
AttributeValueList = new List<AttributeValue> { value },
ComparisonOperator = comparison
};
var comparison = parameter.Operation.ToQueryOperator();

filter.AddCondition(attribute, condition);
switch (parameter.Value)
{
case Boolean value:
filter.AddCondition(attribute, comparison, value);
break;
case Char value:
filter.AddCondition(attribute, comparison, value);
break;
case Byte value:
filter.AddCondition(attribute, comparison, value);
break;
case Decimal value:
filter.AddCondition(attribute, comparison, value);
break;
case Double value:
filter.AddCondition(attribute, comparison, value);
break;
case Int16 value:
filter.AddCondition(attribute, comparison, value);
break;
case Int32 value:
filter.AddCondition(attribute, comparison, value);
break;
case Int64 value:
filter.AddCondition(attribute, comparison, value);
break;
case SByte value:
filter.AddCondition(attribute, comparison, value);
break;
case Single value:
filter.AddCondition(attribute, comparison, value);
break;
case String value:
filter.AddCondition(attribute, comparison, value);
break;
case UInt16 value:
filter.AddCondition(attribute, comparison, value);
break;
case UInt32 value:
filter.AddCondition(attribute, comparison, value);
break;
case UInt64 value:
filter.AddCondition(attribute, comparison, value);
break;
}
}

return filter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DocumentModel;
using YuckQi.Data.Filtering;

namespace YuckQi.Data.DocumentDb.DynamoDb.Extensions;
Expand All @@ -20,4 +20,17 @@ public static ComparisonOperator ToComparisonOperator(this FilterOperation opera
_ => throw new ArgumentOutOfRangeException(nameof(operation), operation, null)
};
}

public static QueryOperator ToQueryOperator(this FilterOperation operation)
{
return operation switch
{
FilterOperation.Equal => QueryOperator.Equal,
FilterOperation.GreaterThan => QueryOperator.GreaterThan,
FilterOperation.GreaterThanOrEqual => QueryOperator.GreaterThanOrEqual,
FilterOperation.LessThan => QueryOperator.LessThan,
FilterOperation.LessThanOrEqual => QueryOperator.LessThanOrEqual,
_ => throw new ArgumentOutOfRangeException(nameof(operation), operation, null)
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.3</Version>
<Version>6.3.4</Version>
<Description>An implementation of YuckQi.Data for Amazon DynamoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.3</Version>
<Version>6.3.4</Version>
<Description>An implementation of YuckQi.Data for MongoDB databases.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data.MemDb/YuckQi.Data.MemDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.3</Version>
<Version>6.3.4</Version>
<Description>An implementation of YuckQi.Data for a in-memory "database" (ConcurrentDictionary), ideal for rapid development without external dependencies.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.3</Version>
<Version>6.3.4</Version>
<Description>An implementation of YuckQi.Data for MySQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.3</Version>
<Version>6.3.4</Version>
<Description>An implementation of YuckQi.Data for Oracle databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.3</Version>
<Version>6.3.4</Version>
<Description>An implementation of YuckQi.Data for MSSQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data.Sql.Dapper/YuckQi.Data.Sql.Dapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.3</Version>
<Version>6.3.4</Version>
<Description>An implementation of YuckQi.Data for SQL databases using Dapper and SimpleCRUD.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.3</Version>
<Version>6.3.4</Version>
<Description>An implementation of YuckQi.Data for SQL databases using Entity Framework.</Description>
<Product>YuckQi.Data</Product>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Data/YuckQi.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>6.3.3</Version>
<Version>6.3.4</Version>
<Description>A .NET library of lightweight data access handlers which can be used to compose repositories and domain services.</Description>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Data.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down

0 comments on commit f2d2a77

Please sign in to comment.