Skip to content

Store a String representation in SqlValue #56

@olafklinke

Description

@olafklinke

Some backends, e.g. HDBC-odbc pass SqlValue parameters as strings to the database. When the source of the SqlValue is a string, e.g. via Read or parsing, the construction of the SqlValue is unnecessary, since we're using Convertible SqlValue String anyways. We might as well store the original string and emit that, if someone requests a string representation.

data SqlValue' = SqlValue' {textSqlValue :: Text, actualSqlValue :: SqlValue}
instance Convertible SqlValue' Text where
    convert = textSqlValue
instance Convertible SqlValue' String where
    convert = unpack.textSqlValue
instance Convertible SqlValue SqlValue' where
   convert x = SqlValue' (convert x) x 

Here the actualSqlValue is lazy so that the SqlValue is never constructed in case the value is only used as string. The textSqlValue should be lazy as well in case the source is not a string. Whether Text, String or even ByteString is best remains to be seen. I don't know the details of other instances of IConnection so I can't say whether this is useful in general. But for shoveling data into a SQL database it might give a huge speedup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions