Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed May 2, 2024
1 parent be97102 commit 236b682
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/YesSql.Core/Services/DefaultQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,16 +1396,16 @@ private string GetDeduplicatedQuery()
sqlBuilder.Selector(selector);
sqlBuilder.GroupBy(selector);

var aggregates = _query._dialect.GetAggregateOrders(sqlBuilder.GetSelectors().ToList(), sqlBuilder.GetOrders().ToList());
var results = _query._dialect.GetAggregateOrders(sqlBuilder.GetSelectors().ToList(), sqlBuilder.GetOrders().ToList());

if (sqlBuilder.HasOrder)
{
sqlBuilder.ClearOrder();
foreach (var aggregate in aggregates)
foreach (var result in results)
{
sqlBuilder.AddSelector(", ");
sqlBuilder.AddSelector(aggregate.aggregate);
sqlBuilder.ThenOrderBy(aggregate.alias);
sqlBuilder.AddSelector(result.aggregate);
sqlBuilder.ThenOrderBy(result.alias);
}

// Add a 0 offset if not offset was specified as it might be required by the RDBMS
Expand All @@ -1423,7 +1423,7 @@ private string GetDeduplicatedQuery()

if (sqlBuilder.HasOrder)
{
sql += $" ORDER BY {string.Join(", ", aggregates.Select(x => x.alias).ToList())}";
sql += $" ORDER BY {string.Join(", ", results.Select(x => x.alias).ToList())}";
}

return sql;
Expand Down
7 changes: 6 additions & 1 deletion src/YesSql.Core/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,12 @@ public IQuery<T> ExecuteQuery<T>(ICompiledQuery<T> compiledQuery, string collect

private void CheckDisposed()
{
ObjectDisposedException.ThrowIf(true, _disposed);
#pragma warning disable CA1513 // Use ObjectDisposedException throw helper
if (_disposed)
{
throw new ObjectDisposedException(nameof(Session));
}
#pragma warning restore CA1513 // Use ObjectDisposedException throw helper
}

~Session()
Expand Down
26 changes: 13 additions & 13 deletions test/YesSql.Tests/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task InitializeAsync()
await _store.InitializeCollectionAsync("Col1");
_store.TypeNames[typeof(Person)] = "People";

await CreateTablesAsync(_configuration);
await CoreTests.CreateTablesAsync(_configuration);
}
else
{
Expand Down Expand Up @@ -204,7 +204,7 @@ protected virtual Task OnCleanDatabaseAsync(SchemaBuilder builder, DbTransaction
protected virtual Task OnClearTablesAsync(DbConnection connection)
=> Task.CompletedTask;

public async Task CreateTablesAsync(IConfiguration configuration)
public static async Task CreateTablesAsync(IConfiguration configuration)
{
await using var connection = configuration.ConnectionFactory.CreateConnection();
await connection.OpenAsync();
Expand Down Expand Up @@ -1346,11 +1346,11 @@ public async Task ShouldQueryInnerSelect()

await using (var session = _store.CreateSession())
{
Assert.Equal(1, await session.Query<Person, PersonByAge>().Where(x => x.Name.IsIn<PersonByName>(y => y.SomeName, y => y.SomeName.StartsWith("B") || y.SomeName.StartsWith("C"))).CountAsync());
Assert.Equal(2, await session.Query<Person, PersonByAge>().Where(x => x.Name.IsIn<PersonByName>(y => y.SomeName, y => y.SomeName.StartsWith("B") || y.SomeName.Contains("lo"))).CountAsync());
Assert.Equal(1, await session.Query<Person, PersonByAge>().Where(x => x.Name.IsIn<PersonByName>(y => y.SomeName, y => y.SomeName.StartsWith('B') || y.SomeName.StartsWith('C'))).CountAsync());
Assert.Equal(2, await session.Query<Person, PersonByAge>().Where(x => x.Name.IsIn<PersonByName>(y => y.SomeName, y => y.SomeName.StartsWith('B') || y.SomeName.Contains("lo"))).CountAsync());

Assert.Equal(1, await session.Query<Person, PersonByAge>().Where(x => x.Name.IsNotIn<PersonByName>(y => y.SomeName, y => y.SomeName.StartsWith("B") || y.SomeName.StartsWith("C"))).CountAsync());
Assert.Equal(0, await session.Query<Person, PersonByAge>().Where(x => x.Name.IsNotIn<PersonByName>(y => y.SomeName, y => y.SomeName.StartsWith("B") || y.SomeName.Contains("lo"))).CountAsync());
Assert.Equal(1, await session.Query<Person, PersonByAge>().Where(x => x.Name.IsNotIn<PersonByName>(y => y.SomeName, y => y.SomeName.StartsWith('B') || y.SomeName.StartsWith('C'))).CountAsync());
Assert.Equal(0, await session.Query<Person, PersonByAge>().Where(x => x.Name.IsNotIn<PersonByName>(y => y.SomeName, y => y.SomeName.StartsWith('B') || y.SomeName.Contains("lo"))).CountAsync());
}
}

Expand Down Expand Up @@ -1966,19 +1966,19 @@ public async Task ShouldOrderJoinedMapIndexes()
await using (var session = _store.CreateSession())
{
Assert.Equal(2, await session.Query().For<Person>()
.With<PersonByName>(x => x.SomeName.StartsWith("S"))
.With<PersonByName>(x => x.SomeName.StartsWith('S'))
.With<PersonByAge>(x => x.Age == 2)
.CountAsync());

Assert.Equal("Scott", (await session.Query().For<Person>()
.With<PersonByName>(x => x.SomeName.StartsWith("S"))
.With<PersonByName>(x => x.SomeName.StartsWith('S'))
.OrderBy(x => x.SomeName)
.With<PersonByAge>(x => x.Age == 2)
.FirstOrDefaultAsync())
.Firstname);

Assert.Equal("Steve", (await session.Query().For<Person>()
.With<PersonByName>(x => x.SomeName.StartsWith("S"))
.With<PersonByName>(x => x.SomeName.StartsWith('S'))
.OrderByDescending(x => x.SomeName)
.With<PersonByAge>(x => x.Age == 2)
.FirstOrDefaultAsync())
Expand Down Expand Up @@ -2108,9 +2108,9 @@ public async Task JoinOrderShouldNotMatter()
await using (var session = _store.CreateSession())
{
Assert.Equal("Steve", (await session.Query().For<Person>()
.With<PersonByName>(x => x.SomeName.StartsWith("S"))
.With<PersonByName>(x => x.SomeName.StartsWith('S'))
.With<PersonByAge>(x => x.Age == 2)
.With<PersonByName>(x => x.SomeName.EndsWith("e"))
.With<PersonByName>(x => x.SomeName.EndsWith('e'))
.FirstOrDefaultAsync()).Firstname);
}
}
Expand Down Expand Up @@ -4180,9 +4180,9 @@ public async Task ShouldQueryInnerSelectWithCollection()
Assert.Equal(1, await session.Query<Person, PersonByNameCol>(x => x.Name == "Bill", "Col1").CountAsync());
Assert.Equal(1, await session.Query<Person, PersonByBothNamesCol>(x => x.Lastname == "Gates", "Col1").CountAsync());

Assert.Equal(1, await session.Query<Person, PersonByNameCol>(collection: "Col1").Where(x => x.Name.IsIn<PersonByBothNamesCol>(y => y.Firstname, y => y.Lastname.StartsWith("G"))).CountAsync());
Assert.Equal(1, await session.Query<Person, PersonByNameCol>(collection: "Col1").Where(x => x.Name.IsIn<PersonByBothNamesCol>(y => y.Firstname, y => y.Lastname.StartsWith('G'))).CountAsync());

Assert.Equal(0, await session.Query<Person, PersonByNameCol>(collection: "Col1").Where(x => x.Name.IsNotIn<PersonByBothNamesCol>(y => y.Firstname, y => y.Lastname.StartsWith("G") || y.Lastname.StartsWith("M"))).CountAsync());
Assert.Equal(0, await session.Query<Person, PersonByNameCol>(collection: "Col1").Where(x => x.Name.IsNotIn<PersonByBothNamesCol>(y => y.Firstname, y => y.Lastname.StartsWith('G') || y.Lastname.StartsWith('M'))).CountAsync());

Assert.Equal(2, await session.Query<Person, PersonByNameCol>(collection: "Col1").Where(x => x.Name.IsInAny<PersonByBothNamesCol>(y => y.Firstname)).CountAsync());
Assert.Equal(0, await session.Query<Person, PersonByNameCol>(collection: "Col1").Where(x => x.Name.IsNotInAny<PersonByBothNamesCol>(y => y.Firstname)).CountAsync());
Expand Down

0 comments on commit 236b682

Please sign in to comment.