Questions tagged [esqueleto]

The esqueleto EDSL (embedded domain specific language) for SQL queries which replaces Database.Persist

esqueleto is a bare bones, type-safe EDSL for SQL queries that works with unmodified persistent SQL backends. Its language closely resembles SQL, so (a) you don't have to learn new concepts, just new syntax, and (b) it's fairly easy to predict the generated SQL and optimize it for your backend. Most kinds of errors committed when writing SQL are caught as compile-time errors---although it is possible to write type-checked esqueleto queries that fail at runtime.

persistent is a library for type-safe data serialization. It has many kinds of backends, such as SQL backends (persistent-mysql, persistent-postgresql, persistent-sqlite) and NoSQL backends (persistent-mongoDB).

While persistent is a nice library for storing and retrieving records, currently it has a poor interface for SQL backends compared to SQL itself. For example, it's extremely hard to do a type-safe JOIN on a many-to-one relation, and simply impossible to do any other kinds of JOINs (including for the very common many-to-many relations). Users have the option of writing raw SQL, but that's error prone and not type-checked.

The name of this library means "skeleton" in Portuguese and contains all three SQL letters in the correct order =). It was inspired by Scala's Squeryl but created from scratch.

Taken from the HackageDB site

77 questions
2
votes
0 answers

Haskell Esqueleto - update with join

Can I make an update query with join in Haskell? Maybe something like this: putPromotionInStoreItemsFromStoreBySItemId :: SItemId -> SItemPromoId -> YesodDB App () putPromotionInStoreItemsFromStoreBySItemId siId pId = update $ \(si `InnerJoin` s…
FtheBuilder
  • 1,410
  • 12
  • 19
2
votes
0 answers

How to query array contains in Haskell Esqueleto

I'm trying to select all Events from the database that contain a Tag in the Event's tags column. Event is a model with a column tags that is defined in Yesod's model file as tags [Tag]. Tag is a model that is simply newtype Tag = Tag Text with a lot…
2
votes
1 answer

YesodDB, how to put types correctly

I have created a function for loading some Entities but I am having some trouble to understand how I should put its type declaration, so I took this Yesod book chapter about Yesod monads, to understand it better, and I came to this snippet: -- type…
FtheBuilder
  • 1,410
  • 12
  • 19
2
votes
1 answer

Unique post author from Esqueleto

I have an Esqueleto query that selects all of the StatusUpdates and their respective Users. I'd like to limit it to only one StatusUpdate per User, and only StatusUpdates from the current day. I have a working SQL query, I'm just struggling with…
Jezen Thomas
  • 13,619
  • 6
  • 53
  • 91
2
votes
2 answers

How to apply a function before comparison in an esqueleto query

For a query simple as that runDb . select . from $ \cell -> do where_ $ cell ^. CellCode ==. val "x" return cell I want to apply a function before the comparison of the field value with "x". The reason is that the cell code has trailing spaces…
ruben.moor
  • 1,876
  • 15
  • 27
2
votes
1 answer

Haskell persistent w/ esqueleto: read entire table, and count records

I have the following schema: share [ mkPersist sqlSettings, mkMigrate "migrateAll" ] [persistLowerCase| AdminChan timestamp T.Text name T.Text msg T.Text BanHost timestamp T.Text host T.Text isBanned Bool reason …
the-konapie
  • 601
  • 3
  • 10
2
votes
1 answer

Error trying to setup Esqueleto with my models

This morning I started setting up Esqueleto in a Yesod app. I'm really trying to do a LeftOuterJoin, but I've simplified the query down quite a bit in order to get the basics working. I can't even get that. To be sure there are no conflicts with…
Joe Fiorini
  • 641
  • 5
  • 15
2
votes
1 answer

Joining on a view in esqueleto

I have an sql view V which has a 0:1 correspondence to a table X. I would like to join this view onto another table, Y, which has a reference to X (type XId). I have specified the view as I would any other table in persistent. V's id column is a…
unohoo
  • 378
  • 4
  • 14
2
votes
1 answer

How to Use Group By and Sum in an Esqueleto Query

I am trying to use one of the example queries from Esqueleto but I cannot get it to compile. The only variation is that I am using it without a join. I have a table that looks like this: sqlite> select * from…
Ecognium
  • 2,046
  • 1
  • 19
  • 35
2
votes
0 answers

Join in Esqueleto between different types

I'm trying to use Esqueleto on an existing database and I encountered this problem : two columns that I need to join are of a different types. One is Integer (normal), the other (the "foreign key") is a String instead of being an Integer…
mb14
  • 22,276
  • 7
  • 60
  • 102
2
votes
1 answer

How do you add a unique key to a Database.Persist model using the quasiquoter?

How do you build a unique key with two or more fields using the persistLowerCase quasiquoter? When using Database.Persist to create models for a simple website using guidance from the Yesod book, the following error crops up: Build…
2
votes
1 answer

Esqueleto simple type error

I'm getting a type error with a query right from the hackage page. The query is supposed to select a GolfCourse whose name is equal to "Miniota". Query: getTestR :: Handler Html getTestR = do gcs <- runDB $ E.select $ E.from $…
ChrisU
  • 473
  • 4
  • 14
1
vote
1 answer

Dealing with different time precision between Data.Time and Postgresql

I have some database functions which I'm testing (to make sure my queries etc. work) -- in them, I'm de/serialising records (via Database.Esqueleto.Experimental) and these contain values of type UTCTime (and Maybe UTCTime, etc.). The problem is that…
GTF
  • 8,031
  • 5
  • 36
  • 59
1
vote
1 answer

How to encode VALUES constant table expression in esqueleto?

In a Yesod application using the Esqueleto EDSL, I desire to perform an anti-join with a table living in Haskell. In pure PostgreSQL, the query would look like this: CREATE TEMPORARY TABLE antijoin_demo (x INT); INSERT INTO antijoin_demo (x) …
STurtle
  • 21
  • 3
1
vote
0 answers

Update depending on a column's value with Esqueleto

I want to update a table t having column c1 and c2 by a Haskell function of type fx :: c1 -> c2 now I want to apply this function to my table t and update the values of c2. How I can do this in one run? Like in postgres I will write it as: update t…