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

Esqueleto/raw SQL -- Sorting a query by the result of a sort on another table?

I actually am a little new to how SQL works -- i've always let my ORM's handle everything for me. But this in this case Persistent doesn't expose this kind of functionality so I'm at lost at what to do. I have a many-to-many…
Justin L.
  • 13,510
  • 5
  • 48
  • 83
1
vote
1 answer

Running join on Maybe Relation

I have a model Assignment blah Text .... and a model File assignmentId AssignmentId Maybe ... and I want to get all the files associated with an assignment in a join query. I have tried Esqueleto and runJoin with selectOneMany but…
No Context
  • 167
  • 1
  • 6
0
votes
1 answer

Yesod Esqueleto: could not load module; member of hidden package ‘esqueleto-3.5.8.1’

Been playing around with Yesod for a few weeks. Installed stack on freebsd. Got a templated postgresql site working. Now trying to test out Esqueleto for a join query. Installed esqueleto as so: stack update stack install esqueleto my handler…
Abner
  • 31
  • 3
0
votes
1 answer

Haskell persistent - getting value via foreign key

Let's assume I've got a very simple db with a Foreign Key (for simplicity of the example: one table with a self reference; context - modelling a financial instrument): Instrument ticker String name String denomination InstrumentId -- FK…
LA.27
  • 1,888
  • 19
  • 35
0
votes
1 answer

Join on result of subquery in Esqueleto

The essential part of the query I'm trying to translate is like this: SELECT c.id, c.name, officer.id, officer.name FROM ( SELECT DISTINCT ON (company.number) company.id, company.name FROM company ORDER BY company.number DESC LIMIT 15 ) AS…
Jezen Thomas
  • 13,619
  • 6
  • 53
  • 91
0
votes
0 answers

Extracting the year from a timestamp field inside an Esqueleto query

I am trying to make use of the unsafeSqlExtractSubField from Esqueleto to create one that will extract the year from a date, such as: data ReportRow = ReportRow Text userSignupData :: MonadIO m => Key User -> SqlPersistT m…
danbroooks
  • 2,712
  • 5
  • 21
  • 43
0
votes
0 answers

Raw sql with many columns

I'm building a CRUD application that pulls data using Persistent and executes a number of fairly complicated queries, for instance using window functions. Since these aren't supported by either Persistent or Esqueleto, I need to use raw sql. A good…
cgold
  • 4,075
  • 1
  • 12
  • 13
0
votes
2 answers

How to compare for equality Data.Text.Internal.Lazy.Text and [Char]?

The previousLogItem data type returned by esqueleto contains Data.Text.Internal.Lazy.Text import Data.Text.Lazy (pack) previousLogItem <- select $ from $ \l -> do orderBy [desc (l ^. LogItemId)] …
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
0
votes
0 answers

Is it possible to use deleteCascade with esqueleto?

I did not found any mentions of deleteCascade and deleteCascadeWhere in esqueleto... Is there an esqueleto equivalent to these functions?
gueux
  • 323
  • 1
  • 12
0
votes
1 answer

Need to convert OUTER JOIN with multiple "AND"

I have this raw sql I'd like to convert to Esqueleto. It should bring all the groups that user ID 1, isn't registered to via the group_membership table. SELECT * FROM group LEFT OUTER JOIN group_membership ON (group.id = group_membership.group_id…
amitaibu
  • 1,026
  • 1
  • 7
  • 23
0
votes
0 answers

Haskell Esqueleto function to compare with a time offset

How could I do something similar to this in Esqueleto: DATE_ADD(myDate, INTERVAL 2 HOUR) > otherDate
FtheBuilder
  • 1,410
  • 12
  • 19
0
votes
1 answer

Yesod Esqueleto - How can I express selects with inner pagination?

I am doing a paginated resource, which will require an inner select, which I've already designed in sql terms. It has the following structure: select * from ( select w.*, d.distance from `Work` w inner join AdrDistance d on…
FtheBuilder
  • 1,410
  • 12
  • 19
0
votes
1 answer

Esqueleto where on entity ID

I have been following the examples in Yesod's SQL Joins, and I'd like to add to the Inner Join example also a where_ clause - it should show only the blogs where author ID is above 1. I think my mistake is probably that I'm doing E.val 1, but not…
amitaibu
  • 1,026
  • 1
  • 7
  • 23
0
votes
0 answers

Esqueleto: how to apply lower_ to maybe field?

How to apply function lower_ to (Value (Maybe typ))? I have maybe string field in db, so after (^.) operator I'll have expression with type: SqlExpr (Value (Maybe String)). Let us suppose lower_ is SqlExpr (Value String) -> SqlExpr (Value…
0
votes
1 answer

How to use unless (or when) in an Esqueleto query?

I build a query that joins a few tables and restricts the result further unless one field called IncludeAll equals True. I'm trying to write it like this fetch i = runDb . select . from $ \(a, b, c) -> do where_ $ a ^. AId ==. valkey i …
ruben.moor
  • 1,876
  • 15
  • 27