Skip to content

Foxcapades/java-sql-import

Repository files navigation

sql-import

sql import Codacy code quality License Java Version

SQL resource loading & caching.

Reads from a configurable standardized directory layout organized by query type.

Queries are cached per SqlLoader instance so repeated loads of the same query will only incur the filesystem I/O cost once.

Import functions utilize the java.util.Optional type. In the event that a query does not exist or cannot be loaded, an empty Optional will be returned, otherwise the Optional will contain the SQL text loaded from the specified file.

Examples

Resource directory using default settings
/resource-dir (src/main/resources for Gradle projects)
  └─ /sql
      ├─ /delete
      │   ├─ /comments
      │   │   ├─ by-id.sql
      │   │   └─ by-user.sql
      │   └─ /users
      │       └─ by-id.sql
      ├─ /insert
      │   ├─ /comment.sql
      │   └─ /user.sql
      ├─ /select
      (etc...)

Using the example above loading queries could be accomplished by the following:

Example.java
public void example() {
  var loader      = new SqlLoader(); // (1)
  var delComments = loader.delete("comments.by-user"); // (2)
  var delUsers    = loader.delete("users/by-id"); // (3)
  var insUser     = loader.insert("user");
}
  1. Defaulted SqlLoader instance

  2. Import using dot notation

  3. Import using path notation

About

SQL resource loading & caching

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages