Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Anton Ekblad
    @valderman
    (thank god for GeneralizedNewtypeDeriving :P)
    then you get getUsers :: App [User], which is a bit more manageable
    note that you need to be more specific about the return type than just a; since userspresumably refers to a table of some concrete type (I'm assuming Table User)
    Anton Ekblad
    @valderman
    another thing to note is that your code will probably compose better if you also make your monad an instance of MonadSelda and lift the withPostgreSQL call to the top (or at least, a bit further up); each call to it will open a new connection to the db, which means extra overhead and that any prepared statements will need to be recompiled
    sorry about the late response, things have been a bit hectic lately
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    Don't worry @valderman! And thank you very much!
    I'm indeed writing an application, so your advice is helpful!
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    @valderman Are Selda's migrations akin to ActiveRecord/Ecto's where you also describe the creation of the tables with a DSL/SQL? And is there any example I could look at, so I can check how things are done? :)
    Anton Ekblad
    @valderman
    @TechnoEmpress_twitter currently, migrations handle only going from one table to another; create/drop are a separate operation
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    @valderman thanks!
    Anton Ekblad
    @valderman
    currently, migrations are a little bit of a pain point since you need the type you're migrating from as well as the one you're migrating to
    (and also, there's this lovely bug WRT migrating indexes until the next release: valderman/selda#107)
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    Also, do you know if there's a mechanism to debug selda-postgresql? the SQL Selda produces is completely valid when pasted in the cockroach SQL shell, but not when I use query
    I get this:
    λ❯ runReaderT (runApp getUsers) config
    *** Exception: SqlError "error executing query `SELECT \"username_0\", \"uuid_1\", \"isAdmin_2\", \"password_3\", \"biography_4\" FROM (SELECT \"username\" AS \"username_0\", \"uuid\" AS \"uuid_1\", \"isAdmin\" AS \"isAdmin_2\", \"password\" AS \"password_3\", \"biography\" AS \"biography_4\" FROM \"users\") AS q0': ERROR:  relation \"users\" does not exist\n"
    whereas in the cockroach shell I've got:
    root@localhost:26257/defaultdb> SELECT "username_0", "uuid_1", "isAdmin_2", "password_3", "biography_4" FROM (SELECT "username" AS "username_0", "uuid" AS "uuid_1", "isAdmin" AS "isAdmin_2", "password" AS "password_3", "biography" AS "biography_4" FROM "users") AS q0
    
      username_0 | uuid_1 | isAdmin_2 | password_3 | biography_4
    +------------+--------+-----------+------------+-------------+
    (0 rows)
    Anton Ekblad
    @valderman
    are you specifying the right database in your connection info? it looks like the db thinks there's no users table
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    yeah… I guess?
    lemme double-check
    Anton Ekblad
    @valderman
    hm, that's weird
    could it be that cockroach is doing something almost-but-not-quite postgres compatible to switch databases?
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    that's would be super fucking weird
    Anton Ekblad
    @valderman
    agree
    they support postgres ORMs from other languages
    Anton Ekblad
    @valderman
    it seems to use libpq for Go at least, which is what selda uses under the hood, so that shouldn't be an issue
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    I'm going to use CockroachDB's own debugging features, like audit logs and such
    Anton Ekblad
    @valderman
    that's probably the best way to go about it; the error selda throws when a query goes wrong contains pretty much all the info there is to be had from the db connection layer
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    yep

    (for what it's worth, I've also got this configuration:

    λ❯ pgConnString . connectInfo $ config
    "host=localhost port=26257 dbname=defaultdb user=euphrate connect_timeout=10 client_encoding=UTF8"

    )

    Anton Ekblad
    @valderman
    as for migration examples, there's not much to it; you need to give the source and destination tables as well as a selda expression to convert a row from the source table into one for the destination table, so something like this:
    data User1 = User1 {name :: Text, password :: Text}
    t1 :: Table User1
    t1 = table "user" []
    
    data User2 = User2 {name :: Text, password :: Text, age :: Int}
    t2 :: Table User2
    t2 = table "user" []
    
    main = withPostgreSQL $ migrate t1 t2 (\user -> user `with` [#age := 0])
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    cool, I'm keeping that snippet for later
    :)
    Anton Ekblad
    @valderman
    having to keep the old table around is annoying, as you can see :P
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    yuup
    Anton Ekblad
    @valderman
    I have a pretty neat idea of how to get around that while still preserving type safety, and it's probably implementable as a much higher level selda-migrations library on top of the current migrations, but I haven't had the time to try it out in practice yet
    that config looks sound to me; extremely weird that it can't find the users table
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    yep'
    Al͜l ̸͑ha͂͟il̶!
    @TechnoEmpress_twitter
    blah
    I give up for tonight
    David Johnson
    @dmjio
    selda is great. Thanks @valderman
    Anton Ekblad
    @valderman
    @dmjio thanks! hopefully the upcoming changes in 0.4 will earn a stamp of approval as well; that stuff's been piling up for a while :)
    Alexander Gerasimov
    @DaQuirm
    hi
    I'm building my first app with selda and I ran into a problem: I'm using the ID type in my entity and that prevents me from deriving generic aeson instances for it (as there appears to be no aeson or generic instances for ID).
    Any elegant way to solve this?
    Thanks!
    @valderman
    Anton Ekblad
    @valderman
    @DaQuirm not really elegant perhaps, but you could manually create instances for ID using toId and fromId
    also, not having those instances are a bit of an oversight, so I'll make a new release soonish which adds Generic instances in selda, and To/FromJSON in selda-json
    Alexander Gerasimov
    @DaQuirm
    Thank you, did just that :)
    Yes, it would be cool to have the instances out of the box, awesome!
    Anis Jonischkeit
    @anisjonischkeit
    Hey @valderman , I just tried installing from the latest version on hackage and it looks like SeldaM takes two parameters now. What's the additional one I need to include?
    Anis Jonischkeit
    @anisjonischkeit
    nevermind, I figured it out with:
    import           Database.Selda.PostgreSQL (PG)
    SeldaM PG a
    Alexander Gerasimov
    @DaQuirm

    Hej @valderman
    I'm trying to migrate to selda-0.5.0.0 but stack refuses to build selda-postgresql:

    stack build
    
    Error: While constructing the build plan, the following exceptions were encountered:
    
    In the dependencies for selda-postgresql-0.1.8.0:
        selda-0.5.0.0 from stack configuration does not match >=0.4 && <0.5

    The dependency seems to be listed correctly in the cabal file in the repo (< 0.6):
    https://github.com/valderman/selda/blob/master/selda-postgresql/selda-postgresql.cabal

    But it's still 0.4 as seen on Hackage:
    https://hackage.haskell.org/package/selda-postgresql

    Thanks!

    Anton Ekblad
    @valderman
    @DaQuirm: oops, that's me messing up the release! the version bounds on the -sqlite and -postgresql packages didn't get updated properly; I bumped the bounds on hackage, so hopefully it should work now after a cabal update
    sorry about that
    Alexander Gerasimov
    @DaQuirm
    it does work now, thank you! :+1: