[jOOQ/jOOQ#8944] Add support for the JSON array constructor.
This commit is contained in:
parent
b8e58b2605
commit
c751499831
@ -78,6 +78,8 @@ import static org.jooq.SQLDialect.SQLITE;
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.impl.SQLDataType.JSON;
|
||||
import static org.jooq.impl.SQLDataType.JSONB;
|
||||
import static org.jooq.impl.Term.CUME_DIST;
|
||||
import static org.jooq.impl.Term.DENSE_RANK;
|
||||
import static org.jooq.impl.Term.FIRST_VALUE;
|
||||
@ -225,6 +227,8 @@ import org.jooq.InsertValuesStep7;
|
||||
import org.jooq.InsertValuesStep8;
|
||||
import org.jooq.InsertValuesStep9;
|
||||
import org.jooq.InsertValuesStepN;
|
||||
import org.jooq.JSON;
|
||||
import org.jooq.JSONB;
|
||||
import org.jooq.Keyword;
|
||||
// ...
|
||||
// ...
|
||||
@ -17678,6 +17682,42 @@ public class DSL {
|
||||
return field("rownum", Integer.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX JSON functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The JSON array constructor.
|
||||
*/
|
||||
@Support({ MYSQL, POSTGRES })
|
||||
public static Field<JSON> jsonArray(Field<?>... fields) {
|
||||
return jsonArray(Arrays.asList(fields));
|
||||
}
|
||||
|
||||
/**
|
||||
* The JSON array constructor.
|
||||
*/
|
||||
@Support({ MYSQL, POSTGRES })
|
||||
public static Field<JSON> jsonArray(Collection<? extends Field<?>> fields) {
|
||||
return new JSONArray(JSON, fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* The JSONB array constructor.
|
||||
*/
|
||||
@Support({ MYSQL, POSTGRES })
|
||||
public static Field<JSONB> jsonbArray(Field<?>... fields) {
|
||||
return jsonbArray(Arrays.asList(fields));
|
||||
}
|
||||
|
||||
/**
|
||||
* The JSONB array constructor.
|
||||
*/
|
||||
@Support({ MYSQL, POSTGRES })
|
||||
public static Field<JSONB> jsonbArray(Collection<? extends Field<?>> fields) {
|
||||
return new JSONArray(JSONB, fields);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// XXX Aggregate functions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -193,6 +193,8 @@ final class Keywords {
|
||||
static final Keyword K_IS_NOT_NULL = keyword("is not null");
|
||||
static final Keyword K_IS_NULL = keyword("is null");
|
||||
static final Keyword K_ITERATE = keyword("iterate");
|
||||
static final Keyword K_JSON_ARRAY = keyword("json_array");
|
||||
static final Keyword K_JSON_OBJECT = keyword("json_object");
|
||||
static final Keyword K_KEEP = keyword("keep");
|
||||
static final Keyword K_KEY = keyword("key");
|
||||
static final Keyword K_LAST = keyword("last");
|
||||
|
||||
@ -292,6 +292,7 @@ import static org.jooq.impl.Keywords.K_UPDATE;
|
||||
import static org.jooq.impl.ParserImpl.Type.A;
|
||||
import static org.jooq.impl.ParserImpl.Type.B;
|
||||
import static org.jooq.impl.ParserImpl.Type.D;
|
||||
import static org.jooq.impl.ParserImpl.Type.J;
|
||||
import static org.jooq.impl.ParserImpl.Type.N;
|
||||
import static org.jooq.impl.ParserImpl.Type.S;
|
||||
import static org.jooq.impl.ParserImpl.Type.X;
|
||||
@ -5084,6 +5085,24 @@ final class ParserImpl implements Parser {
|
||||
return sort;
|
||||
}
|
||||
|
||||
private static final List<Field<?>> parseFieldsOrEmptyParenthesised(ParserContext ctx) {
|
||||
List<Field<?>> result = new ArrayList<>();
|
||||
|
||||
parse(ctx, '(');
|
||||
if (parseIf(ctx, ')')) {
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
do {
|
||||
result.add(parseField(ctx));
|
||||
}
|
||||
while (parseIf(ctx, ','));
|
||||
parse(ctx, ')');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final List<Field<?>> parseFields(ParserContext ctx) {
|
||||
List<Field<?>> result = new ArrayList<>();
|
||||
do {
|
||||
@ -5143,7 +5162,8 @@ final class ParserImpl implements Parser {
|
||||
S("string"),
|
||||
N("numeric"),
|
||||
B("boolean"),
|
||||
X("binary");
|
||||
X("binary"),
|
||||
J("json");
|
||||
|
||||
private final String name;
|
||||
|
||||
@ -5674,6 +5694,14 @@ final class ParserImpl implements Parser {
|
||||
else
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
case 'J':
|
||||
if (J.is(type))
|
||||
if ((field = parseFieldJSONArrayConstructorIf(ctx)) != null)
|
||||
return field;
|
||||
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
case 'L':
|
||||
if (S.is(type))
|
||||
@ -6218,6 +6246,13 @@ final class ParserImpl implements Parser {
|
||||
CURRVAL;
|
||||
}
|
||||
|
||||
private static final Field<?> parseFieldJSONArrayConstructorIf(ParserContext ctx) {
|
||||
if (parseKeywordIf(ctx, "JSON_ARRAY"))
|
||||
return DSL.jsonArray(parseFieldsOrEmptyParenthesised(ctx));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final Field<?> parseArrayValueConstructorIf(ParserContext ctx) {
|
||||
if (parseKeywordIf(ctx, "ARRAY")) {
|
||||
parse(ctx, '[');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user