Persistent is a type-safe, universal data store interface for Haskell with support for various backends, including PostgreSQL, SQLite, MySQL and MongoDB.
Questions tagged [haskell-persistent]
57 questions
6
votes
0 answers
Replace a record if it exists and gracefully fail if it doesn't?
Persistent comes with two operations for wholesale replacement of records: replace and repsert. With repsert, a new record is inserted into the database if the record to be replaced did not originally exist. With replace, if the record to be…

Alexis King
- 43,109
- 15
- 131
- 205
5
votes
1 answer
Dynamically build SQL-Queries wit Esqueleto and Template Haskell?
I'm writing a webapp wit Yesod & Persistent. I have a SQL-Database with several tables, containing characteristics of my "projects". I have a main table and for the Option with multiple values extra tables linked with the id.
The user should be able…

Nudin
- 351
- 2
- 11
5
votes
1 answer
Using an SQL table without an ID column in Haskell/Persistent
I want to use an existing database with Persistent using this simplified schema:
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Entity sql=entities
deriving Show
EntityLink sql=entity_links
sourceId EntityId
targetId…

eugenk
- 472
- 4
- 11
5
votes
1 answer
Persistent selectList causing error of "Couldn't match type ‘BaseBackend backend0’ with ‘SqlBackend’"
I'm running into the below compile error:
• Couldn't match type ‘BaseBackend backend0’ with ‘SqlBackend’
arising from a use of ‘runSqlite’
The type variable ‘backend0’ is ambiguous
• In the expression: runSqlite ":memory:"
In the…

Chris Stryczynski
- 30,145
- 48
- 175
- 286
4
votes
1 answer
Custom ToJSON instance for Persistent Key
I am building a web application in Haskell. I am using the persistent library to connect to a postgresql database.
I am using the standard schema definition file system where template Haskell is used to generate types from the schema.
share…

Harpo
- 81
- 3
4
votes
1 answer
Haskell Persistent query on dates (Yesod)
I am trying to add date parts into an URL for a blog post, lets say
/blog/2016/11/23/my-blog-post-slug
I want to check not only for the slug but the date parts as well. This is what I got so far:
getBlogPostR :: Int -> Int -> Int -> Slug -> Handler…

Alebon
- 1,189
- 2
- 11
- 24
3
votes
1 answer
Select list from list of IDs using persistent
In my application I need to be able to write a query that takes a list of IDs and returns a list of each of those records.
From what I can tell from the yesod persistent page I could do something like
selectList (UserId ==. 1 ||. UserId ==. 2 ||.…

Qwertie
- 5,784
- 12
- 45
- 89
3
votes
1 answer
Haskell - Couldn't match type ‘PersistEntityBackend record0’ with ‘SqlBackend’
I am trying to get a record by id in Yesod. My code is:
getEditActorR :: Handler Html
getEditActorR = do
actorId <- runInputGet $ ireq intField "id"
actor <- runDB $ get $ Key $ PersistInt64 (fromIntegral actorId)
defaultLayout $ do
…

Vitaly Olegovitch
- 3,509
- 6
- 33
- 49
3
votes
1 answer
Dealing with database access in transformer stacks
This question is about groundhog or persistent, because I believe both share the same problem.
Say I have a transformer Tr m a that provides some functionality f :: Int -> Tr m (). This functionality requires database access. There are a few options…

Luka Horvat
- 4,283
- 3
- 30
- 48
3
votes
2 answers
Represent Foreign Key Relationship in JSON using Servant and Persistent
This morning I was following along with this interesting tutorial on using Servant to build a simple API server.
At the end of the tutorial, the author suggests adding a Blog type, so I figured I would give it a shot, but I got stuck trying to…

erewok
- 7,555
- 3
- 33
- 45
2
votes
1 answer
How to fix missing instance of IO for a function constrained on MonadReader and MonadIO?
I have been trying to get a good understanding of mtl by building a project using it in combination with persistent.
One module of that project has a function which uses insertMany_
service
:: (MonadReader ApplicationConfig m, MonadIO m) =>
…

atis
- 881
- 5
- 22
2
votes
1 answer
Persistent - how to filter on a field of a record column
I'm in the middle of trying to build my first "real" Haskell app, an API using Servant, where I'm using Persistent for the database backend. But I've run into a problem when trying to use Persistent to make a certain type of database query.
My real…

Robin Zigmond
- 17,805
- 2
- 23
- 34
2
votes
0 answers
Define a custom type using Persistent generated types
I believe this question is more related to the Haskell structure itself than Persistent's, but I've been looking through some questions here and I stumbled upon this.
Now, I wonder, is there a way to use a type generated through mkPersist inside a…

ptkato
- 668
- 1
- 7
- 14
2
votes
1 answer
Mixing Esqueleto and Persistent in same function
I might be doing something horribly stupid, but I would like to mix some Esqueleto with regular Persistent queries in same function.
I have function:
handleFactionConstruction :: (BaseBackend backend ~ SqlBackend,
PersistStoreWrite backend,…

Tuukka Turto
- 145
- 1
- 2
- 7
2
votes
0 answers
How to "combine" Persistent's SqlBackend with a custom monad?
I have a custom monad stack for my Servant app, which I'd like to keep to a single ReaderT without making it an "onion" over SqlPersistT or suchlike. Problem is, I haven't been able to find any code samples that do this.
It seems like most…

Saurabh Nanda
- 6,373
- 5
- 31
- 60