Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/endtoend/testdata/virtual_table/sqlite/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions internal/endtoend/testdata/virtual_table/sqlite/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,38 @@ INSERT INTO tbl VALUES(2, 'aa bb', 't', 'a', 22);

INSERT INTO ft VALUES('xx cc');
INSERT INTO ft VALUES('cc bb');

CREATE TABLE weather (
id INTEGER PRIMARY KEY AUTOINCREMENT,
latitude REAL NOT NULL,
longitude REAL NOT NULL
);


CREATE VIRTUAL TABLE weather_rtree USING rtree(
id,
min_lang, max_long,
min_lat, max_lat
);

CREATE TRIGGER weather_insert
AFTER INSERT
ON weather BEGIN
INSERT INTO
weather_rtree (
id,
min_lang,
max_long,
min_lat,
max_lat
)
VALUES
(
NEW.id,
NEW.latitude,
NEW.latitude,
NEW.longitude,
NEW.longitude
);

END;
35 changes: 35 additions & 0 deletions internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (c *cc) convertCreate_virtual_table_stmtContext(n *parser.Create_virtual_ta
case "fts5":
// https://www.sqlite.org/fts5.html
return c.convertCreate_virtual_table_fts5(n)
case "rtree":
// https://www.sqlite.org/rtree.html
return c.convertCreate_virtual_table_rtree(n)
default:
return todo(
fmt.Sprintf("create_virtual_table. unsupported module name: %q", moduleName),
Expand All @@ -140,6 +143,38 @@ func (c *cc) convertCreate_virtual_table_stmtContext(n *parser.Create_virtual_ta
}
}

func (c *cc) convertCreate_virtual_table_rtree(n *parser.Create_virtual_table_stmtContext) ast.Node {
stmt := &ast.CreateTableStmt{
Name: parseTableName(n),
IfNotExists: n.EXISTS_() != nil,
}

for i, arg := range n.AllModule_argument() {
columnExpr, ok := arg.Expr().(*parser.Expr_qualified_column_nameContext)
if !ok {
continue
}

columnName := columnExpr.Column_name().GetText()

col := ast.ColumnDef{
Colname: identifier(columnName),
IsNotNull: true,
}

// first argument in the rtree is an integer (ID)
// https://www.sqlite.org/rtree.html#column_naming_details
if i == 0 {
col.TypeName = &ast.TypeName{Name: "integer"}
} else {
col.TypeName = &ast.TypeName{Name: "real"}
}

stmt.Cols = append(stmt.Cols, &col)
}
return stmt
}

func (c *cc) convertCreate_virtual_table_fts5(n *parser.Create_virtual_table_stmtContext) ast.Node {
stmt := &ast.CreateTableStmt{
Name: parseTableName(n),
Expand Down
Loading