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
2
votes
2 answers
In Persistent (Haskell), how can I insert a record only if it doesn't already exist?
I'm a Haskell beginner, so apologies in advance!
I've been following the Persistent tutorial here.
I have a data model with a uniqueness constraint:
Book
gutId Int
UniqueGutId gutId
...
author [AuthorId]
...
Author
gutId…

Jonathan
- 10,571
- 13
- 67
- 103
2
votes
1 answer
How can I use a field from my Persistent model as a path piece in my routes file?
I have a Persistent model like so:
Organization sql=organizations
Id UUID default=uuid_generate_v1mc
name Text
UniqueOrganizationName name
deriving Show Eq Typeable
I'd like to use the organization name in my Yesod routes file like…

MaxGabriel
- 7,617
- 4
- 35
- 82
2
votes
1 answer
How does "import Database.Persist as X hiding (get)" from the yesod-sqlite template works
I am using the yesod-sqlite template and trying to use the get function from Database.Persist in a test.
Here is my code:
[Entity _ task] <- runDB $ selectList [TaskName ==. name] []
...
user <- runDB $ X.get (taskUserId task)
And the error I am…

Fábio Roberto Teodoro
- 499
- 1
- 6
- 17
2
votes
2 answers
Inner join in persistent or should I use esqueleto?
I have this fragment describing Notification and Notified entities:
Notification
type NotiType
release ReleaseId
date UTCTime
Notified
aboutWhat NotificationId
unread Bool
user UserId
Now I…

Mark Karpov
- 7,499
- 2
- 27
- 62
2
votes
0 answers
Is there a tool for generating Persistent entity definitions from an existing database?
I understand you can use persistent-template to declare entities, but is there a tool for building those from an existing database? Specifically is there a tool that can be pointed at a MySQL database and return definitions that can be used by…

ryantm
- 8,217
- 6
- 45
- 57
1
vote
0 answers
How can I generate the list of `EntityField`s for a `PersistEntity`?
I was trying to implement some form of repsertBy: repsert where the key is a provided Unique, in the line of getBy, upsertBy etc.
My approach: implement it on top of upsertBy. Now upsertBy takes a unique constraint, a record, and a list of changes…

JB.
- 40,344
- 12
- 79
- 106
1
vote
1 answer
How do I pass a rendered persistent/esqueleto query to another query?
I'd like to use Persistent/Esqueleto to implement count estimates.
One approach recommended in this article is to define a function like this
CREATE FUNCTION count_estimate(query text) RETURNS integer AS $$
DECLARE
rec record;
rows …

Jezen Thomas
- 13,619
- 6
- 53
- 91
1
vote
1 answer
Haskell + Persistent: parse error possibly incorrect indentation or mismatched brackets
I have been learning Haskell for the last several months and am trying to follow along with this tutorial on Haskell + Persistent:
https://www.yesodweb.com/book/persistent#persistent_code_generation
module Main where
{-# LANGUAGE GADTs …

Will Taylor
- 1,650
- 9
- 23
1
vote
2 answers
What is the strategy for working with different types of Monad Transformers?
I'm trying to implement a simple web server that interacts with some other API and stores the response after doing some processing.
To encapsulate the possibility of failure (empty response, incorrect request, etc) I am using ExceptT as…

atis
- 881
- 5
- 22
1
vote
0 answers
Copying data between databases using Haskell Persistent
First up, I have a large Sqlite database. I want to copy a subset of the data in this database to another Sqlite database in a streaming fashion using the Haskell persistent library.
Here's the only I managed to do it, but its very slow (and uses…

kolam
- 731
- 4
- 17
1
vote
2 answers
Haskell and postgresql - build error "The program pg_config is required but it could not be found."
I am currently learning haskell and just tried using postgresql as a database.
I generated my project with stack (stack new -> stack setup -> stack build)
and then all I changed was adding the dependencies needed to persistent and postgresql…

B16
- 50
- 1
- 7
1
vote
1 answer
Inserting entry into database using PostGreSQL & Persistent
I'm trying to learn the Persistent Library.
I have two files one with all the types I've defined for my project (diet tracker)
Report.hs
data FoodEntry = FoodEntry { report :: Report
, date :: UTCTime
…

distro.obs
- 181
- 9
1
vote
1 answer
How to get referenced model information in Yesod?
I have 3 Models
Address json
number Text
street Text
pincode Text
deriving Show
Person json
email Text
name Text
telephone Text
deriving Show
House json
rent Int
ownerId PersonId
addressId AddressId
…

Sumanth Kumar Mora
- 637
- 1
- 5
- 15
1
vote
2 answers
Yesod return whole Entity after insert?
Basically right now I run fbId <- runDB $ insert myNewFooBar and I get back a Key FooBar. Is there any way to return the value of the whole FooBar directly from an insert without running a separate query of runDB $ get404 fbId after?

BWStearns
- 2,567
- 2
- 19
- 33
1
vote
1 answer
Haskell Esqueleto 3 table join
These are my attempts to do a SELECT from three tables. But they don't compile and I don't understand the error (I don't know why it expects a tuple (Entity Issue, b0) instead of the triplet I think the code attempts to get).
Attempt 1:
{-# LANGUAGE…

hhefesto
- 331
- 1
- 11