Open utterances-bot opened 3 years ago
Thanks for the article, @
always confused me.
two questions if I may, what is the hash sign in orderBy #createdAt
, I have not seen this before
also what is the tilde in table ~ GetTableName model
@abdallahz3 good questions! Those are two more language extensions :) these are a bit more complicated and I don't fully understand them, but here's my understanding of the high level idea of what's going on.
The hash sign comes from the Overloaded labels extension. #createdAt
is just syntactic sugar for fromLabel @"createdAt"
. Our User
type would have a instance of HasLabel
so that given the label "createdAt", it will return the createdAt
field . a bit over my head 😅 but that's the general idea.
The tilde is "type equality". So when we call query @User
, it will be filled in as table ~ GetTableName User
. Elsewhere in the code we have something like
type instance GetTableName User = "users"
so in the end table
turns out to be the type level string "users"
. This is then used in QueryBuilder to construct the queries.
@zacwood9 That was really helpful, Thanks a lot
Haskell's @ symbol - Type Application | Zac Wood
Demystifying a powerful language extension that powers the IHP framework
https://zacwood.me/posts/haskell-type-application/