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
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

case-insensitive uniqueness constraints in Persistent?

This is probably a stupid question and I'm somehow overlooking existing content with sub-par Google-fu skills, but is there a way to create a new Text field using Persistent, with a uniqueness constraint on that field, whereby uniqueness is…
derrgill
  • 15
  • 5
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
1
vote
0 answers

Row count and similar in Esqueleto

Ok, I'll be more concrete {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE…
1
vote
1 answer

Haskell Esqueleto project to list of records instead of tuples

In all the examples I have seen the results from esqueleto are projected into a list of tuples. This makes coding and maintenance harder because of lack of labels. For example: previousLogItems <- select $ from $ \li -> do orderBy [desc (li…
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
1
vote
1 answer

How do I filter Just field in Esqueleto?

With the following Persistent schema, Picture bytes ByteString desc Text Maybe I want to query SELECT id, desc FROM picture WHERE desc IS NOT NULL. But previews :: SqlPersistT Handler [(E.Value (Key Picture), E.Value Text)] previews = E.select…
jeiea
  • 1,965
  • 14
  • 24
1
vote
1 answer

esqueleto: outer join doesn't compile

Here's a subset of my model: ServerWebsite desc Text url Text text Text username Text password Password serverDatabaseId ServerDatabaseId Maybe groupName Text Maybe serverId ServerId deriving Show…
Emmanuel Touzery
  • 9,008
  • 3
  • 65
  • 81
1
vote
1 answer

Esqueleto: How to execute a query with more then 16 columns?

Well basically it boils down to is it possible to have a query that returns more then 16 columns in esqueleto? I have a legacy db that I have to interact with and it requires joining tables with 30-40 columns then picking out like 20 of the possible…
sbditto85
  • 1,485
  • 14
  • 21
1
vote
1 answer

Esqueleto count inside select

I have the following Entities: Group name Text GroupUser user UserId group GroupId and I would like to do a query like this: select g.* /* Everything from g */ , count(gu.id) groupUsersCount from Group g left outer join GroupUser…
FtheBuilder
  • 1,410
  • 12
  • 19
1
vote
1 answer

Esqueleto query that returns constant value

Is it possible to use esqueleto to create a query that returns a constant value? Like SELECT 1 for example.
snøreven
  • 1,904
  • 2
  • 19
  • 39
1
vote
1 answer

Yesod Esqueleto isJust

I've been using isNothing, from Esqueleto, but now I would like to just test if it is not null, I've noticed that there is no isJust, I would like to know the reason it doesn't exist, and what could I do to achieve similar effect: isJust (a ^.…
FtheBuilder
  • 1,410
  • 12
  • 19
1
vote
1 answer

How to compose queries/subselect with Esqueleto?

Based on this answer, I conclude that Esqueleto does not allow to compose two queries with a left outer join. However, I hope there still is a solution to my problem, somewhere. I want to do a left outer join with a table that is additionally…
ruben.moor
  • 1,876
  • 15
  • 27
1
vote
0 answers

Yesod Esqueleto Unknow for ModelId While Joining

I have a problem when it comes on compiling my code on esqueleto. For some reason my IDE which is fpcomplete says that there is now an error. But, when I build it it says the My ModelId is unknown. Here is my code: qryStrainsList :: SqlBackend ->…
Ryan Monreal
  • 587
  • 5
  • 16
1
vote
1 answer

Joining with Maybe Fields

I have a table with a Maybe Foreign Key. I am trying to join but cannot get it to compile. CatTable name Text MyTable category CatTableId Maybe amount Double My query: myQuery :: (PersistQuery (SqlPersistT m), MonadLogger m ,…
Ecognium
  • 2,046
  • 1
  • 19
  • 35
1
vote
1 answer

Haskell: Yesod and Esqueleto

How do you get runDB in Yesod 1.2 to work with Esqueleto? import Database.Esqueleto as E getMainR :: Handler Html getMainR = do leases <- runDB $ E.select $ E.from $ \l -> do E.where_ (l…
MCH
  • 2,124
  • 1
  • 19
  • 34