evt-message_store-postgres-database 0.4.0.0 → 0.4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/database/functions/get-stream-summary.sql +52 -0
- data/database/functions/get-type-summary.sql +52 -0
- data/database/install-functions.sh +6 -0
- data/database/install.sh +0 -9
- data/database/print-messages.sh +2 -10
- data/database/print-stream-summary.sh +4 -4
- data/database/print-type-summary.sh +4 -4
- data/database/types/message.sql +13 -11
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 604e3e9dd41d52af97049bce34b923de1f54d7295ca225de0cc1ce7cc4476dc6
|
4
|
+
data.tar.gz: 4c8f7eddd2654732b7b8173af70c45f8eb7ae48eaf82f064a79d6c51963c79d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8edddd7a0cc4d9bd68e6b1db51a576196703fe4afce43886cdb03909664ffdbff1f1e266ca1ba7f6c78cd391734e7063de756db927250e519acd070f26300f8d
|
7
|
+
data.tar.gz: 2833db92e4a33d1f0a193aeadbddb4739d92e4b9254103f5f2be97c31e5068bd66f69ebfd81f8775661d7b9287efc7d5d80fed56adcbce996b93d821bee3edc3
|
@@ -0,0 +1,52 @@
|
|
1
|
+
CREATE OR REPLACE FUNCTION get_stream_summary(
|
2
|
+
_stream_name varchar DEFAULT NULL
|
3
|
+
)
|
4
|
+
RETURNS TABLE (
|
5
|
+
stream_name varchar,
|
6
|
+
message_count bigint,
|
7
|
+
percent decimal
|
8
|
+
)
|
9
|
+
AS $$
|
10
|
+
DECLARE
|
11
|
+
command text;
|
12
|
+
BEGIN
|
13
|
+
command := '
|
14
|
+
SELECT
|
15
|
+
stream_name,
|
16
|
+
message_count,
|
17
|
+
ROUND((SELECT (message_count::decimal / count(*)::decimal * 100.0) FROM messages)::decimal, 2) AS percent
|
18
|
+
FROM
|
19
|
+
(
|
20
|
+
SELECT
|
21
|
+
DISTINCT stream_name,
|
22
|
+
count(stream_name) AS message_count
|
23
|
+
FROM
|
24
|
+
messages';
|
25
|
+
|
26
|
+
command := command || '
|
27
|
+
GROUP BY
|
28
|
+
stream_name
|
29
|
+
) summary';
|
30
|
+
|
31
|
+
|
32
|
+
IF _stream_name is not null THEN
|
33
|
+
_stream_name := '%' || _stream_name || '%';
|
34
|
+
command := command || '
|
35
|
+
WHERE
|
36
|
+
stream_name LIKE $1';
|
37
|
+
END IF;
|
38
|
+
|
39
|
+
command := command || '
|
40
|
+
ORDER BY
|
41
|
+
message_count DESC';
|
42
|
+
|
43
|
+
-- RAISE NOTICE '%', command;
|
44
|
+
|
45
|
+
IF _stream_name is not null THEN
|
46
|
+
RETURN QUERY EXECUTE command USING _stream_name;
|
47
|
+
ELSE
|
48
|
+
RETURN QUERY EXECUTE command;
|
49
|
+
END IF;
|
50
|
+
END;
|
51
|
+
$$ LANGUAGE plpgsql
|
52
|
+
VOLATILE;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
CREATE OR REPLACE FUNCTION get_type_summary(
|
2
|
+
_type varchar DEFAULT NULL
|
3
|
+
)
|
4
|
+
RETURNS TABLE (
|
5
|
+
type varchar,
|
6
|
+
message_count bigint,
|
7
|
+
percent decimal
|
8
|
+
)
|
9
|
+
AS $$
|
10
|
+
DECLARE
|
11
|
+
command text;
|
12
|
+
BEGIN
|
13
|
+
command := '
|
14
|
+
SELECT
|
15
|
+
type,
|
16
|
+
message_count,
|
17
|
+
ROUND((SELECT (message_count::decimal / count(*)::decimal * 100.0) FROM messages)::decimal, 2) AS percent
|
18
|
+
FROM
|
19
|
+
(
|
20
|
+
SELECT
|
21
|
+
DISTINCT type,
|
22
|
+
count(type) AS message_count
|
23
|
+
FROM
|
24
|
+
messages';
|
25
|
+
|
26
|
+
command := command || '
|
27
|
+
GROUP BY
|
28
|
+
type
|
29
|
+
) summary';
|
30
|
+
|
31
|
+
|
32
|
+
IF _type is not null THEN
|
33
|
+
_type := '%' || _type || '%';
|
34
|
+
command := command || '
|
35
|
+
WHERE
|
36
|
+
type LIKE $1';
|
37
|
+
END IF;
|
38
|
+
|
39
|
+
command := command || '
|
40
|
+
ORDER BY
|
41
|
+
message_count DESC';
|
42
|
+
|
43
|
+
-- RAISE NOTICE '%', command;
|
44
|
+
|
45
|
+
IF _type is not null THEN
|
46
|
+
RETURN QUERY EXECUTE command USING _type;
|
47
|
+
ELSE
|
48
|
+
RETURN QUERY EXECUTE command;
|
49
|
+
END IF;
|
50
|
+
END;
|
51
|
+
$$ LANGUAGE plpgsql
|
52
|
+
VOLATILE;
|
@@ -50,6 +50,12 @@ function create-functions {
|
|
50
50
|
echo "get_last_message function"
|
51
51
|
psql $database -f $base/functions/get-last-message.sql
|
52
52
|
|
53
|
+
echo "get_stream_summary function"
|
54
|
+
psql $database -f $base/functions/get-stream-summary.sql
|
55
|
+
|
56
|
+
echo "get_type_summary function"
|
57
|
+
psql $database -f $base/functions/get-type-summary.sql
|
58
|
+
|
53
59
|
echo
|
54
60
|
}
|
55
61
|
|
data/database/install.sh
CHANGED
data/database/print-messages.sh
CHANGED
@@ -27,14 +27,6 @@ echo "Database name is: $database"
|
|
27
27
|
|
28
28
|
default_table_name=messages
|
29
29
|
|
30
|
-
if [ -z ${TABLE_NAME+x} ]; then
|
31
|
-
echo "(TABLE_NAME is not set)"
|
32
|
-
table=$default_table_name
|
33
|
-
else
|
34
|
-
table=$TABLE_NAME
|
35
|
-
fi
|
36
|
-
echo "Table name is: $table"
|
37
|
-
|
38
30
|
if [ -z ${STREAM_NAME+x} ]; then
|
39
31
|
echo "(STREAM_NAME is not set)"
|
40
32
|
stream_name=''
|
@@ -46,7 +38,7 @@ fi
|
|
46
38
|
echo
|
47
39
|
|
48
40
|
if [ -z $stream_name ]; then
|
49
|
-
psql $database -x -c "SELECT * FROM
|
41
|
+
psql $database -U $user -x -c "SELECT * FROM messages"
|
50
42
|
else
|
51
|
-
psql $database -x -c "SELECT * FROM
|
43
|
+
psql $database -U $user -x -c "SELECT * FROM messages WHERE stream_name = '$stream_name'"
|
52
44
|
fi
|
@@ -36,9 +36,9 @@ echo "= = ="
|
|
36
36
|
echo
|
37
37
|
|
38
38
|
if [ -z $stream_name ]; then
|
39
|
-
psql $database -U $user -P pager=off -c "SELECT
|
40
|
-
psql $database -U $user -P pager=off -c "SELECT
|
39
|
+
psql $database -U $user -P pager=off -c "SELECT * FROM get_stream_summary();"
|
40
|
+
psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages;"
|
41
41
|
else
|
42
|
-
psql $database -U $user -P pager=off -c "SELECT
|
43
|
-
psql $database -U $user -P pager=off -c "SELECT
|
42
|
+
psql $database -U $user -P pager=off -c "SELECT * FROM get_stream_summary('$stream_name');"
|
43
|
+
psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages WHERE stream_name LIKE '%$stream_name%';"
|
44
44
|
fi
|
@@ -36,9 +36,9 @@ echo "= = ="
|
|
36
36
|
echo
|
37
37
|
|
38
38
|
if [ -z $stream_name ]; then
|
39
|
-
psql $database -U $user -P pager=off -c "SELECT
|
40
|
-
psql $database -U $user -P pager=off -c "SELECT
|
39
|
+
psql $database -U $user -P pager=off -c "SELECT * FROM get_type_summary();"
|
40
|
+
psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages;"
|
41
41
|
else
|
42
|
-
psql $database -U $user -P pager=off -c "SELECT
|
43
|
-
psql $database -U $user -P pager=off -c "SELECT
|
42
|
+
psql $database -U $user -P pager=off -c "SELECT * FROM get_type_summary('$stream_name');"
|
43
|
+
psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages WHERE stream_name LIKE '%$stream_name%';"
|
44
44
|
fi
|
data/database/types/message.sql
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
DO $$
|
2
2
|
BEGIN
|
3
|
-
IF
|
4
|
-
|
5
|
-
id varchar,
|
6
|
-
stream_name varchar,
|
7
|
-
type varchar,
|
8
|
-
position bigint,
|
9
|
-
global_position bigint,
|
10
|
-
data varchar,
|
11
|
-
metadata varchar,
|
12
|
-
time timestamp
|
13
|
-
);
|
3
|
+
IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'message') THEN
|
4
|
+
DROP TYPE message CASCADE;
|
14
5
|
END IF;
|
6
|
+
|
7
|
+
CREATE TYPE message AS (
|
8
|
+
id varchar,
|
9
|
+
stream_name varchar,
|
10
|
+
type varchar,
|
11
|
+
position bigint,
|
12
|
+
global_position bigint,
|
13
|
+
data varchar,
|
14
|
+
metadata varchar,
|
15
|
+
time timestamp
|
16
|
+
);
|
15
17
|
END$$;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-message_store-postgres-database
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: scripts
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " "
|
14
14
|
email: opensource@eventide-project.org
|
@@ -35,6 +35,8 @@ files:
|
|
35
35
|
- database/functions/get-category-messages.sql
|
36
36
|
- database/functions/get-last-message.sql
|
37
37
|
- database/functions/get-stream-messages.sql
|
38
|
+
- database/functions/get-stream-summary.sql
|
39
|
+
- database/functions/get-type-summary.sql
|
38
40
|
- database/functions/hash-64.sql
|
39
41
|
- database/functions/scratch.sql
|
40
42
|
- database/functions/stream-version.sql
|