https://github.com/foxcapades/java-sql-import
SQL resource loading & caching
https://github.com/foxcapades/java-sql-import
files java-10 sql
Last synced: 25 days ago
JSON representation
SQL resource loading & caching
- Host: GitHub
- URL: https://github.com/foxcapades/java-sql-import
- Owner: Foxcapades
- License: apache-2.0
- Created: 2016-08-13T00:07:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-18T13:36:37.000Z (almost 7 years ago)
- Last Synced: 2025-02-13T19:41:11.892Z (3 months ago)
- Topics: files, java-10, sql
- Language: Java
- Homepage:
- Size: 107 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: readme.adoc
- License: LICENSE.txt
Awesome Lists containing this project
README
= sql-import
:jdk-path: https://docs.oracle.com/javase/10/docs/apiimage:https://img.shields.io/maven-central/v/io.vulpine.lib/sql-import.svg?maxAge=14400[link=http://search.maven.org/#artifactdetails|io.vulpine.lib|sql-import]
image:https://api.codacy.com/project/badge/Grade/5feaaf04c0024aa78b194921723b25ad["Codacy code quality", link="https://www.codacy.com/app/Foxcapades/java-sql-import?utm_source=github.com&utm_medium=referral&utm_content=Foxcapades/java-sql-import&utm_campaign=Badge_Grade"]
image:https://img.shields.io/github/license/foxcapades/java-sql-import.svg?maxAge=2592000?style=plastic[License]
image:https://img.shields.io/badge/Java-18.3-red.svg[Java Version, title="Java Version", link={jdk-path}]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
{jdk-path}/java/util/Optional.html[`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
[source]
----
/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
[source, 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