surrealdb 0.6.0 → 0.7.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/LICENSE +190 -0
  4. data/README.md +308 -58
  5. data/lib/surrealdb/cbor/decoder.rb +127 -0
  6. data/lib/surrealdb/cbor/encoder.rb +84 -0
  7. data/lib/surrealdb/cbor/tags.rb +30 -0
  8. data/lib/surrealdb/client.rb +386 -0
  9. data/lib/surrealdb/configuration.rb +16 -0
  10. data/lib/surrealdb/connections/base.rb +52 -0
  11. data/lib/surrealdb/connections/embedded.rb +182 -0
  12. data/lib/surrealdb/connections/http.rb +128 -0
  13. data/lib/surrealdb/connections/reliable_websocket.rb +154 -0
  14. data/lib/surrealdb/connections/websocket.rb +309 -0
  15. data/lib/surrealdb/embedded.rb +21 -0
  16. data/lib/surrealdb/errors.rb +100 -0
  17. data/lib/surrealdb/models/duration.rb +103 -0
  18. data/lib/surrealdb/models/geometry.rb +151 -0
  19. data/lib/surrealdb/models/none.rb +36 -0
  20. data/lib/surrealdb/models/range.rb +73 -0
  21. data/lib/surrealdb/models/record_id.rb +93 -0
  22. data/lib/surrealdb/models/table.rb +34 -0
  23. data/lib/surrealdb/native/ffi.rb +50 -0
  24. data/lib/surrealdb/native/platform.rb +65 -0
  25. data/lib/surrealdb/protocol/methods.rb +38 -0
  26. data/lib/surrealdb/protocol/response.rb +44 -0
  27. data/lib/surrealdb/protocol/rpc.rb +46 -0
  28. data/lib/surrealdb/query_result.rb +55 -0
  29. data/lib/surrealdb/version.rb +4 -2
  30. data/lib/surrealdb.rb +57 -5
  31. metadata +76 -34
  32. data/.editorconfig +0 -19
  33. data/.gitignore +0 -67
  34. data/.rspec +0 -3
  35. data/.travis.yml +0 -6
  36. data/CODE_OF_CONDUCT.md +0 -74
  37. data/Gemfile +0 -11
  38. data/Gemfile.lock +0 -45
  39. data/Rakefile +0 -6
  40. data/bin/console +0 -14
  41. data/bin/setup +0 -8
  42. data/lib/surrealdb/clients/http.rb +0 -156
  43. data/lib/surrealdb/common/surreal_error.rb +0 -15
  44. data/lib/surrealdb/models/http_response.rb +0 -29
  45. data/surrealdb.gemspec +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a087a8822b9e2778168c1636c38cd40d7a5c7af873d251f8faa99cc257996119
4
- data.tar.gz: 6f5f0112cd1e81edd57281f3cd664bfd10efaa0da71c3da31eb1e686ae722f16
3
+ metadata.gz: 0a5975be9d7fe6a527781f77b2d20e0a7d05eb255527977910e81e92d53d82cd
4
+ data.tar.gz: ca498dcf067c797cd43c5f7ad4f9d6e2b7e710bdea9074cc630b02e016d69011
5
5
  SHA512:
6
- metadata.gz: a989d16f06c616ef9f04797624e47e703e92cd6628d78106329445cb61cdea718bab16e3726e0dfc690f3da3c8bdf07d399e720f4c279dcc39e795698e97c0e5
7
- data.tar.gz: fd3287ff01f7b9b9e7d6b451195576c1f3b8f495eb0f15c31f288b10d0e595e7666260aae78380af9affb5ebbb183d73d900f032d0259daacb11bfc3daee38e8
6
+ metadata.gz: 521b1b6bfb4c1ea15e1dbe6d4c5c942f6b727055a0bf406ec9d222583fd77392ef2646c6299b730e3b5f291bcd445ede5db236a58d31707872419d1fbf0b52aa
7
+ data.tar.gz: 4cea41371a39cc17e0b1738df649e16235924d20b0b2fb5e39ddf7e7e35a512b3b1820535f232e6d6c38ab83b21031364a1437aa3dffecd8972b01e4b596abbd
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.7.0] - 2026-04-01
6
+
7
+ ### Added
8
+
9
+ - Initial SDK implementation with WebSocket and HTTP transports
10
+ - CBOR serialization with custom SurrealDB type tags
11
+ - Full CRUD operations (create, select, insert, update, upsert, merge, patch, delete)
12
+ - Raw SurrealQL query support with parameterized variables
13
+ - Authentication (signin, signup, authenticate, invalidate)
14
+ - Live query support over WebSocket
15
+ - SurrealDB types: RecordID, Table, Duration, None, Range, Geometry
16
+ - Structured error hierarchy matching SurrealDB server errors
data/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024 SurrealDB Ltd.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
data/README.md CHANGED
@@ -1,109 +1,359 @@
1
- # SurrealDB
2
- Ruby driver for SurrealDB databases.
1
+ # surrealdb.rb
2
+
3
+ The official SurrealDB SDK for Ruby.
4
+
5
+ [![CI](https://github.com/surrealdb/surrealdb.rb/actions/workflows/ci.yml/badge.svg)](https://github.com/surrealdb/surrealdb.rb/actions/workflows/ci.yml)
6
+ [![Gem Version](https://badge.fury.io/rb/surrealdb.svg)](https://badge.fury.io/rb/surrealdb)
7
+ [![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)
3
8
 
4
9
  ## Installation
5
10
 
6
- Add this line to your application's Gemfile:
11
+ ```bash
12
+ gem install surrealdb
13
+ ```
14
+
15
+ Or add to your Gemfile:
7
16
 
8
17
  ```ruby
9
- gem 'surrealdb'
18
+ gem "surrealdb"
10
19
  ```
11
20
 
12
- And then execute:
21
+ ## Quick Start
13
22
 
14
- $ bundle install
23
+ ```ruby
24
+ require "surrealdb"
15
25
 
16
- Or install it yourself as:
26
+ SurrealDB.connect("ws://localhost:8000") do |db|
27
+ db.signin("user" => "root", "pass" => "root")
28
+ db.use("test", "test")
17
29
 
18
- $ gem install surrealdb
30
+ # Create
31
+ db.create("person", { "name" => "Alice", "age" => 30 })
19
32
 
20
- ## Usage
33
+ # Select
34
+ people = db.select("person")
35
+
36
+ # Query
37
+ results = db.query("SELECT * FROM person WHERE age > $min", { "min" => 25 })
38
+
39
+ # Update
40
+ db.merge("person:alice", { "email" => "alice@example.com" })
41
+
42
+ # Delete
43
+ db.delete("person:alice")
44
+ end
45
+ ```
21
46
 
22
- Included with this module are two Classes, `SurrealDB::HTTPClient` and `SurrealDB::SurrealError`, where `SurrealError` is raised for any errors that occur during the HTTP request.
47
+ ## Connection Types
48
+
49
+ The SDK supports three transport protocols, selected automatically by URL scheme:
50
+
51
+ | Scheme | Transport | Live Queries | Sessions | Requires |
52
+ |--------|-----------|:------------:|:--------:|----------|
53
+ | `ws://`, `wss://` | WebSocket | Yes | Yes | -- |
54
+ | `http://`, `https://` | HTTP | No | No | -- |
55
+ | `mem://`, `surrealkv://`, `file://` | Embedded | Yes | Yes | `surrealdb-embedded` gem |
23
56
 
24
- ### HTTPClient
25
- Create a client with the following code:
26
57
  ```ruby
27
- require "surrealdb"
58
+ # WebSocket (recommended for most use cases)
59
+ client = SurrealDB::Client.new("ws://localhost:8000")
60
+
61
+ # HTTP (stateless, simpler)
62
+ client = SurrealDB::Client.new("http://localhost:8000")
63
+
64
+ # Embedded (in-process, no server needed)
65
+ require "surrealdb/embedded"
66
+ client = SurrealDB::Client.new("mem://")
67
+ ```
68
+
69
+ ## Authentication
70
+
71
+ ```ruby
72
+ SurrealDB.connect("ws://localhost:8000") do |db|
73
+ # Root authentication
74
+ db.signin("user" => "root", "pass" => "root")
75
+
76
+ # Namespace authentication
77
+ db.signin("user" => "ns_user", "pass" => "ns_pass", "ns" => "my_namespace")
28
78
 
29
- SurrealDB::HTTPClient.new(
30
- "http://localhost:8000/",
31
- namespace: "test",
32
- database: "test",
33
- username: "root",
34
- password: "root"
35
- ) do |client|
36
- ...
79
+ # Database authentication
80
+ db.signin("user" => "db_user", "pass" => "db_pass", "ns" => "my_namespace", "db" => "my_database")
81
+
82
+ # Record user authentication
83
+ token = db.signup(
84
+ "ns" => "my_namespace",
85
+ "db" => "my_database",
86
+ "ac" => "user_access",
87
+ "username" => "alice",
88
+ "password" => "password123"
89
+ )
90
+
91
+ # Token authentication
92
+ db.authenticate(token)
93
+
94
+ # Invalidate session
95
+ db.invalidate
37
96
  end
38
97
  ```
39
98
 
40
- > The following examples assume that the client is created as above.
99
+ ## CRUD Operations
100
+
101
+ ```ruby
102
+ SurrealDB.connect("ws://localhost:8000") do |db|
103
+ db.signin("user" => "root", "pass" => "root")
104
+ db.use("test", "test")
105
+
106
+ # Create a record (auto-generated ID)
107
+ person = db.create("person", { "name" => "Alice", "age" => 30 })
108
+
109
+ # Create with specific ID
110
+ db.create("person:bob", { "name" => "Bob", "age" => 25 })
111
+
112
+ # Select all records from a table
113
+ people = db.select("person")
114
+
115
+ # Select a specific record
116
+ alice = db.select("person:alice")
117
+
118
+ # Insert multiple records
119
+ db.insert("person", [
120
+ { "name" => "Charlie", "age" => 35 },
121
+ { "name" => "Diana", "age" => 28 }
122
+ ])
41
123
 
42
- #### `execute`
43
- Execute a query. It takes a string as the table name to select from, and returns `Array<Hash>`.
124
+ # Update (full replace)
125
+ db.update("person:bob", { "name" => "Bob", "age" => 26, "email" => "bob@example.com" })
126
+
127
+ # Upsert (insert or update)
128
+ db.upsert("person:eve", { "name" => "Eve", "age" => 22 })
129
+
130
+ # Merge (partial update)
131
+ db.merge("person:bob", { "email" => "bob@newmail.com" })
132
+
133
+ # Patch (JSON Patch)
134
+ db.patch("person:bob", [
135
+ { "op" => "replace", "path" => "/age", "value" => 27 }
136
+ ])
137
+
138
+ # Delete a record
139
+ db.delete("person:bob")
140
+
141
+ # Delete all records from a table
142
+ db.delete("person")
143
+
144
+ # Create a relation
145
+ db.relate("person:alice", "knows", "person:bob", { "since" => 2024 })
146
+ end
147
+ ```
148
+
149
+ ## Queries
44
150
 
45
151
  ```ruby
46
- client.execute("SELECT * FROM test")
47
- # => [{"id"=>1, "name"=>"test"}]
152
+ SurrealDB.connect("ws://localhost:8000") do |db|
153
+ db.signin("user" => "root", "pass" => "root")
154
+ db.use("test", "test")
155
+
156
+ # Simple query
157
+ results = db.query("SELECT * FROM person")
48
158
 
49
- client.execute("DELETE test:1")
50
- # => []
159
+ # Parameterized query
160
+ results = db.query(
161
+ "SELECT * FROM person WHERE age > $min_age AND name = $name",
162
+ { "min_age" => 25, "name" => "Alice" }
163
+ )
164
+
165
+ # Multi-statement query
166
+ results = db.query(<<~SQL)
167
+ CREATE person:alice SET name = 'Alice', age = 30;
168
+ CREATE person:bob SET name = 'Bob', age = 25;
169
+ SELECT * FROM person;
170
+ SQL
171
+
172
+ # Connection-scoped variables
173
+ db.set("current_user", "alice")
174
+ results = db.query("SELECT * FROM person WHERE name = $current_user")
175
+ db.unset("current_user")
176
+
177
+ # Run a SurrealDB function
178
+ result = db.run("fn::my_function", "arg1", "arg2")
179
+ end
51
180
  ```
52
181
 
53
- #### `select_all`
54
- Retrieve all of the data from a table. Takes a string as the table name to select from. Returns `Array<Hash>`.
182
+ ## Structured Query Results
183
+
184
+ Use `query_raw` to get per-statement metadata (status, timing, errors) for multi-statement queries:
55
185
 
56
186
  ```ruby
57
- client.select_all("test")
58
- # => [{"id"=>1, "name"=>"test"}]
187
+ results = db.query_raw("CREATE person:a SET name = 'Alice'; SELECT * FROM missing_table;")
188
+ results.each do |qr|
189
+ if qr.ok?
190
+ puts "#{qr.time}: #{qr.result}"
191
+ else
192
+ puts "Error: #{qr.error}"
193
+ end
194
+ end
59
195
  ```
60
196
 
61
- #### `select_one`
62
- Retrieve one record from a table. Takes a string as as the table name to select from, and an id of any type. Returns `Hash`.
197
+ ## Embedded Database
198
+
199
+ For in-process usage without a separate server, install the embedded gem:
200
+
201
+ ```bash
202
+ gem install surrealdb-embedded
203
+ ```
204
+
205
+ Then opt in with an extra require:
206
+
63
207
  ```ruby
64
- client.select_one("test", 1)
65
- # => {"id"=>1, "name"=>"test"}
208
+ require "surrealdb"
209
+ require "surrealdb/embedded"
210
+
211
+ SurrealDB.connect("mem://") do |db|
212
+ db.use("test", "test")
213
+ db.create("person", { "name" => "Alice" })
214
+ end
66
215
  ```
67
216
 
68
- #### `replace_one`
69
- Replace a record in a table. Takes a string as the table name the record exists in, an id of any type, and a `Hash` of values to replace. Returns `Hash`.
217
+ Supported schemes: `mem://` (in-memory), `surrealkv://path` (persistent), `file://path` (file-based).
218
+
219
+ Requires `libsurrealdb_c` installed on the system or pointed to via `SURREALDB_LIB_PATH`.
220
+
221
+ ## Automatic Reconnection
222
+
223
+ Enable automatic WebSocket reconnection with exponential backoff:
224
+
70
225
  ```ruby
71
- client.replace_one("test", 1, {name: "test2", title: "test"})
72
- # => {"id"=>1, "name"=>"test2", "title"=>"test"}
226
+ client = SurrealDB::Client.new("ws://localhost:8000",
227
+ reconnect: true,
228
+ reconnect_max_retries: 5,
229
+ reconnect_delay: 1.0
230
+ )
231
+ client.connect
232
+ client.signin("user" => "root", "pass" => "root")
233
+ client.use("test", "test")
234
+
235
+ # If the connection drops, the SDK will automatically reconnect,
236
+ # replay use/signin/let state, and retry the failed request.
237
+ client.query("SELECT * FROM person")
73
238
  ```
74
239
 
75
- #### `upsert_one`
76
- Update values of a record in a table. Takes a string as the table name to update a record in, an id of any type, and a `Hash` of values to replace. Returns `Hash`.
240
+ ## Live Queries
241
+
242
+ Live queries are supported over WebSocket and embedded connections.
243
+
77
244
  ```ruby
78
- client.upsert_one("test", 1, {name: "test4"})
79
- # => {"id"=>1, "name"=>"test4", "title"=>"test"}
245
+ SurrealDB.connect("ws://localhost:8000") do |db|
246
+ db.signin("user" => "root", "pass" => "root")
247
+ db.use("test", "test")
248
+
249
+ # Start a live query
250
+ live_id = db.live("person")
251
+
252
+ # Subscribe to notifications
253
+ db.subscribe(live_id) do |notification|
254
+ puts "Action: #{notification['action']}"
255
+ puts "Result: #{notification['result']}"
256
+ end
257
+
258
+ # Changes to the table will trigger notifications
259
+ db.create("person", { "name" => "Alice" })
260
+
261
+ # Stop the live query
262
+ db.kill(live_id)
263
+ end
80
264
  ```
81
265
 
82
- #### `delete_all`
83
- Delete all records from a table. Takes a string as the table name to delete records from. Returns `nil`.
266
+ ## SurrealDB Types
267
+
268
+ The SDK provides Ruby types that map to SurrealDB's type system:
269
+
84
270
  ```ruby
85
- client.delete_all("test")
86
- # => nil
271
+ # RecordID
272
+ rid = SurrealDB::RecordID.new("person", "alice")
273
+ rid = SurrealDB::RecordID.parse("person:alice")
274
+ rid.table # => "person"
275
+ rid.id # => "alice"
276
+
277
+ # Table
278
+ table = SurrealDB::Table.new("person")
279
+
280
+ # Duration
281
+ duration = SurrealDB::Duration.parse("1h30m")
282
+ duration.secs # => 5400
283
+ duration.to_f # => 5400.0
284
+
285
+ # None (distinct from nil/NULL)
286
+ SurrealDB::NONE
287
+
288
+ # Geometry
289
+ point = SurrealDB::GeometryPoint.new(-122.4194, 37.7749)
290
+ line = SurrealDB::GeometryLine.new(point1, point2)
291
+ polygon = SurrealDB::GeometryPolygon.new(exterior_ring)
292
+
293
+ # Range
294
+ range = SurrealDB::Range.new(
295
+ SurrealDB::BoundIncluded.new(1),
296
+ SurrealDB::BoundExcluded.new(10)
297
+ )
87
298
  ```
88
299
 
89
- #### `delete_one`
90
- Delete a record from a table. Takes a string as the table name to delete a record from, and an id of any type. Returns `nil`.
300
+ ## Error Handling
301
+
91
302
  ```ruby
92
- client.delete_one("test", 1)
93
- # => nil
303
+ begin
304
+ db.query("INVALID SYNTAX")
305
+ rescue SurrealDB::QueryError => e
306
+ puts "Query failed: #{e.message}"
307
+ rescue SurrealDB::NotFoundError => e
308
+ puts "Not found: #{e.message}"
309
+ rescue SurrealDB::NotAllowedError => e
310
+ puts "Permission denied: #{e.message}"
311
+ rescue SurrealDB::ServerError => e
312
+ # Catch-all for server errors
313
+ puts "Server error (#{e.kind}): #{e.message}"
314
+ puts "Cause: #{e.server_cause.message}" if e.server_cause
315
+ rescue SurrealDB::ConnectionError => e
316
+ puts "Connection lost: #{e.message}"
317
+ rescue SurrealDB::TimeoutError => e
318
+ puts "Request timed out: #{e.message}"
319
+ end
94
320
  ```
95
321
 
96
- ## Development
322
+ ## Configuration
97
323
 
98
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
324
+ ```ruby
325
+ SurrealDB.configure do |config|
326
+ config.timeout = 60 # seconds (default: 30)
327
+ config.logger = Logger.new($stdout)
328
+ end
99
329
 
100
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
330
+ # Per-connection timeout
331
+ client = SurrealDB::Client.new("ws://localhost:8000", timeout: 10)
332
+ ```
101
333
 
102
334
  ## Contributing
103
335
 
104
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/surrealdb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/surrealdb/blob/master/CODE_OF_CONDUCT.md).
336
+ 1. Fork the repository
337
+ 2. Create your feature branch (`git checkout -b feature/my-feature`)
338
+ 3. Run the tests (`bundle exec rspec`)
339
+ 4. Run the linter (`bundle exec rubocop`)
340
+ 5. Commit your changes
341
+ 6. Push to the branch
342
+ 7. Create a Pull Request
343
+
344
+ ### Running Integration Tests
105
345
 
346
+ Integration tests require a running SurrealDB instance:
347
+
348
+ ```bash
349
+ docker run --rm -p 8000:8000 surrealdb/surrealdb:latest start --user root --pass root --allow-all
350
+ bundle exec rspec spec/integration
351
+ ```
106
352
 
107
- ## Code of Conduct
353
+ ## Links
108
354
 
109
- Everyone interacting in the Surrealdb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sam-kenney/surrealdb.rb/blob/main/CODE_OF_CONDUCT.md).
355
+ - [SurrealDB Documentation](https://surrealdb.com/docs)
356
+ - [SurrealDB Ruby SDK Docs](https://surrealdb.com/docs/sdk/ruby)
357
+ - [API Reference](https://rubydoc.info/gems/surrealdb)
358
+ - [GitHub Issues](https://github.com/surrealdb/surrealdb.rb/issues)
359
+ - [Discord](https://discord.gg/surrealdb)