baza 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +157 -0
- data/Gemfile +11 -9
- data/Gemfile.lock +41 -9
- data/README.md +1 -1
- data/Rakefile +19 -16
- data/VERSION +1 -1
- data/baza.gemspec +31 -7
- data/config/best_project_practice_rubocop.yml +2 -0
- data/config/best_project_practice_rubocop_todo.yml +157 -0
- data/lib/baza/base_sql_driver.rb +79 -20
- data/lib/baza/cloner.rb +2 -2
- data/lib/baza/column.rb +6 -0
- data/lib/baza/database.rb +33 -0
- data/lib/baza/database_model.rb +26 -0
- data/lib/baza/database_model_functionality.rb +10 -0
- data/lib/baza/database_model_name.rb +16 -0
- data/lib/baza/db.rb +210 -413
- data/lib/baza/dbtime.rb +20 -20
- data/lib/baza/driver.rb +3 -3
- data/lib/baza/drivers/active_record/columns.rb +1 -1
- data/lib/baza/drivers/active_record/indexes.rb +1 -1
- data/lib/baza/drivers/active_record/result.rb +3 -5
- data/lib/baza/drivers/active_record/tables.rb +2 -2
- data/lib/baza/drivers/active_record.rb +30 -16
- data/lib/baza/drivers/mysql/column.rb +51 -48
- data/lib/baza/drivers/mysql/columns.rb +8 -8
- data/lib/baza/drivers/mysql/database.rb +28 -0
- data/lib/baza/drivers/mysql/databases.rb +35 -0
- data/lib/baza/drivers/mysql/index.rb +32 -22
- data/lib/baza/drivers/mysql/result.rb +24 -24
- data/lib/baza/drivers/mysql/sqlspecs.rb +1 -1
- data/lib/baza/drivers/mysql/table.rb +80 -91
- data/lib/baza/drivers/mysql/tables.rb +30 -32
- data/lib/baza/drivers/mysql/unbuffered_result.rb +5 -5
- data/lib/baza/drivers/mysql.rb +127 -220
- data/lib/baza/drivers/mysql2/database.rb +2 -0
- data/lib/baza/drivers/mysql2/databases.rb +2 -0
- data/lib/baza/drivers/mysql2/result.rb +3 -5
- data/lib/baza/drivers/mysql2.rb +21 -106
- data/lib/baza/drivers/mysql_java/database.rb +2 -0
- data/lib/baza/drivers/mysql_java/databases.rb +2 -0
- data/lib/baza/drivers/mysql_java.rb +16 -12
- data/lib/baza/drivers/sqlite3/column.rb +33 -33
- data/lib/baza/drivers/sqlite3/columns.rb +6 -6
- data/lib/baza/drivers/sqlite3/database.rb +2 -0
- data/lib/baza/drivers/sqlite3/databases.rb +25 -0
- data/lib/baza/drivers/sqlite3/index.rb +20 -6
- data/lib/baza/drivers/sqlite3/result.rb +16 -17
- data/lib/baza/drivers/sqlite3/sqlspecs.rb +1 -1
- data/lib/baza/drivers/sqlite3/table.rb +99 -100
- data/lib/baza/drivers/sqlite3/tables.rb +30 -23
- data/lib/baza/drivers/sqlite3/unbuffered_result.rb +2 -2
- data/lib/baza/drivers/sqlite3.rb +27 -14
- data/lib/baza/drivers/sqlite3_java/database.rb +2 -0
- data/lib/baza/drivers/sqlite3_java/unbuffered_result.rb +2 -2
- data/lib/baza/drivers/sqlite3_java.rb +12 -10
- data/lib/baza/drivers/sqlite3_rhodes.rb +9 -7
- data/lib/baza/dump.rb +55 -55
- data/lib/baza/errors.rb +5 -0
- data/lib/baza/idquery.rb +25 -25
- data/lib/baza/index.rb +6 -0
- data/lib/baza/jdbc_driver.rb +6 -8
- data/lib/baza/jdbc_result.rb +1 -1
- data/lib/baza/model.rb +299 -309
- data/lib/baza/model_custom.rb +74 -72
- data/lib/baza/model_handler.rb +244 -255
- data/lib/baza/model_handler_sqlhelper.rb +122 -132
- data/lib/baza/mysql_base_driver.rb +112 -0
- data/lib/baza/query_buffer.rb +23 -23
- data/lib/baza/result_base.rb +2 -2
- data/lib/baza/revision.rb +67 -67
- data/lib/baza/row.rb +82 -84
- data/lib/baza/sqlspecs.rb +1 -1
- data/lib/baza/table.rb +31 -0
- data/lib/baza.rb +43 -10
- data/shippable.yml +1 -0
- data/spec/cloner_spec.rb +4 -4
- data/spec/drivers/active_record_mysql2_spec.rb +3 -3
- data/spec/drivers/active_record_mysql_spec.rb +2 -2
- data/spec/drivers/active_record_sqlite3_spec.rb +2 -2
- data/spec/drivers/mysql2_spec.rb +1 -0
- data/spec/drivers/mysql_spec.rb +1 -0
- data/spec/drivers/sqlite3_spec.rb +4 -5
- data/spec/info_active_record_example.rb +4 -6
- data/spec/info_active_record_mysql.rb +6 -7
- data/spec/info_active_record_mysql2.rb +2 -4
- data/spec/info_active_record_mysql2_shippable.rb +2 -4
- data/spec/info_active_record_mysql_shippable.rb +2 -4
- data/spec/info_active_record_sqlite3.rb +5 -6
- data/spec/info_mysql2_example.rb +1 -1
- data/spec/info_mysql2_shippable.rb +1 -1
- data/spec/info_mysql_example.rb +1 -1
- data/spec/info_mysql_shippable.rb +1 -1
- data/spec/info_sqlite3.rb +4 -3
- data/spec/model_handler_spec.rb +102 -115
- data/spec/spec_helper.rb +5 -5
- data/spec/support/driver_collection.rb +98 -95
- data/spec/support/driver_columns_collection.rb +18 -22
- data/spec/support/driver_databases_collection.rb +29 -0
- data/spec/support/driver_indexes_collection.rb +7 -6
- data/spec/support/driver_tables_collection.rb +38 -26
- metadata +49 -3
data/lib/baza/model_custom.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
require "#{$knjpath}event_handler"
|
2
2
|
|
3
3
|
class Baza::ModelCustom
|
4
|
-
#Used to determine if this is a knj-datarow-object.
|
4
|
+
# Used to determine if this is a knj-datarow-object.
|
5
5
|
def is_knj?
|
6
|
-
|
6
|
+
true
|
7
7
|
end
|
8
|
-
|
9
|
-
#Initializes variables on the class from objects.
|
8
|
+
|
9
|
+
# Initializes variables on the class from objects.
|
10
10
|
def self.datarow_init(d)
|
11
11
|
@@ob = d.ob
|
12
12
|
@@db = d.db
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.has_one(arr)
|
16
16
|
arr.each do |val|
|
17
17
|
methodname = nil
|
18
18
|
colname = nil
|
19
19
|
classname = nil
|
20
|
-
|
20
|
+
|
21
21
|
if val.is_a?(Symbol)
|
22
22
|
classname = val
|
23
23
|
methodname = val.to_s.downcase.to_sym
|
@@ -25,129 +25,131 @@ class Baza::ModelCustom
|
|
25
25
|
elsif val.is_a?(Array)
|
26
26
|
classname, colname, methodname = *val
|
27
27
|
elsif val.is_a?(Hash)
|
28
|
-
classname
|
28
|
+
classname = val[:class]
|
29
|
+
colname = val[:col]
|
30
|
+
methodname = val[:method]
|
29
31
|
else
|
30
32
|
raise "Unknown argument-type: '#{arr.class.name}'."
|
31
33
|
end
|
32
|
-
|
33
|
-
methodname = classname.to_s.downcase
|
34
|
-
colname = "#{classname.to_s.downcase}_id".to_sym
|
35
|
-
|
34
|
+
|
35
|
+
methodname = classname.to_s.downcase unless methodname
|
36
|
+
colname = "#{classname.to_s.downcase}_id".to_sym unless colname
|
37
|
+
|
36
38
|
define_method(methodname) do
|
37
39
|
return @@ob.get_try(self, colname, classname)
|
38
40
|
end
|
39
|
-
|
40
|
-
methodname_html = "#{methodname
|
41
|
+
|
42
|
+
methodname_html = "#{methodname}_html".to_sym
|
41
43
|
define_method(methodname_html) do |*args|
|
42
|
-
obj =
|
43
|
-
return @@ob.events.call(:no_html, classname)
|
44
|
-
|
45
|
-
raise "Class '#{classname}' does not have a 'html'-method."
|
44
|
+
obj = send(methodname)
|
45
|
+
return @@ob.events.call(:no_html, classname) unless obj
|
46
|
+
|
47
|
+
raise "Class '#{classname}' does not have a 'html'-method." unless obj.respond_to?(:html)
|
46
48
|
return obj.html(*args)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
50
|
-
|
52
|
+
|
51
53
|
def self.events
|
52
|
-
|
54
|
+
unless @events
|
53
55
|
@events = Knj::Event_handler.new
|
54
|
-
@events.add_event(:
|
55
|
-
@events.add_event(:
|
56
|
-
@events.add_event(:
|
57
|
-
@events.add_event(:
|
56
|
+
@events.add_event(name: :add, connections_max: 1)
|
57
|
+
@events.add_event(name: :update, connections_max: 1)
|
58
|
+
@events.add_event(name: :data_from_id, connections_max: 1)
|
59
|
+
@events.add_event(name: :delete, connections_max: 1)
|
58
60
|
end
|
59
|
-
|
60
|
-
|
61
|
+
|
62
|
+
@events
|
61
63
|
end
|
62
|
-
|
64
|
+
|
63
65
|
def self.classname
|
64
|
-
|
66
|
+
name.split("::").last
|
65
67
|
end
|
66
|
-
|
68
|
+
|
67
69
|
def self.add(d)
|
68
|
-
|
70
|
+
@events.call(:add, d)
|
69
71
|
end
|
70
|
-
|
72
|
+
|
71
73
|
def self.table
|
72
|
-
|
74
|
+
name.split("::").last
|
73
75
|
end
|
74
|
-
|
76
|
+
|
75
77
|
def deleted?
|
76
|
-
return true
|
77
|
-
|
78
|
+
return true unless @data
|
79
|
+
false
|
78
80
|
end
|
79
|
-
|
81
|
+
|
80
82
|
def table
|
81
|
-
|
83
|
+
self.class.table
|
82
84
|
end
|
83
|
-
|
84
|
-
def initialize(data,
|
85
|
+
|
86
|
+
def initialize(data, _args)
|
85
87
|
if data.is_a?(Hash)
|
86
88
|
@data = Knj::ArrayExt.hash_sym(data)
|
87
|
-
@id =
|
89
|
+
@id = id
|
88
90
|
else
|
89
91
|
@id = data
|
90
|
-
|
92
|
+
reload
|
91
93
|
end
|
92
94
|
end
|
93
|
-
|
95
|
+
|
94
96
|
def reload
|
95
|
-
raise "No 'data_from_id'-event connected to class."
|
96
|
-
data = self.class.events.call(:data_from_id, Knj::Hash_methods.new(:
|
97
|
-
raise "No data was received from the event: 'data_from_id'."
|
98
|
-
raise "Data expected to be a hash but wasnt: '#{data.class.name}'."
|
97
|
+
raise "No 'data_from_id'-event connected to class." unless self.class.events.connected?(:data_from_id)
|
98
|
+
data = self.class.events.call(:data_from_id, Knj::Hash_methods.new(id: @id))
|
99
|
+
raise "No data was received from the event: 'data_from_id'." unless data
|
100
|
+
raise "Data expected to be a hash but wasnt: '#{data.class.name}'." unless data.is_a?(Hash)
|
99
101
|
@data = Knj::ArrayExt.hash_sym(data)
|
100
102
|
end
|
101
|
-
|
103
|
+
|
102
104
|
def update(data)
|
103
|
-
ret = self.class.events.call(:update, Knj::Hash_methods.new(:
|
104
|
-
|
105
|
-
|
105
|
+
ret = self.class.events.call(:update, Knj::Hash_methods.new(object: self, data: data))
|
106
|
+
reload
|
107
|
+
ret
|
106
108
|
end
|
107
|
-
|
108
|
-
#Returns a key from the hash that this object is holding or raises an error if it doesnt exist.
|
109
|
+
|
110
|
+
# Returns a key from the hash that this object is holding or raises an error if it doesnt exist.
|
109
111
|
def [](key)
|
110
|
-
raise "No data spawned on object."
|
111
|
-
raise "No such key: '#{key}'. Available keys are: '#{@data.keys.sort.join(", ")}'."
|
112
|
-
|
112
|
+
raise "No data spawned on object." unless @data
|
113
|
+
raise "No such key: '#{key}'. Available keys are: '#{@data.keys.sort.join(", ")}'." unless @data.key?(key)
|
114
|
+
@data[key]
|
113
115
|
end
|
114
|
-
|
115
|
-
#Returns the ID of the object.
|
116
|
+
|
117
|
+
# Returns the ID of the object.
|
116
118
|
def id
|
117
|
-
|
119
|
+
self[:id]
|
118
120
|
end
|
119
|
-
|
120
|
-
#Returns the name of the object, which can be taken from various data or various defined methods.
|
121
|
+
|
122
|
+
# Returns the name of the object, which can be taken from various data or various defined methods.
|
121
123
|
def name
|
122
124
|
if @data.key?(:title)
|
123
125
|
return @data[:title]
|
124
126
|
elsif @data.key?(:name)
|
125
127
|
return @data[:name]
|
126
128
|
end
|
127
|
-
|
129
|
+
|
128
130
|
obj_methods = self.class.instance_methods(false)
|
129
131
|
[:name, :title].each do |method_name|
|
130
|
-
return
|
132
|
+
return method(method_name).call if obj_methods.index(method_name)
|
131
133
|
end
|
132
|
-
|
134
|
+
|
133
135
|
raise "Couldnt figure out the title/name of the object on class #{self.class.name}."
|
134
136
|
end
|
135
|
-
|
136
|
-
|
137
|
-
|
137
|
+
|
138
|
+
alias_method :title, :name
|
139
|
+
|
138
140
|
def delete
|
139
|
-
self.class.events.call(:delete, Knj::Hash_methods.new(:
|
141
|
+
self.class.events.call(:delete, Knj::Hash_methods.new(object: self))
|
140
142
|
end
|
141
|
-
|
143
|
+
|
142
144
|
def destroy
|
143
145
|
@data = nil
|
144
146
|
end
|
145
|
-
|
147
|
+
|
146
148
|
def each(&args)
|
147
|
-
|
149
|
+
@data.each(&args)
|
148
150
|
end
|
149
|
-
|
151
|
+
|
150
152
|
def to_hash
|
151
|
-
|
153
|
+
@data.clone
|
152
154
|
end
|
153
|
-
end
|
155
|
+
end
|