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

Allow import/export of arbitrary postgres array types #171

Closed
llogiq opened this issue Sep 27, 2021 · 2 comments · Fixed by #233
Closed

Allow import/export of arbitrary postgres array types #171

llogiq opened this issue Sep 27, 2021 · 2 comments · Fixed by #233
Assignees
Labels
bug Something isn't working

Comments

@llogiq
Copy link
Contributor

llogiq commented Sep 27, 2021

Describe the bug

Currently, due to the way we interface with postgres via sqlx, their Encode trait does not allow encoding types containing slices (or things that deref to slices) of other custom types that implement Encode. I am not sure if we can solve this without changing sqlx.

To Reproduce
Steps to reproduce the behavior:

  1. Schema (if applicable)
{
    "type": "array",
    "content": {
        "type": "object",
        "intmatrix": {
            "type": "array",
            "length": {
                "type": "number",
                "range": {
                    "low": 1,
                    "high": 8,
                    "step": 1
                },
                "subtype": "u64"
            },
            "content": {
                "type": "array",
                "length": {
                    "type": "number",
                    "constant": 8
                },
                "content": {
                    "type": "number",
                    "subtype": "i32",
                    "range": {
                        "low": -32768,
                        "high": 32767,
                        "step": 1
                    }
                }
            }
        }
    },
    "length": {
        "type": "number",
        "range": {
          "low": 1,
          "high": 10,
          "step": 1
        },
        "subtype": "u64"
    }
}
  1. See error
wrong element type

Expected behavior
The array should be generated and inserted into the database

Environment (please complete the following information):

  • OS: any
  • Version: 0.5.5

Additional context
The problem stems from the implementation of the Encode trait that appears not recurse into array elements. Even if we tried changing our code to construct the "correct" types before insertion, we'd run into the requirement of constructing a value of an arbitrary type. To see why this is the case, consider that arrays can nest any number of levels. So we'd need at least to be able to construct a Vec<i32>, a Vec<Vec<i32>>, a Vec<Vec<Vec<i32>>>, etc. ad infinitum (and also any other type). Given that sqlx does not have Encode for Box<dyn Encode>, we could not even try using trait objects to overcome that issue.

@llogiq llogiq added the bug Something isn't working label Sep 27, 2021
@chesedo
Copy link
Contributor

chesedo commented Oct 13, 2021

Fyi, I am on this one 😄

@chesedo
Copy link
Contributor

chesedo commented Oct 22, 2021

I've reproduced a minimal example of this in launchbadge/sqlx#1504 so will delve into the sqlx code a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants