postspec 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ #db.logger = PgDevUtils::Logger.new
2
+
3
+ $runs = 100
4
+
5
+ # 'use' performance ~ 13.42ms per run, 74.5 runs/second, 4471 runs/minute
6
+ describe "'use' performance" do
7
+ t0 = nil
8
+
9
+ use "examples/seed.fox"
10
+
11
+ describe "timing..." do
12
+ t0 = nil
13
+
14
+ before(:all) {
15
+ t0 = Time.now
16
+ }
17
+
18
+ after(:all) {
19
+ t1 = Time.now
20
+ delta = ((t1 - t0) * 1000)
21
+ per_run = delta / $runs
22
+ per_second = 1000 / per_run
23
+ per_minute = 60 * per_second
24
+ puts "Executed in #{delta.round(2)}ms"
25
+ puts " #{per_run.round(2)}ms per run"
26
+ puts " #{per_second.round(1)} runs/second"
27
+ puts " #{per_minute.round(0)} runs/minute"
28
+ }
29
+
30
+ for i in 1..$runs
31
+ describe "USERS" do
32
+ use "examples/users.fox"
33
+ it "loads a number of users" do
34
+ expect(db.count("select * from users")).to eq 2
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ # 'statement with #db' performance ~ 0.72ms per run, 1394.8 runs/second, 83688 runs/minute
42
+ describe "'statement with #db' performance" do
43
+ t0 = nil
44
+
45
+ use "examples/seed.fox"
46
+ use "examples/users.fox"
47
+
48
+ describe "timing..." do
49
+
50
+ before(:all) {
51
+ t0 = Time.now
52
+ }
53
+
54
+ after(:all) {
55
+ t1 = Time.now
56
+ delta = ((t1 - t0) * 1000)
57
+ per_run = delta / $runs
58
+ per_second = 1000 / per_run
59
+ per_minute = 60 * per_second
60
+ puts "Executed in #{delta.round(2)}ms"
61
+ puts " #{per_run.round(2)}ms per run"
62
+ puts " #{per_second.round(1)} runs/second"
63
+ puts " #{per_minute.round(0)} runs/minute"
64
+ }
65
+
66
+ for i in 1..$runs
67
+ describe "insert record" do
68
+ statement "insert into users (name, age) values ('Cloe', 30)"
69
+ it "sets created_at to now()" do
70
+ expect(db.value("select created_at from users where name = 'Cloe'")).to eq postspec.timestamp
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+ # 'statement with #data' performance ~ 4.35ms per run, 229.7 runs/second, 13783 runs/minute
79
+ describe "'statement with #data' performance" do
80
+ t0 = nil
81
+
82
+ use "examples/seed.fox"
83
+ use "examples/users.fox"
84
+
85
+ describe "timing..." do
86
+
87
+ before(:all) {
88
+ t0 = Time.now
89
+ }
90
+
91
+ after(:all) {
92
+ t1 = Time.now
93
+ delta = ((t1 - t0) * 1000)
94
+ per_run = delta / $runs
95
+ per_second = 1000 / per_run
96
+ per_minute = 60 * per_second
97
+ puts "Executed in #{delta.round(2)}ms"
98
+ puts " #{per_run.round(2)}ms per run"
99
+ puts " #{per_second.round(1)} runs/second"
100
+ puts " #{per_minute.round(0)} runs/minute"
101
+ }
102
+
103
+ for i in 1..$runs
104
+ describe "insert record" do
105
+ statement "insert into users (name, age) values ('Cloe', 30)"
106
+ it "sets created_at to now()" do
107
+ created_at = data["public"]["users"][2][:created_at].value
108
+ expect(created_at).to eq postspec.timestamp
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+
data/postspec.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ require_relative 'lib/postspec/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "postspec"
5
+ spec.version = Postspec::VERSION
6
+ spec.authors = ["Claus Rasmussen"]
7
+ spec.email = ["claus.l.rasmussen@gmail.com"]
8
+
9
+ spec.summary = %q{postspec gem}
10
+ spec.description = %q{postspec gem}
11
+ spec.homepage = "http://www.nowhere.com/"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+
27
+ # FIXME: Not necessary when dependent packages are installed as gems
28
+ spec.add_dependency "dry-inflector"
29
+ spec.add_dependency "pg"
30
+ spec.add_dependency "boolean"
31
+ spec.add_dependency "indented_io"
32
+ spec.add_dependency "developer_exceptions"
33
+ spec.add_dependency "constrain"
34
+ spec.add_dependency "forward_to"
35
+ spec.add_dependency "pg_graph"
36
+ spec.add_dependency "fixture_fox"
37
+
38
+ spec.add_development_dependency "rake"
39
+ spec.add_development_dependency "rspec"
40
+ spec.add_development_dependency "simplecov"
41
+ end
@@ -0,0 +1,19 @@
1
+
2
+ -- Get current sequence value for all sequences
3
+ create or replace function getallseqid() returns table(name text, val bigint) as $$
4
+ declare
5
+ f record;
6
+ name varchar(255);
7
+ literal varchar(255);
8
+ ident varchar(255);
9
+ begin
10
+ for name in
11
+ select relnamespace::regnamespace::text || '.' || relname as name
12
+ from pg_class
13
+ where (relkind = 'S')
14
+ loop
15
+ return query execute 'select ' || quote_literal(name) || '::text, last_value from ' || name;
16
+ end loop;
17
+ return;
18
+ end
19
+ $$ language 'plpgsql';
@@ -0,0 +1,13 @@
1
+
2
+ -- Doesn't work as currval is only defined if the current session has requested an ID from the sequence
3
+ select n.nspname as "schema",
4
+ c.relname as "table",
5
+ last_value(pg_get_serial_sequence(n.nspname || '.' || c.relname, 'id'))
6
+ -- currval(pg_get_serial_sequence(n.nspname || '.' || c.relname, 'id'))
7
+ from pg_class c
8
+ join pg_namespace n on n.oid = c.relnamespace
9
+ where n.nspname not like 'pg_%'
10
+ and n.nspname <> 'information_schema'
11
+ and c.relkind = 'r'
12
+ ;
13
+
@@ -0,0 +1,14 @@
1
+ select event_object_schema as table_schema,
2
+ event_object_table as table_name,
3
+ trigger_schema,
4
+ trigger_name,
5
+ string_agg(event_manipulation, ',') as event,
6
+ action_timing as activation,
7
+ action_condition as condition,
8
+ action_statement as definition
9
+ from information_schema.triggers
10
+ group by
11
+ 1,2,3,4,6,7,8
12
+ order by
13
+ table_schema,
14
+ table_name;
metadata ADDED
@@ -0,0 +1,237 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Claus Rasmussen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-inflector
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: boolean
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: indented_io
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: developer_exceptions
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: constrain
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: forward_to
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pg_graph
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fixture_fox
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: postspec gem
182
+ email:
183
+ - claus.l.rasmussen@gmail.com
184
+ executables:
185
+ - postspec
186
+ extensions: []
187
+ extra_rdoc_files: []
188
+ files:
189
+ - ".gitignore"
190
+ - ".rspec"
191
+ - ".ruby-version"
192
+ - ".travis.yml"
193
+ - Gemfile
194
+ - README.md
195
+ - Rakefile
196
+ - TODO
197
+ - bin/console
198
+ - bin/setup
199
+ - exe/postspec
200
+ - lib/postspec.rb
201
+ - lib/postspec/config.rb
202
+ - lib/postspec/environment.rb
203
+ - lib/postspec/frame.rb
204
+ - lib/postspec/render.rb
205
+ - lib/postspec/state.rb
206
+ - lib/postspec/version.rb
207
+ - lib/postspec_helper.rb
208
+ - lib/share/postspec_schema.sql
209
+ - performance/performance_spec.rb
210
+ - postspec.gemspec
211
+ - snippets/sequences.sql
212
+ - snippets/serials.sql
213
+ - snippets/triggers.sql
214
+ homepage: http://www.nowhere.com/
215
+ licenses: []
216
+ metadata:
217
+ homepage_uri: http://www.nowhere.com/
218
+ post_install_message:
219
+ rdoc_options: []
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: 2.3.0
227
+ required_rubygems_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ requirements: []
233
+ rubygems_version: 3.1.4
234
+ signing_key:
235
+ specification_version: 4
236
+ summary: postspec gem
237
+ test_files: []