edgedb / edgedb-net

The official .NET client library for EdgeDB
https://edgedb.com
Apache License 2.0
83 stars 9 forks source link

[Feature Request] Add support for Some type in parameters #55

Closed Darkle closed 1 year ago

Darkle commented 1 year ago

It would be very handy if edgedb-net supported passing in a Some type in query parameters.

Since the edgedb-net client doesn't support passing in Some values, I have to manually unwrap the optionals to get the value or set them to null. Since you can already pass in a None value as a parameter, it would make things a lot simpler if you could also pass in a Some value too. That would mean I wouldn't have to unwrap them or set them to null.

A somewhat contrived example: This doesnt work:

let getSinglePost (postId: string option) =
  let queryParams = new Dictionary<string, obj>()
  queryParams.Add("postId", postId)

  task {
    try
      let! results =
        dbClient.QuerySingleAsync<Post>(
          "select Post{*} filter .postId = <optional str>$postId",
          queryParams
        )

      return Ok(results)
    with err ->
      Logger.Error(message = "Error with getSinglePost", error = err)
      return Error err
  }

So I have to do:

let getSinglePost (postId: string option) =
  let pId = Option.defaultValue null postId
  let queryParams = new Dictionary<string, obj>()
  queryParams.Add("postId", pId)

  task {
    try
      let! results =
        dbClient.QuerySingleAsync<Post>(
          "select Post{*} filter .postId = <optional str>$postId",
          queryParams
        )

      return Ok(results)
    with err ->
      Logger.Error(message = "Error with getSinglePost", error = err)
      return Error err
  }
quinchs commented 1 year ago

Implemented in #58