edgedb / edgedb-net

The official .NET client library for EdgeDB

Home Page:https://edgedb.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Add support for Some type in parameters

Darkle opened this issue · comments

commented

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
  }

Implemented in #58