Skip to content

baudoliver7/lightweight-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

PDD status License

Java version supported Javadoc Maven Central

codecov Hits-of-Code

What does it do ?

Lightweight DB allows you to run PostgreSQL, Oracle, MySQL, MS SQL Server... databases for fast use purposes. It's very suitable for unit and integration Testing.

All currently supported databases are :

  • PostgreSQL
  • Oracle
  • MySQL
  • MS SQL Server
  • DB2
  • Derby
  • HSQLDB
  • H2

How does it work ?

This is how you can create an embedded PostgreSQL database and do common SQL tasks on it.

final DataSource source = new EmbeddedPostgreSQLDataSource();
try (
    Connection connection = source.getConnection();
    Statement s = connection.createStatement()
) {
    s.execute(
        String.join(
            " ",
            "CREATE TABLE accounting_chart (",
            "   id BIGSERIAL NOT NULL,",
            "   type VARCHAR(25) NOT NULL,",
            "   state VARCHAR(10) NOT NULL,",
            "   version VARCHAR(10) NOT NULL,",
            "   CONSTRAINT accounting_chart_pkey PRIMARY KEY (id)",
            ")"
        )
    );
    s.execute(
        String.join(
            " ",
            "INSERT INTO accounting_chart (type, state, version)",
            "VALUES ('SYSCOHADA', 'ACTIVE', '2018');"
        )
    );
}

You can use Liquibase to execute theses operations like this (provided that liquibase folder is at the root of folder resources) :

final DataSource source =  
    new LiquibaseDataSource(
        new EmbeddedPostgreSQLDataSource(), 
        "liquibase/db.changelog-master-test.xml"
    );

Simply import Easy-liquibase4j to achieve that (with Maven by example):

<dependency>
    <groupId>com.baudoliver7</groupId>
    <artifactId>easy-liquibase4j</artifactId>
    <version><!-- latest version --></version>
    <scope>test</scope>
</dependency>

Using with Maven

If you're using Maven, you should add this to your pom.xml dependencies:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version><!-- 1.4.200 or above --></version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>com.baudoliver7</groupId>
    <artifactId>lightweight-db</artifactId>
    <version><!-- latest version --></version>
    <scope>test</scope>
</dependency>

Using with Gradle

If you're using Gradle, you should add this to your build.gradle file:

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'com.h2database:h2:/* 1.4.200 or above */'
    testImplementation 'com.baudoliver7:lightweight-db:/* latest version */'
}

How to contribute

Fork repository, make changes, send us a pull request. We will review your changes and apply them to the main branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build:

mvn clean install -Pqulice

Keep in mind that JDK 8 and Maven 3.1.0 are the lowest versions you may use.

Got questions ?

If you have questions or general suggestions, don't hesitate to submit a new Github issue.

About

Databases for fast uses in Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages