package solutions.bitbadger.documents import java.sql.Connection import solutions.bitbadger.documents.query.Find import solutions.bitbadger.documents.query.orderBy /** * Functions to find and retrieve documents */ object Find { /** * Retrieve all documents in the given table * * @param tableName The table from which documents should be retrieved * @param conn The connection over which documents should be retrieved * @return A list of documents from the given table */ inline fun all(tableName: String, conn: Connection) = conn.customList(Find.all(tableName), mapFunc = Results::fromData) /** * Retrieve all documents in the given table * * @param tableName The table from which documents should be retrieved * @return A list of documents from the given table */ inline fun all(tableName: String) = Configuration.dbConn().use { all(tableName, it) } /** * Retrieve all documents in the given table * * @param tableName The table from which documents should be retrieved * @param orderBy Fields by which the query should be ordered * @param conn The connection over which documents should be retrieved * @return A list of documents from the given table */ inline fun all(tableName: String, orderBy: Collection>, conn: Connection) = conn.customList(Find.all(tableName) + orderBy(orderBy), mapFunc = Results::fromData) /** * Retrieve all documents in the given table * * @param tableName The table from which documents should be retrieved * @param orderBy Fields by which the query should be ordered * @return A list of documents from the given table */ inline fun all(tableName: String, orderBy: Collection>) = Configuration.dbConn().use { all(tableName, orderBy, it) } }