Skip to content

Instantly share code, notes, and snippets.

@Y-Koji
Last active August 31, 2019 12:32
Show Gist options
  • Save Y-Koji/8cce9819379f913fbf31958df29d2d7f to your computer and use it in GitHub Desktop.
Save Y-Koji/8cce9819379f913fbf31958df29d2d7f to your computer and use it in GitHub Desktop.
備忘録

F# SQLiteの設定

1. パッケージの追加

NuGetにより以下のパッケージを導入する.

  • System.Data.SQLite.Core
  • SQLProvider

System.Dataを参照に追加する.

2. データベースの構築

SQLiteのデータベースを構築する.

3. DataProviderの作成

SQLProvider型プロバイダを作成する.

open FSharp.Data.Sql
open FSharp.Data.Sql.Common

type Database =
    SqlDataProvider<
        DatabaseVendor = DatabaseProviderTypes.SQLITE,
        SQLiteLibrary = SQLiteLibrary.SystemDataSQLite,
        ConnectionString = """Data Source=.\sampledb.sqlite;""",
        CaseSensitivityChange = Common.CaseSensitivityChange.ORIGINAL>
        
[<EntryPoint>]
let main argv = 
    let context = Database.GetDataContext()
    let person = context.Main.Person.Create()
    person.Name <- "sample"
    person.Age <- 20L;
    context.SubmitUpdates()

    printfn "%A" argv
    0

実行

  1. のプログラムを実行すると以下の結果が得られる.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment