Skip to content

Commit

Permalink
Merge pull request #2259 from cloudflare/mhart/1540/allow-list-fts5vocab
Browse files Browse the repository at this point in the history
Allow fts5vocab module (#1540)
  • Loading branch information
mhart authored Jun 12, 2024
2 parents 20e090d + 3cdcd61 commit 5f54478
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/workerd/api/sql-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ async function test(storage) {
assert.throws(() => sql.exec('SAVEPOINT foo'), /not authorized/)

// Virtual tables
// Only fts5 module is allowed
// Only fts5 and fts5vocab modules are allowed
assert.throws(
() => sql.exec(`CREATE VIRTUAL TABLE test_fts USING fts5abcd(id);`),
/not authorized/
Expand All @@ -371,10 +371,19 @@ async function test(storage) {
);
`)

// Module name is case-insensitive
// Module names are case-insensitive
sql.exec(`
CREATE VIRTUAL TABLE documents_fts USING FtS5(id, title, content, tokenize = porter);
`)
sql.exec(`
CREATE VIRTUAL TABLE documents_fts_v_col USING fTs5VoCaB(documents_fts, col);
`)
sql.exec(`
CREATE VIRTUAL TABLE documents_fts_v_row USING FtS5vOcAb(documents_fts, row);
`)
sql.exec(`
CREATE VIRTUAL TABLE documents_fts_v_instance USING fTs5VoCaB(documents_fts, instance);
`)

sql.exec(`
CREATE TRIGGER documents_fts_insert
Expand Down Expand Up @@ -498,10 +507,10 @@ async function test(storage) {
)
)[0].data
)
assert.equal(jsonResult.length, 8)
assert.equal(jsonResult.length, 11)
assert.equal(
jsonResult.map((r) => r.name).join(','),
'myTable,documents,documents_fts,documents_fts_data,documents_fts_idx,documents_fts_content,documents_fts_docsize,documents_fts_config'
'myTable,documents,documents_fts,documents_fts_data,documents_fts_idx,documents_fts_content,documents_fts_docsize,documents_fts_config,documents_fts_v_col,documents_fts_v_row,documents_fts_v_instance'
)
assert.equal(jsonResult[0].columns.foo, 'TEXT')
assert.equal(jsonResult[0].columns.bar, 'INTEGER')
Expand Down
6 changes: 4 additions & 2 deletions src/workerd/util/sqlite.c++
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,12 @@ bool SqliteDatabase::isAuthorized(int actionCode,

case SQLITE_CREATE_VTABLE : /* Table Name Module Name */
case SQLITE_DROP_VTABLE : /* Table Name Module Name */
// Virtual tables are tables backed by some native-code callbacks. We don't support these except for FTS5 (Full Text Search) https://www.sqlite.org/fts5.html
// Virtual tables are tables backed by some native-code callbacks.
// We don't support these except for FTS5 (Full Text Search) https://www.sqlite.org/fts5.html
// (Which also includes fts5vocab: "[fts5vocab] is available whenever FTS5 is")
{
KJ_IF_SOME (moduleName, param2) {
if (strcasecmp(moduleName.begin(), "fts5") == 0) {
if (strcasecmp(moduleName.begin(), "fts5") == 0 || strcasecmp(moduleName.begin(), "fts5vocab") == 0) {
return true;
}
}
Expand Down

0 comments on commit 5f54478

Please sign in to comment.