cfgdatabase 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/app-database.rb +43 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b271fb9a9c94ce05de34ef3997124c8fa19a99ba3f3ab674c71c426f37a4fa94
|
4
|
+
data.tar.gz: cc261a477e286785ecbad926e111c28dc98e7a78f138e93fc2c703c4837d7e3a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a92faf73dd97e686fe6af39dc28b87515910f759e01fa2d77cf6d14b7191c7b6d252c0d9ffc82c9d437581279ce7903c2e1cfd49481e795c357f65fab2cbc99e
|
7
|
+
data.tar.gz: 7faf038cdf8daf07140edeed5802abaf6583fcc118f78945f21557aa8c394e4449b0d77815537da4b83cfb114e33f94f291a0e139f22366986baa0c5e49dd38a
|
data/lib/app-database.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
require 'singleton'
|
3
|
+
require 'app-config'
|
4
|
+
require 'app-logger'
|
5
|
+
|
6
|
+
##
|
7
|
+
# Основной смысл надстройки -- красиво начать.
|
8
|
+
# Остальное Sequel и сам умеет.
|
9
|
+
# Модуль создаёт глобальную переменную Db
|
10
|
+
# Предполагается использование глобальной Cfg для настроек
|
11
|
+
|
12
|
+
module App
|
13
|
+
class Database
|
14
|
+
include Singleton
|
15
|
+
attr_reader :db
|
16
|
+
|
17
|
+
##
|
18
|
+
# Ищем секцию настроек Cfg.db
|
19
|
+
def initialize
|
20
|
+
raise ArgumentError.new("Cfg not found!") if ! defined?( ::Cfg ) || ! Cfg.db || Cfg.db.empty?
|
21
|
+
if (! defined? @db ) || ( @db.nil? ) || ( ! @db ) || ( ! @db.test_connection )
|
22
|
+
Log.info{ "БД #{ Cfg.db.database }." }
|
23
|
+
Sequel.extension :pg_array, :pg_inet, :pg_json, :pg_json_ops, :pg_array, :pg_array_ops, :pg_row, :pg_hstore, :pg_json_ops
|
24
|
+
Sequel::Model.raise_on_save_failure = false
|
25
|
+
Sequel::Model.plugin :validation_helpers
|
26
|
+
Sequel::Database.extension :pg_inet, :pg_json, :pg_array, :pg_range, :pg_row, :pg_enum
|
27
|
+
counter = Cfg.app.tmout.database_start
|
28
|
+
begin
|
29
|
+
@db = Sequel.connect Cfg.db.to_hash
|
30
|
+
rescue Sequel::DatabaseConnectionError => e
|
31
|
+
Log.error{"Шо-то с базой: #{ ( e.message.dup ).force_encoding('UTF-8') }"}
|
32
|
+
( counter -= 1 ) > 0 ? ( sleep(1); retry ) : raise
|
33
|
+
end
|
34
|
+
Sequel::Model.db = @db
|
35
|
+
@db.tables.each{ |t| @db.reset_primary_key_sequence t } # Настоящие герои всегда идут в обход
|
36
|
+
@db.freeze if Cfg.env == :production
|
37
|
+
Kernel.const_set 'Db', @db
|
38
|
+
end
|
39
|
+
return @db
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cfgdatabase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- deemytch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sequel
|
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: monkey-hash
|
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: cfgstore
|
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
|
+
description:
|
56
|
+
email: aspamkiller@yandex.ru
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/app-database.rb
|
62
|
+
homepage: https://gitlab.sudo.su/amqp-lib/cfgdatabase
|
63
|
+
licenses:
|
64
|
+
- GPL-2.0
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.1.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Удобная загрузка настроек Sequel.
|
85
|
+
test_files: []
|