Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for FTS5 special INSERT Commands #3322

Open
FaFre opened this issue Nov 3, 2024 · 2 comments
Open

Support for FTS5 special INSERT Commands #3322

FaFre opened this issue Nov 3, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@FaFre
Copy link
Contributor

FaFre commented Nov 3, 2024

This is a low priority point and doesn't affect the actual functionality (theoretically, right now).

The FTS5 index can be optimized with a special command as defined here.

At the moment this leads to following warning:

[WARNING] drift_dev on lib/features/bangs/data/database/database.dart:
line 75, column 41: Some columns are required but not present here. Expected values for trigger, website_name.
   ╷
75 │   INSERT INTO bang_fts(bang_fts) VALUES ('optimize');
   │                                         ^^^^^^^^^^^^
   ╵

The table definition is as follows to understand the warning:

CREATE VIRTUAL TABLE bang_fts 
	USING fts5(
    trigger,
    website_name,
    content=bang,
    prefix='2 3'
  );

In fact, there are a few more special commands, that might not match the actual FTS columns and lead to warnings a s well (I do not use them): https://www.sqlite.org/fts5.html#special_insert_commands

@FaFre FaFre added the enhancement New feature or request label Nov 3, 2024
@FaFre
Copy link
Contributor Author

FaFre commented Nov 3, 2024

@simolus3 with a bit of guidance I might me also able to contribute the code :)

@simolus3
Copy link
Owner

simolus3 commented Nov 3, 2024

Thanks for offering your help! At the moment, the error is generated by _LintingVisitor.visitInsertStatement in drift_dev/lib/src/analysis/resolver/drift/sqlparser/drift_lints.dart. That's kind of misplaced, this particular error can be detected and raised by the LintingVisitor in the sqlparser package instead.

We need to recognize these scenarios for that linting step, and possibly also in the type inference visitor (TypeResolver in sqlparser).
I think a possible approach here would be to introduce a VirtualTable interface in sqlparser that extends Table. That could have optional methods used as hooks (e.g. validateInsert(InsertSource) and infertInsertTypes(InsertSource)) to customize the behavior of these steps for virtual tables. Let me know if that helps to get you started (I might be overlooking some complexity here), so if you have any questions or run into issues I'm happy to look at them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants