ClickHouseFixedStringToStringPropertyHandler
A property handler that maps the ClickHouse FixedString(N) type into a string property without the trailing NUL padding.
A property handler that maps the ClickHouse FixedString(N) type into a string property. ClickHouse pads a shorter value with trailing NUL (\0) characters up to N bytes; this handler removes that padding when reading, so the property holds the original text.
Overview
| Name | Description |
|---|---|
| Class | ClickHouseFixedStringToStringPropertyHandler |
| Namespace | RepoDb.PropertyHandlers.ClickHouse |
| Package | RepoDb.ClickHouse |
| Implements | IPropertyHandler<object, string> |
| Column type | The ClickHouse FixedString(N) type |
| Property type | string |
Conversions
| Method | Direction | Description |
|---|---|---|
| Get | Database to property | Converts the value returned by the driver (a string or a UTF-8 byte[]) into a string without the trailing NUL padding. null and DBNull are returned as null. |
| Set | Property to database | Passes the string to the driver as is. The server pads it up to N bytes and rejects a value that is longer than N bytes. |
Exceptions
| Exception | Thrown When |
|---|---|
ArgumentException |
The type of the value returned by the driver is not supported. |
Usability
Bind the handler to the property that maps to a FixedString(N) column.
Attribute
public class Country
{
public int Id { get; set; }
[Map("code"), PropertyHandler(typeof(ClickHouseFixedStringToStringPropertyHandler))]
public string Code { get; set; }
}
Once bound, the library invokes the handler automatically when the property is read or written.
using (var connection = new ClickHouseConnection(connectionString))
{
connection.Insert(new Country { Id = 1, Code = "NO" });
var country = connection.Query<Country>(e => e.Id == 1).First();
// country.Code is "NO", without the padding of a FixedString(3) column
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Country>()
.PropertyHandler<ClickHouseFixedStringToStringPropertyHandler>(e => e.Code);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Country, ClickHouseFixedStringToStringPropertyHandler>(e => e.Code, new ClickHouseFixedStringToStringPropertyHandler(), true);
Type Level Mapping
To apply the handler to every property of the type string:
PropertyHandlerMapper.Add<string, ClickHouseFixedStringToStringPropertyHandler>(new ClickHouseFixedStringToStringPropertyHandler(), true);
A type level mapping is process-wide: it is applied to every
stringproperty of every entity and connection, not only to the intended column. Prefer the attribute, fluent or property level mapping unless everystringproperty maps to aFixedString(N)column.