TsQueryToStringPropertyHandler
A property handler that maps the full-text search tsquery type into a string property.
A property handler that maps the full-text search tsquery type into a string property.
The parsing of the text into an
NpgsqlTsQueryis performed on the client by the driver, which marks it as unreliable for complex values (it cannot fully duplicate the PostgreSQL logic). Prefer simple, well-formed values, or use the server function (to_tsquery) in the SQL for complex ones.
Overview
| Name | Description |
|---|---|
| Class | TsQueryToStringPropertyHandler |
| Namespace | RepoDb.PropertyHandlers.EnterpriseDb |
| Package | RepoDb.EnterpriseDb |
| Implements | IPropertyHandler<object, string> |
| Column type | The full-text search tsquery type |
| Property type | string |
Conversions
| Method | Direction | Description |
|---|---|---|
| Get | Database to property | Converts the value returned by the driver (a string, or an NpgsqlTsQuery) into its text form (for example 'fat' & 'cat'). null and DBNull are returned as null. |
| Set | Property to database | Parses the text form into an NpgsqlTsQuery, to be written into the tsquery column. A null value is written as null. |
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 tsquery column.
Attribute
public class Article
{
public int Id { get; set; }
[Map("search_query"), PropertyHandler(typeof(TsQueryToStringPropertyHandler))]
public string SearchQuery { get; set; }
}
Once bound, the library invokes the handler automatically when the property is read or written.
using (var connection = new EDBConnection(connectionString))
{
connection.Insert(new Article { Id = 1, SearchQuery = "'fat' & 'cat'" });
var article = connection.Query<Article>(e => e.Id == 1).First();
// article.SearchQuery is the text form of the tsquery value
}
Fluent Mapping
To configure via FluentMapper:
FluentMapper
.Entity<Article>()
.PropertyHandler<TsQueryToStringPropertyHandler>(e => e.SearchQuery);
Property Level Mapping
To configure via PropertyHandlerMapper:
PropertyHandlerMapper.Add<Article, TsQueryToStringPropertyHandler>(e => e.SearchQuery, new TsQueryToStringPropertyHandler(), true);
Type Level Mapping
To apply the handler to every property of the type string:
PropertyHandlerMapper.Add<string, TsQueryToStringPropertyHandler>(new TsQueryToStringPropertyHandler(), 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 atsquerycolumn.