azure-storage-table 1.0.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/azure/storage/table.rb +26 -26
- data/lib/azure/storage/table/auth/shared_key.rb +69 -69
- data/lib/azure/storage/table/autoload.rb +48 -48
- data/lib/azure/storage/table/batch.rb +366 -366
- data/lib/azure/storage/table/batch_response.rb +133 -133
- data/lib/azure/storage/table/default.rb +165 -165
- data/lib/azure/storage/table/edmtype.rb +134 -134
- data/lib/azure/storage/table/entity.rb +39 -39
- data/lib/azure/storage/table/guid.rb +35 -35
- data/lib/azure/storage/table/query.rb +118 -118
- data/lib/azure/storage/table/serialization.rb +116 -116
- data/lib/azure/storage/table/table_service.rb +778 -775
- data/lib/azure/storage/table/version.rb +49 -49
- metadata +10 -31
@@ -1,134 +1,134 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#-------------------------------------------------------------------------
|
4
|
-
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
-
#
|
6
|
-
# The MIT License(MIT)
|
7
|
-
|
8
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
# of this software and associated documentation files(the "Software"), to deal
|
10
|
-
# in the Software without restriction, including without limitation the rights
|
11
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
-
# copies of the Software, and to permit persons to whom the Software is
|
13
|
-
# furnished to do so, subject to the following conditions :
|
14
|
-
|
15
|
-
# The above copyright notice and this permission notice shall be included in
|
16
|
-
# all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
# THE SOFTWARE.
|
25
|
-
#--------------------------------------------------------------------------
|
26
|
-
require "time"
|
27
|
-
require "date"
|
28
|
-
|
29
|
-
module Azure::Storage
|
30
|
-
module Table
|
31
|
-
module EdmType
|
32
|
-
# Public: Get the Edm type of an object
|
33
|
-
#
|
34
|
-
# value - Object. An typed instance
|
35
|
-
#
|
36
|
-
# Returns the Edm type as a String
|
37
|
-
def self.property_type(value)
|
38
|
-
case value
|
39
|
-
when Float
|
40
|
-
"Edm.Double"
|
41
|
-
when Date, Time, DateTime
|
42
|
-
"Edm.DateTime"
|
43
|
-
when Integer
|
44
|
-
value.abs < 2**31 ? "Edm.Int32" : "Edm.Int64"
|
45
|
-
when TrueClass, FalseClass
|
46
|
-
"Edm.Boolean"
|
47
|
-
when GUID
|
48
|
-
"Edm.Guid"
|
49
|
-
when IO, File
|
50
|
-
"Edm.Binary"
|
51
|
-
when String
|
52
|
-
value.encoding.names.include?("BINARY") ? "Edm.Binary" : ""
|
53
|
-
else
|
54
|
-
value.kind_of?(IO) ? "Edm.Binary" : ""
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Public: Get the value of a property in a serialized way
|
59
|
-
#
|
60
|
-
# value - Object. An typed instance
|
61
|
-
#
|
62
|
-
# Returns the Edm type as a String
|
63
|
-
def self.serialize_value(type, value)
|
64
|
-
case type
|
65
|
-
when "Edm.Double", "Edm.Int32", "Edm.Int64", "Edm.Guid", "Edm.String", nil
|
66
|
-
value.to_s
|
67
|
-
when "Edm.Binary"
|
68
|
-
Base64.encode64(value.to_s).chomp("\n")
|
69
|
-
when "Edm.DateTime"
|
70
|
-
to_edm_time(value)
|
71
|
-
else
|
72
|
-
value.to_s
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Public: Serializes EDM value into proper value to be used in query.
|
77
|
-
#
|
78
|
-
# value - String. The value to serialize.
|
79
|
-
#
|
80
|
-
# Returns the serialized value
|
81
|
-
def self.serialize_query_value(value)
|
82
|
-
case value
|
83
|
-
when Date, Time, DateTime
|
84
|
-
"datetime'#{value.iso8601}'"
|
85
|
-
when TrueClass, FalseClass
|
86
|
-
value ? "true" : "false"
|
87
|
-
when Float, Integer
|
88
|
-
value.abs < 2**31 ? value.to_s : value.to_s + "L"
|
89
|
-
when GUID
|
90
|
-
"guid'#{value.to_s}'"
|
91
|
-
when IO, File
|
92
|
-
"X'" + value.to_s.unpack("H*").join("") + "'"
|
93
|
-
else
|
94
|
-
if value != nil && value.encoding.names.include?("BINARY")
|
95
|
-
"X'" + value.to_s.unpack("H*").join("") + "'"
|
96
|
-
else
|
97
|
-
# NULL also is treated as EdmType::STRING
|
98
|
-
value.to_s.gsub("'", "''");
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Public: Convert a serialized value into an typed object
|
104
|
-
#
|
105
|
-
# value - String. The Edm value
|
106
|
-
# type - String. The Edm datatype
|
107
|
-
#
|
108
|
-
# Returns an typed object
|
109
|
-
def self.deserialize_value(value, type)
|
110
|
-
case type
|
111
|
-
when "Edm.DateTime"
|
112
|
-
Time.parse(value)
|
113
|
-
when "Edm.Double"
|
114
|
-
Float(value)
|
115
|
-
when "Edm.Int32", "Edm.Int64"
|
116
|
-
Integer(value)
|
117
|
-
when "Edm.Boolean"
|
118
|
-
value == true || value == "true" ? true : false
|
119
|
-
when "Edm.Guid"
|
120
|
-
GUID.new(value.to_s)
|
121
|
-
when "Edm.Binary"
|
122
|
-
Base64.decode64(value.to_s).force_encoding("BINARY")
|
123
|
-
else
|
124
|
-
value == "" ? nil : value.to_s
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def self.to_edm_time(value)
|
129
|
-
date = value.is_a?(Time) ? value : Time.parse(value)
|
130
|
-
date.utc.strftime("%Y-%m-%dT%H:%M:%S.%6N0Z")
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#-------------------------------------------------------------------------
|
4
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
+
#
|
6
|
+
# The MIT License(MIT)
|
7
|
+
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files(the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions :
|
14
|
+
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#--------------------------------------------------------------------------
|
26
|
+
require "time"
|
27
|
+
require "date"
|
28
|
+
|
29
|
+
module Azure::Storage
|
30
|
+
module Table
|
31
|
+
module EdmType
|
32
|
+
# Public: Get the Edm type of an object
|
33
|
+
#
|
34
|
+
# value - Object. An typed instance
|
35
|
+
#
|
36
|
+
# Returns the Edm type as a String
|
37
|
+
def self.property_type(value)
|
38
|
+
case value
|
39
|
+
when Float
|
40
|
+
"Edm.Double"
|
41
|
+
when Date, Time, DateTime
|
42
|
+
"Edm.DateTime"
|
43
|
+
when Integer
|
44
|
+
value.abs < 2**31 ? "Edm.Int32" : "Edm.Int64"
|
45
|
+
when TrueClass, FalseClass
|
46
|
+
"Edm.Boolean"
|
47
|
+
when GUID
|
48
|
+
"Edm.Guid"
|
49
|
+
when IO, File
|
50
|
+
"Edm.Binary"
|
51
|
+
when String
|
52
|
+
value.encoding.names.include?("BINARY") ? "Edm.Binary" : ""
|
53
|
+
else
|
54
|
+
value.kind_of?(IO) ? "Edm.Binary" : ""
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Public: Get the value of a property in a serialized way
|
59
|
+
#
|
60
|
+
# value - Object. An typed instance
|
61
|
+
#
|
62
|
+
# Returns the Edm type as a String
|
63
|
+
def self.serialize_value(type, value)
|
64
|
+
case type
|
65
|
+
when "Edm.Double", "Edm.Int32", "Edm.Int64", "Edm.Guid", "Edm.String", nil
|
66
|
+
value.to_s
|
67
|
+
when "Edm.Binary"
|
68
|
+
Base64.encode64(value.to_s).chomp("\n")
|
69
|
+
when "Edm.DateTime"
|
70
|
+
to_edm_time(value)
|
71
|
+
else
|
72
|
+
value.to_s
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Public: Serializes EDM value into proper value to be used in query.
|
77
|
+
#
|
78
|
+
# value - String. The value to serialize.
|
79
|
+
#
|
80
|
+
# Returns the serialized value
|
81
|
+
def self.serialize_query_value(value)
|
82
|
+
case value
|
83
|
+
when Date, Time, DateTime
|
84
|
+
"datetime'#{value.iso8601}'"
|
85
|
+
when TrueClass, FalseClass
|
86
|
+
value ? "true" : "false"
|
87
|
+
when Float, Integer
|
88
|
+
value.abs < 2**31 ? value.to_s : value.to_s + "L"
|
89
|
+
when GUID
|
90
|
+
"guid'#{value.to_s}'"
|
91
|
+
when IO, File
|
92
|
+
"X'" + value.to_s.unpack("H*").join("") + "'"
|
93
|
+
else
|
94
|
+
if value != nil && value.encoding.names.include?("BINARY")
|
95
|
+
"X'" + value.to_s.unpack("H*").join("") + "'"
|
96
|
+
else
|
97
|
+
# NULL also is treated as EdmType::STRING
|
98
|
+
value.to_s.gsub("'", "''");
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Public: Convert a serialized value into an typed object
|
104
|
+
#
|
105
|
+
# value - String. The Edm value
|
106
|
+
# type - String. The Edm datatype
|
107
|
+
#
|
108
|
+
# Returns an typed object
|
109
|
+
def self.deserialize_value(value, type)
|
110
|
+
case type
|
111
|
+
when "Edm.DateTime"
|
112
|
+
Time.parse(value)
|
113
|
+
when "Edm.Double"
|
114
|
+
Float(value)
|
115
|
+
when "Edm.Int32", "Edm.Int64"
|
116
|
+
Integer(value)
|
117
|
+
when "Edm.Boolean"
|
118
|
+
value == true || value == "true" ? true : false
|
119
|
+
when "Edm.Guid"
|
120
|
+
GUID.new(value.to_s)
|
121
|
+
when "Edm.Binary"
|
122
|
+
Base64.decode64(value.to_s).force_encoding("BINARY")
|
123
|
+
else
|
124
|
+
value == "" ? nil : value.to_s
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.to_edm_time(value)
|
129
|
+
date = value.is_a?(Time) ? value : Time.parse(value)
|
130
|
+
date.utc.strftime("%Y-%m-%dT%H:%M:%S.%6N0Z")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#-------------------------------------------------------------------------
|
4
|
-
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
-
#
|
6
|
-
# The MIT License(MIT)
|
7
|
-
|
8
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
# of this software and associated documentation files(the "Software"), to deal
|
10
|
-
# in the Software without restriction, including without limitation the rights
|
11
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
-
# copies of the Software, and to permit persons to whom the Software is
|
13
|
-
# furnished to do so, subject to the following conditions :
|
14
|
-
|
15
|
-
# The above copyright notice and this permission notice shall be included in
|
16
|
-
# all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
# THE SOFTWARE.
|
25
|
-
#--------------------------------------------------------------------------
|
26
|
-
|
27
|
-
module Azure::Storage
|
28
|
-
module Table
|
29
|
-
class Entity
|
30
|
-
def initialize
|
31
|
-
@properties = {}
|
32
|
-
yield self if block_given?
|
33
|
-
end
|
34
|
-
|
35
|
-
attr_accessor :etag
|
36
|
-
attr_accessor :properties
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#-------------------------------------------------------------------------
|
4
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
+
#
|
6
|
+
# The MIT License(MIT)
|
7
|
+
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files(the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions :
|
14
|
+
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#--------------------------------------------------------------------------
|
26
|
+
|
27
|
+
module Azure::Storage
|
28
|
+
module Table
|
29
|
+
class Entity
|
30
|
+
def initialize
|
31
|
+
@properties = {}
|
32
|
+
yield self if block_given?
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_accessor :etag
|
36
|
+
attr_accessor :properties
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,35 +1,35 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#-------------------------------------------------------------------------
|
4
|
-
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
-
#
|
6
|
-
# The MIT License(MIT)
|
7
|
-
|
8
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
# of this software and associated documentation files(the "Software"), to deal
|
10
|
-
# in the Software without restriction, including without limitation the rights
|
11
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
-
# copies of the Software, and to permit persons to whom the Software is
|
13
|
-
# furnished to do so, subject to the following conditions :
|
14
|
-
|
15
|
-
# The above copyright notice and this permission notice shall be included in
|
16
|
-
# all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
# THE SOFTWARE.
|
25
|
-
#--------------------------------------------------------------------------
|
26
|
-
require "delegate"
|
27
|
-
|
28
|
-
module Azure::Storage
|
29
|
-
module Table
|
30
|
-
# Public: Wrapper around a string to represent a GUID
|
31
|
-
#
|
32
|
-
class GUID < SimpleDelegator
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#-------------------------------------------------------------------------
|
4
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
+
#
|
6
|
+
# The MIT License(MIT)
|
7
|
+
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files(the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions :
|
14
|
+
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#--------------------------------------------------------------------------
|
26
|
+
require "delegate"
|
27
|
+
|
28
|
+
module Azure::Storage
|
29
|
+
module Table
|
30
|
+
# Public: Wrapper around a string to represent a GUID
|
31
|
+
#
|
32
|
+
class GUID < SimpleDelegator
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,118 +1,118 @@
|
|
1
|
-
#-------------------------------------------------------------------------
|
2
|
-
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
3
|
-
#
|
4
|
-
# The MIT License(MIT)
|
5
|
-
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
# of this software and associated documentation files(the "Software"), to deal
|
8
|
-
# in the Software without restriction, including without limitation the rights
|
9
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
10
|
-
# copies of the Software, and to permit persons to whom the Software is
|
11
|
-
# furnished to do so, subject to the following conditions :
|
12
|
-
|
13
|
-
# The above copyright notice and this permission notice shall be included in
|
14
|
-
# all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
19
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
-
# THE SOFTWARE.
|
23
|
-
#--------------------------------------------------------------------------
|
24
|
-
require "azure/storage/table/table_service"
|
25
|
-
|
26
|
-
module Azure::Storage
|
27
|
-
module Table
|
28
|
-
class Query
|
29
|
-
def initialize(table = "", partition = nil, row = nil, &block)
|
30
|
-
@table = table
|
31
|
-
@partition_key = partition
|
32
|
-
@row_key = row
|
33
|
-
@fields = []
|
34
|
-
@filters = []
|
35
|
-
@top_n = nil
|
36
|
-
@table_service = Azure::Storage::Table::TableService.create_from_env
|
37
|
-
self.instance_eval(&block) if block_given?
|
38
|
-
end
|
39
|
-
|
40
|
-
attr_reader :table
|
41
|
-
attr_reader :partition_key
|
42
|
-
attr_reader :row_key
|
43
|
-
|
44
|
-
attr_reader :fields
|
45
|
-
attr_reader :filters
|
46
|
-
attr_reader :top_n
|
47
|
-
|
48
|
-
attr_reader :next_partition_key
|
49
|
-
attr_reader :next_row_key
|
50
|
-
|
51
|
-
attr_reader :table_service
|
52
|
-
|
53
|
-
def from(table_name)
|
54
|
-
@table = table_name
|
55
|
-
self
|
56
|
-
end
|
57
|
-
|
58
|
-
def partition(partition_key)
|
59
|
-
@partition_key = partition_key
|
60
|
-
self
|
61
|
-
end
|
62
|
-
|
63
|
-
def row(row_key)
|
64
|
-
@row_key = row_key
|
65
|
-
self
|
66
|
-
end
|
67
|
-
|
68
|
-
def select(*p)
|
69
|
-
@fields.concat(p)
|
70
|
-
self
|
71
|
-
end
|
72
|
-
|
73
|
-
def where(*p)
|
74
|
-
@filters.push(p)
|
75
|
-
self
|
76
|
-
end
|
77
|
-
|
78
|
-
def top(n)
|
79
|
-
@top_n = n
|
80
|
-
self
|
81
|
-
end
|
82
|
-
|
83
|
-
def next_partition(next_partition_key)
|
84
|
-
@next_partition_key = next_partition_key
|
85
|
-
self
|
86
|
-
end
|
87
|
-
|
88
|
-
def next_row(next_row_key)
|
89
|
-
@next_row_key = next_row_key
|
90
|
-
self
|
91
|
-
end
|
92
|
-
|
93
|
-
def execute
|
94
|
-
@table_service.query_entities(@table, partition_key: @partition_key,
|
95
|
-
row_key: @row_key,
|
96
|
-
select: @fields.map { |f| f.to_s },
|
97
|
-
filter: _build_filter_string,
|
98
|
-
top: (@top_n ? @top_n.to_i : @top_n),
|
99
|
-
continuation_token: {
|
100
|
-
next_partition_key: @next_partition_key,
|
101
|
-
next_row_key: @next_row_key
|
102
|
-
})
|
103
|
-
end
|
104
|
-
|
105
|
-
def _build_filter_string
|
106
|
-
result = ""
|
107
|
-
clauses = []
|
108
|
-
filters.each { |f|
|
109
|
-
clauses.push "#{f[0]} #{f[1]} #{Azure::Storage::Table::EdmType.serialize_query_value(f[2])}"
|
110
|
-
}
|
111
|
-
return nil if clauses.length == 0
|
112
|
-
|
113
|
-
result << clauses.join(" and ")
|
114
|
-
result
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
1
|
+
#-------------------------------------------------------------------------
|
2
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
3
|
+
#
|
4
|
+
# The MIT License(MIT)
|
5
|
+
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files(the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions :
|
12
|
+
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
# THE SOFTWARE.
|
23
|
+
#--------------------------------------------------------------------------
|
24
|
+
require "azure/storage/table/table_service"
|
25
|
+
|
26
|
+
module Azure::Storage
|
27
|
+
module Table
|
28
|
+
class Query
|
29
|
+
def initialize(table = "", partition = nil, row = nil, &block)
|
30
|
+
@table = table
|
31
|
+
@partition_key = partition
|
32
|
+
@row_key = row
|
33
|
+
@fields = []
|
34
|
+
@filters = []
|
35
|
+
@top_n = nil
|
36
|
+
@table_service = Azure::Storage::Table::TableService.create_from_env
|
37
|
+
self.instance_eval(&block) if block_given?
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_reader :table
|
41
|
+
attr_reader :partition_key
|
42
|
+
attr_reader :row_key
|
43
|
+
|
44
|
+
attr_reader :fields
|
45
|
+
attr_reader :filters
|
46
|
+
attr_reader :top_n
|
47
|
+
|
48
|
+
attr_reader :next_partition_key
|
49
|
+
attr_reader :next_row_key
|
50
|
+
|
51
|
+
attr_reader :table_service
|
52
|
+
|
53
|
+
def from(table_name)
|
54
|
+
@table = table_name
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def partition(partition_key)
|
59
|
+
@partition_key = partition_key
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
def row(row_key)
|
64
|
+
@row_key = row_key
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
def select(*p)
|
69
|
+
@fields.concat(p)
|
70
|
+
self
|
71
|
+
end
|
72
|
+
|
73
|
+
def where(*p)
|
74
|
+
@filters.push(p)
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
def top(n)
|
79
|
+
@top_n = n
|
80
|
+
self
|
81
|
+
end
|
82
|
+
|
83
|
+
def next_partition(next_partition_key)
|
84
|
+
@next_partition_key = next_partition_key
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def next_row(next_row_key)
|
89
|
+
@next_row_key = next_row_key
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
def execute
|
94
|
+
@table_service.query_entities(@table, partition_key: @partition_key,
|
95
|
+
row_key: @row_key,
|
96
|
+
select: @fields.map { |f| f.to_s },
|
97
|
+
filter: _build_filter_string,
|
98
|
+
top: (@top_n ? @top_n.to_i : @top_n),
|
99
|
+
continuation_token: {
|
100
|
+
next_partition_key: @next_partition_key,
|
101
|
+
next_row_key: @next_row_key
|
102
|
+
})
|
103
|
+
end
|
104
|
+
|
105
|
+
def _build_filter_string
|
106
|
+
result = ""
|
107
|
+
clauses = []
|
108
|
+
filters.each { |f|
|
109
|
+
clauses.push "#{f[0]} #{f[1]} #{Azure::Storage::Table::EdmType.serialize_query_value(f[2])}"
|
110
|
+
}
|
111
|
+
return nil if clauses.length == 0
|
112
|
+
|
113
|
+
result << clauses.join(" and ")
|
114
|
+
result
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|