Skip to content

Instantly share code, notes, and snippets.

@teyc
Created March 14, 2020 08:41
Show Gist options
  • Save teyc/6cfd974277035b81aee037d12aff12a8 to your computer and use it in GitHub Desktop.
Save teyc/6cfd974277035b81aee037d12aff12a8 to your computer and use it in GitHub Desktop.
F# SQL provider
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
</ItemGroup>
<Import Project=".paket\Paket.Restore.targets" />
</Project>
source https://api.nuget.org/v3/index.json
storage: none
framework: netcore3.1, netstandard2.0, netstandard2.1
nuget Npgsql
nuget SQLProvider
open FSharp.Data.Sql
type DB = SqlDataProvider<
Common.DatabaseProviderTypes.POSTGRESQL,
"Host=localhost;Port=5432;User ID=postgres;Database=Chui">
let db = DB.GetDataContext()
let allCustomers =
query {
for customer in db.Public.Customers do
where (customer.Firstname.Length > 3)
select customer
}
[<EntryPoint>]
let main argv =
for customer in allCustomers do
printfn "%A" customer.Firstname
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment