Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update table with dynamic column name? #25

Closed
dredgy opened this issue May 9, 2021 · 2 comments
Closed

Update table with dynamic column name? #25

dredgy opened this issue May 9, 2021 · 2 comments

Comments

@dredgy
Copy link

dredgy commented May 9, 2021

Not exactly a big deal but wanting to do a simple update column function

eg let updateColumn key column value

Looking at the partial update expression, I’d want something similar to this:

let updateColumn key column value  =
    update {
        table "Persons"
        set {| column = value |}
        where (eq "person-id" key)
    } |> conn.UpdateAsync

Is this possible? Computation expressions are very confusing to me!

@Dzoukr
Copy link
Owner

Dzoukr commented May 10, 2021

Good day to you too! 😄

If you need this kind of flexibility, where you don't know column name or value upfront, fallback to plain Dapper then. Column names are generated via reflection from anonymous/named records and if you take away this, there's no need to use anything else than plain Dapper like:

let updateColumn key column value =
    let sql = "UPDATE Persons SET @col = @val WHERE person-id = @key"
    let pars = [("col", box column); ("val", box value); ("key", box key)]
    connection.ExecuteAsync(sql, pars)

@dredgy
Copy link
Author

dredgy commented May 10, 2021 via email

@Dzoukr Dzoukr closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants