Skip to content

efekos/SimpleQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleQL

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.

Installation

Maven

  1. Add this repository if you don't have it in your repositories.
<repository>
    <id>efekosdev</id>
    <url>https://efekos.dev/maven</url>
</repository>
  1. Add this dependency. Replace the version with the latest version, which is (without v).
<dependency>
    <groupId>dev.efekos</groupId>
    <artifactId>SimpleQL</artifactId>
    <version>1.0.0</version>
</dependency> 

Gradle

  1. Add this repository if you don't have it in your repositories
maven { url 'https://efekos.dev/maven' } 
  1. Add this dependency. Replace the version with the latest version. which is (without v).
implementation 'dev.efekos:SimpleQL:1.0.0' 

License

This project is licensed under the MIT License.