Giter Site home page Giter Site logo

Comments (12)

JordanMarr avatar JordanMarr commented on July 21, 2024 1

Ok I see what needs to happen:

        testTask "Insert Enum ADONET" {
            use conn = new Npgsql.NpgsqlConnection(connectionString)
            use cmd = conn.CreateCommand()
            cmd.CommandText <- 
                """
                INSERT INTO experiments.person (name, current_mood)
                VALUES (@name, @mood::mood)
                """
            let pName = cmd.CreateParameter()
            pName.ParameterName <- "@name"
            pName.Value <- "john doe"
            cmd.Parameters.Add pName |> ignore

            let pMood = cmd.CreateParameter()
            pMood.ParameterName <- "@mood"
            pMood.Value <- "happy"
            cmd.Parameters.Add pMood |> ignore

            conn.Open()

            let! results = cmd.ExecuteNonQueryAsync()

            Expect.isTrue (results > 0) ""
        }

from sqlhydra.

JordanMarr avatar JordanMarr commented on July 21, 2024

That sounds doable as long as there is a way to query the custom types.
It may be possible through the NpgslConnection GetSchema method; otherwise, we will need a query to get it.

from sqlhydra.

JordanMarr avatar JordanMarr commented on July 21, 2024

I got it working already (with strings).
It would cool to have it generate a discriminated union for each enum type, but that's for another day.
Will let you know when this is ready on NuGet.

from sqlhydra.

JordanMarr avatar JordanMarr commented on July 21, 2024

SqlHyrda.Npgsql v0.800.1 is published.
Let me know if that causes any issues with inserts/updates.

from sqlhydra.

JordanMarr avatar JordanMarr commented on July 21, 2024

I assume this is resolved so closing.

from sqlhydra.

EverybodyKurts avatar EverybodyKurts commented on July 21, 2024

Sorry, I should have gotten back to you sooner... I get an Npgsql.PostgresException when attempting to insert a column:

Npgsql.PostgresException (0x80004005): 42804: column "color" is of type colors but expression is of type text

Basically, any string being inserted needs to be typecasted to the proper enum type like the following:

SELECT 'blue'::colors;

** EDIT **: Changed "blue" to 'blue'

from sqlhydra.

JordanMarr avatar JordanMarr commented on July 21, 2024

Any chance that it could it be a case-sensitivity issue?

from sqlhydra.

EverybodyKurts avatar EverybodyKurts commented on July 21, 2024

I think I would have gotten a different error had it been a case-sensitivity issue:

db=# CREATE TYPE colors AS ENUM ('red', 'green', 'blue');
CREATE TYPE

db=# SELECT 'Blue'::colors;
ERROR:  invalid input value for enum colors: "Blue"
LINE 1: SELECT 'Blue'::colors;

db=# SELECT 'blue'::colors;
 colors 
--------
 blue
(1 row)

from sqlhydra.

EverybodyKurts avatar EverybodyKurts commented on July 21, 2024

I don't know if this helps or not, but here's me creating a table and inserting a row from the psql command line:

db=# CREATE TABLE cars (color colors);
CREATE TABLE

db=# INSERT INTO cars (color) VALUES ('blue');
INSERT 0 1

db=# SELECT * FROM cars;
 color 
-------
 blue
(1 row)

from sqlhydra.

JordanMarr avatar JordanMarr commented on July 21, 2024

This is going to be really cool... 😎

from sqlhydra.

JordanMarr avatar JordanMarr commented on July 21, 2024

New release!
https://github.com/JordanMarr/SqlHydra/releases/tag/v0.810.0

You will need to manually register the generated enums with Npgsql (at least for now).

from sqlhydra.

JordanMarr avatar JordanMarr commented on July 21, 2024

Added a caveat that you may need to watch out for in the release notes.
I filed an npgsql issue.

from sqlhydra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.