by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 09 15:05
    bitemyapp commented #1097
  • Jul 09 15:05
    bitemyapp review_requested #1097
  • Jul 08 13:02
    MaxGabriel commented #1097
  • Jul 07 17:08
    bitemyapp commented #1097
  • Jul 07 16:47
    psibi commented #775
  • Jul 07 16:12
    MaxGabriel commented #775
  • Jul 07 16:07
    psibi commented #775
  • Jul 07 15:58
    MaxGabriel commented #775
  • Jul 07 15:57

    MaxGabriel on configurableIdleTimeout

    wip (compare)

  • Jul 07 15:56
    MaxGabriel commented #775
  • Jul 07 15:56
    MaxGabriel synchronize #1097
  • Jul 07 15:56

    MaxGabriel on connectionTimeoutIncrease

    .. (compare)

  • Jul 07 15:55
    MaxGabriel opened #1097
  • Jul 07 15:54

    MaxGabriel on connectionTimeoutIncrease

    Increase default idle timeout t… (compare)

  • Jul 07 10:47

    snoyberg on longer-timeouts

    Longer timeouts (compare)

  • Jul 07 10:44

    snoyberg on longer-timeouts

    Longer timeouts (compare)

  • Jul 07 02:18
    erikd commented #1096
  • Jul 07 02:13
    erikd commented #1096
  • Jul 07 02:04
    erikd commented #1096
  • Jul 06 08:42
    erikd commented #1096
Maximilian Tagher
@MaxGabriel
Oh sweet
Christine Dodrill
@Xe
I'm having trouble defining a set of data models: https://gist.github.com/Xe/ffb1394e315f39804cbf
Divam
@dfordivam
@gregwebs Hi Greg, the persistent-mongodb package on stackage doesn't have the > 2.5 version, though hackage has. Is this intended because of some incompatibility or the stackage has not been upated yet?
Rui Afonso Pereira
@rpereira

Hey guys. I'm using Servant and Database.Persist.Postgresql and struggling with relations in persistent. Perhaps you guys can give me some help, please :) I have the two following entities:

Schedule json
  trainId       Int
  stationId     StationId
  srcStationId  Int
  dstStationId  Int
  arrivalTime   UTCTime Maybe
  departureTime UTCTime Maybe
  deriving Show

Station json
  name      Text
  crsCode Text sqltype=varchar(3)
  UniqueCode crsCode tiplicCode
  deriving Show

I'm trying to get all schedule trains for a given station. So far this is what I have:

getScheduleForStation :: Text -> App [Entity Schedule]
getScheduleForStation crsCode = do
  station <- runDb (selectFirst [StationId ==. crsCode] [])
  runDb (selectList [ScheduleStationId ==. station] [])

and this is the error I'm getting:

/Users/rap/code/thesis/TicketReservation/src/Api/Schedule.hs:29:34: error:
    • Couldn't match type ‘Text’ with ‘Key Station’
        arising from a use of ‘StationId’
    • In the first argument of ‘(==.)’, namely ‘StationIdIn the expression: StationId ==. crsCode
      In the first argument of ‘selectFirst’, namely
        ‘[StationId ==. crsCode]’

/Users/rap/code/thesis/TicketReservation/src/Api/Schedule.hs:30:22: error:
    • Couldn't match type ‘Maybe (Entity Station)’ withKey Station’
        arising from a use of ‘ScheduleStationId’
    • In the first argument of ‘(==.)’, namely ‘ScheduleStationIdIn the expression: ScheduleStationId ==. station
      In the first argument of ‘selectList’, namely
        ‘[ScheduleStationId ==. station]’

can anyone please help me understand what's wrong with the relation? Thanks in advance.

odsogunro
@odsogunro

hello all
a beginner here
I am looking for the best haskell ORM to use for abstracting SQL and NoSQL backends.
I have been using/working with Yesod's persistent and made progress; however, I am having problems connecting to an existing database in sqlite3 using persistent.

https://pastebin.com/ChaB0zG7

Felix Schlitter
@felixSchl
@odsogunro what's your problem?
Question: Is there a way to perform data migrations using persistent? By that I mean a way to safely write a migration in haskell code that will only be executed once on a given database.
Felix Schlitter
@felixSchl
Another question: is it possible to insert an Entity? I have a bunch of records with existing ids that I need to insert
Eugen Kuksa
@eugenk
@felixSchl , if you have an id, then it's already inserted. The id is generated at insertion.

Is it possible to create an index on an sql table column? I don't mean a unique index. Just a regular index without constraints.
Example:

share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
MyObject
  myValue String
  UniqueMyValue myValue
|]

would create a unique index on the column myValue, but how would I create a regular index?

Felix Schlitter
@felixSchl
@eugenk yes, but if you have data from elsewhere that already has ids then you need to insert an existing id. anyway, i asked that in july and have long solved it :P It's pretty quite in here. I'd be interested in the index question, too.
to be honest, i think you would need to create that index in an extra sql script
Eugen Kuksa
@eugenk
@felixSchl how have you inserted the ids?
Eugen Kuksa
@eugenk
thanks
Eugen Kuksa
@eugenk
@felixSchl I searched the source code of persistent and could not find any trace of creating indexes
Ricardo Sanchez
@ricksanchez
Hello, is somebody using Esqueleto? do you know about some way to unValue tuples? e.g. (Value x, Value y, Value z) = (x,y,z) or some generic way to run functions in tuples?

I made a class with a type family for this issue:

class EsqueletoValued m where
    type ValuesResult m
    unValueTuple :: m -> ValuesResult m

But maybe there is an existing solution in Esqueleto

Felix Schlitter
@felixSchl
@ricksanchez I don't think so, but I am curious how does code look like with your solution?
Ricardo Sanchez
@ricksanchez
@felixSchl I made instances for a simple value and tuples of 2 elements to 8, and a function selectUnvalue, so I can use the values directly, without having to pattern match the constructor. The (Value x,...) is something that really makes me feel not DRY at all. Needless to say, this only applies for tuples without Entity
Ricardo Sanchez
@ricksanchez
or maybe a new operator that returns the values without Value, does it exist? if no, is it worthy to add it to esqueleto?
Sandy Maguire
@isovector
hey! is there an easy way to add instrumentation to the individual actual IO actions that hit sql dbs?
i want to add some automatic timing around them
Alexis King
@lexi-lambda
I would really like to find a way to fix this issue I opened a couple days ago, but the persist-template code is rather confusing to me. yesodweb/persistent#729
It seems like Database.Persist.TH makes some awkward assumptions and relies very heavily on names rather than bindings, so it only looks at the syntactic structure of field types. I was looking to see if there was a place I could insert a call to reifyRoles, but it doesn’t seem obvious to me.
Is solving that issue hopeless without restructuring the way it handles fields, or is there something I could do to get it working, even in a hacky way?
Maximilian Tagher
@MaxGabriel
Maybe wrap runDB with some function that takes the time before and after, and sends it off to STATSD or something?
@isovector
naushadh
@naushadh

re: instrumentation - @MaxGabriel such a runDB wrapper would only show how long database call(s) took. What would be ideal is to capture stats of each call (sql + duration). Sometimes an inefficient database query does not manifest itself until it's already in Production (an unusual amount of data added to a table that used to be small).

I can think of couple of options

  • quick and dirty: bracket each database query with timing and log it along with the query. persistent users either then manually grep through logs or use a log processor to push to say statsD.

  • stats tooling: persistent adds ability to track the timing+sql of each database query (ex: in an IORef) and exposes an API to get the latest stats (ex: getStats or runDbWithStats).

Sibi Prabakaran
@psibi

@MaxGabriel Saw your change to Yesod wiki - https://github.com/yesodweb/yesod/wiki/ghci/_compare/02fd78f%5E...02fd78f

IIRC, that page has been migrated to yesod-cookbook repo previously. We really need to fix up the yesod wiki (Just like how persistent wiki was cleaned up some months ago).

Maximilian Tagher
@MaxGabriel
Ah ok, yeah I remember now
Steven Leiva
@StevenXL
Folks, a little help
Where does db come from?
Steven Leiva
@StevenXL
@psibi thank you. I was able to find it eventually. Appreciate the help!
Benjamin Goldstein
@benjamingoldstein
Hi all! Ben here, wanting to participate and give back to the community of Haskellers
Benjamin Goldstein
@benjamingoldstein
I posted a few simple questions on stack overflow about Yesod, but have received no answers, is the community still alive? I said "hi" almost a week ago here, is there somewhere cooler where everyone is hanging out that I have missed?
Benjamin Goldstein
@benjamingoldstein
It would be a sad thing if Haskell is not really used in production. :cry: I am so excited about functional programming and using my haskell knowledge with Yesod! I would gladly put some bitcoin bounty on answering this question for example: https://stackoverflow.com/questions/58591677/mystery-of-subsite-types
Drew Boardman
@drewboardman
anyone notice the tutorial example doesn't compile?
Sibi Prabakaran
@psibi
@drewboardman Add a main function and a language extension MultiParamTypeClases and it should work.
This works for me as a stack script
#!/usr/bin/env stack
-- stack --resolver lts-13.19 script
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}

import Control.Monad.IO.Class (liftIO)
import Database.Persist
import Database.Persist.Sqlite
import Database.Persist.TH

mkPersist
  sqlSettings
  [persistLowerCase|
Person
    name String
    age Int
    deriving Show
|]

main :: IO ()
main = print "hello world"
Nhan Thai
@dandoh
it says here in the tutorial (https://www.yesodweb.com/book/persistent)
that this code runs fine
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}

module Main where

import Conduit
import Control.Monad.IO.Class (liftIO)
import Control.Monad.IO.Unlift
import Control.Monad.Logger
import Control.Monad.Reader
import Data.Text
import Database.Persist
import Database.Persist.Sqlite
import Database.Persist.TH

share [mkPersist sqlSettings, mkSave "entityDefs"]
    [persistLowerCase|
Person
    name String
    age Int Maybe
    deriving Show
|]

runSqlite' ::
       (MonadUnliftIO m)
    => Text
    -> ReaderT SqlBackend (NoLoggingT (ResourceT m)) a
    -> m a
runSqlite' = runSqlite

main :: IO ()
main =
    runSqlite' ":memory:" $ do
        michaelId <- insert $ Person "Michael" $ Just 26
        michael <- get michaelId
        liftIO $ print michael
but I got
image.png
Nhan Thai
@dandoh
ok because of this: