Firstly, for [Level]
, storing just the ID allows you to store a simple type in a json list.
type Price = Int
type Volume = Int
share [mkPersist sqlSettings, mkMigrate "migrateBook"]
[persistLowerCase|
Level
limit Price
volumes [Volume]
deriving Show Read Eq
Book
time Time
asks [LevelId]
bids [LevelId]
deriving Show Read Eq
|]
Alternatively, if you need to query across the relation, you need to define a "through" or M2M table, just like in a normal relational database design.
type Price = Int
type Volume = Int
share [mkPersist sqlSettings, mkMigrate "migrateBook"]
[persistLowerCase|
Level
limit Price
volumes [Volume]
deriving Show Read Eq
Book
time Time
deriving Show Read Eq
BookAsk
book BookId
level LevelId
BookBid
book BookId
level LevelId
|]
As is the case for, for [Volume]
, the problem is in persistent-postgresql. persistent is hardwired to marshal PersistList
values as JSON, instead of using postgres's native support for array column types. If you want to fix this, you'll need to submit an issue or a pull request.