refactor: statement classifier #101
Labels
No labels
CI/CD
UI/UX
autorelease: pending
bug
docs
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
size
L
size
M
size
S
size
XL
size
XS
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
noe.trevino/dadbod-ui.nvim#101
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What we need
One module that answers what kind of statement we are looking at, so the three features that need to know can stop each having their own regex pile.
Three questions, from the same place:
Dangerous is a subset of changing. Everything dangerous mutates, not everything that mutates is dangerous.
Why
We already ask a version of question 3.
paginator.luahas a guard that checks the statement is a single plain select and bails if it sees limit / offset / fetch / top / into / update / procedure, all so it can safely append a paging clause.Question 1 and 2 are about to get asked by read only connections (#92) and dangerous statement detection (#96). Question 3 is about to get asked again by query transformers (#97), which needs the same "can i safely rewrite this" answer for all seven of its rewrites.
Thats four consumers of one question. Better as a module than as four copies that drift, we should probably just refactor now while we havent implemented anythig so we dont have to spend time going back and forth
Notes
Patterns live on the adapter spec, since dialects differ. Oracle has PURGE, clickhouse does
ALTER TABLE ... DELETE, and mongo isnt sql at all so it cant be parsed by any of this and needs to say so rather than guess.Worth splitting question 3 into two facts rather than one boolean.
paginator.luawants "plain select AND no paging clause already", but #97 needs those apart. Fetch all rows has to find and strip the paging clause, and row count wants to wrapSELECT ... LIMIT 10in a subquery, which is fine even though you couldnt append a LIMIT to it. If it ships as one boolean #97 ends up re-parsing.This is a refactor. No user visible change should come out of it on its own.
How
TBD, but i want a method on the module that is something like
M.classify. This will be the main public method. it will return a struct like this:This will let us go:
Query shouldnt be a string it should at least carry these fields:
adapter type should just be the static enum of what is currently
dadbod-ui.adapters.*We should just turn this into an enum
Acceptance Criteria
paginator.luauses it instead of its own guardBlocks