fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
564 stars 144 forks source link

[Question] How to use Pragma with SQLITE? #794

Open OnurGumus opened 1 year ago

OnurGumus commented 1 year ago

When you use pragma statements with sqlite, you need to do it at the beginning of your connection. I am not sure how this is achievable with SqlProvider, any hints appreciated.

Thorium commented 1 year ago

As SQLite doesn't support stored procedures and the features was already there, you can do pragma via them: https://fsprojects.github.io/SQLProvider/core/programmability.html

Thorium commented 1 year ago

As in test-project:

    let dc = sql.GetDataContext()
    let pragmaSchemav = dc.Pragma.Get.Invoke("schema_version")
    let res = pragmaSchemav.ResultSet |> Array.map(fun i -> i.ColumnValues |> Map.ofSeq)
    let ver = (res |> Seq.head).["schema_version"] :?> Int64

    let pragmaFk = dc.Pragma.GetOf.Invoke("foreign_key_list", "EmployeesTerritories")
    let res = pragmaFk.ResultSet |> Array.map(fun i -> i.ColumnValues |> Map.ofSeq)
OnurGumus commented 1 year ago

In particular I'd like to set busy_timeout per connection. How can I do it? as in PRAGMA busy_timeout

Thorium commented 1 year ago

What happens if you do this: dc.Pragma.Get.Invoke("busy_timeout=300")

OnurGumus commented 1 year ago

@Thorium, Invoke doesn't take any parameter with sqlite, not for get not for getof.

image
Thorium commented 1 year ago

That's a bit weird because I took my code line from the test-project:

https://github.com/fsprojects/SQLProvider/blob/e1c768a701a0a6ec5ff47ddb74f6f1ef1ff7cbc2/tests/SqlProvider.Tests/QueryTests.fs#L2259