Skip to content

Commit 55fc3b9

Browse files
committed
[ksqlDb.RestApi.Client]: added AsStruct to Fluent API documentation section #89
1 parent 0455d00 commit 55fc3b9

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

docs/modelbuilder.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,34 @@ CREATE TABLE IF NOT EXISTS Accounts (
9696
) WITH ( KAFKA_TOPIC='Account', VALUE_FORMAT='Json', PARTITIONS='1', REPLICAS='3' );
9797
```
9898

99+
## Dependency injection
100+
This setup ensures that the `ksqlDB` client, context, and model configuration are properly injected throughout your application.
101+
102+
```C#
103+
using ksqlDb.RestApi.Client.DependencyInjection;
104+
using ksqlDb.RestApi.Client.FluentAPI.Builders;
105+
using ksqlDB.RestApi.Client.KSql.Query.Options;
106+
using ksqlDB.RestApi.Client.KSql.RestApi.Enums;
107+
108+
var builder = WebApplication.CreateBuilder(args);
109+
110+
ModelBuilder modelBuilder = new();
111+
112+
builder.Services.ConfigureKSqlDb(
113+
builder.Configuration.GetConnectionString("KafkaConnection")!,
114+
parameters =>
115+
{
116+
parameters
117+
.SetAutoOffsetReset(AutoOffsetReset.Latest)
118+
.SetIdentifierEscaping(IdentifierEscaping.Always)
119+
.SetJsonSerializerOptions(options =>
120+
{
121+
options.PropertyNameCaseInsensitive = true;
122+
});
123+
}
124+
).AddSingleton(modelBuilder);
125+
```
126+
99127
## IFromItemTypeConfiguration
100128
**v5.0.0**
101129

@@ -248,3 +276,44 @@ The KSQL snippet illustrates an example INSERT statement with the overridden col
248276
INSERT INTO Payments (Id, Amount, Desc)
249277
VALUES ('1', 33, 'Purchase');
250278
```
279+
280+
### AsSource
281+
**v6.2.0**
282+
283+
The `AsSource` function designates fields in entity types as ksqlDB struct types.
284+
285+
The following code showcases how to use the `AsSource` method in the fluent API to infer the underlying `ksqlDB` type as a struct during code generation:
286+
287+
```C#
288+
private record KeyValuePair
289+
{
290+
public string Key { get; set; } = null!;
291+
public byte[] Value { get; set; } = null!;
292+
}
293+
294+
private record Record
295+
{
296+
public KeyValuePair[] Headers { get; init; } = null!;
297+
}
298+
```
299+
300+
```C#
301+
ModelBuilder builder = new();
302+
303+
builder.Entity<Record>()
304+
.Property(b => b.Headers)
305+
.AsStruct();
306+
307+
var creationMetadata = new EntityCreationMetadata("my_topic", partitions: 3);
308+
309+
var ksql = new StatementGenerator(builder).CreateTable<Record>(creationMetadata, ifNotExists: true);
310+
```
311+
312+
The KSQL snippet illustrates an example CREATE TABLE statement with the injected `STRUCT` type,
313+
showing how it corresponds to the fluent API configuration:
314+
315+
```SQL
316+
CREATE TABLE IF NOT EXISTS Records (
317+
Headers ARRAY<STRUCT<Key VARCHAR, Value BYTES>>
318+
) WITH ( KAFKA_TOPIC='my_topic', VALUE_FORMAT='Json', PARTITIONS='3' );
319+
```

ksqlDb.RestApi.Client/ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ksqlDB.RestApi.Client
22

33
# 6.3.0-rc.1
4-
- added `AsStruct` function to the Fluent API for marking fields as ksqldb `STRUCT` types
4+
- added `AsStruct` function to the Fluent API for marking fields as ksqldb `STRUCT` types #89 (proposed by @mrt181)
55

66
# 6.2.1
77

0 commit comments

Comments
 (0)