-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fails to insert jsonb values in Postgres #7
Comments
Looks like it's not actually implemented to me. There is a "jsonb" but it looks like it's treating it like a string? -> This implementation looks like it's depending on System.Data.DbType which do not have any |
What should happen during the insert for the jsonb field? |
No, I think the exception comes from the native |
The DbType mapping is only used for inspection purposes when creating the generated code, so that won't make a difference here. |
How is |
There seem to be a few related issues on the SqlKata repo: Maybe @toburger has some insights into a workaround? |
Oh right, it might be a problem in |
Right -- I don't actually send the |
However, I do build the command, so perhaps there is a fix that can be implemented at this point. |
Yeah, if I use that code for building the command and set the correct type of the parameter manually, like this p.NpgsqlDbType <- NpgsqlDbType.Jsonb it works. Do you think it is possible to make it work in a generic case? Maybe allow having specific type mappings for different database drivers and set the type depending on the driver? |
There are two ways I can think of to do this. Option 1 would involve creating many provider specific versions of SqlHydra.Query. I would prefer to avoid this option. Option 2 would involve using reflection to set provider specific type mapping enum:
|
The second option sounds great, we could map certain How do you run the tests? I have started the dev container and tried following the "Contributing"-section of the readme, |
How do I run the tests for |
The most simple way if you are using vscode is to (I personally use VS2019 which allows me to specify test(s) via Test Explorer.) |
I started looking into this issue, and while I am able to generate the attribute as you suggested, I am not sure I understand how to access this value inside type DbColumnType =
| Npgsql of NpgsqlDbType
| Mssql of .... Although this would have to be inside |
The technique would be the same one used by SQLProvider to do load provider-specific objects via reflection.
|
Ok, I got the idea, and all the reflection business seems to work. The problem I am having now is how to match the field attributes to the corresponding parameter in |
The plot thickens! It seems that we may need to check for the existence of the column metadata attribute in the The nice thing is that the Then the |
I am not sure we can rely on the order of the parameters since |
Good point. It does not look like the SqlKata maintainer is going to implement the change. But I think I have a workaround:
type QueryParameter =
{
Value: obj
Type: string // Ex: "NpgsqlDbType.jsonb"
}
Getting the attributes in the builders as I suggested earlier probably isn't possible since entities are sometimes passed instead of individual values. This means that it would need to be done in This sounds like it has become a fairly involved change, so I'd be glad to help with any of this if you want to submit a pull request with what you have. Of course if you are enjoying the process, then by all means please keep slogging through! |
Oh, that's genius 😄 I almost made it work with this new suggestion ... will need to clean up the mess and open a PR in the beginning of the week. Yeah, I am enjoying the process, thanks for the help! |
We have a table with a field of type
jsonb
, which becomesstring
in the generated type, but it doesn't seem to work when inserting a string with the json format, the exception I get is:when trying to insert
"""{"publisher": "test"}"""
.Would you be able to help with this?
The text was updated successfully, but these errors were encountered: