com.firefly.db.SQLConnection Maven / Gradle / Ivy
package com.firefly.db;
import com.firefly.utils.function.Func1;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
/**
* The asynchronous SQL connection. It can execute SQL and bind result to Java bean.
*
* @author Pengtao Qiu
*/
public interface SQLConnection {
/**
* Query single column record by SQL
*
* @param sql An SQL that may contain one or more '?' IN parameter placeholders
* @param params SQL parameters
* @param The type of column
* @return The future result
* @throws RecordNotFound If the database has not record throw RecordNotFound exception
*/
CompletableFuture queryForSingleColumn(String sql, Object... params);
/**
* Query record and bind object
*
* @param sql An SQL that may contain one or more '?' IN parameter placeholders
* @param clazz The Class reference of bound object
* @param params SQL parameters
* @param The type of bound object
* @return The future result
* @throws RecordNotFound If the database has not record throw RecordNotFound exception
*/
CompletableFuture queryForObject(String sql, Class clazz, Object... params);
/**
* Query record by id
*
* @param id Primary key
* @param clazz The Class reference of bound object
* @param The type of bound object
* @return The future result
* @throws RecordNotFound If the database has not record of this id throw RecordNotFound exception
*/
CompletableFuture queryById(Object id, Class clazz);
/**
* Query records and convert records to a Map
*
* @param sql An SQL that may contain one or more '?' IN parameter placeholders
* @param valueClass The Class reference of bound object
* @param params SQL parameters
* @param The type of primary key
* @param The type of bound object
* @return The future result that contains a map, the key is primary key of record, the value is bound object.
*/
CompletableFuture