Skip to content

#67: Csv rowparser improvements #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: releases/r3.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions facilejdbc/src/main/java/io/jenetics/facilejdbc/Param.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
* );
* }
* <p>
* <b>Creating (lazy) single-valued parameters</b>
* {@snippet lang="java":
* INSERT_QUERY.on(
* Param.lazyValue("inserted_at", Instant::now),
* Param.value("forename", "Werner"),
* Param.value("email", "some.email@gmail.com")
* );
* }
* <p>
* <b>Creating multi-valued parameters</b>
* {@snippet lang="java":
* var query = Query.of("SELECT * FROM table WHERE id = IN(:ids);")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,37 @@ T parse(final ResultSet rs, final Connection conn)
/**
* Return a {@link ResultSet} parser, which converts the query result to a
* CSV line.
* {@snippet lang="java":
* {@snippet lang = "java":
* final var select = Query.of("SELECT * FROM book;");
* final var csv = select.as(ResultSetParser.csv(), conn);
* System.out.println(csv);
*}
* The CSV output will look like this:
* <pre>
* "ID","PUBLISHED_AT","TITLE","ISBN","PAGES"
* "0","1987-02-04","Auf der Suche nach der verlorenen Zeit","978-3518061756","5100"
* "1","1945-01-04","Database Design for Mere Mortals","978-0321884497","654"
* "2","1887-02-04","Der alte Mann und das Meer","B00JM4RD2S","142"
* </pre>
*
* @since 3.0
*
* @see RowParser#csvLine()
*
* @return a CSV {@link ResultSet} parser
*/
static ResultSetParser<String> csv() {
return CSV::string;
}

/**
* Return a {@link ResultSet} parser, which converts the query result to a
* CSV line.
* {@snippet lang = "java":
* final var select = Query.of("SELECT * FROM book;");
* final var csv = select.as(ResultSetParser.csvLine(), conn);
* System.out.println(csv);
* }
*}
* The CSV output will look like this:
* <pre>
* "ID","PUBLISHED_AT","TITLE","ISBN","PAGES"
Expand All @@ -87,6 +113,7 @@ T parse(final ResultSet rs, final Connection conn)
*
* @return a CSV {@link ResultSet} parser
*/
@Deprecated(since = "3.0", forRemoval = true)
static ResultSetParser<String> csvLine() {
return CSV::string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ static RowParser<LocalDate> date(final int index) {
*
* @since 1.3
*
* @see ResultSetParser#csvLine()
* @see ResultSetParser#csv()
* @see #ofColumns(Function)
*
* @return a row parser which converts a DB row into a CSV row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.jenetics.facilejdbc;

import java.sql.SQLException;
import java.time.Instant;
import java.util.List;

import org.testng.Assert;
Expand All @@ -39,7 +40,8 @@ public void set() throws SQLException {
Param.value("name_2", "value_2"),
Param.value("name_3", "value_3"),
Param.value("name_4", "value_4"),
Param.value("name_5", "value_5")
Param.value("name_5", "value_5"),
Param.lazyValue("inserted_at", Instant::now)
));

params.set(List.of("name_2", "name_5", "name_1"), stmt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void selectEmptyStream() throws SQLException {
public void selectToCSV() throws SQLException {
db.transaction().accept(conn -> {
final var select = Query.of("SELECT * FROM book ORDER BY id;");
final var csv = select.as(ResultSetParser.csvLine(), conn);
final var csv = select.as(ResultSetParser.csv(), conn);

final var expected = """
"ID","PUBLISHED_AT","TITLE","LANGUAGE","ISBN","PAGES"
Expand Down
Loading