Skip to content

Commit

Permalink
Make pgvector available with JDBC syntax (testcontainers#8633)
Browse files Browse the repository at this point in the history
  • Loading branch information
thijslemmens committed May 16, 2024
1 parent 18ea976 commit 58072a7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
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");

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),
},
}
);
}
}

0 comments on commit 58072a7

Please sign in to comment.