jylis-rb 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +221 -0
  3. data/doc/Jylis.html +1087 -6
  4. data/doc/Jylis/Connection.html +1128 -0
  5. data/doc/Jylis/Connection/HostMissingError.html +135 -0
  6. data/doc/Jylis/Connection/UnsupportedSchemaError.html +135 -0
  7. data/doc/Jylis/DataType.html +135 -0
  8. data/doc/Jylis/DataType/Base.html +346 -0
  9. data/doc/Jylis/DataType/GCOUNT.html +331 -0
  10. data/doc/Jylis/DataType/GCOUNT/Result.html +132 -0
  11. data/doc/Jylis/DataType/MVREG.html +318 -0
  12. data/doc/Jylis/DataType/PNCOUNT.html +404 -0
  13. data/doc/Jylis/DataType/TLOG.html +750 -0
  14. data/doc/Jylis/DataType/TLOG/Result.html +640 -0
  15. data/doc/Jylis/DataType/TLOG/Row.html +616 -0
  16. data/doc/Jylis/DataType/TREG.html +345 -0
  17. data/doc/Jylis/DataType/TREG/Result.html +616 -0
  18. data/doc/Jylis/DataType/UJSON.html +549 -0
  19. data/doc/_index.html +185 -4
  20. data/doc/class_list.html +1 -1
  21. data/doc/file.README.html +223 -3
  22. data/doc/file.license.html +3 -3
  23. data/doc/frames.html +1 -1
  24. data/doc/index.html +223 -3
  25. data/doc/method_list.html +512 -0
  26. data/doc/top-level-namespace.html +3 -3
  27. data/lib/jylis-rb.rb +9 -0
  28. data/lib/jylis-rb/connection.rb +121 -0
  29. data/lib/jylis-rb/data_types/base.rb +24 -0
  30. data/lib/jylis-rb/data_types/gcount.rb +24 -0
  31. data/lib/jylis-rb/data_types/mvreg.rb +23 -0
  32. data/lib/jylis-rb/data_types/pncount.rb +33 -0
  33. data/lib/jylis-rb/data_types/tlog.rb +157 -0
  34. data/lib/jylis-rb/data_types/treg.rb +57 -0
  35. data/lib/jylis-rb/data_types/ujson.rb +87 -0
  36. data/lib/jylis-rb/jylis.rb +106 -0
  37. data/lib/jylis-rb/version.rb +1 -1
  38. metadata +39 -2
@@ -0,0 +1,87 @@
1
+ require "oj"
2
+
3
+ Oj.default_options = {mode: :compat}
4
+
5
+ class Jylis
6
+ module DataType
7
+ # Unordered JSON.
8
+ #
9
+ # @see https://jemc.github.io/jylis/docs/types/ujson/
10
+ class UJSON < Base
11
+ # Get the JSON representation of the data currently held at `key`.
12
+ def get(*keys)
13
+ unless keys.count >= 1
14
+ raise ArgumentError.new("Must provide at least one key")
15
+ end
16
+
17
+ params = ["UJSON", "GET"] + keys
18
+
19
+ result = connection.query(*params)
20
+
21
+ result == "" ? result : Oj.load(result)
22
+ end
23
+
24
+ # Store the given `ujson` data at the given `key`.
25
+ #
26
+ # @overload set(*keys, value)
27
+ def set(*args)
28
+ key_value_query(__method__, *args)
29
+ end
30
+
31
+ # Remove all data stored at or under the given `key`.
32
+ def clr(*keys)
33
+ unless keys.count >= 1
34
+ raise ArgumentError.new("Must provide at least one key")
35
+ end
36
+
37
+ params = ["UJSON", "CLR"] + keys
38
+
39
+ result = connection.query(*params)
40
+
41
+ unless result == "OK"
42
+ raise "Failed: UJSON CLR #{params.join(' ')}"
43
+ end
44
+ end
45
+
46
+ # Insert the given `value` as a new element in the set of values stored
47
+ # at `key`.
48
+ #
49
+ # @overload ins(*keys, value)
50
+ def ins(*args)
51
+ key_value_query(__method__, *args)
52
+ end
53
+
54
+ # Remove the specified `value` from the set of values stored at `key`.
55
+ #
56
+ # @overload rm(*keys, value)
57
+ def rm(*args)
58
+ key_value_query(__method__, *args)
59
+ end
60
+
61
+ private
62
+
63
+ # Execute a query consisting of (*keys, value) that returns "OK" on success.
64
+ #
65
+ # @param function [String, Symbol] the Jylis function name
66
+ # @param args [Array] the list of keys, with the value last
67
+ def key_value_query(function, *args)
68
+ unless args.count >= 2
69
+ raise ArgumentError.new("Must provide at least one key and the value")
70
+ end
71
+
72
+ function = function.to_s.upcase
73
+ value = args.pop
74
+ keys = args
75
+
76
+ params = ["UJSON", function] + keys
77
+ params.push Oj.dump(value)
78
+
79
+ result = connection.query(*params)
80
+
81
+ unless result == "OK"
82
+ raise "Failed: UJSON #{function} #{params.join(' ')}"
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -1,5 +1,111 @@
1
1
  require_relative "version" # Version reopens this class.
2
+ require_relative "connection"
2
3
 
3
4
  # Jylis database adapter.
4
5
  class Jylis
6
+ private_class_method :new
7
+
8
+ class << self
9
+ # The current connection.
10
+ attr_accessor :current
11
+
12
+ # Connect to a server and store the current connection.
13
+ #
14
+ # @param server_uri [URI, String] uri of the server to connect to
15
+ #
16
+ # @return [Jylis::Connection] connection
17
+ def connect(server_uri)
18
+ disconnect if current && current.connected?
19
+
20
+ self.current = Jylis::Connection.new(server_uri)
21
+ end
22
+
23
+ # @return [Boolean] true if a connection to the current server is established
24
+ # @see Jylis::Connection#connected?
25
+ def connected?
26
+ current.connected?
27
+ end
28
+
29
+ # Reconnect to the current server.
30
+ # @see Jylis::Connection#reconnect
31
+ def reconnect
32
+ current.reconnect
33
+ end
34
+
35
+ # Disconnect from the current server.
36
+ # @see Jylis::Connection#disconnect
37
+ def disconnect
38
+ current.disconnect
39
+ end
40
+
41
+ # Make a query to the database.
42
+ #
43
+ # @param args data type function args. Can be an args list or array.
44
+ #
45
+ # @return [Array] query response
46
+ #
47
+ # @see Jylis::Connection#query
48
+ # @see https://jemc.github.io/jylis/docs/types/
49
+ def query(*args)
50
+ current.query(*args)
51
+ end
52
+
53
+ # @!group Data Types
54
+
55
+ # TREG functions
56
+ #
57
+ # @return [Jylis::DataType::TREG]
58
+ #
59
+ # @see Jylis::Connection#treg
60
+ def treg
61
+ current.treg
62
+ end
63
+
64
+ # TLOG functions
65
+ #
66
+ # @return [Jylis::DataType::TLOG]
67
+ #
68
+ # @see Jylis::Connection#tlog
69
+ def tlog
70
+ current.tlog
71
+ end
72
+
73
+ # GCOUNT functions
74
+ #
75
+ # @return [Jylis::DataType::GCOUNT]
76
+ #
77
+ # @see Jylis::Connection#gcount
78
+ def gcount
79
+ current.gcount
80
+ end
81
+
82
+ # PNCOUNT functions
83
+ #
84
+ # @return [Jylis::DataType::PNCOUNT]
85
+ #
86
+ # @see Jylis::Connection#pncount
87
+ def pncount
88
+ current.pncount
89
+ end
90
+
91
+ # MVREG functions
92
+ #
93
+ # @return [Jylis::DataType::MVREG]
94
+ #
95
+ # @see Jylis::Connection#mvreg
96
+ def mvreg
97
+ current.mvreg
98
+ end
99
+
100
+ # UJSON functions
101
+ #
102
+ # @return [Jylis::DataType::UJSON]
103
+ #
104
+ # @see Jylis::Connection#ujson
105
+ def ujson
106
+ current.ujson
107
+ end
108
+
109
+ # @!endgroup
110
+ end
5
111
  end
@@ -1,4 +1,4 @@
1
1
  class Jylis
2
2
  # Gem version.
3
- VERSION = "0.0.1".freeze
3
+ VERSION = "0.1.0".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jylis-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex McLain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-02 00:00:00.000000000 Z
11
+ date: 2018-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hiredis
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.6.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.6'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +137,21 @@ extra_rdoc_files: []
123
137
  files:
124
138
  - README.md
125
139
  - doc/Jylis.html
140
+ - doc/Jylis/Connection.html
141
+ - doc/Jylis/Connection/HostMissingError.html
142
+ - doc/Jylis/Connection/UnsupportedSchemaError.html
143
+ - doc/Jylis/DataType.html
144
+ - doc/Jylis/DataType/Base.html
145
+ - doc/Jylis/DataType/GCOUNT.html
146
+ - doc/Jylis/DataType/GCOUNT/Result.html
147
+ - doc/Jylis/DataType/MVREG.html
148
+ - doc/Jylis/DataType/PNCOUNT.html
149
+ - doc/Jylis/DataType/TLOG.html
150
+ - doc/Jylis/DataType/TLOG/Result.html
151
+ - doc/Jylis/DataType/TLOG/Row.html
152
+ - doc/Jylis/DataType/TREG.html
153
+ - doc/Jylis/DataType/TREG/Result.html
154
+ - doc/Jylis/DataType/UJSON.html
126
155
  - doc/_index.html
127
156
  - doc/class_list.html
128
157
  - doc/css/common.css
@@ -139,6 +168,14 @@ files:
139
168
  - doc/method_list.html
140
169
  - doc/top-level-namespace.html
141
170
  - lib/jylis-rb.rb
171
+ - lib/jylis-rb/connection.rb
172
+ - lib/jylis-rb/data_types/base.rb
173
+ - lib/jylis-rb/data_types/gcount.rb
174
+ - lib/jylis-rb/data_types/mvreg.rb
175
+ - lib/jylis-rb/data_types/pncount.rb
176
+ - lib/jylis-rb/data_types/tlog.rb
177
+ - lib/jylis-rb/data_types/treg.rb
178
+ - lib/jylis-rb/data_types/ujson.rb
142
179
  - lib/jylis-rb/jylis.rb
143
180
  - lib/jylis-rb/version.rb
144
181
  - license.txt