Replies: 3 comments 6 replies
-
I believe that any linting should actually occur during execution of the query, not construction of a query from a |
Beta Was this translation helpful? Give feedback.
-
Yes, you can write the schema info into a db agnostic |
Beta Was this translation helpful? Give feedback.
-
Instead of creating a separate |
Beta Was this translation helpful? Give feedback.
-
(Taken from the proposal)
Design
For lints that require knowledge of the database schema (such as for type errors), the
Schema
types defined insea-schema
would need to be pulled out intosea-query
so it can be used insea-linter
. It is intended thatMockDatabase
contain aSchema
for the respectiveDatabaseBackend
that it was initialized with inMockDatabase::new()
. Thisschema
field is updated on each successful transaction.(Only
MockDatabase
has this field as there is a high chance of user error with using real databases, such as using a database with an already defined schema.)Linting will occur in
DatabaseBackend::build()
using a static instance of aLinter
type that contains all lints. Each lint is defined as anFn(Context) -> Result<(), LintDiagnostic>
whereContext
is a type referencing the database'sschema
and the executing statement, and whereLintDiagnostic
is a type containing information about what triggered the lint and potentially how to fix it, like inclippy
. TheLinter
will stop on the firstLintDiagnostic
and propogate it.A lint is registered when it is passed to
Linter::register()
. However, it is possible to turn thelints
field ofLinter
into a const array and thus avoiding the need to register lints to a static instance ofLinter
. If third-party lints are not intended, then the latter option would be the better choice.Backend-specific lints can be supported either through feature-gating, or using an enum type that wraps each backend
Schema
. For general lints, SQLite'sSchema
could act as a common denominator to convert each backend'sSchema
into, but I'm not sure if clean conversions are possible.Lints for types such as
Paginator
might need extra work to get working, as it might be impossible to deduce what the query is intended to do if it's just aSelectStatement
. Therefore,SelectStatement
might need to be modified to trace its use through its lifetime. This doesn't sound ideal, so there may be a better solution or it's a non-issue in practice.Beta Was this translation helpful? Give feedback.
All reactions