-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Saurabh's tutorial to the README #447
Comments
Hey, should i spruce this up for the latest version? I have a bunch of
other chapters that I didn't manage to publish. But this might be the
required push to get this out there.
…On Thu, 19 Dec 2019, 20:13 tomjaguarpaw, ***@***.***> wrote:
Requested by @williamyaoh <https://github.com/williamyaoh>. I'll have to
refamiliarise myself with it.
https://haskell-webapps.readthedocs.io/en/latest/docs/opaleye/opaleye.html
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#447?email_source=notifications&email_token=AAAG5UK4FNQB2LCQP75U44LQZOCBPA5CNFSM4J5H6D52YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IBVFXRA>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAG5UPZNRWXJTJXO5B5EJTQZOCBPANCNFSM4J5H6D5Q>
.
|
Updating to use the new names would be great. |
@saurabhnanda Is the source code for your tutorial available in a repo? If so I will try to bring it up to date with current Opaleye. |
Please give me a few more days. I'm on it -- just got side-tracked with my
static-site builder.
…On Sun, Aug 23, 2020 at 2:12 PM tomjaguarpaw ***@***.***> wrote:
@saurabhnanda <https://github.com/saurabhnanda> Is the source code for
your tutorial available in a repo? If so I will try to bring it up to date
with current Opaleye.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAG5UK2GCZVJS6K4IOEHYDSCDI5ZANCNFSM4J5H6D5Q>
.
|
@tomjaguarpaw I finally got around to finishing my static site builder and am now revamping the tutorial. Even when I was writing the first one, I was unable to explain why the userTable :: Table (Field SqlInt4, Field SqlText, Field SqlText)
(Field SqlInt4, Field SqlText, Field SqlText)
userTable = Table "users" (p3 ( required "id"
, required "name"
, required "email")) Aren't the type annotations enough? Is it even possible to have a While we are cleaning-up (and introducing breaking changes), would it be possible to re-consider this design decision? |
I'm getting used to the new API myself, I think my previous comment should read as |
the API has changed significantly since 0.5-0.6 that we are using in production. Is Also, data OnConflict = OnConflictOmit | OnConflictDoNothing |
They're not required. If you use |
Yes it is. We have some freedom to come up with a better API because the the old version of |
The API hasn't fully switched to the requiredTableField :: String -> TableFields (Field_ n a) (Field_ n a)
optionalTableField :: String -> TableFields (Maybe (Field_ n a)) (Field_ n a) That is, the |
Is there any reason why Returning a b doesn't have a |
I had this note in my old tutorial. Is there a technical explanation for why the API behaves this way (
Also, in a tutorial, how does one explain why some API functions have a trailing underscore, while others don't? |
I'm trying to rediscover Opaleye as a beginner, to be able to write an effective tutorial. When I look at
Is there a valid (and extremely common) use-case for updating a row with runUpdate_ conn Update
{ uTable = sometable
, uUpdateWith = (\r -> r & _3 .~ (toFields "someText"))
, uWhere = whatever
, uReturning = rCount
} Generated SQL: UPDATE sometable
SET col3 = "someText" -- all other columns are omitted
WHERE whatever
RETURNING count(*) |
Yeah, we could add the ability to return nothing (or more precisely, |
|
I'm not sure what you mean. How does |
Let me rephrase. |
No, I don't think so.
The current API is a consequence of the structure of the The API you propose is achievable with runUpdate_ conn Update
{ uTable = sometable
, uUpdateWith = updateEasy (\r -> r & _3 .~ (toFields "someText"))
, uWhere = whatever
, uReturning = rCount
} This still generates code for all fields. It will be something like
but I suppose I can detect unchanged columns and leave them out. |
Hang on, I think I just got confused. I wrote the following example in the tutorial and I think it can be written with updateUser :: Connection
-> (Int, String, String, Maybe Day)
-> IO ()
updateUser conn (i, n, e, d) =
void $ runUpdate_ conn u
where
u = Update
{ uTable = userTable
, uUpdateWith = (\(iDb, _, _, _) -> (iDb, toFields n, toFields e, toFields d))
, uWhere = (\(iDb, _, _, _) -> iDb .== toFields i)
, uReturning = rCount
} Is |
Right, so the way I see this is that I think of this as a "lower level" API that other APIs can be written in terms of. If you think there's a nicer higher-level API then let's see what that could be. |
Unfortunately |
Correct. |
And more precisely, this occurs exactly when some fields are |
And |
Yes, true, but there isn't an appropriate instance to make |
Btw - I've updated the first chapter of the tutorial, and it's available at https://www.haskelltutorials.com/opaleye/instant-gratification.html -- still working on the rest. Targeting to update and publish one chapter every 2 days, or so. |
We use our own hacked-up version of read-only fields a lot in production. We use it for |
Very cool idea. Would be good to see how you did this. |
@tomjaguarpaw is this section approximately correct? https://www.haskelltutorials.com/opaleye/instant-gratification.html#tofields_note |
Yes, looks approximately correct. It would be more correct to say that it is to do with the Also, there's a typo in "stange". |
@tomjaguarpaw I've completed one more chapter in the tutorial (and also ended up creating a bunch of other TODOs in the process!). Any feedback on this - https://www.haskelltutorials.com/opaleye/implementation-guide.html ? |
Another minor disadvantage could be the dependency on using the `Arrows` language extension. Some people still consider it to be highly experimental.
This is no longer true, and Opaleye can now be used through just it's Functor/Applicative/Monad interface, with no loss of functionality
…On Sun, 13 Sep 2020, at 10:45 AM, Saurabh Nanda wrote:
@tomjaguarpaw <https://github.com/tomjaguarpaw> I've completed one more chapter in the tutorial (and also ended up creating a bunch of other TODOs in the process!). Any feedback on this - https://www.haskelltutorials.com/opaleye/implementation-guide.html ?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#447 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAFDDRMNMINMF7BXJDLBOLSFSIDVANCNFSM4J5H6D5Q>.
|
How did I miss this! When did this happen? |
276ff5b :)
…On Sun, 13 Sep 2020, at 12:21 PM, Saurabh Nanda wrote:
> This is no longer true, and Opaleye can now be used through just it's Functor/Applicative/Monad interface, with no loss of functionality
How did I miss this! When did this happen?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#447 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAFDDXQ5T3GYPA7ZRKTM6DSFSTLPANCNFSM4J5H6D5Q>.
|
Let me update my code samples in that case. Is any interface preferred? Any known drawbacks of the new Monad interface? @ocharles any other feedback on the implementation guide? Does this match your experience of using opaleye in production? |
On Sun, 13 Sep 2020, at 2:52 PM, Saurabh Nanda wrote:
Let me update my code samples in that case. Is any interface preferred? Any known drawbacks of the new Monad interface?
We only recently converted all our code to it, but haven't encountered a problem yet!
@ocharles <https://github.com/ocharles> any other feedback on the implementation guide? Does this match your experience of using opaleye in production?
I can't really comment on that, we use rel8 which only uses Opaleye for implementation - none of Opaleye is visible in the client API.
|
I'd say it's more than just benchmarks - we run with a fork that literally adds |
@saurabhnanda Very nice indeed! Just a few comments below. By the way, I implemented a sample database for Munihac. I'd like to tidy it up and publish it more officially as a suite of Opaleye examples.
As Ollie pointed out, there is a Monad interface now.
Small typo here: should be "strongly recommended" |
@tomjaguarpaw I'm working on updating the chapters related to setting up Haskell <=> DB bridge using |
If you have myTable :: Table (Field SqlInt4, Field SqlInt4) (Field SqlInt4, Field SqlInt4)
q1 = selectTable myTable
q2 = fmap fst (selectTable myTable) Then SELECT column1, column2 FROM mytable and SELECT column1 FROM mytable It's the |
But the fact that a |
Based on this explanation, shouldn't Unpackspec be part of Query instead of FromField? I was under the impression that via Unpackspec one has the ability to map multiple DB fields to a single Haskell value. Then that's not the case, right? And would it be right to say, that via FromField one sets up the field/col level bridge and via Table (including profunctor magic) one sets up the row-level bridge? |
@tomjaguarpaw the machinery to use for Haskell => DB conversion would be https://hackage.haskell.org/package/opaleye-0.7.1.0/docs/Opaleye-ToFields.html#t:ToFields , right? Why is it plural? Is there any use-case where one would write |
@tomjaguarpaw and as I'm looking at the user-facing API, I'm wondering whether they asymmetry is really warranted, i.e.
|
@tomjaguarpaw are you happy with the following as a final user-facing API? instance DefaultFromField SqlText OrderStatus where
defaultFromField = fromPGSFieldParser orderStatusFieldParser
instance Default ToFields OrderStatus (Column SqlText) where
def = toToFields (toFields . orderStatusToText) |
Right
You might not write the instance for something containing multiple fields (although you could). But even so you often call it like |
That looks fine
I think On the other hand I added an experimental function to allow easy mapping between Haskell and DB types called
This is a bit of a wart that was needed to support nullable and non-nullable fields uniformly. I hope it won't be needed in the new
This is getting into quite technical areas. I don't understand why this question needs answering. The fact that a
The
|
Requested by @williamyaoh. I'll have to refamiliarise myself with it.
https://haskell-webapps.readthedocs.io/en/latest/docs/opaleye/opaleye.html
The text was updated successfully, but these errors were encountered: