
F# scripts with NuGet packages
F# 5.1 finally brings joy of using NuGet packages without much hassle.
This is how you can use Npgsql library to create a new PostgreSQL database.
#r "nuget: Npgsql"
open Npgsql
let connString =
"User ID=postgres;Password=Password1!;Host=localhost;Port=5432;Database=postgres;Pooling=true;"
let conn = new NpgsqlConnection(connString)
conn.Open()
let sql = """
CREATE DATABASE "Foobar"
WITH
OWNER = postgres
ENCODING = 'UTF8'
CONNECTION LIMIT = -1;
"""
let cmd = new NpgsqlCommand(sql, conn)
cmd.ExecuteScalar()
printfn "Database created!"
You run the .fsx
script with `--langversion:preview
flag
dotnet fsi --langversion:preview .\create-database.fsx