Skip to content

Instantly share code, notes, and snippets.

@brianm
Last active December 22, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianm/6521592 to your computer and use it in GitHub Desktop.
Save brianm/6521592 to your computer and use it in GitHub Desktop.
try (EmbeddedPostgreSQL db = EmbeddedPostgreSQL.start()) {
try (Handle h = DBI.open(db.getPostgresDatabase())) {
h.execute("CREATE DATABASE breakfast");
h.execute("CREATE USER brianm with password 'secret'");
h.execute("grant all privileges on database breakfast to brianm");
}
try (Handle h = DBI.open(db.getDatabase("brianm", "breakfast"))) {
h.execute("create table food (id serial primary key, name text)");
h.execute("insert into food (name) values ('pancake')");
}
}
<dependency>
<groupId>com.nesscomputing.components</groupId>
<artifactId>ness-pg-embedded</artifactId>
<version>2.5.0</version> <!-- 2.5.X is postgres 9.3 -->
<scope>test</scope>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment