Skip to content

Commit 23e86ac

Browse files
committed
feat(sqlite): virtual tables and fts5 supported
Fixes: sqlc-dev#1797 Out of scope: * table-valued function. https://www.sqlite.org/vtab.html#tabfunc2 * insert commands. https://www.sqlite.org/fts5.html#special_insert_commands * you cannot use table name to the left of MATCH or equality operator
1 parent 3a67691 commit 23e86ac

File tree

11 files changed

+471
-3
lines changed

11 files changed

+471
-3
lines changed

internal/endtoend/testdata/sqlc_slice_prepared/sqlite/go/db.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/sqlc_slice_prepared/sqlite/go/models.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/sqlc_slice_prepared/sqlite/go/query.sql.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/virtual_table/sqlite/go/db.go

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/virtual_table/sqlite/go/models.go

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/virtual_table/sqlite/go/query.sql.go

+248
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- name: SelectAllColsFt :many
2+
SELECT b FROM ft
3+
WHERE b MATCH ?;
4+
5+
-- name: SelectAllColsTblFt :many
6+
SELECT b, c FROM tbl_ft
7+
WHERE b MATCH ?;
8+
9+
-- name: SelectOneColFt :many
10+
SELECT b FROM ft
11+
WHERE b = ?;
12+
13+
-- name: SelectOneColTblFt :many
14+
SELECT c FROM tbl_ft
15+
WHERE b = ?;
16+
17+
-- name: SelectHightlighFunc :many
18+
SELECT highlight(tbl_ft, 0, '<b>', '</b>') FROM tbl_ft
19+
WHERE b MATCH ?;
20+
21+
-- name: SelectSnippetFunc :many
22+
SELECT snippet(tbl_ft, 0, '<b>', '</b>', 'aa', ?) FROM tbl_ft;
23+
24+
-- name: SelectBm25Func :many
25+
SELECT *, bm25(tbl_ft, 2.0) FROM tbl_ft
26+
WHERE b MATCH ? ORDER BY bm25(tbl_ft);
27+
28+
-- name: UpdateTblFt :exec
29+
UPDATE tbl_ft SET c = ? WHERE b = ?;
30+
31+
-- name: DeleteTblFt :exec
32+
DELETE FROM tbl_ft WHERE b = ?;
33+
34+
-- name: InsertTblFt :exec
35+
INSERT INTO tbl_ft(b, c) VALUES(?, ?);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE TABLE tbl(a INTEGER PRIMARY KEY, b TEXT, c TEXT, d TEXT, e INTEGER);
2+
3+
CREATE VIRTUAL TABLE tbl_ft USING fts5(b, c UNINDEXED, content='tbl', content_rowid='a');
4+
5+
CREATE VIRTUAL TABLE ft USING fts5(b);
6+
7+
CREATE TRIGGER tbl_ai AFTER INSERT ON tbl BEGIN
8+
INSERT INTO tbl_ft(rowid, b, c) VALUES (new.a, new.b, new.c);
9+
END;
10+
11+
INSERT INTO tbl VALUES(1, 'xx yy cc', 't', 'a', 11);
12+
INSERT INTO tbl VALUES(2, 'aa bb', 't', 'a', 22);
13+
14+
INSERT INTO ft VALUES('xx cc');
15+
INSERT INTO ft VALUES('cc bb');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '2'
2+
sql:
3+
- schema: schema.sql
4+
queries: query.sql
5+
engine: sqlite
6+
gen:
7+
go:
8+
package: querytest
9+
out: go

0 commit comments

Comments
 (0)