tomasfabian / ksqlDB.RestApi.Client-DotNet

ksqlDb.RestApi.Client is a C# LINQ-enabled client API for issuing and consuming ksqlDB push and pull queries and executing statements.
MIT License
93 stars 24 forks source link

Feature/insert function values #42

Closed tomasfabian closed 1 year ago

tomasfabian commented 1 year ago

This PR extends the library with enabling custom KSQL functions in the following manner:

var insertValues = new InsertValues<Article>(new Article())
  .WithValue(c => c.Release_Date, FormatTimestamp(FROM_UNIXTIME(UnixTimestamp()), "yyyy"));

var insertStatement = ClassUnderTest.ToInsertStatement(insertValues);
[KSqlFunction]
public static string FormatTimestamp(long input, string format) => throw new NotSupportedException();

[KSqlFunction]
public static long FROM_UNIXTIME(long milliseconds) => throw new NotSupportedException();

[KSqlFunction]
public static long UnixTimestamp() => throw new NotSupportedException();

private struct Article
{
  [IgnoreByInserts]
  public long RowTime { get; set; }
  public string Title { get; set; }
  [Key]
  public int Id { get; set; }
  public string Release_Date { get; set; }
}