How to set column mapping relation when generating entities in Haskell?

64 Views Asked by At

I am trying to use Persistent to access my database. I know that Persistent can generate the code of entity, but there is something I can't generate so easily. Like I got a table which looks like:

CREATE TABLE `user` (
  `user_id` bigint(11) NOT NULL,
  `user_name` varchar(255) DEFAULT NULL,
  `user_password` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

then my haskell code like :

mkPersist sqlSettings [persistLowerCase|
User
  name String
  password String
  deriving Show
|]

These fields are different include the primary key, I want to set their mapping relation. The official page (https://www.yesodweb.com/book/persistent) doesn't say how to do it.

Need I write the code to define it instead of generating it?

1

There are 1 best solutions below

0
Jacky Wong On

I've found it on this page https://github.com/yesodweb/persistent/blob/master/docs/Persistent-entity-syntax.md

I can do some customization follow these syntax.