Skip to content

Repository files navigation

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 without the use of Reflections.

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 queryval 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:

About

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

Resources

Stars

1 star

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages