Questions tagged [postgresql-simple]

Mid-level client library for accessing PostgreSQL from Haskell

Homepage: https://github.com/lpsmith/postgresql-simple

22 questions
4
votes
2 answers

Creating a streaming Conduit Source with postgresql-simple

postgresql-simple provides functions for streaming queries, e.g. fold :: (FromRow row, ToRow params) => Connection -> Query -> params -> a -> (a -> row -> IO a) -> IO a I want to create a conduit source which takes full advantage of…
icz
  • 537
  • 1
  • 7
  • 14
4
votes
1 answer

Database-backed REST API with servant?

I am running into a problem setting up a simple proof of concept servant API. This is my User datatype and my API type: data User = User { id :: Int, first_name :: String, last_name :: String } deriving (Eq, Show, Generic) instance FromRow…
asg0451
  • 493
  • 4
  • 13
4
votes
2 answers

count(*) type compatibility error with Database.PostgreSQL.Simple?

The error is *** Exception: Incompatible {errSQLType = "int8", errHaskellType = "Int", errMessage = "types incompatible"} It looks like any value returned by count(*) in the query must be converted into Integer rather than Int. If I change those…
dan
  • 43,914
  • 47
  • 153
  • 254
3
votes
1 answer

How to retrieve JSON jsonb value with postgresql-simple?

I have a column (jsonExample) in the postgresql database with type jsonb. selectCALogs :: IO [(Int, Object)] selectCALogs = do con <- connection query_ con "select \"clusterId\", \"jsonExample\" from cluster" This gives an error of: • No…
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
3
votes
1 answer

PostgreSQL Simple supports only up 10 variables in a tuple, but I need more

I have a postgresql table with a bunch of columns, it's around 20-30 columns. Posgresql Simple supports only up 10 variables in a tuple…
Judi
  • 147
  • 2
  • 7
2
votes
2 answers

postgres-simple - No instance for (ToRow Int) arising from a use of ‘query’

I am new to haskell and have honestly hard times with it. But it expands my thinking, so here we go. I am trying to run a really simple Webserver that queries a Postgres DB and should return the result as JSON. The query is absolutely…
2
votes
2 answers

Haskell PostgreSQL Simple FromField

I'm having trouble with defining FromField instance for my custom enum data type: data Role = Staff | Student deriving (Eq, Ord, Show) To represent Role in my database, I will use ints 0 and 1 (more roles could be added later) most likely…
Reygoch
  • 1,204
  • 1
  • 11
  • 24
1
vote
1 answer

Error of `Incompatible {errSQLType = "varchar",...` for simple select query using postgresql-simple

I have defined a PostgreSQL table as follows: > \d+ public."Users" Table "public.Users" Column | Type | Collation | Nullable | Default …
altern
  • 5,829
  • 5
  • 44
  • 72
1
vote
0 answers

How to Dynamically assemble SQL queries with haskell based on route parameters

I've got a scotty web app that I am trying to implement a dynamic search interface over and keep hitting a wall on how I should implement it. The Basic premise is the following: Given a list of URL parameters: let params = [Param] where param: type…
emg184
  • 850
  • 8
  • 19
1
vote
0 answers

Suggested approach for building dynamic sql queries with haskell

I would like to use postgresql-simple for my database access layer in my application and i was wondering what the best method would be for dynamically building my sql queries. A simple example of what i would want to accomplish would be the…
emg184
  • 850
  • 8
  • 19
1
vote
1 answer

How to Serialize a Type to specified database columns

I am using postgresql-simple in a haskell application, and i want to be able to serialize a data type to a row in my database that doesn't have a 1 to 1 mapping of the record fields used in the data type because i am using them in other data types.…
emg184
  • 850
  • 8
  • 19
1
vote
1 answer

Nested data types in postgresql-simple

Consider following code which can find some set of coordinates: data Coord = Coord { lat :: Float , lon :: Float } instance FromRow Coord where fromRow = Coord <$> field <*> field findSomePoints ::…
user1518183
  • 4,651
  • 5
  • 28
  • 39
1
vote
1 answer

‘toRow’ is not a (visible) method of class ‘ToRow’

I'm learning Haskell so I decided to write a web app. I did choose PostgreSQL Simple to work with the database. I successfully connected to it and tried simple math operations but I'm having problems trying to map records to data. This code doesn't…
Tae
  • 1,665
  • 5
  • 24
  • 45
1
vote
0 answers

How to begin and rollback a transaction with hspec?

I am trying to write a test using hspec involving postgres transaction rollback as with postgresql-simple's begin and rollback commands. However, applying postgresql-simple's begin and rollback commands appears to cause my 'insert' command not to…
mherzl
  • 5,624
  • 6
  • 34
  • 75
1
vote
1 answer

haskell postgresql-simple, how to access specific data from a broader query

How can i access the data that`s in my query [VarcharIntDate] ? data VarcharIntDate = VarcharIntDate { vc :: Maybe String, i :: Maybe Int, d :: Maybe Date } deriving (Show) instance FromRow VarcharIntDate where fromRow = VarcharIntDate…
John Brown
  • 13
  • 5
1
2