Skip to content

Commit

Permalink
Add Schema to IndexCommand CompoundKey (#501)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastien Ros <sebastienros@gmail.com>
  • Loading branch information
jtkech and sebastienros authored Oct 11, 2023
1 parent c1ac054 commit af36b67
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 104 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ jobs:
steps:
- uses: actions/checkout@v3

# as of 12/2022, 3.1 and 5.0 are not installed by default on the images
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
3.1.x
5.0.x
# Required if the .NET version is not available on the GH Actions images
# - uses: actions/setup-dotnet@v3
# with:
# dotnet-version: |
# 6.0.x
# 7.0.x

- name: Build
run: dotnet build --configuration Release
Expand All @@ -64,12 +64,6 @@ jobs:
- name: Test - Sqlite .NET 6.0
run: dotnet test --configuration Release --filter YesSql.Tests.SqliteTests --no-restore --no-build --framework net6.0

- name: Test - Sqlite .NET 5.0
run: dotnet test --configuration Release --filter YesSql.Tests.SqliteTests --no-restore --no-build --framework net5.0

- name: Test - Sqlite .NET 3.1
run: dotnet test --configuration Release --filter YesSql.Tests.SqliteTests --no-restore --no-build --framework netcoreapp3.1

- name: Test - PostgresQL .NET 7.0
run: dotnet test --configuration Release --filter YesSql.Tests.PostgreSqlTests --no-restore --no-build --framework net7.0

Expand Down
18 changes: 6 additions & 12 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ jobs:
steps:
- uses: actions/checkout@v3

# as of 12/2022, 3.1 and 5.0 are not installed by default on the images
- uses: actions/setup-dotnet@v3
with:
dotnet-version: |
3.1.x
5.0.x
# Required if the .NET version is not available on the GH Actions images
# - uses: actions/setup-dotnet@v3
# with:
# dotnet-version: |
# 6.0.x
# 7.0.x

- name: Build
run: dotnet build --configuration Release
Expand All @@ -65,12 +65,6 @@ jobs:
- name: Test - Sqlite .NET 6.0
run: dotnet test --configuration Release --filter YesSql.Tests.SqliteTests --no-restore --no-build --framework net6.0

- name: Test - Sqlite .NET 5.0
run: dotnet test --configuration Release --filter YesSql.Tests.SqliteTests --no-restore --no-build --framework net5.0

- name: Test - Sqlite .NET 3.1
run: dotnet test --configuration Release --filter YesSql.Tests.SqliteTests --no-restore --no-build --framework netcoreapp3.1

- name: Test - PostgresQL .NET 7.0
run: dotnet test --configuration Release --filter YesSql.Tests.PostgreSqlTests --no-restore --no-build --framework net7.0

Expand Down
2 changes: 1 addition & 1 deletion samples/YesSql.Bench/YesSql.Bench.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<DebugType>portable</DebugType>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>YesSql.Bench</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<DebugType>portable</DebugType>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>YesSql.Samples.FullText</AssemblyName>
Expand Down
2 changes: 1 addition & 1 deletion samples/YesSql.Samples.Hi/YesSql.Samples.Hi.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<DebugType>portable</DebugType>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>YesSql.Samples.Hi</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<AssemblyName>YesSql.Samples.Performance</AssemblyName>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
Expand Down
4 changes: 2 additions & 2 deletions samples/YesSql.Samples.Web/YesSql.Samples.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Copyright>Sebastien Ros</Copyright>
<Authors>Sebastien Ros</Authors>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>portable</DebugType>
<PackageProjectUrl>https://github.com/sebastienros/yessql</PackageProjectUrl>
Expand Down
76 changes: 18 additions & 58 deletions src/YesSql.Core/Commands/IndexCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ protected static PropertyInfo[] TypePropertiesCache(Type type)

protected string Inserts(Type type, ISqlDialect dialect)
{
var key = new CompoundKey(dialect.Name, type.FullName, _store.Configuration.TablePrefix, Collection);
var key = new CompoundKey(
dialect.Name,
type.FullName,
_store.Configuration.Schema,
_store.Configuration.TablePrefix,
Collection);

if (!InsertsList.TryGetValue(key, out var result))
{
Expand All @@ -91,22 +96,22 @@ protected string Inserts(Type type, ISqlDialect dialect)
{
var sbColumnList = new StringBuilder(null);

for (var i = 0; i < allProperties.Count(); i++)
for (var i = 0; i < allProperties.Length; i++)
{
var property = allProperties.ElementAt(i);
sbColumnList.Append(dialect.QuoteForColumnName(property.Name));
if (i < allProperties.Count() - 1)
if (i < allProperties.Length - 1)
{
sbColumnList.Append(", ");
}
}

var sbParameterList = new StringBuilder(null);
for (var i = 0; i < allProperties.Count(); i++)
for (var i = 0; i < allProperties.Length; i++)
{
var property = allProperties.ElementAt(i);
sbParameterList.Append("@").Append(property.Name).Append(ParameterSuffix);
if (i < allProperties.Count() - 1)
if (i < allProperties.Length - 1)
{
sbParameterList.Append(", ");
}
Expand Down Expand Up @@ -136,12 +141,17 @@ protected string Inserts(Type type, ISqlDialect dialect)
InsertsList[key] = result = $"insert into {dialect.QuoteForTableName(_store.Configuration.TablePrefix + _store.Configuration.TableNameConvention.GetIndexTable(type, Collection), _store.Configuration.Schema)} {values} {dialect.IdentitySelectString} {dialect.QuoteForColumnName("Id")};";
}

return result;
return result;
}

protected string Updates(Type type, ISqlDialect dialect)
{
var key = new CompoundKey(dialect.Name, type.FullName, _store.Configuration.TablePrefix, Collection);
var key = new CompoundKey(
dialect.Name,
type.FullName,
_store.Configuration.Schema,
_store.Configuration.TablePrefix,
Collection);

if (!UpdatesList.TryGetValue(key, out var result))
{
Expand Down Expand Up @@ -176,56 +186,6 @@ private static bool IsWriteable(PropertyInfo pi)

public abstract bool AddToBatch(ISqlDialect dialect, List<string> queries, DbCommand batchCommand, List<Action<DbDataReader>> actions, int index);

public struct CompoundKey : IEquatable<CompoundKey>
{
private readonly string _key1;
private readonly string _key2;
private readonly string _key3;
private readonly string _key4;

public CompoundKey(string key1, string key2, string key3, string key4)
{
_key1 = key1;
_key2 = key2;
_key3 = key3;
_key4 = key4;
}

/// <inheritdoc />
public override bool Equals(object obj)
{
if (obj is CompoundKey other)
{
return Equals(other);
}

return false;
}

/// <inheritdoc />
public bool Equals(CompoundKey other)
{
return String.Equals(_key1, other._key1)
&& String.Equals(_key2, other._key2)
&& String.Equals(_key3, other._key3)
&& String.Equals(_key4, other._key4)
;
}

/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = 13;
hashCode = (hashCode * 397) ^ (!string.IsNullOrEmpty(_key1) ? _key1.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (!string.IsNullOrEmpty(_key2) ? _key2.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (!string.IsNullOrEmpty(_key3) ? _key3.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (!string.IsNullOrEmpty(_key4) ? _key4.GetHashCode() : 0);

return hashCode;
}
}
}
private record CompoundKey(string Dialect, string Type, string Schema, string Prefix, string Collection);
}
}
4 changes: 0 additions & 4 deletions src/YesSql.Core/Provider/BaseDialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,7 @@ public virtual string GetAddForeignKeyConstraintString(string name, string[] src
res.Append(" constraint ")
.Append(name)
.Append(" foreign key (")
#if NETSTANDARD2_1
.AppendJoin(", ", srcColumns)
#else
.Append(String.Join(", ", srcColumns))
#endif
.Append(") references ")
.Append(destQuotedTable);

Expand Down
7 changes: 1 addition & 6 deletions src/YesSql.Core/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,14 +1375,9 @@ public async Task<DbTransaction> BeginTransactionAsync(IsolationLevel isolationL
{
await CreateConnectionAsync();

// In the case of shared connections (InMemory) this can throw as the transation
// In the case of shared connections (InMemory) this can throw as the transaction
// might already be set by a concurrent thread on the same shared connection.
#if SUPPORTS_ASYNC_TRANSACTIONS
_transaction = await _connection.BeginTransactionAsync(isolationLevel);
#else
_transaction = _connection.BeginTransaction(isolationLevel);
#endif

}

return _transaction;
Expand Down
6 changes: 3 additions & 3 deletions test/YesSql.Tests/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ public async Task ShouldSupportAsyncEnumerable()
results.Add(person);
}

Assert.Equal(2, results.Count());
Assert.Equal(2, results.Count);
}
}

Expand Down Expand Up @@ -3825,7 +3825,7 @@ public virtual async Task ShouldReadCommittedRecords()
* session2 1 index found (session1 statements isolated)
* session2 save and commit person
* session2 2 index found (session2 statements flushed)
* session2 disposed (session2 transation committed)
* session2 disposed (session2 transaction committed)
* session2 2 index found
* session1 2 index found
*/
Expand Down Expand Up @@ -3924,7 +3924,7 @@ public virtual async Task ShouldReadUncommittedRecords()
* session2 1 index found (session1 statements isolated)
* session2 save and commit person
* session2 2 index found (session2 statements flushed)
* session2 disposed (session2 transation committed)
* session2 disposed (session2 transaction committed)
* session2 2 index found
* session1 disposed
* session1 2 index found
Expand Down
2 changes: 1 addition & 1 deletion test/YesSql.Tests/Indexes/AttachmentByDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override void Describe(DescribeContext<Email> context)
.Map(email => new AttachmentByDay
{
Date = email.Date.DayOfYear,
Count = email.Attachments.Count()
Count = email.Attachments.Count
})
.Group(email => email.Date)
.Reduce(group => new AttachmentByDay
Expand Down
2 changes: 1 addition & 1 deletion test/YesSql.Tests/YesSql.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<AssemblyName>YesSql.Tests</AssemblyName>
<PackageId>YesSql.Tests</PackageId>
Expand Down

0 comments on commit af36b67

Please sign in to comment.