Skip to content

Commit

Permalink
Alpha version
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaferlez committed Apr 8, 2024
1 parent 584ff8d commit f9003b3
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public class IdentityQueryFilter
{
public string Name { get; set; }
public virtual string Name { get; set; }
}
}
114 changes: 108 additions & 6 deletions src/Simpleverse.Repository.Db/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Dapper.Contrib.Extensions;
using Simpleverse.Repository.ChangeTracking;
using Simpleverse.Repository.Db.Extensions.Dapper;
using Simpleverse.Repository.Db.Meta;
using Simpleverse.Repository.Db.Operations;
using Simpleverse.Repository.Db.SqlServer;
using Simpleverse.Repository.Db.SqlServer.Merge;
Expand Down Expand Up @@ -161,11 +162,62 @@ protected void Query(QueryBuilder<TModel> builder, TFilter filter)
Filter(builder, filter);
}

protected virtual void Filter(QueryBuilder<TModel> builder, TFilter filter) { }
//protected virtual void Filter(QueryBuilder<TModel> builder, TFilter filter) { }

//protected virtual TFilter GetFilter(Action<TFilter> filterSetup)
//{
// return filterSetup.Get(() => Activator.CreateInstance<TFilter>());
//}
protected virtual TFilter GetFilter(Action<TFilter> filterSetup)
{
return filterSetup.Get(() => Activator.CreateInstance<TFilter>());
return filterSetup.Get(
() => ChangeProxyFactory.Create<TFilter>()
);
}

protected virtual void Filter(QueryBuilder<TModel> builder, TFilter filter)
{
var changeTrack = filter as IChangeTrack;
if (changeTrack == null)
return;

foreach (var propertyName in changeTrack.Changed)
{
var property = builder.Table.Meta.Properties.SingleOrDefault(x => x.Name == propertyName);
if (property is null)
continue;

var column = builder.Table.Column(property.Name);

var filterProperty = TypeMeta.Get<TFilter>().Properties.Single(x => x.Name == propertyName);
var value = filterProperty.GetValue(filter);

if (value is null)
{
builder.WhereNull(column);
}
else if (value is string stringValue)
{
builder.Where(
column,
stringValue
);
}
else if (value is DateTime dateTimeValue)
{
builder.Where(
column,
dateTimeValue
);
}
else
{
builder.Where(
column,
value
);
}
}
}

#endregion
Expand Down Expand Up @@ -283,15 +335,65 @@ protected virtual SqlBuilder.Template UpdateTemplate(QueryBuilder<TModel> builde
return builder.AsUpdate();
}

//protected virtual void Set(QueryBuilder<TModel> builder, TUpdate update)
//{
// if (update is UpdateOptions<TModel> updateOptions)
// updateOptions.Apply(builder);
//}

//protected virtual TUpdate GetUpdate(Action<TUpdate> updateSetup)
//{
// return updateSetup.Get(() => Activator.CreateInstance<TUpdate>());
//}
protected virtual TUpdate GetUpdate(Action<TUpdate> updateSetup)
{
return updateSetup.Get(
() => ChangeProxyFactory.Create<TUpdate>()
);
}

protected virtual void Set(QueryBuilder<TModel> builder, TUpdate update)
{
if (update is UpdateOptions<TModel> updateOptions)
updateOptions.Apply(builder);
}

protected virtual TUpdate GetUpdate(Action<TUpdate> updateSetup)
{
return updateSetup.Get(() => Activator.CreateInstance<TUpdate>());
var changeTrack = update as IChangeTrack;
if (changeTrack == null)
return;

foreach (var propertyName in changeTrack.Changed)
{
var property = builder.Table.Meta.Properties.FirstOrDefault(x => x.Name == propertyName);
if (property is null)
continue;

var column = builder.Table.Column(property.Name);

var updateProperty = TypeMeta.Get<TUpdate>().Properties.Single(x => x.Name == propertyName);
var value = updateProperty.GetValue(update);

if (value is string stringValue)
{
builder.Set(
column,
stringValue
);
}
else if (value is DateTime dateTimeValue)
{
builder.Set(
column,
dateTimeValue
);
}
else
{
builder.Set(
column,
value
);
}
}
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>2.1.0-alpha</Version>
<Description>High performance operation for MS SQL Server built for Dapper ORM. Including bulk operations Insert, Update, Delete, Get as well as Upsert both single and bulk.</Description>
<AssemblyVersion>2.1.0-alpha</AssemblyVersion>
<FileVersion>2.1.0-alpha</FileVersion>
<AssemblyVersion>2.1.0.1</AssemblyVersion>
<FileVersion>2.1.0.1</FileVersion>
<RepositoryUrl>https://github.com/lukaferlez/Simpleverse.Repository</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<EmbedAllSources>true</EmbedAllSources>
Expand Down
6 changes: 3 additions & 3 deletions src/Simpleverse.Repository/Simpleverse.Repository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>Repository</PackageTags>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>1.0.10-alpha</Version>
<Version>1.1.0-alpha</Version>
<Description>Base repository elements.</Description>
<AssemblyVersion>1.0.10-alpha</AssemblyVersion>
<FileVersion>1.0.10-alpha</FileVersion>
<AssemblyVersion>1.1.0.1</AssemblyVersion>
<FileVersion>1.1.0.1</FileVersion>
<RepositoryUrl>https://github.com/lukaferlez/Simpleverse.Repository</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
Expand Down

0 comments on commit f9003b3

Please sign in to comment.