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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fee61d1167444b80c9b38b26b0f26f1ebdc604c354c5f2acd744d4d7f77867b7
4
- data.tar.gz: 8af326596da6f662bd3ab8090c8fb187331e600f6169353ff7cf4c3cdfae8cf5
3
+ metadata.gz: 604e3e9dd41d52af97049bce34b923de1f54d7295ca225de0cc1ce7cc4476dc6
4
+ data.tar.gz: 4c8f7eddd2654732b7b8173af70c45f8eb7ae48eaf82f064a79d6c51963c79d6
5
5
  SHA512:
6
- metadata.gz: 92ade25f7017c6455ae7350efbb73b30128445ad44458936b3c2b009d39f60d0b749d61802a630a61efe4f8b8a6ee9a6194f39771011f86de49b091d2dcdcbdb
7
- data.tar.gz: 8585cb96a901fcdda4c9835c394d47d546f21c2c45500c45a18f3c527b408831e021985efb7bde436e7979e554725a75ee72b4e4022a48e5a8c0610f4d59ff6d
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
 
@@ -53,15 +53,6 @@ function create-table {
53
53
  echo
54
54
  }
55
55
 
56
- function create-types {
57
- base=$(script_dir)
58
-
59
- echo "message type"
60
- psql $database -f $base/types/message.sql
61
-
62
- echo
63
- }
64
-
65
56
  function create-indexes {
66
57
  base=$(script_dir)
67
58
 
@@ -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 $table"
41
+ psql $database -U $user -x -c "SELECT * FROM messages"
50
42
  else
51
- psql $database -x -c "SELECT * FROM $table WHERE stream_name = '$stream_name'"
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 DISTINCT stream_name, count(stream_name) FROM messages GROUP BY stream_name ORDER BY count DESC;"
40
- psql $database -U $user -P pager=off -c "SELECT count(*) FROM messages;"
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 DISTINCT stream_name, count(stream_name) FROM messages WHERE stream_name LIKE '%$stream_name%' GROUP BY stream_name ORDER BY count DESC;"
43
- psql $database -U $user -P pager=off -c "SELECT count(*) FROM messages WHERE stream_name LIKE '%$stream_name%';"
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 DISTINCT type, count(type) FROM messages GROUP BY type ORDER BY count DESC;"
40
- psql $database -U $user -P pager=off -c "SELECT count(*) FROM messages;"
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 DISTINCT type, count(type) FROM messages WHERE stream_name LIKE '%$stream_name%' GROUP BY type ORDER BY count DESC;"
43
- psql $database -U $user -P pager=off -c "SELECT count(*) FROM messages WHERE stream_name LIKE '%$stream_name%';"
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
@@ -1,15 +1,17 @@
1
1
  DO $$
2
2
  BEGIN
3
- IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'message') THEN
4
- CREATE TYPE message AS (
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.0.0
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-17 00:00:00.000000000 Z
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