Skip to content

Commit

Permalink
using snake case instead of kebab casing for derived column names w/ …
Browse files Browse the repository at this point in the history
…flat projections. Closes GH-2778
  • Loading branch information
jeremydmiller committed Nov 30, 2023
1 parent 282e19c commit 497dde1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs/events/projections/flat.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public record ImportFinished(DateTimeOffset Finished);

public record ImportFailed;
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/FlatTableProjection.cs#L9-L26' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_flat_table_events' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/FlatTableProjection.cs#L12-L29' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_flat_table_events' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

At some point, we’re going to want to apply some metrics to the execution history to understand the average size of the
Expand Down Expand Up @@ -80,7 +80,7 @@ public class ImportSqlProjection: EventProjection
}
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/FlatTableProjection.cs#L30-L72' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_import_sql_projection' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/FlatTableProjection.cs#L33-L75' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_import_sql_projection' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

A couple notes about the code above:
Expand Down Expand Up @@ -156,7 +156,7 @@ public class FlatImportProjection: FlatTableProjection
}
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/FlatTableProjection.cs#L76-L129' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_flat_import_projection' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/FlatTableProjection.cs#L88-L141' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_flat_import_projection' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

A couple notes on this version of the code:
Expand Down
14 changes: 13 additions & 1 deletion src/Marten.Testing/Examples/FlatTableProjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
using Marten.Events;
using Marten.Events.Projections;
using Marten.Events.Projections.Flattened;
using Marten.Util;
using Shouldly;
using Weasel.Postgresql.Tables;
using Xunit;

namespace Marten.Testing.Examples;

Expand Down Expand Up @@ -72,6 +75,15 @@ public void Project(IEvent<ImportFailed> e, IDocumentOperations ops)
#endregion


public class KebabNamingTests
{
[Fact]
public void get_the_name_with_underscores()
{
"ActivityType".ToSnakeCase().ShouldBe("activity_type");
}
}


#region sample_flat_import_projection

Expand All @@ -89,7 +101,7 @@ public FlatImportProjection() : base("import_history", SchemaNameSource.EventSch
Project<ImportStarted>(map =>
{
// Set values in the table from the event
map.Map(x => x.ActivityType).NotNull();
map.Map(x => x.ActivityType);
map.Map(x => x.CustomerId);
map.Map(x => x.PlannedSteps, "total_steps")
.DefaultValue(0);
Expand Down
3 changes: 2 additions & 1 deletion src/Marten/Events/Projections/Flattened/MemberMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using JasperFx.CodeGeneration.Model;
using JasperFx.Core;
using Marten.Linq.Parsing;
using Marten.Util;
using Weasel.Postgresql.Tables;

namespace Marten.Events.Projections.Flattened;
Expand All @@ -21,7 +22,7 @@ public MemberMap(Expression<Func<TEvent, TMember>> members, string? tableColumn,
_members = MemberFinder.Determine(members);
_mapType = columnMapType;

ColumnName = tableColumn ?? _members.Select(x => x.Name.ToKebabCase()).Join("_");
ColumnName = tableColumn ?? _members.Select(x => x.Name.ToSnakeCase()).Join("_");
}

public string ColumnName { get; }
Expand Down

0 comments on commit 497dde1

Please sign in to comment.