beam icon indicating copy to clipboard operation
beam copied to clipboard

Is there any way to reuse a `ToField`, `FromField` definitions from sqlite-simple?

Open andrewerf opened this issue 1 year ago • 1 comments

Beam uses sqlite-simple as a backend for SQLite database. I have some instances of classes ToField and FromField for sqlite-simple, which could convert my datatypes to sql field and vice versa. However, it is unclear to me how I should write an instance of kind

instance ( Typeable a, FromField a ) => FromBackendRow Sqlite a where
...

instance ( ToField a ) => HasSqlValueSyntax Sqlite a where
...

Is there a way to define such instances?

andrewerf avatar Jun 16 '23 20:06 andrewerf

I think for HasSqlValueSyntax the following would be enough:

instance ( ToField a ) => HasSqlValueSyntax SqliteValueSyntax a where
  sqlValueSyntax f = SqliteValueSyntax . emitValue $ toField f

Although, for some reason, my custom type does not become convertible with val_ even with the definition of this instance.

The FromBackendRow is trickier because it involves conversion of errors.

andrewerf avatar Jun 18 '23 09:06 andrewerf