Skip to content

Commit

Permalink
优化 records 类的编码方式
Browse files Browse the repository at this point in the history
  • Loading branch information
vnobo committed Oct 27, 2023
1 parent 12896ad commit 16d2c29
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,35 @@

import com.google.common.collect.Maps;

import java.io.Serializable;
import java.util.Map;
import java.util.StringJoiner;

/**
* ParamSql represents a SQL query with parameters.
* It includes a SQL string and a map of parameter values.
* The whereSql() method returns the WHERE clause of the SQL query.
* @author <a href="https://github.com/vnobo">Alex bob</a>
*/
public record ParamSql(StringJoiner sql, Map<String, Object> params) {
public record ParamSql(StringJoiner sql, Map<String, Object> params) implements Serializable {
public final static ParamSql EMPTY = ParamSql.of(new StringJoiner(" AND "), Maps.newHashMap());

/**
* Creates a new ParamSql instance with the given SQL string and parameters.
*
* @param sql The SQL string.
* @param params The map of parameter values.
* @return A new ParamSql instance.
*/
public static ParamSql of(StringJoiner sql, Map<String, Object> params) {
return new ParamSql(sql, params);
}

/**
* Returns the WHERE clause of the SQL query.
*
* @return The WHERE clause.
*/
public String whereSql() {
if (this.sql.length() > 0) {
return " Where " + this.sql;
Expand Down

0 comments on commit 16d2c29

Please sign in to comment.