This library lets you use an SQL database without knowing the SQL language at all! You can easily create tables, insert, update and delete rows and manage database connections.
Here is a working example:
package dev.efekos.simple_ql;
import dev.efekos.simple_ql.data.Database;
import dev.efekos.simple_ql.data.Table;
import java.util.Optional;
import java.util.UUID;
// Checkout test classes to learn more
public class SimpleQLExample {
public static void main(String[] args) throws Exception {
// Database connection. Database name, username and password is ignored since this is SQLite.
Database database = SimpleQL.createDatabase("jdbc:sqlite:my.db","simpleql","admin","12345678");
database.connect();
// Getting tables.
Table<Customer> customers = database.registerTable("customers", Customer.class);
// Data insertion.
UUID id = UUID.randomUUID();
Customer customer = customers.insertRow(c -> {
c.setId(id);
c.setName("John Doe");
c.setMoney(new CustomerMoney(50,0));
c.setGender(CustomerGender.FEMALE);
});
// Getting data.
Optional<Customer> row = customers.getRow(id);
// Querying data.
QueryResult<Customer> result = customers.query(new QueryBuilder()
.filterWithCondition(Conditions.lessThan("age", 18))
.sortAscending("age")
.skip(5)
.limit(10)
.getQuery()
);
// Updating data.
customer.setName("John Boe");
CustomerMoney money = customer.getMoney();
money.setCents(10);
customer.setMoney(money);
customer.setGender(CustomerGender.MALE);
customer.clean(); // saves changes to database
// Deleting data.
customer.delete();
// Database disconnection.
database.disconnect();
}
}
Note
You can look at the full example here.
- Add this repository if you don't have it in your repositories.
<repository>
<id>efekosdev</id>
<url>https://efekos.dev/maven</url>
</repository>
<dependency>
<groupId>dev.efekos</groupId>
<artifactId>SimpleQL</artifactId>
<version>1.0.0</version>
</dependency>
- Add this repository if you don't have it in your repositories
maven { url 'https://efekos.dev/maven' }
implementation 'dev.efekos:SimpleQL:1.0.0'
This project is licensed under the MIT License.