Skip to content

Commit 221cc34

Browse files
authored
#17 Added turso libsql url support (#22)
* #17 Added turso libsql url support * #17 Added https url handling * #17 Added libsql url
1 parent b964947 commit 221cc34

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LibSqlConstants.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
public class LibSqlConstants {
2222

23-
public static final Pattern CONNECTION_URL_EXAMPLE = Pattern.compile("jdbc:dbeaver:libsql:<server-url>");
24-
public static final Pattern CONNECTION_URL_PATTERN = Pattern.compile("jdbc:dbeaver:libsql:(.+)");
23+
public static final String CONNECTION_URL_EXAMPLES = "jdbc:dbeaver:libsql:<hostname>, libsql://<hostname>";
24+
public static final String CONNECTION_PROTOCOLS_REGEXP = "jdbc:dbeaver:libsql:(https://)?(libsql://)?|libsql://";
25+
public static final Pattern CONNECTION_URL_PATTERN =
26+
Pattern.compile("(" + CONNECTION_PROTOCOLS_REGEXP + ")[a-z0-9.-]+");
2527

2628
public static final int DRIVER_VERSION_MAJOR = 1;
2729
public static final int DRIVER_VERSION_MINOR = 0;

com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LibSqlDriver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ public Connection connect(String url, Properties info) throws SQLException {
4646
if (!matcher.matches()) {
4747
throw new LibSqlException(
4848
"Invalid connection URL: " + url +
49-
".\nExpected URL format: " + LibSqlConstants.CONNECTION_URL_EXAMPLE);
49+
".\nExpected URL formats: " + LibSqlConstants.CONNECTION_URL_EXAMPLES);
5050
}
51-
String targetUrl = matcher.group(1);
51+
String targetUrl = matcher.group(0)
52+
.replaceAll(LibSqlConstants.CONNECTION_PROTOCOLS_REGEXP, "https://");
5253

5354
Map<String, Object> props = new LinkedHashMap<>();
5455
for (Enumeration<?> pne = info.propertyNames(); pne.hasMoreElements(); ) {

0 commit comments

Comments
 (0)