Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Ben Plommer
    @bplommer
    ah ok, pity I never read docs 😁
    Rob Norris
    @tpolecat
    Ah, pity indeed.
    You can certainly run many sessions concurrently and their transactions will be independent.
    Ben Plommer
    @bplommer
    Is it a bad idea to use a semaphore to make concurrent transactions run serially (if I'm willing to take the throughput hit)?
    Rob Norris
    @tpolecat
    You can't do that. Semaphores aren't re-entrant.
    What are you trying to do?
    Ben Plommer
    @bplommer
    just foo.parTraverse(doSomethingWithDbTransaction)
    Not reentrant code
    Rob Norris
    @tpolecat
    Yeah just .traverse
    transactions are absolutely sequential, there's no benefit trying to do them in parallel
    Ben Plommer
    @bplommer
    It does a bunch of HTTP stuff first though, is the thing.
    the doSomethingWithDbTransaction spends most of its time waiting for downstream REST services
    Rob Norris
    @tpolecat
    I see. Can you restructure to do the http stuff first?
    A semaphore should work ok if you know you're not re-entering.
    But it won't work in general (otherwise skunk would do it for you).
    Mathieu Prevel
    @mprevel
    Hey everyone.
    I'm experimenting with skunk :)
    Is there a clever way to do an insert with an auto generated id (serial) from postgresql ? (Maybe I missed it from the docs)
    Mathieu Prevel
    @mprevel
    I am able to get the id with this query :
    sql"INSERT INTO mytable(title) VALUES ($varchar) RETURNING id".query(int4)
    Rob Norris
    @tpolecat
    Yep, that’s how you do it.
    Kapil Koju
    @TheKojuEffect

    Hi,

    From the skunk command example, update is done like following.

    sql"""
        UPDATE country
        SET    headofstate = $varchar
        WHERE  code = ${bpchar(3)}
      """.command
         .gcontramap[Info]

    Is it possible to write the update query like following in which value is interpolated instead of type?

    sql"""
       UPDATE country
       SET headofstate = $hos
       WHERE code = $code
    """

    Thank you,

    Rob Norris
    @tpolecat
    Kind of. You can apply a fragment to arguments and get an AppliedFragment back. There is an example in modules/examples/
    There is nothing immediately analogous to what doobie does.
    Kapil Koju
    @TheKojuEffect
    Thank you @tpolecat , yes I was looking to do something like in doobie. :)
    Brandon Stilson
    @bbstilson
    hey quick question. how does one run the tests?
    Rob Norris
    @tpolecat
    docker-compose up to start all the test servers and then sbt test
    Should probably write a contributors guide.
    Brandon Stilson
    @bbstilson

    I can add some notes to the readme (to to a contribution readme).

    I think some other steps might be needed. I'm getting this from the docker compose logs:

    trust_1     | 2020-10-12 00:08:34.984 UTC [38] FATAL:  database "bogus" does not exist
    trust_1     | 2020-10-12 00:08:35.020 UTC [39] FATAL:  role "bogus" does not exist
    scram_1     | 2020-10-12 00:08:35.336 UTC [35] FATAL:  database "blah" does not exist
    scram_1     | 2020-10-12 00:08:35.368 UTC [36] FATAL:  expected SASL response, got message type 88
    scram_1     | 2020-10-12 00:08:35.408 UTC [37] FATAL:  password authentication failed for user "frank"
    scram_1     | 2020-10-12 00:08:35.408 UTC [37] DETAIL:  Role "frank" does not exist.
    scram_1     |   Connection matched pg_hba.conf line 95: "host all all all scram-sha-256"
    scram_1     | 2020-10-12 00:08:35.462 UTC [38] FATAL:  password authentication failed for user "jimmy"
    scram_1     | 2020-10-12 00:08:35.462 UTC [38] DETAIL:  Connection matched pg_hba.conf line 95: "host all all all scram-sha-256"
    trust_1     | 2020-10-12 00:09:35.811 UTC [47] FATAL:  database "bogus" does not exist
    trust_1     | 2020-10-12 00:09:35.831 UTC [48] FATAL:  role "bogus" does not exist
    scram_1     | 2020-10-12 00:09:36.101 UTC [42] FATAL:  database "blah" does not exist
    scram_1     | 2020-10-12 00:09:36.127 UTC [43] FATAL:  expected SASL response, got message type 88
    scram_1     | 2020-10-12 00:09:36.166 UTC [44] FATAL:  password authentication failed for user "frank"
    scram_1     | 2020-10-12 00:09:36.166 UTC [44] DETAIL:  Role "frank" does not exist.
    scram_1     |   Connection matched pg_hba.conf line 95: "host all all all scram-sha-256"
    scram_1     | 2020-10-12 00:09:36.211 UTC [45] FATAL:  password authentication failed for user "jimmy"
    scram_1     | 2020-10-12 00:09:36.211 UTC [45] DETAIL:  Connection matched pg_hba.conf line 95: "host all all all scram-sha-256"
    Brandon Stilson
    @bbstilson
    actually those are expected failures at the pg level. i am getting sbt failures. I'll keep investigating.
    Rob Norris
    @tpolecat
    Yeah there are a lot of tests for error conditions. You can usually ignore the logs. Hit ^c and do docker-compose up -d to background it.
    Brandon Stilson
    @bbstilson
    ah i think I found the issue
    postgres_1  | waiting for server to start....2020-10-12 01:06:14.508 UTC [47] FATAL:  private key file "/var/lib/postgresql/server.key" has group or world access
    postgres_1  | 2020-10-12 01:06:14.508 UTC [47] DETAIL:  File must have permissions u=rw (0600) or less if owned by the database user, or permissions u=rw,g=r (0640) or less if owned by root.
    postgres_1  | 2020-10-12 01:06:14.508 UTC [47] LOG:  database system is shut down
    i'll chmod that key file and see if that helps
    Rob Norris
    @tpolecat
    ah yeah sorry, that needs to be in the doc
    look at the gh action source under .github to see what CI does
    Brandon Stilson
    @bbstilson
    got it! the chown shouldn't be necessary right? just the chmod command
    okay i got it to work. the issue was that i had the postgres app running. it was probably preventing the docker network from using localhost:5432
    Brandon Stilson
    @bbstilson
    is there any reason not to commit the permissions for server.key at 600 to source?
    Rob Norris
    @tpolecat
    I don’t know how to do that. If it’s possible then yes.
    Brandon Stilson
    @bbstilson
    i was mistaken; it's not possible. git only tracks the executable bit of a file.
    Brandon Stilson
    @bbstilson
    I opened a PR to ease new users into contributing. Thanks for the help!
    Doron Somech
    @somdoron
    Does skunk support postgres composite types?
    Rob Norris
    @tpolecat
    Not yet. It supports row types for parameters but not for column values, so you would need to pull out the components. It’s on the list.
    Doron Somech
    @somdoron
    Thanks. My company might be interested in contribute that, any pointers you might have would be welcomed.
    Hossam El-Deen
    @hossameldeen

    How to use skunk in non-cats-effects code?

    I tried skunk in some sketch code and really liked its error messages, non-blocking nature, ... etc. However, I couldn't really wrap my head around cats-effects would like to be able to use skunk in non-cats-effects project. How to go about that?

    E.g., how to build such an API on top of skunk?

    def withSession[T](f: Session => Future[T]): Future[T]
    def unique[A, B](s: Session, query: Query, a: A): Future[B]
    // ...

    Of course, the above is only pseudo-code. E.g., there's query preparation, ... etc. But the gist is how to call skunk from non-cats-effects code?

    Rob Norris
    @tpolecat
    You can’t. You can program in IO and turn the resulting IO into a Future but you can’t use Future as your effect in your Skunk code. It can’t do what’s needed.
    Hossam El-Deen
    @hossameldeen

    You can’t. You can program in IO and turn the resulting IO into a Future.

    That's exactly what I need. Using Future as effect is not what I need.

    I.e., how to go about implementing, e.g., unique[A, B](query: Query[A, B], A): Future[B]? (Forget the Session thing). And preferably, how to implement this efficiently/properly?

    So, the question in another way: Outside of an IOApp, how can I call the code here? https://tpolecat.github.io/skunk/tutorial/Query.html#service-oriented-example

    And a subsequent question: The linked code uses Session.single; how would I go about the same thing with Session.pooled? (Actually, I don't know how to reuse preparation, like in the linked example, when using Session.pooled. But that's another point)

    Rob Norris
    @tpolecat
    @hossameldeen ^^ but you will still need to understand cats-effect and fs2 in order to implement anything serious. In general interacting with Future will be tricky and isn't a use case we're spending any effort to support.
    Hossam El-Deen
    @hossameldeen

    Wow, thank you very much for your help! @tpolecat ... Your example will allow me to take a step forward for now :thumbsup:

    And yes, I understand this is out-of-scope of skunk and that I could shoot myself in the foot using it. Let's hope that with time I betters understand cats-effect and fs2.

    Rob Norris
    @tpolecat
    :+1: good luck!
    Gavin Bisesi
    @Daenyth

    @hossameldeen I have a tech talk aimed at folks in your situation - https://github.com/daenyth/intro-cats-effect/

    If you can understand correctly how to use Future, you should find IO easier to use (if less familiar).

    If you think Future is always easy to use, you might not understand how to use it correctly ;)