JordanMarr / SqlHydra

SqlHydra is a suite of NuGet packages for working with databases in F# including code generation tools and query expressions.
MIT License
212 stars 20 forks source link

SqlHydra.Cli doesn't map Sqlite longvarchar column types #90

Closed robmaw closed 1 month ago

robmaw commented 2 months ago

When using SqlHydra.Cli against a Sqlite database, the F# types and readers do not include columns that are of type longvarchar.

A mapping is missing in SqlHydra.Cli/Sqlite/SqliteDataTypes.fs

e.g. "longvarchar", "string", DbType.String, nameof r.GetString

Happy to provide a PR, but will need some guidance on integrating a test for it.

JordanMarr commented 2 months ago

Fortunately, you won’t need to mess with the containers to add a Sqlite test, so that should make it a lot easier. You can just edit the Sqlite db file directly if you need to add a new table or column.

I use “Verify” to test the generated files:

https://github.com/JordanMarr/SqlHydra/blob/main/src/Tests/Sqlite/Generation.fs

The tests in that file all pass now. After you modify the generation code, the verification test will fail because it will no longer match the snapshot. So you can either debug the output in those tests to ensure your change was successful, or you can just run the sqlite .bat file in the Tests project folder to regen it.

At that point you can submit the PR and I will run the full test suite.

robmaw commented 2 months ago

In my testing, the change to the generation code only results in a change in the first line against the snapshot. The PR contains 2 changes- the update to the generation code, and an update in the AdventureWorksLT.db , changing the SalesOrderHeader.SalesOrderNumber field from TEXT to LONGVARCHAR. please let me know if I've missed your point above, and I'll adjust the PR.

JordanMarr commented 2 months ago

You changed SalesOrderHeader.SalesOrderNumber from a TEXT to a LONGVARCHAR. Since the generated file still includes the SalesOrderNumber, your change appears to be working properly.

JordanMarr commented 2 months ago

Released as SqlHydra.Cli v2.4.1.

JordanMarr commented 2 months ago

On second thought, it probably would be a good idea to have an integration test to make sure that inserts and updates work properly and don’t truncate the string. I’m not sure if the parameter will be set properly, or if the parameter type matters for sqlite.