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
3
votes
1 answer

Haskell Esqueleto project subset of columns to list of custom records

In all the examples I have seen the results from esqueleto are projected into a list of tuples or to entities records. For example: previousLogItems <- select $ from $ \li -> do orderBy [desc (li ^. LogItemId)] limit 10 …
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
3
votes
1 answer

How to do a "SELECT ... IN (SELECT ...)" using Esqueleto?

Considering the following two models and a GET /articles/:slug/comments request, I want to retrieve the comments that belong to an article, based on its slug. Article json sql=articles slug Slug title Text description Text …
3
votes
1 answer

Returning `Maybe (Entity a)` from Esqueleto `LeftOuterJoin`

From a contrived config/models in a scaffolded site: Inventory name Text description Text Container name Text ContainerSlot container ContainerId item InventoryId Maybe Now, using Esqueleto, I want to use…
Greyson
  • 3,598
  • 1
  • 21
  • 22
3
votes
2 answers

SQL: List-Field contains sublist

Quick preface: I use the SQL implementation persistent (Haskell) and esqueleto. Anyway, I want to have a SQL table with a column of type [String], i.e. a list of strings. Now I want to make a query which gives me all the records where a given list…
elfeck
  • 385
  • 1
  • 8
3
votes
0 answers

A Database.Esqueleto riddle regarding ==. val True

While debugging a query that unexpectedly returned an empty list, I realized that I wrote something silly: fetchDim cId = runDb . select . from $ \dim -> do where_ dim ^. DimensionIsRowKey ==. val True return dim ... because you can append ==…
ruben.moor
  • 1,876
  • 15
  • 27
3
votes
2 answers

Multiplying Int and double values in esqueleto?

The problem I'm facing is pretty simple: Basically I'm trying to calculate the product of an Int and a Double. In plain Haskell I would just run product = (fromIntegral int_val) * double_val However I can't figure out how to do it in esqueleto. I'm…
Joel Hermanns
  • 355
  • 1
  • 4
  • 11
3
votes
1 answer

How to enable automatic logging of SQL statements with Persistent

I have searched for a clear answer to this question but haven't been able to find one yet - How do I enable automatic logging of SQL statements being executed by persistent? Can someone give me a small example program for this? Following is an…
Anupam Jain
  • 7,851
  • 2
  • 39
  • 74
3
votes
1 answer

Getting the result of aggregate functions in Esqueleto

Say I have the following model: Person stackOverflowUser Bool age Int Maybe Using Esqueleto (& Yesod), say I want to get the average age of Stack Overflow users. I'd like to make a function with the type signature: userAge :: Handler (Maybe…
fimbul
  • 273
  • 1
  • 2
  • 7
3
votes
1 answer

Outer Joins with Esqueleto

I am a bit confused about how outer joins work with esqueleto. I have created the following query (simplified): select $ from $ \(rep `LeftOuterJoin` event) -> do on (rep ^. RepAtomId ==. event ^. EventAtomId ) where_ (rep ^.…
nomen
  • 3,626
  • 2
  • 23
  • 40
3
votes
1 answer

Esqueleto `selectDistinct` not working

selectDistinct seems to not be working for me, it's probably a simple error. the query: info <- runDB $ E.selectDistinct $ E.from $ \(tp `E.InnerJoin` rnd `E.InnerJoin` h) -> do E.on (rnd E.^. RoundId E.==. h E.^.…
ChrisU
  • 473
  • 4
  • 14
2
votes
1 answer

Combining countRows with a having clause in esqueleto

I'm working on a very simple toy API to improve my Haskell skills. The relevant database table is called ingredients and has some fields (id, name, category). I'm now trying to get a selection query working that shows possible duplicates. It does…
Arne Goeteyn
  • 166
  • 9
2
votes
0 answers

Haskell Esqueleto: perform join on list of values using "with"

I am trying to do a join on a list of values known beforehand. In the following example - to get prices for each sku in the list. I have found a link suggesting a use of "with"…
2
votes
0 answers

Custom function in Esqueleto "where_" cluase

I'd like to write a function that checks if user's login and hashed password exists in database. Let's assume DB is very simple: share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| User login String passHash…
LA.27
  • 1,888
  • 19
  • 35
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
2 answers

Update a row with specific ID in Esqueleto

I can change a field of a row with entryId in Esqueleto like this: update $ \entry -> do set entry [ EntryFoo =. val bar ] where_ (entry ^. EntryId ==. val entryId) However, writing it all the time gets annoying. I'd like to be able to…
Emily
  • 2,577
  • 18
  • 38