Skip to content

Commit

Permalink
edgeql: Add re_replace function to std.
Browse files Browse the repository at this point in the history
  • Loading branch information
vpetrovykh committed Jun 27, 2018
1 parent 7d57f1f commit 9c20ef1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions edb/lang/schema/_graphql.eql
Expand Up @@ -18,8 +18,8 @@


CREATE FUNCTION graphql::short_name(std::str) -> std::str
FROM SQL $$
SELECT regexp_replace($1, '.+?::(.+$)', '\1');
FROM EdgeQL $$
SELECT re_replace($0, '.+?::(.+$)', '\1')
$$;

# create Query
Expand Down
6 changes: 6 additions & 0 deletions edb/lang/schema/_std.eql
Expand Up @@ -167,6 +167,12 @@ CREATE FUNCTION std::re_test(std::str, std::str) -> std::bool
SELECT $1 ~ $2;
$$;

CREATE FUNCTION std::re_replace(std::str, std::str, std::str, std::str = '')
-> std::str
FROM SQL $$
SELECT regexp_replace($1, $2, $3, $4);
$$;

CREATE FUNCTION std::current_date() -> std::date
FROM SQL 'SELECT current_date';

Expand Down
26 changes: 26 additions & 0 deletions tests/test_edgeql_functions.py
Expand Up @@ -466,6 +466,32 @@ async def test_edgeql_functions_re_test_02(self):
[True],
])

async def test_edgeql_functions_re_replace_01(self):
await self.assert_query_result(r'''
SELECT re_replace('Hello World', 'l', 'L');
SELECT re_replace('Hello World', 'l', 'L', 'g');
SELECT re_replace('Hello World', '[a-z]', '~', 'i');
SELECT re_replace('Hello World', '[a-z]', '~', 'gi');
''', [
['HeLlo World'],
['HeLLo WorLd'],
['~ello World'],
['~~~~~ ~~~~~'],
])

async def test_edgeql_functions_re_replace_02(self):
await self.assert_query_result(r'''
SELECT re_replace(test::User.name, '[aeiou]', '~');
SELECT re_replace(test::User.name, '[aeiou]', '~', 'g');
SELECT re_replace(test::User.name, '[aeiou]', '~', 'i');
SELECT re_replace(test::User.name, '[aeiou]', '~', 'gi');
''', [
{'Elv~s', 'Y~ry'},
{'Elv~s', 'Y~ry'},
{'~lvis', 'Y~ry'},
{'~lv~s', 'Y~ry'},
])

async def test_edgeql_functions_sum_01(self):
await self.assert_query_result(r'''
SELECT sum({1, 2, 3, -4, 5});
Expand Down

0 comments on commit 9c20ef1

Please sign in to comment.