Skip to content

Externalize SQL statements to .sql files that can be consumed directly by your Java application

License

Notifications You must be signed in to change notification settings

douglasjose/sql-file-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL File Reader

Summary

Externalize SQL statements to .sql files that can be consumed directly by your Java application.

Motivation

Allow developers to externalize their queries in a SQL-friendly format, without having to worry about limitations of other formats, such as properties and XML files, that were not designed to support SQL queries.

SQL files can be easily consumed by database clients while preserving the queries formatting and leveraging the SQL support of text editors and IDEs.

Dependency Management

<dependencies>
  <dependency>
    <groupId>com.douglasjose.tech</groupId>
    <artifactId>sql-file-reader</artifactId>
    <version>1.0.0</version>
  </dependency>
</dependencies>

Basic Usage

Declare your queries in a .sql file (e.g., queries.sql). Name your queries using the #queryName format in the comments:

-- #selectAllCustomers
SELECT * FROM CUSTOMER;

-- #selectCustomerByLastName
SELECT * FROM CUSTOMER WHERE LASTNAME = ?;

Initialize a SQLFile object

InputStream is = getClass().getClassLoader().getResourceAsStream("queries.sql");
SQLFile sqlFile = new SQLFile(is);
String query = sqlFile.query("selectAllCustomers");

Logging

Enable INFO logging for com.douglasjose.tech to log information about the queries:

[main] INFO  com.douglasjose.tech.SQLFile - 2 queries initialized: [selectAllCustomers, selectCustomerByLastName]

Continuous Integration

Master: Build Status

Development: Build Status

Releases

License

Apache License Version 2.0

About

Externalize SQL statements to .sql files that can be consumed directly by your Java application

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages