Q:

Putting/Getting compressed data in SQLite with F#

I am attempting to port an existing project of mine (a web scraper) from Python to F#, in order to learn F#. A component of the program saves compresses large strings (raw HTML) using LZMA, and stores it in SQLite in a makeshift key value table. The HTML string should always be unicode.
Because I am an F# beginner and this requires a lot of .NET interop, I am very confused as to how to accomplish this.
I would like to know how to do this properly in F#, and using LZMA instead of GZip.
Edit
I had difficulty finding an LZMA2 compatible .NET library, as LZMA-SDK uses LZMA1. This would not have been compatible with my existing data compressed using LZMA2. Therefore, along with help from comments I went ahead and implemented this using Gzip.

A:

This uses Gzip for compression and is compatible with the gzip.compress/gzip.decompress functions in Python 3.5.
#if INTERACTIVE
#r "../packages/System.Data.SQLite.Core/lib/net46/System.Data.SQLite.dll"
#endif

open System.IO
open System.IO.Compression
open System.Data.SQLite

let compressString (s:string) =
  let bs = System.Text.Encoding.UTF8.GetBytes(s)
  use outStream = new MemoryStream()
  use gzOutStream = new GZipStream(outStream, CompressionMode.Compress, false)
  gzOutStream.Write(bs, 0, bs.Length)
  outStream.ToArray()

let decompressString (bs:byte[]) =
  use newInStream = new MemoryStream(bs)
  use gzOutStream = new GZipStream(newInStream, CompressionMode.Decompress, false)
  use sr = new StreamReader(gzOutStream)
  sr.ReadToEnd()

let insert dbc (key:string) (value:string) =
    let compressed = compressString value
    let cmd = new SQLiteCommand("INSERT into kvt (key, value) VALUES (@key, @value)", dbc)
    cmd.Parameters.Add(new SQLiteParameter("@key", key)) |> ignore
    cmd.Parameters.Add(new SQLiteParameter("@value", compressed)) |> ignore
    let res = cmd.ExecuteNonQuery()
    res

let fetch dbc (key:string) =
    let cmd = new SQLiteCommand("SELECT value FROM kvt WHERE key = @key", dbc)
    cmd.Parameters.Add(new SQLiteParameter("@key", key)) |> ignore
    let reader = cmd.ExecuteReader()
    reader.Read() |> ignore
    let compressed = unbox<byte[]> reader.["value"]
    decompressString compressed

let create() = 
    System.Data.SQLite.SQLiteConnection.CreateFile("mydb.sqlite")
    let dbc = new SQLiteConnection("Data Source=mydb.sqlite;Version=3;")
    dbc.Open()
    let cmd = new SQLiteCommand("CREATE TABLE kvt (key TEXT PRIMARY KEY, value BLOB)", dbc)
    let res = cmd.ExecuteNonQuery()
    dbc

