Skip to content
New issue

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

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

Already on GitHub? # to your account

Make pgvector available with JDBC syntax (#8633) #8638

Merged
merged 1 commit into from
May 20, 2024
Merged
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
4 changes: 4 additions & 0 deletions docs/modules/databases/jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ Insert `tc:` after `jdbc:` as follows. Note that the hostname, port and database

`jdbc:tc:timescaledb:2.1.0-pg13:///databasename`

#### Using PGVector

`jdbc:tc:pgvector:pg16:///databasename`

#### Using TiDB

`jdbc:tc:tidb:v6.1.0:///databasename`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ private void performTestForJDBCParamUsage(HikariDataSource dataSource) throws SQ
if (
databaseType.equalsIgnoreCase("postgresql") ||
databaseType.equalsIgnoreCase("postgis") ||
databaseType.equalsIgnoreCase("timescaledb")
databaseType.equalsIgnoreCase("timescaledb") ||
databaseType.equalsIgnoreCase("pgvector")
) {
databaseQuery = "SELECT CURRENT_DATABASE()";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.testcontainers.containers;

import org.testcontainers.jdbc.ConnectionUrl;
import org.testcontainers.utility.DockerImageName;

/**
* Factory for PgVector containers.
*
* @see <a href="https://github.com/pgvector/pgvector">https://github.com/pgvector/pgvector</a>
*/
public class PgVectorContainerProvider extends JdbcDatabaseContainerProvider {

private static final String NAME = "pgvector";

private static final String DEFAULT_TAG = "pg16";

private static final DockerImageName DEFAULT_IMAGE = DockerImageName
.parse("pgvector/pgvector")
.asCompatibleSubstituteFor("postgres");
Comment on lines +17 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static final DockerImageName DEFAULT_IMAGE = DockerImageName
.parse("pgvector/pgvector")
.asCompatibleSubstituteFor("postgres");
private static final DockerImageName DEFAULT_IMAGE = DockerImageName
.parse("pgvector/pgvector");


public static final String USER_PARAM = "user";

public static final String PASSWORD_PARAM = "password";

@Override
public boolean supports(String databaseType) {
return databaseType.equals(NAME);
}

@Override
public JdbcDatabaseContainer newInstance() {
return newInstance(DEFAULT_TAG);
}

@Override
public JdbcDatabaseContainer newInstance(String tag) {
return new PostgreSQLContainer(DEFAULT_IMAGE.withTag(tag));
}

@Override
public JdbcDatabaseContainer newInstance(ConnectionUrl connectionUrl) {
return newInstanceFromConnectionUrl(connectionUrl, USER_PARAM, PASSWORD_PARAM);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.testcontainers.containers.PostgreSQLContainerProvider
org.testcontainers.containers.PostgisContainerProvider
org.testcontainers.containers.TimescaleDBContainerProvider
org.testcontainers.containers.PgVectorContainerProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.testcontainers.jdbc.pgvector;

import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.testcontainers.jdbc.AbstractJDBCDriverTest;

import java.util.Arrays;
import java.util.EnumSet;

@RunWith(Parameterized.class)
public class PgVectorJDBCDriverTest extends AbstractJDBCDriverTest {

@Parameterized.Parameters(name = "{index} - {0}")
public static Iterable<Object[]> data() {
return Arrays.asList(
new Object[][] {
{
"jdbc:tc:pgvector://hostname/databasename?user=someuser&password=somepwd",
EnumSet.of(Options.JDBCParams),
},
{
"jdbc:tc:pgvector:pg14://hostname/databasename?user=someuser&password=somepwd",
EnumSet.of(Options.JDBCParams),
},
}
);
}
}
Loading