Skip to content

Commit c4c5329

Browse files
committed
[ksqlDb.RestApi.Client]: added IgnoreInDML function to the fluent API documentation sections #90
1 parent 45cad72 commit c4c5329

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

docs/ksqldbrestapiclient.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,3 +1311,22 @@ var restApiClientOptions = new KSqlDBRestApiClientOptions
13111311
};
13121312
servicesCollection.AddSingleton(restApiClientOptions);
13131313
```
1314+
1315+
1316+
## IgnoreAttribute
1317+
**v6.4.0**
1318+
1319+
Properties and fields decorated with the `IgnoreAttribute` are excluded from both DDL and DML statements.
1320+
1321+
```C#
1322+
public class Movie
1323+
{
1324+
[ksqlDB.RestApi.Client.KSql.RestApi.Statements.Annotations.Key]
1325+
public int Id { get; set; }
1326+
public string Title { get; set; }
1327+
public int Release_Year { get; set; }
1328+
1329+
[ksqlDB.RestApi.Client.KSql.RestApi.Statements.Annotations.Ignore]
1330+
public int IgnoredProperty { get; set; }
1331+
}
1332+
```

docs/modelbuilder.md

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ public static async Task InitModelAndCreateTableAsync(CancellationToken cancella
3434
BaseAddress = new Uri("http://localhost:8088")
3535
};
3636
var httpClientFactory = new HttpClientFactory(httpClient);
37-
var restApiProvider = new KSqlDbRestApiClient(httpClientFactory, builder);
37+
var restApiClient = new KSqlDbRestApiClient(httpClientFactory, builder);
3838

3939
var entityCreationMetadata = new EntityCreationMetadata(kafkaTopic: nameof(Payment), partitions: 3);
4040

41-
var responseMessage = await restApiProvider.CreateTableAsync<Payment>(entityCreationMetadata, true, cancellationToken);
41+
var responseMessage = await restApiClient.CreateTableAsync<Payment>(entityCreationMetadata, true, cancellationToken);
4242
var content = await responseMessage.Content.ReadAsStringAsync(cancellationToken);
4343

4444
entityCreationMetadata = new EntityCreationMetadata(kafkaTopic: nameof(Account), partitions: 1)
4545
{
4646
Replicas = 3
4747
};
48-
responseMessage = await restApiProvider.CreateTableAsync<Account>(entityCreationMetadata, true, cancellationToken);
48+
responseMessage = await restApiClient.CreateTableAsync<Account>(entityCreationMetadata, true, cancellationToken);
4949
}
5050
```
5151

@@ -189,7 +189,7 @@ var entityCreationMetadata = new EntityCreationMetadata(kafkaTopic: nameof(PocoW
189189
{
190190
Replicas = 3
191191
};
192-
var responseMessage = await restApiProvider.CreateStreamAsync<PocoWithHeader>(entityCreationMetadata, true);
192+
var responseMessage = await restApiClient.CreateStreamAsync<PocoWithHeader>(entityCreationMetadata, true);
193193

194194
private record PocoWithHeader
195195
{
@@ -317,3 +317,53 @@ CREATE TABLE IF NOT EXISTS Records (
317317
Headers ARRAY<STRUCT<Key VARCHAR, Value BYTES>>
318318
) WITH ( KAFKA_TOPIC='my_topic', VALUE_FORMAT='Json', PARTITIONS='3' );
319319
```
320+
321+
### IgnoreInDML
322+
**v6.4.0**
323+
324+
The purpose of the `IgnoreInDML` function is to exclude specific fields from INSERT statements.
325+
326+
```C#
327+
using System.ComponentModel.DataAnnotations;
328+
329+
public class Actor
330+
{
331+
[Key]
332+
public int Id { get; set; }
333+
public string Name { get; set; } = null!;
334+
}
335+
```
336+
337+
```C#
338+
using ksqlDb.RestApi.Client.FluentAPI.Builders;
339+
using ksqlDB.RestApi.Client.KSql.Query.Context;
340+
using ksqlDB.RestApi.Client.KSql.RestApi;
341+
using ksqlDB.RestApi.Client.KSql.RestApi.Http;
342+
343+
var ksqlDbUrl = "http://localhost:8088";
344+
345+
var httpClientFactory = new HttpClientFactory(new HttpClient() { BaseAddress = new Uri(ksqlDbUrl) });
346+
347+
var restApiClientOptions = new KSqlDBRestApiClientOptions
348+
{
349+
ShouldPluralizeFromItemName = false,
350+
};
351+
352+
var restApiClient = new KSqlDbRestApiClient(httpClientFactory, restApiClientOptions);
353+
354+
var modelBuilder = new ModelBuilder();
355+
modelBuilder.Entity<Actor>()
356+
.Property(c => c.Name)
357+
.IgnoreInDML();
358+
359+
var actor = new Actor { Id = 1, Name = "Matthew David McConaughey" };
360+
361+
var ksql = restApiClient.ToInsertStatement(actor);
362+
```
363+
364+
Generated KSQL:
365+
```SQL
366+
INSERT INTO Actor (Id) VALUES (1);
367+
```
368+
369+
`WithHeaders` internally automatically marks the property to be ignored in DML statements.

0 commit comments

Comments
 (0)