demetrixbio / FSharp.Data.Npgsql

F# type providers to support statically typed access to input parameters and result set of sql statement in idiomatic F# way. Data modifications via statically typed tables.
Apache License 2.0
127 stars 15 forks source link

Support .pgsql file #27

Closed vfat0 closed 4 years ago

vfat0 commented 5 years ago

It would be great if the CommandProvider also worked with script files, e.g. DB.CreateCommand<"Script.pgsql">(connString) This would allow checking pgsql scripts for correctness at compile time, while maintaining syntax highlighting when viewing those script files.

davidspiess commented 5 years ago

Are there any plans to support this?

Zaid-Ajaj commented 4 years ago

This is supported by doing the following: Use FSharp.Data.LiteralProviders with this type provider as follows:

open FSharp.Data.LiteralProviders
open FSharp.Data.Npgsql

let [<Literal>] GetData = TextFile<"./queries/script.sql">.Text

let [<Literal>] ConnectionString = TextFile<"CONNECTION_STRING.txt">.Text

type Database = NpgsqlConnection<ConnectionString>

let getDataFromDb() =
    let query = Database .CreateCommand<GetData> (ConnectionString)
    let data = query.Execute()
    for row in data do
        printfn "%A" row
vfat0 commented 4 years ago

Thank you this is certainly a good solution.