fulcrologic / fulcro-rad-sql

SQL Plugin for Fulcro RAD
MIT License
4 stars 12 forks source link

Support MS SQLAdapter NEXTVAL syntax #14

Closed danskarda closed 1 year ago

danskarda commented 2 years ago

As stated in #13 MS SQL uses ANSI syntax to obtain next sequence value.

This patch:

Some notable remarks:

I run clojure -M:dev:test:clj-tests with success. However I am afraid that the only test for INSERT I have seen call scalar-insert, which does not include call to generate-tempids. I guess that use of sequences is not covered by test.

awkay commented 2 years ago

I'm very happy that you are submitting improvements to this adapter. I don't currently use it, and it is in alpha status, but I'm very interested in it getting better. That said, does your add-referential-column-statement method break the other database's support for migrations? If so, then I'm going to have to insist that you complete the work there, and make sure it tests out. I don't remember if there are tests for the migrations, though. It's been a while since I looked at this code, and it was originally heavily contributed by others.

awkay commented 2 years ago

On the relaxation of constraints. Well, mainly that is to fix problems with automatic generation of saves in a transaction. The current logic doesn't do a very good job of figuring out how to get a save to work when there are arbitrary constraints that might temporarily be unsatisfied while issuing the statements in a transaction. Would love a patch for that that is better than relaxing constraints.

danskarda commented 2 years ago

You are right. I was too enthusiastic when I wrote one record to the database :) Just to hit a roadblock few miles later.

Now I see that it is necessary to relax constrains to save more complex data structures. Even more - now I understand why the model in our ms sql database avoids cyclic relations and models features like "account primary user" as a flag, not as a reference.

My proposal for going onward with ms sql:

awkay commented 2 years ago

Right, I'll add you to the repo so you can manage PRs and issues. There are some existing help-wanted open issues that are related to this.

We're probably going to need some addl declarations on the attributes in order to instruct the save system how to proceed.

IF the SQL schema has no loops (which would require some kind of constraint give-n-take) then it might be possible to just sort the statements such that the references are written last. Depends on the NULL handling of said references. If NULL is allowed, then we could do all inserts of scalars, then issue updates to set references...but if the columns are also NOT NULL then sorting the INSERT statements might be doable (if there are not cycles). If there are cycles and NOT NULL constraints, it seems you have to have a way of relaxing the constraint during a transaction or it would be impossible to proceed.