query-builder

Criterion for jdbc, but not only Criterion

License

License

Categories

Categories

Net
GroupId

GroupId

net.turnbig
ArtifactId

ArtifactId

query-builder
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

query-builder
Criterion for jdbc, but not only Criterion
Project URL

Project URL

https://github.com/IamFive/query-builder
Source Code Management

Source Code Management

https://github.com/IamFive/query-builder

Download query-builder

How to add to project

<!-- https://jarcasting.com/artifacts/net.turnbig/query-builder/ -->
<dependency>
    <groupId>net.turnbig</groupId>
    <artifactId>query-builder</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.turnbig/query-builder/
implementation 'net.turnbig:query-builder:2.0.0'
// https://jarcasting.com/artifacts/net.turnbig/query-builder/
implementation ("net.turnbig:query-builder:2.0.0")
'net.turnbig:query-builder:jar:2.0.0'
<dependency org="net.turnbig" name="query-builder" rev="2.0.0">
  <artifact name="query-builder" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.turnbig', module='query-builder', version='2.0.0')
)
libraryDependencies += "net.turnbig" % "query-builder" % "2.0.0"
[net.turnbig/query-builder "2.0.0"]

Dependencies

compile (5)

Group / Artifact Type Version
commons-beanutils : commons-beanutils-core jar 1.8.3
org.apache.commons : commons-collections4 jar 4.0
org.apache.commons : commons-lang3 jar 3.3.2
org.slf4j : slf4j-api jar 1.7.5
ch.qos.logback : logback-classic Optional jar 1.0.13

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

Query Builder

Build Status

A simple tool to parse specify filter to sql.

Basic Example

	HashMap<String, String> map = new HashMap<String, String>();
	map.put("q_startTime_eq_d", "2009-10-10");
	map.put("q_endTime_eq_d", "2009-10-10");
	map.put("q_buyer_isnull", "");
	map.put("q_amount_gt_i", "20");
	map.put("q_name_LIKE_s", "woo");
	// map.put("q_param6_like_b", 1);

	SqlSegment segment = new QueryBuilder().build(map);

	String asSql = segment.asSql();
	Map<String, Object> params = segment.getParams();

Sql:

(
	1=1 
	AND (
		amount > ':amount_aZJ' 
		AND endTime=:endTime_JFn 
		AND buyer is null 
		AND name like '%:name_FJy%' 
		AND startTime=:startTime_Rkz
	)
)

Named-Query Parameters:

{
	name_FJy=woo, 
	endTime_dVZ=Sat Oct 10 00:00:00 CST 2009, 
	amount_aZJ=20, 
	startTime_zYR=Sat Oct 10 00:00:00 CST 2009
}

Example with combined groups (and & or)

HashMap<String, String> map = new HashMap<String, String>();
map.put("q_[or:a1]startTime_eq_d", "2009-10-10");
map.put("q_[or:a1]endTime_eq_d", "2009-10-10");
map.put("q_[and:a2]amount_gt_i", "10");
map.put("q_[and:a2]amount_le_i", "20");
map.put("q_buyer_isnull", "");
// map.put("q_param6_like_b", 1);

SqlSegment segment = new QueryBuilder().build(map);
String sql = segment.asSql();
Map<String, Object> params = segment.getParams();

sql:

(
	1=1 
	AND (buyer is null) 
	AND (endTime=:endTime_ewZ OR startTime=:startTime_dtu) 
	AND (amount <= ':amount_piK' AND amount > ':amount_USR')
)

Named-Query Parameters:

{
	amount_USR=10, 
	startTime_NJQ=Sat Oct 10 00:00:00 CST 2009, 
	endTime_TRp=Sat Oct 10 00:00:00 CST 2009, 
	amount_piK=20
}

Versions

Version
2.0.0