Beginner's question about getting query lists
See original GitHub issueHi, I am using Npgsql.FSharp to create an API using SAFE.
I was able to connect to the database and generate records randomly. However, I fail when I try to select all records from my table.
Consideing my “table” as this type:
type Market = {
Id : int
Pair : string
Quantity : int
Price : float
}
Then, I created another type to manage my database, as well as members. Similar to the example with LiteDB/default from SAFE. A fragment from code is as follow:
type DbNpgsqlStorage() =
let connectionString : string =
Sql.host "localhost"
|> Sql.database "postgres"
|> Sql.username "postgres"
|> Sql.password "postgres"
|> Sql.port 5432
|> Sql.formatConnectionString
member __.GetMarkets () =
connectionString
|> Sql.connect
|> Sql.query "SELECT Id, Pair, Price, Quantity FROM market"
|> Sql.executeAsync (fun read ->
{
Id = read.int "Id"
Pair = read.text "Pair"
Price = read.double "Price"
Quantity = read.int "Quantity"
})
|> ignore
member __.GetCountMarkets() =
connectionString
|> Sql.connect
|> Sql.query "SELECT COUNT(*) as count_markets FROM market"
|> Sql.executeRow(fun read -> read.int "count_markets")
|> function
| Ok count -> count
| Error e -> 0
The question is: considering GetMarkets(), how can I get the list from the query? When I try to use ignore the result is a “unit”. I already used match but without success.
Similar problem I had on GetCountMarkets(), then, I used a bad workaround.
Sorry, I am learning F# and SAFE this week. I have never seen them before. Consequently, I do not know how to deal with F# Railway properly.
Every help is welcome 😄
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)

Top Related StackOverflow Question
No problem, I am glad you were able to fix the problem. I will be adding better docs soon to help with these kinds of issues 😄
I do not know why but it is working now! I guess I was trying before change the column names…sorry
Thanks a lot @Zaid-Ajaj !