Skip to content

Commit 468d763

Browse files
committed
pub and priv schemas (database)
1 parent ce3dced commit 468d763

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- Deploy schemas/inflection/procedures/dashed to pg
2+
3+
-- requires: schemas/inflection/schema
4+
-- requires: schemas/inflection/procedures/underscore
5+
6+
BEGIN;
7+
8+
CREATE FUNCTION inflection.dashed(str text)
9+
RETURNS text
10+
AS $$
11+
WITH underscored AS (
12+
SELECT
13+
inflection.underscore(str) AS value
14+
),
15+
dashes AS (
16+
SELECT
17+
regexp_replace(value, '_', '-', 'gi') AS value
18+
FROM
19+
underscored
20+
)
21+
SELECT
22+
value
23+
FROM
24+
dashes;
25+
$$
26+
LANGUAGE 'sql'
27+
IMMUTABLE;
28+
COMMIT;
29+

packages/inflection/deploy/schemas/inflection/procedures/underscore.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ removedups AS (
2727
regexp_replace(value, E'[_]+', '_', 'gi') AS value
2828
FROM
2929
noprefix
30+
),
31+
stripedges AS (
32+
SELECT
33+
regexp_replace(regexp_replace(value, E'([A-Z])_$', E'\\1', 'gi'), E'^_([A-Z])', E'\\1', 'gi') AS value
34+
FROM
35+
removedups
3036
)
3137
SELECT
3238
value
3339
FROM
34-
removedups;
40+
stripedges;
3541
$$
3642
LANGUAGE 'sql'
3743
IMMUTABLE;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Revert schemas/inflection/procedures/dashed from pg
2+
3+
BEGIN;
4+
5+
DROP FUNCTION inflection.dashed;
6+
7+
COMMIT;

packages/inflection/sqitch.plan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ schemas/inflection/procedures/no_consecutive_caps [schemas/inflection/schema] 20
77
schemas/inflection/procedures/pg_slugify [schemas/inflection/schema schemas/inflection/procedures/no_consecutive_caps] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/pg_slugify
88
schemas/inflection/procedures/underscore [schemas/inflection/schema schemas/inflection/procedures/pg_slugify] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/underscore
99
schemas/inflection/procedures/camel [schemas/inflection/schema schemas/inflection/procedures/underscore] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/camel
10+
schemas/inflection/procedures/dashed [schemas/inflection/schema schemas/inflection/procedures/underscore] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/dashed
1011
schemas/inflection/procedures/pascal [schemas/inflection/schema schemas/inflection/procedures/camel] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/pascal
1112
schemas/inflection/tables/inflection_rules/table [schemas/inflection/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/tables/inflection_rules/table
1213
schemas/inflection/procedures/plural [schemas/inflection/schema schemas/inflection/tables/inflection_rules/table] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/inflection/procedures/plural

packages/inflection/sql/inflection--0.0.1.sql

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,17 @@ removedups AS (
9292
regexp_replace(value, E'[_]+', '_', 'gi') AS value
9393
FROM
9494
noprefix
95+
),
96+
stripedges AS (
97+
SELECT
98+
regexp_replace(regexp_replace(value, E'([A-Z])_$', E'\\1', 'gi'), E'^_([A-Z])', E'\\1', 'gi') AS value
99+
FROM
100+
removedups
95101
)
96102
SELECT
97103
value
98104
FROM
99-
removedups;
105+
stripedges;
100106
$EOFCODE$ LANGUAGE sql IMMUTABLE;
101107

102108
CREATE FUNCTION inflection.camel ( str text ) RETURNS text AS $EOFCODE$
@@ -113,6 +119,23 @@ BEGIN
113119
END;
114120
$EOFCODE$ LANGUAGE plpgsql STABLE;
115121

122+
CREATE FUNCTION inflection.dashed ( str text ) RETURNS text AS $EOFCODE$
123+
WITH underscored AS (
124+
SELECT
125+
inflection.underscore(str) AS value
126+
),
127+
dashes AS (
128+
SELECT
129+
regexp_replace(value, '_', '-', 'gi') AS value
130+
FROM
131+
underscored
132+
)
133+
SELECT
134+
value
135+
FROM
136+
dashes;
137+
$EOFCODE$ LANGUAGE sql IMMUTABLE;
138+
116139
CREATE FUNCTION inflection.pascal ( str text ) RETURNS text AS $EOFCODE$
117140
DECLARE
118141
result text[];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Verify schemas/inflection/procedures/dashed on pg
2+
3+
BEGIN;
4+
5+
SELECT verify_function ('inflection.dashed');
6+
7+
ROLLBACK;

0 commit comments

Comments
 (0)