Skip to content

Non standard parameter conversions

Jacek edited this page Oct 21, 2019 · 12 revisions

There are also built-in parameter conversions:

  • listDirectParamBuilder modifies sql statement by replacing parameter with list of comma-separated values. E.g.

    select * from post where id in (@postIds)

    executed with [1, 2, 3] as a parameter, is transformed to

    select * from post where id in (1, 2, 3)

    Queries with literals in an in clause are very efficient, but they shouldn't be used with collections of strings.

  • listParamBuilder modifies sql statement by replacing one parameter with many parameters representing elements of the list. E.g. the query above with the same parameter would be transformed to

    select * from post where id in (@postIds1, @postIds2, @postIds3)

To leverage non-standard conversion, the configuration of code generator must be changed. Let assume, that we'd like to use both param builders, listDirectParamBuilder for int parameters, listParamBuilder for all other basic types:

    let generatorConfig = 
        let defaultConfig = createDefaultConfig createConnection
        { defaultConfig with
            paramBuilder = 
                (listDirectParamBuilder (string >> Set([string typeof<int>]).Contains) string) <+> 
                (listParamBuilder isSimpleType "@") <+> 
                defaultConfig.paramBuilder
        }
Clone this wiki locally