td-client 0.8.13 → 0.8.14
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +6 -0
- data/lib/td/client.rb +9 -9
- data/lib/td/client/api.rb +12 -3
- data/lib/td/client/model.rb +25 -2
- data/lib/td/client/version.rb +1 -1
- metadata +7 -7
data/ChangeLog
CHANGED
data/lib/td/client.rb
CHANGED
@@ -43,18 +43,18 @@ class Client
|
|
43
43
|
|
44
44
|
# => [Database]
|
45
45
|
def databases
|
46
|
-
|
47
|
-
|
48
|
-
Database.new(self, db_name)
|
46
|
+
m = @api.list_databases
|
47
|
+
m.map {|db_name,(count,created_at,updated_at)|
|
48
|
+
Database.new(self, db_name, nil, count, created_at, updated_at)
|
49
49
|
}
|
50
50
|
end
|
51
51
|
|
52
52
|
# => Database
|
53
53
|
def database(db_name)
|
54
|
-
|
55
|
-
|
56
|
-
if
|
57
|
-
return Database.new(self,
|
54
|
+
m = @api.list_databases
|
55
|
+
m.each {|name,(count,created_at,updated_at)|
|
56
|
+
if name == db_name
|
57
|
+
return Database.new(self, name, nil, count, created_at, updated_at)
|
58
58
|
end
|
59
59
|
}
|
60
60
|
raise NotFoundError, "Database '#{db_name}' does not exist"
|
@@ -83,9 +83,9 @@ class Client
|
|
83
83
|
# => [Table]
|
84
84
|
def tables(db_name)
|
85
85
|
m = @api.list_tables(db_name)
|
86
|
-
m.map {|table_name,(type,schema,count)|
|
86
|
+
m.map {|table_name,(type,schema,count,created_at,updated_at)|
|
87
87
|
schema = Schema.new.from_json(schema)
|
88
|
-
Table.new(self, db_name, table_name, type, schema, count)
|
88
|
+
Table.new(self, db_name, table_name, type, schema, count, created_at, updated_at)
|
89
89
|
}
|
90
90
|
end
|
91
91
|
|
data/lib/td/client/api.rb
CHANGED
@@ -140,8 +140,15 @@ class API
|
|
140
140
|
raise_error("List databases failed", res)
|
141
141
|
end
|
142
142
|
js = checked_json(body, %w[databases])
|
143
|
-
|
144
|
-
|
143
|
+
result = {}
|
144
|
+
js["databases"].each {|m|
|
145
|
+
name = m['name']
|
146
|
+
count = m['count']
|
147
|
+
created_at = m['created_at']
|
148
|
+
updated_at = m['updated_at']
|
149
|
+
result[name] = [count, created_at, updated_at]
|
150
|
+
}
|
151
|
+
return result
|
145
152
|
end
|
146
153
|
|
147
154
|
# => true
|
@@ -179,8 +186,10 @@ class API
|
|
179
186
|
name = m['name']
|
180
187
|
type = (m['type'] || '?').to_sym
|
181
188
|
count = (m['count'] || 0).to_i # TODO?
|
189
|
+
created_at = m['created_at']
|
190
|
+
updated_at = m['updated_at']
|
182
191
|
schema = JSON.parse(m['schema'] || '[]')
|
183
|
-
result[name] = [type, schema, count]
|
192
|
+
result[name] = [type, schema, count, created_at, updated_at]
|
184
193
|
}
|
185
194
|
return result
|
186
195
|
end
|
data/lib/td/client/model.rb
CHANGED
@@ -11,10 +11,13 @@ class Model
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Database < Model
|
14
|
-
def initialize(client, db_name, tables=nil)
|
14
|
+
def initialize(client, db_name, tables=nil, count=nil, created_at=nil, updated_at=nil)
|
15
15
|
super(client)
|
16
16
|
@db_name = db_name
|
17
17
|
@tables = tables
|
18
|
+
@count = count
|
19
|
+
@created_at = created_at
|
20
|
+
@updated_at = updated_at
|
18
21
|
end
|
19
22
|
|
20
23
|
def name
|
@@ -46,19 +49,31 @@ class Database < Model
|
|
46
49
|
@client.query(@db_name, q)
|
47
50
|
end
|
48
51
|
|
52
|
+
attr_reader :count
|
53
|
+
|
54
|
+
def created_at
|
55
|
+
@created_at && !@created_at.empty? ? Time.parse(@created_at) : nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def updated_at
|
59
|
+
@updated_at && !@updated_at.empty? ? Time.parse(@updated_at) : nil
|
60
|
+
end
|
61
|
+
|
49
62
|
def update_tables!
|
50
63
|
@tables = @client.tables(@db_name)
|
51
64
|
end
|
52
65
|
end
|
53
66
|
|
54
67
|
class Table < Model
|
55
|
-
def initialize(client, db_name, table_name, type, schema, count)
|
68
|
+
def initialize(client, db_name, table_name, type, schema, count, created_at=nil, updated_at=nil)
|
56
69
|
super(client)
|
57
70
|
@db_name = db_name
|
58
71
|
@table_name = table_name
|
59
72
|
@type = type
|
60
73
|
@schema = schema
|
61
74
|
@count = count
|
75
|
+
@created_at = created_at
|
76
|
+
@updated_at = updated_at
|
62
77
|
end
|
63
78
|
|
64
79
|
attr_reader :type, :db_name, :table_name, :schema, :count
|
@@ -66,6 +81,14 @@ class Table < Model
|
|
66
81
|
alias database_name db_name
|
67
82
|
alias name table_name
|
68
83
|
|
84
|
+
def created_at
|
85
|
+
@created_at && !@created_at.empty? ? Time.parse(@created_at) : nil
|
86
|
+
end
|
87
|
+
|
88
|
+
def updated_at
|
89
|
+
@updated_at && !@updated_at.empty? ? Time.parse(@updated_at) : nil
|
90
|
+
end
|
91
|
+
|
69
92
|
def database
|
70
93
|
@client.database(@db_name)
|
71
94
|
end
|
data/lib/td/client/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-03 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70097319678140 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70097319678140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70097319677440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.4.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70097319677440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70097319676680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 2.8.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70097319676680
|
47
47
|
description:
|
48
48
|
email:
|
49
49
|
executables: []
|