Simpli SQL

Tools that makes SQL connections easier and don't use ORM

License

License

GroupId

GroupId

br.com.simpli
ArtifactId

ArtifactId

simpli-sql
Last Version

Last Version

3.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

Simpli SQL
Tools that makes SQL connections easier and don't use ORM
Project URL

Project URL

https://github.com/simplitech/simpli-sql
Source Code Management

Source Code Management

https://github.com/simplitech/simpli-sql

Download simpli-sql

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
mysql : mysql-connector-java jar 5.1.44
br.com.simpli : simpli-model jar 1.1.0

runtime (7)

Group / Artifact Type Version
javax : javaee-web-api jar 7.0
commons-dbcp : commons-dbcp jar 1.4
commons-pool : commons-pool jar 1.6
commons-collections : commons-collections jar 3.2.1
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.50
junit : junit jar 4.12
br.com.simpli : simpli-tools jar 1.3.0

Project Modules

There are no modules declared in this project.

Simpli

simpli-sql

You don't need to use reflection! They are heavy to process.

Simpli-SQL is a Kotlin and Java library that makes SQL operations easier and more flexible than using an ORM.

Install

Gradle

compile group: 'br.com.simpli', name: 'simpli-sql', version: '3.2.1'

Maven

<dependency>
  <groupId>br.com.simpli</groupId>
  <artifactId>simpli-sql</artifactId>
  <version>3.2.1</version>
</dependency>

Get a transactional connector to read and write

val transacPipe = TransacConPipe("jdbc/datasourceName")

transacPipe.handle { con ->
  val num = con.getFirstInt(Query("SELECT COUNT(*) FROM table"))
  con.execute(Query("UPDATE table_count SET num = ? ", num))
  // all good!
}

Get a read-only connector, to make sure you will not try to write accidentally

val conPipe = ReadConPipe("jdbc/datasourceName")

conPipe.handle { con ->
  val num = con.getFirstInt(Query("SELECT COUNT(*) FROM table"))
  con.execute(Query("UPDATE table_count SET num = ? ", num))
  // ⚠ Exception: You can't update using a read connection
}

How to make a Select

// build your query
val myQuery = Query()
    .select("mycolumn")
    .from("mytable")
    .innerJoin("othertable", "idOtherTableFk", "idOtherTablePk")
    .whereEq("myothercolumn", 2) // 'where' methods adds WHERE or AND (if not the first)
    .whereSomeEq(
        "columito" to 5,
        "otrita" to "abc"
     )
     
// run the query using a connector, in this case we are getting a simple String List   
val mycolumnList = con.getStringList(myQuery)

query translated to:

SELECT mycolumn
FROM mytable
INNER JOIN othertable ON idOtherTableFk = idOtherTablePk
WHERE myothercolumn = 2
AND (
    columito = 5
    OR otrita = "abc"
)

How to make an Insert

val myQuery = Query().insertInto("mytable").insertValues(
    "mycolumn" to "thenewvalue",
    "myothercolumn" to 5)
val newId = con.execute(myQuery).key // key is the generated ID

Update

val myQuery = Query().updateTable("mytable")
    .updateSet(
        "mycolumn" to "thenewvalue",
        "myothercolumn" to 5)
    .whereGt("myothercolumn", 2)
val numOfRowsAffected = con.execute(myQuery).affectedRows
// affectedRows are the number of rows affected by the query

Documentation

Really EASY and QUICK documentation

Deprecated:

br.com.simpli

Simpli

Blockchain, AI, Datamining, Geolocation, Distributed, Fullstack.

Versions

Version
3.3.0
3.2.4
3.2.3
3.2.2
3.2.1
3.2.0
3.1.3
3.1.2
3.1.0
3.0.3
3.0.2
3.0.1
3.0.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.0
1.1.0
1.0.1
1.0.0