Created
November 19, 2014 13:36
-
-
Save mikaelhg/01fd12c019010247a685 to your computer and use it in GitHub Desktop.
jOOQ DSL demo
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
package test; | |
import org.jooq.SQLDialect; | |
import org.jooq.impl.DSL; | |
import org.postgresql.ds.PGSimpleDataSource; | |
import java.sql.Connection; | |
import java.util.Objects; | |
public class JooqDslTest { | |
public static void main(final String ... args) throws Exception { | |
final PGSimpleDataSource ds = new PGSimpleDataSource(); | |
ds.setDatabaseName(args[1]); | |
final Connection connection = ds.getConnection(); | |
DSL.using(connection, SQLDialect.POSTGRES) | |
.meta() | |
.getTables() | |
.stream() | |
.map(t -> t.getPrimaryKey()) | |
.filter(Objects::nonNull) | |
.forEach(System.out::println); | |
connection.close(); | |
} | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>test</groupId> | |
<artifactId>jooq-test</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>org.jooq</groupId> | |
<artifactId>jooq</artifactId> | |
<version>3.4.4</version> | |
</dependency> | |
<dependency> | |
<groupId>org.postgresql</groupId> | |
<artifactId>postgresql</artifactId> | |
<version>9.3-1102-jdbc41</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment