Skip to content

Commit

Permalink
Rename json functions to postgres names
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and nirvn committed Jan 18, 2019
1 parent 01e2b80 commit 008dfee
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "load_json",
"name": "from_json",
"type": "function",
"description": "Loads a JSON formatted string.",
"arguments": [
{"arg":"string", "description":"JSON string"}],
"examples": [
{"expression":"load_json('{\"qgis\":\"rocks\"}')", "returns":"{ \"qgis\" : \"rocks\" }"},
{"expression":"load_json('[1,2,3]')", "returns":"[1,2,3]"}
{"expression":"from_json('{\"qgis\":\"rocks\"}')", "returns":"{ \"qgis\" : \"rocks\" }"},
{"expression":"from_json('[1,2,3]')", "returns":"[1,2,3]"}
]
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "write_json",
"name": "to_json",
"type": "function",
"description": "Create a JSON formatted string from a map, array or other value.",
"arguments": [
{"arg":"value", "description":"The input value"}],
"examples": [
{ "expression":"write_json(map('qgis','rocks'))", "returns":"{\"qgis\":\"rocks\"}"},
{ "expression":"write_json(array(1,2,3))", "returns":"[1,2,3]"}
{ "expression":"to_json(map('qgis','rocks'))", "returns":"{\"qgis\":\"rocks\"}"},
{ "expression":"to_json(array(1,2,3))", "returns":"[1,2,3]"}
]
}
4 changes: 2 additions & 2 deletions src/core/expression/qgsexpressionfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5300,9 +5300,9 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()

//functions for maps
<< new QgsStaticExpressionFunction( QStringLiteral( "json_to_map" ), 1, fcnLoadJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "load_json" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "value" ) ), fcnLoadJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "from_json" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "value" ) ), fcnLoadJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "map_to_json" ), 1, fcnWriteJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "write_json" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "json_string" ) ), fcnWriteJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "to_json" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "json_string" ) ), fcnWriteJson, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "hstore_to_map" ), 1, fcnHstoreToMap, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "map_to_hstore" ), 1, fcnMapToHstore, QStringLiteral( "Maps" ) )
<< new QgsStaticExpressionFunction( QStringLiteral( "map" ), -1, fcnMap, QStringLiteral( "Maps" ) )
Expand Down
8 changes: 4 additions & 4 deletions tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2962,11 +2962,11 @@ class TestQgsExpression: public QObject
QCOMPARE( QgsExpression( "map_concat(map('1', 'one', '2', 'overridden by next map'), map('2', 'two', '3', 'three'))" ).evaluate( &context ), QVariant( concatExpected ) );

QCOMPARE( QgsExpression( "json_to_map('{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}')" ).evaluate( &context ), QVariant( concatExpected ) );
QCOMPARE( QgsExpression( "load_json('{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}')" ).evaluate( &context ), QVariant( concatExpected ) );
QCOMPARE( QgsExpression( "load_json('[1,2,3]')" ).evaluate( &context ), QVariant( QVariantList() << 1 << 2 << 3 ) );
QCOMPARE( QgsExpression( "from_json('{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}')" ).evaluate( &context ), QVariant( concatExpected ) );
QCOMPARE( QgsExpression( "from_json('[1,2,3]')" ).evaluate( &context ), QVariant( QVariantList() << 1 << 2 << 3 ) );
QCOMPARE( QgsExpression( "map_to_json(map('1','one','2','two','3','three'))" ).evaluate( &context ), QVariant( "{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}" ) );
QCOMPARE( QgsExpression( "write_json(map('1','one','2','two','3','three'))" ).evaluate( &context ), QVariant( "{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}" ) );
QCOMPARE( QgsExpression( "write_json(array(1,2,3))" ).evaluate( &context ), QVariant( QStringLiteral( "[1,2,3]" ) ) );
QCOMPARE( QgsExpression( "to_json(map('1','one','2','two','3','three'))" ).evaluate( &context ), QVariant( "{\"1\":\"one\",\"2\":\"two\",\"3\":\"three\"}" ) );
QCOMPARE( QgsExpression( "to_json(array(1,2,3))" ).evaluate( &context ), QVariant( QStringLiteral( "[1,2,3]" ) ) );

QCOMPARE( QgsExpression( "hstore_to_map('1=>one,2=>two,3=>three')" ).evaluate( &context ), QVariant( concatExpected ) );
QCOMPARE( QgsExpression( "map_to_hstore(map('1','one','2','two','3','three'))" ).evaluate( &context ), QVariant( "\"1\"=>\"one\",\"2\"=>\"two\",\"3\"=>\"three\"" ) );
Expand Down

0 comments on commit 008dfee

Please sign in to comment.