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 |
Yes, you can write the schema info into a db agnostic |
|
Instead of creating a separate |
Uh oh!
There was an error while loading. Please reload this page.
(Taken from the proposal)
Design
For lints that require knowledge of the database schema (such as for type errors), the
Schematypes defined insea-schemawould need to be pulled out intosea-queryso it can be used insea-linter. It is intended thatMockDatabasecontain aSchemafor the respectiveDatabaseBackendthat it was initialized with inMockDatabase::new(). Thisschemafield is updated on each successful transaction.(Only
MockDatabasehas 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 aLintertype that contains all lints. Each lint is defined as anFn(Context) -> Result<(), LintDiagnostic>whereContextis a type referencing the database'sschemaand the executing statement, and whereLintDiagnosticis a type containing information about what triggered the lint and potentially how to fix it, like inclippy. TheLinterwill stop on the firstLintDiagnosticand propogate it.A lint is registered when it is passed to
Linter::register(). However, it is possible to turn thelintsfield ofLinterinto 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'sSchemacould act as a common denominator to convert each backend'sSchemainto, but I'm not sure if clean conversions are possible.Lints for types such as
Paginatormight 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,SelectStatementmight 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.All reactions