sql-import
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");
}
-
Defaulted SqlLoader instance
-
Import using dot notation
-
Import using path notation