generated from kestra-io/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement queries for postgres
refactor AbstractJdbcQueries to split queries and commiting separately when non-transactional mode is effective
- Loading branch information
Showing
6 changed files
with
475 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
plugin-jdbc-postgres/src/main/java/io/kestra/plugin/jdbc/postgresql/Queries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.kestra.plugin.jdbc.postgresql; | ||
|
||
import io.kestra.core.models.annotations.Example; | ||
import io.kestra.core.models.annotations.Plugin; | ||
import io.kestra.core.models.tasks.RunnableTask; | ||
import io.kestra.core.runners.RunContext; | ||
import io.kestra.plugin.jdbc.AbstractCellConverter; | ||
import io.kestra.plugin.jdbc.AbstractJdbcQueries; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.time.ZoneId; | ||
import java.util.Properties; | ||
|
||
|
||
@SuperBuilder | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
@NoArgsConstructor | ||
@Schema( | ||
title = "Preform multiple queries on a PostgreSQL server." | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
full = true, | ||
title = "Execute a query and fetch results in a task.", | ||
code = """ | ||
id: postgres_query | ||
namespace: company.team | ||
tasks: | ||
- id: fetch | ||
type: io.kestra.plugin.jdbc.postgresql.Queries | ||
url: jdbc:postgresql://127.0.0.1:56982/ | ||
username: pg_user | ||
password: pg_password | ||
sql: | | ||
SELECT firstName, lastName FROM employee; | ||
SELECT brand FROM laptop; | ||
fetchType: FETCH | ||
""" | ||
) | ||
} | ||
) | ||
public class Queries extends AbstractJdbcQueries implements RunnableTask<AbstractJdbcQueries.MultiQueryOutput>, PostgresConnectionInterface { | ||
@Builder.Default | ||
protected Boolean ssl = false; | ||
protected SslMode sslMode; | ||
protected String sslRootCert; | ||
protected String sslCert; | ||
protected String sslKey; | ||
protected String sslKeyPassword; | ||
|
||
@Override | ||
public Properties connectionProperties(RunContext runContext) throws Exception { | ||
Properties properties = super.connectionProperties(runContext); | ||
PostgresService.handleSsl(properties, runContext, this); | ||
|
||
return properties; | ||
} | ||
|
||
@Override | ||
protected AbstractCellConverter getCellConverter(ZoneId zoneId) { | ||
return new PostgresCellConverter(zoneId); | ||
} | ||
|
||
@Override | ||
public void registerDriver() throws SQLException { | ||
DriverManager.registerDriver(new org.postgresql.Driver()); | ||
} | ||
|
||
} |
Oops, something went wrong.