Skip to content

Commit

Permalink
feat(mysql): Add a test for VECTOR column type (#3734)
Browse files Browse the repository at this point in the history
* feat(mysql): Add a test for VECTOR column type

* Fix invalid Go file

* Use MySQL 9.0 for tests

* Fix reference issue

* Fix last two test failures

* Add UNIQUE
  • Loading branch information
kyleconroy authored Dec 24, 2024
1 parent 6a4bfb5 commit 86c1d77
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
# Start a MySQL server
- uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: "8.1"
mysql-version: "9.0"

- name: test ./...
run: gotestsum --junitfile junit.xml -- --tags=examples -timeout 20m ./...
Expand Down
2 changes: 1 addition & 1 deletion examples/ondeck/mysql/schema/0002_venue.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE venues (
statuses text, -- status[],
slug text not null COMMENT 'This value appears in public URLs',
name varchar(255) not null,
city text not null references city(slug),
city varchar(255) not null references city(slug),
spotify_playlist varchar(255) not null,
songkick_id text,
tags text -- text[]
Expand Down
4 changes: 2 additions & 2 deletions internal/endtoend/testdata/join_right/mysql/go/models.go

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

6 changes: 3 additions & 3 deletions internal/endtoend/testdata/join_right/mysql/go/query.sql.go

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

9 changes: 7 additions & 2 deletions internal/endtoend/testdata/join_right/mysql/schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
CREATE TABLE foo (id serial not null, bar_id int references bar(id));
CREATE TABLE bar (id serial not null);
CREATE TABLE bar (
id integer not null,
UNIQUE(id)
);

CREATE TABLE foo (id integer not null, bar_id integer references bar(id));


4 changes: 2 additions & 2 deletions internal/endtoend/testdata/join_table_name/mysql/go/models.go

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

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

8 changes: 6 additions & 2 deletions internal/endtoend/testdata/join_table_name/mysql/schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
CREATE TABLE bar (id serial not null);
CREATE TABLE foo (id serial not null, bar integer references bar(id));
CREATE TABLE bar (
id integer not null,
UNIQUE (id)
);

CREATE TABLE foo (id integer not null, bar integer references bar(id));

31 changes: 31 additions & 0 deletions internal/endtoend/testdata/mysql_vector/mysql/go/db.go

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

10 changes: 10 additions & 0 deletions internal/endtoend/testdata/mysql_vector/mysql/go/models.go

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

48 changes: 48 additions & 0 deletions internal/endtoend/testdata/mysql_vector/mysql/go/query.sql.go

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

7 changes: 7 additions & 0 deletions internal/endtoend/testdata/mysql_vector/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- name: InsertVector :exec
INSERT INTO foo(embedding) VALUES (STRING_TO_VECTOR('[0.1, 0.2, 0.3, 0.4]'));

-- name: SelectVector :many
SELECT id FROM foo
ORDER BY DISTANCE(STRING_TO_VECTOR('[1.2, 3.4, 5.6]'), embedding, 'L2_squared')
LIMIT 10;
4 changes: 4 additions & 0 deletions internal/endtoend/testdata/mysql_vector/mysql/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE foo(
id INT PRIMARY KEY auto_increment,
embedding VECTOR(4)
);
14 changes: 14 additions & 0 deletions internal/endtoend/testdata/mysql_vector/mysql/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "1",
"packages": [
{
"path": "go",
"sql_package": "database/sql",
"sql_driver": "github.com/go-sql-driver/mysql",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

0 comments on commit 86c1d77

Please sign in to comment.