Comment by claytongulick

1 day ago

Hmm, yep I didn't see that, thanks!

It's a confusing way to do do things to me, like, why not select ordered by task date limit 1? Still using for update and skip locked etc... hold the transaction, and update to 'complete' or delete/move the row when done? What's the advantage of the inner select like that?

And I'm still totally confused by:

    const [{ usr_id } = { usr_id: null }] = await sql`
        with usr_ as (
          insert into usr (email, password)
          values (${email}, crypt(${password}, gen_salt('bf')))
          returning *
        ), task_ as (
          insert into task (task_type, params)
          values ('SEND_EMAIL_WELCOME', ${sql({ usr_id })})
        )
        select * from usr_
      `;

This looks to me like usr_id would always be null?

I think the idea is great, I think I'm just struggling a bit with the code style, it seems to be "clever" in a way that increases cognitive load without a real benefit that I can see, but I suppose that's pretty subjective.