tricoredb 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 735d173a09ff6f3b5251bbade94d449f563aad10257266b7aaa6e15030ad2fe8
4
+ data.tar.gz: 93d4dc22f7e1c09b0617d1826b5f7037a4c4313b58afd6c2493216dde1714161
5
+ SHA512:
6
+ metadata.gz: f55362c4d3caaec273f45bd09861a2ae5f3e6b47707914009828a20fc6be04d3a75e22fa5f6febe8857b4b106420dfe0ad7498b2fee00fbd92455ef8f6d4fda3
7
+ data.tar.gz: 88df99ed1634d7c5eacd010861dbc72bf690d96500e282d2daa89d35a46249151e9d66eaa8003f2a75460e84f558dadff235b369cb9bd20a07bbafc043fc499f
data/CHANGELOG.md ADDED
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ All notable changes to the `tricoredb` gem are recorded here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the gem uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-09-16
10
+
11
+ First release.
12
+
13
+ ### Added
14
+
15
+ - `TriCoreDB::Client`: the native `tricore` wire protocol over TCP or TLS, with
16
+ HELLO feature negotiation and password authentication. Ruby 3.1 and later, and
17
+ nothing outside the standard library.
18
+ - SQL: `query` and `execute` with `?` placeholders bound **by the server**, plus
19
+ one-request scripts (`transaction`) and session transactions
20
+ (`begin_transaction`, `commit`, `rollback`).
21
+ - `TriCoreDB::Pool`: a thread-safe pool that lends a connection to a block and never
22
+ returns one with a transaction still open.
23
+ - Families for documents, cache (keys, lists, sets, hashes, streams), vectors,
24
+ graphs, LLM context export and the admin reads.
25
+ - Builders for filters, aggregation stages, accumulators and LLM sources, so the
26
+ request JSON is never written by hand.
27
+ - Typed failures under `TriCoreDB::Error`, each carrying the server's own `code`;
28
+ `redirect?` and `leader_hint` for a `not_leader` refusal.
29
+ - `TriCoreDB::Binary` for values bound to a `BLOB` column, whatever the String's
30
+ encoding.
31
+
32
+ ### Security
33
+
34
+ - A call that needs a capability the server did not grant — server-side parameters,
35
+ session transactions — raises `FeatureNotGranted` before anything is sent, rather
36
+ than falling back to a weaker behaviour.
37
+ - Both directions enforce the protocol's frame ceilings, and a declared length is
38
+ checked before a payload byte is read, so a wrong or hostile peer cannot make the
39
+ driver allocate what it claimed.
40
+ - A connection that timed out or lost frame alignment is dropped rather than reused:
41
+ a late reply can never be read as the answer to the next request.
42
+ - A value with no SQL form is refused by name instead of being pushed through
43
+ `to_s`, and text that is not valid UTF-8 is refused rather than sent as mojibake.
44
+
45
+ [Unreleased]: https://github.com/trinesh14/tricoredb-sdk-ruby/compare/v0.1.0...HEAD
46
+ [0.1.0]: https://github.com/trinesh14/tricoredb-sdk-ruby/releases/tag/v0.1.0
data/LICENSE ADDED
@@ -0,0 +1,201 @@
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 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 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 those 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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 TriCoreDB Authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,377 @@
1
+ # tricoredb
2
+
3
+ Official Ruby client for [TriCoreDB](https://hub.docker.com/r/trinesh14/tricoredb):
4
+ SQL, documents, vectors, graphs and cache over one native connection.
5
+
6
+ [![Gem Version](https://img.shields.io/gem/v/tricoredb?logo=rubygems&label=gem&color=blue&cacheSeconds=1800)](https://rubygems.org/gems/tricoredb)
7
+ [![Downloads](https://img.shields.io/gem/dt/tricoredb?label=downloads&color=blue&cacheSeconds=1800)](https://rubygems.org/gems/tricoredb)
8
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue?cacheSeconds=86400)](LICENSE)
9
+
10
+ - **No dependencies** beyond the Ruby standard library.
11
+ - **Server-side parameters.** Values never become part of the SQL text.
12
+ - **Typed errors** you rescue by class and branch on by code.
13
+ - **Transactions, a thread-safe pool, TLS and mutual TLS.**
14
+
15
+ ## Contents
16
+
17
+ - [Requirements](#requirements)
18
+ - [Installation](#installation)
19
+ - [Running a server](#running-a-server)
20
+ - [Quick start](#quick-start)
21
+ - [Connecting](#connecting)
22
+ - [SQL](#sql)
23
+ - [Transactions](#transactions)
24
+ - [Connection pool](#connection-pool)
25
+ - [Cache](#cache)
26
+ - [Documents](#documents)
27
+ - [Vectors](#vectors)
28
+ - [Graphs](#graphs)
29
+ - [LLM context](#llm-context)
30
+ - [Admin](#admin)
31
+ - [Errors](#errors)
32
+ - [TLS](#tls)
33
+ - [Testing](#testing)
34
+
35
+ ## Requirements
36
+
37
+ - Ruby **3.1** or later
38
+ - A TriCoreDB server speaking protocol 1.0 (`tricore-server` 0.1.0-rc.1 or later).
39
+ See [Running a server](#running-a-server).
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ gem install tricoredb
45
+ ```
46
+
47
+ Or in a Gemfile:
48
+
49
+ ```ruby
50
+ gem "tricoredb"
51
+ ```
52
+
53
+ ## Running a server
54
+
55
+ The quickest way is the official Docker image,
56
+ [`trinesh14/tricoredb`](https://hub.docker.com/r/trinesh14/tricoredb).
57
+
58
+ **Local development** (no TLS and no encryption, for this machine only). Set
59
+ `TRICORE_ADMIN_PASSWORD` in your shell first. Then create the admin and start the
60
+ server:
61
+
62
+ ```bash
63
+ docker run --rm -v tricoredb-dev:/var/lib/tricoredb -e TRICORE_ADMIN_PASSWORD --entrypoint /usr/local/bin/tricore trinesh14/tricoredb:0.1.0-rc.1-r2 auth init-admin --user admin --password-env TRICORE_ADMIN_PASSWORD --data-dir /var/lib/tricoredb/data
64
+ docker run -d --name tricoredb-dev -p 127.0.0.1:8427:8427 -e TRICORE_TLS=off -e TRICORE_ENCRYPTION=off -e TRICORE_MODULES=all -v tricoredb-dev:/var/lib/tricoredb trinesh14/tricoredb:0.1.0-rc.1-r2
65
+ ```
66
+
67
+ **Anything else:** by default the image runs with **TLS on** and an **encrypted data
68
+ volume**. Follow the quick start on the
69
+ [Docker Hub page](https://hub.docker.com/r/trinesh14/tricoredb) to create the
70
+ certificate and key, then connect with [TLS](#tls).
71
+
72
+ `TRICORE_MODULES=all` enables every data model. The image's default is `sql`,
73
+ `document` and `cache`; a call to a disabled model raises `TriCoreDB::ServerError`
74
+ whose `code` is `engine.disabled`.
75
+
76
+ ## Quick start
77
+
78
+ ```ruby
79
+ require "tricoredb"
80
+
81
+ db = TriCoreDB::Client.connect(host: "127.0.0.1", port: 8427, user: "admin", secret: "your-password")
82
+
83
+ db.execute("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY, name TEXT)")
84
+ db.execute("INSERT INTO users VALUES (?, ?)", [1, "O'Hara"])
85
+
86
+ rows = db.query("SELECT id, name FROM users WHERE id = ?", [1])
87
+ rows.first # => ["1", "O'Hara"]
88
+ rows.to_hashes # => [{"id" => "1", "name" => "O'Hara"}]
89
+
90
+ db.cache_set("sessions", "u1", "token")
91
+ db.cache_get("sessions", "u1") # => "token", or nil on a miss
92
+
93
+ db.close
94
+ ```
95
+
96
+ ## Connecting
97
+
98
+ `TriCoreDB::Client.connect` opens one authenticated connection.
99
+
100
+ | Keyword | Default | Meaning |
101
+ | --- | --- | --- |
102
+ | `host` | `"127.0.0.1"` | Server host |
103
+ | `port` | `8427` | Server port |
104
+ | `user` | `nil` | Principal to authenticate as; `nil` skips authentication |
105
+ | `secret` | `""` | Password or token |
106
+ | `database` | `"main"` | Database named in every request |
107
+ | `connect_timeout` | `10` | Seconds allowed for the connect, TLS and handshake |
108
+ | `read_timeout` | `nil` | Seconds allowed for each reply |
109
+ | `request_timeout_ms` | `nil` | Server-side deadline stamped on each request |
110
+ | `tls` | `nil` | See [TLS](#tls) |
111
+ | `client_name` | `"tricoredb-ruby/<version>"` | Name reported in the handshake |
112
+ | `features` | every capability | Bitmap announced in the handshake |
113
+
114
+ A connection is a single request/response stream, so one connection serves one
115
+ thread. For concurrent work use a [pool](#connection-pool).
116
+
117
+ ## SQL
118
+
119
+ `query` runs only `SELECT`. `execute` runs everything else. The server enforces the
120
+ split: a write sent through `query` is refused.
121
+
122
+ ```ruby
123
+ db.execute("INSERT INTO users VALUES (?, ?)", [2, "ada"])
124
+ rows = db.query("SELECT id, name FROM users")
125
+
126
+ rows.size # => 2
127
+ rows.each { |row| puts row.inspect }
128
+ rows.to_hashes # rows keyed by column name
129
+ ```
130
+
131
+ Placeholders are bound **on the server**: the values travel next to the statement,
132
+ so a value can never be read as SQL syntax, however it is spelled. How a Ruby value
133
+ goes out:
134
+
135
+ | Ruby value | Sent as |
136
+ | --- | --- |
137
+ | `nil`, `true`, `false` | themselves |
138
+ | `Integer` | an exact number, Bignum included |
139
+ | `Float` | a number; `NaN` and infinities are refused |
140
+ | `BigDecimal` | plain digits, no exponent — for `DECIMAL` |
141
+ | `String` (UTF-8) | text; invalid UTF-8 is refused |
142
+ | `String` (ASCII-8BIT) or `TriCoreDB::Binary` | `0x`-prefixed hex, for `BLOB` |
143
+ | `Time`, `Date`, `DateTime` | ISO-8601 text |
144
+
145
+ Anything else is refused by name rather than pushed through `to_s`:
146
+
147
+ ```ruby
148
+ db.execute("INSERT INTO files VALUES (?, ?)", [1, TriCoreDB::Binary.new(File.binread("a.png"))])
149
+ db.execute("INSERT INTO t VALUES (?)", [[1, 2]]) # raises TriCoreDB::ParameterError
150
+ ```
151
+
152
+ Binding needs the `SERVER_PARAMS` capability, agreed in the handshake
153
+ (`db.features[:server_params]`). Against a server that did not grant it, a call with
154
+ parameters raises `TriCoreDB::FeatureNotGranted` **before anything is sent** — it
155
+ never falls back to pasting values into the statement text.
156
+
157
+ ## Transactions
158
+
159
+ `transaction` sends a whole `BEGIN … COMMIT` script in **one request**, and rolls
160
+ back if the block raises:
161
+
162
+ ```ruby
163
+ db.transaction do
164
+ db.execute("UPDATE accounts SET balance = balance - ? WHERE id = ?", [10, 1])
165
+ db.execute("UPDATE accounts SET balance = balance + ? WHERE id = ?", [10, 2])
166
+ end
167
+ ```
168
+
169
+ `begin_transaction`, `commit` and `rollback` keep a transaction open **across
170
+ requests on this connection**, so a later statement can depend on what an earlier
171
+ one read. They need the `SESSION_TXN` capability; without it `begin_transaction`
172
+ raises by name rather than running each statement on its own.
173
+
174
+ ```ruby
175
+ db.begin_transaction
176
+ begin
177
+ db.execute("INSERT INTO t VALUES (?, ?)", [1, "ada"])
178
+ db.commit
179
+ rescue StandardError
180
+ db.rollback
181
+ raise
182
+ end
183
+ ```
184
+
185
+ The transaction belongs to this connection: another connection cannot commit it, and
186
+ a dropped socket rolls it back. `db.in_transaction?` says whether one is open.
187
+
188
+ ## Connection pool
189
+
190
+ ```ruby
191
+ pool = TriCoreDB::Pool.new(size: 8, host: "db.internal", user: "admin", secret: "your-password")
192
+
193
+ threads = 8.times.map do |i|
194
+ Thread.new { pool.with { |db| db.execute("INSERT INTO users VALUES (?, ?)", [i, "grace"]) } }
195
+ end
196
+ threads.each(&:join)
197
+
198
+ pool.stats # => {size: 8, created: 8, idle: 8, in_use: 0, waiting: 0}
199
+ pool.close
200
+ ```
201
+
202
+ `pool.with` lends a connection for the duration of the block. A connection is never
203
+ returned with a transaction still open, and a broken one is retired rather than
204
+ handed to the next caller. When every connection is busy, a caller waits up to
205
+ `checkout_timeout` seconds and then gets `TriCoreDB::PoolTimeout` — the pool never
206
+ grows past `size`.
207
+
208
+ ## Cache
209
+
210
+ Values are byte strings. `nil` is a miss, which is how a miss is told apart from a
211
+ stored empty value.
212
+
213
+ ```ruby
214
+ db.cache_set("sessions", "u1", "token")
215
+ db.cache_set("sessions", "u2", "token", ttl_ms: 30_000)
216
+ db.cache_get("sessions", "u1") # => "token" | nil
217
+
218
+ db.cache_incr("counters", "hits")
219
+ db.cache_rpush("queue", "jobs", %w[a b])
220
+ db.cache_sadd("tags", "post:1", %w[ruby db])
221
+ db.cache_hset("user:1", "profile", [%w[name ada]])
222
+ id = db.cache_xadd("events", "log", [%w[msg hi]])
223
+ ```
224
+
225
+ | Family | Methods |
226
+ | --- | --- |
227
+ | Keys | `cache_get`, `cache_set`, `cache_set_nx`, `cache_delete`, `cache_exists?`, `cache_ttl`, `cache_expire`, `cache_persist`, `cache_incr`, `cache_keys`, `cache_clear_namespace`, `cache_ping` |
228
+ | Lists | `cache_lpush`, `cache_rpush`, `cache_lpop`, `cache_rpop`, `cache_lrange`, `cache_llen`, `cache_lindex` |
229
+ | Sets | `cache_sadd`, `cache_srem`, `cache_sismember?`, `cache_scard`, `cache_smembers` |
230
+ | Hashes | `cache_hset`, `cache_hget`, `cache_hdel`, `cache_hgetall`, `cache_hexists?`, `cache_hlen` |
231
+ | Streams | `cache_xadd`, `cache_xlen`, `cache_xrange`, `cache_xread`, `cache_xdel`, `cache_xtrim` |
232
+
233
+ ## Documents
234
+
235
+ Filters and pipeline stages are built with `TriCoreDB::Filter`, `TriCoreDB::Stage`
236
+ and `TriCoreDB::Acc`, so the request JSON is never written by hand.
237
+
238
+ ```ruby
239
+ db.doc_create_collection("products")
240
+ id = db.doc_insert("products", { "name" => "widget", "price" => 9 })
241
+ db.doc_find("products", TriCoreDB::Filter.gt("price", 5))
242
+ db.doc_update_one("products", id, inc: { "price" => 1 })
243
+
244
+ totals = db.doc_aggregate("orders", [
245
+ TriCoreDB::Stage.match(TriCoreDB::Filter.eq("status", "paid")),
246
+ TriCoreDB::Stage.group(TriCoreDB::Stage.by_field("customer"), [TriCoreDB::Acc.sum("total", "amount")]),
247
+ TriCoreDB::Stage.sort([["total", true]]),
248
+ TriCoreDB::Stage.limit(10)
249
+ ])
250
+ ```
251
+
252
+ Also available: `doc_get`, `doc_update`, `doc_update_many`, `doc_delete`,
253
+ `doc_list_collections`, `doc_drop_collection`, `doc_create_index`, `doc_drop_index`,
254
+ `doc_list_indexes` and `doc_analyze`.
255
+
256
+ ## Vectors
257
+
258
+ ```ruby
259
+ db.vector_create_collection("embeddings", 3, metric: "cosine")
260
+ db.vector_upsert("embeddings", "a", [0.1, 0.2, 0.3], metadata: { "kind" => "doc" })
261
+
262
+ hits = db.vector_search("embeddings", [0.1, 0.2, 0.3], 5)
263
+ hits.first["id"] # the nearest vector comes first
264
+ hits.first["score"]
265
+
266
+ db.vector_search("embeddings", [0.1, 0.2, 0.3], 5, filter: { "kind" => "doc" })
267
+ ```
268
+
269
+ The score is a **similarity**: higher is closer under every metric. L2 is the case
270
+ worth knowing — the server negates the squared distance, so an L2 score is `<= 0`
271
+ and `-0.02` is nearer than `-196.0`.
272
+
273
+ ## Graphs
274
+
275
+ ```ruby
276
+ db.graph_create("social")
277
+ db.graph_add_node("social", "u1", labels: ["User"], properties: { "name" => "ada" })
278
+ db.graph_add_node("social", "u2", labels: ["User"])
279
+ db.graph_add_edge("social", "e1", "u1", "u2", "FOLLOWS")
280
+
281
+ db.graph_neighbors("social", "u1")
282
+ path = db.graph_shortest_path("social", "u1", "u2")
283
+ path["found"] # => true
284
+ path["node_path"] # => ["u1", "u2"]
285
+ ```
286
+
287
+ "No path" comes back as `found => false`, not as an error. Also available:
288
+ `graph_get_node`, `graph_get_edge`, `graph_delete_node`, `graph_delete_edge`,
289
+ `graph_list`, `graph_drop`, `graph_traverse`, `graph_weighted_shortest_path`,
290
+ `graph_degree`, `graph_list_nodes`, `graph_list_edges` and `graph_query` for the
291
+ read-only Cypher subset.
292
+
293
+ ## LLM context
294
+
295
+ ```ruby
296
+ bundle = db.llm_context([
297
+ TriCoreDB::LlmSource.sql("SELECT id, name FROM users"),
298
+ TriCoreDB::LlmSource.documents("products", limit: 50)
299
+ ], format: "toon")
300
+
301
+ schema = db.llm_schema(format: "markdown")
302
+ ```
303
+
304
+ Sensitive fields are redacted by default (`redact_sensitive: true`).
305
+
306
+ ## Admin
307
+
308
+ ```ruby
309
+ db.admin_ping
310
+ db.admin_status
311
+ ```
312
+
313
+ Admin calls need the cluster module enabled on the server, even on a single node.
314
+ `db.ping` checks the connection itself and reaches no module.
315
+
316
+ ## Errors
317
+
318
+ Every failure is a `TriCoreDB::Error`. Rescue the class you mean, and branch on
319
+ `code` rather than on the message text:
320
+
321
+ | Class | Means |
322
+ | --- | --- |
323
+ | `ServerError` | The request arrived and the operation failed. The connection stays usable. |
324
+ | `AuthError` | The credentials were refused. |
325
+ | `ProtocolError` | An ERROR frame, or a peer that broke the protocol. |
326
+ | `ConnectionError` | The transport failed, or the connection was already closed. |
327
+ | `ReadTimeout` | No reply in time; the connection is dropped, because the late reply must not be read as the next answer. |
328
+ | `FeatureNotGranted` | The server lacks a capability this call needs, so nothing was sent. |
329
+ | `ParameterError` | A value with no SQL form; nothing was sent. |
330
+ | `PoolTimeout` | No pooled connection became free in time. |
331
+
332
+ **Leader redirects.** In a cluster, a write that reaches a follower fails with
333
+ `code == "not_leader"`, which `error.redirect?` and `response.redirect?` test. When
334
+ the cluster knows the leader, `leader_hint` holds its `host:port`; a `nil` hint means
335
+ the destination is unknown yet, so wait and retry — it does not mean the failure was
336
+ something else. This driver does not follow the redirect for you.
337
+
338
+ ```ruby
339
+ begin
340
+ db.execute("INSERT INTO t VALUES (1)")
341
+ rescue TriCoreDB::ServerError => e
342
+ raise unless e.code == TriCoreDB::NOT_LEADER
343
+ retry_against(e.leader_hint) if e.leader_hint
344
+ end
345
+ ```
346
+
347
+ ## TLS
348
+
349
+ TLS is off until `tls:` is given.
350
+
351
+ ```ruby
352
+ db = TriCoreDB::Client.connect(
353
+ host: "db.internal", user: "admin", secret: "your-password",
354
+ tls: { ca_file: "/etc/tricore/ca.pem", server_name: "db.internal" }
355
+ )
356
+ ```
357
+
358
+ `tls: true` uses the system trust store. The options are `ca_file`, `server_name`,
359
+ `client_cert_file` and `client_key_file` (both or neither, for mutual TLS), and
360
+ `danger_accept_invalid_certs` — **development only**, since it encrypts the traffic
361
+ while authenticating nobody.
362
+
363
+ ## Testing
364
+
365
+ ```bash
366
+ rake test # unit tests and the scripted-peer tests; no server needed
367
+ rake test:integration # the live tests, against a private tricore-server
368
+ ```
369
+
370
+ The scripted-peer tests play the answers a real cluster would send — a `not_leader`
371
+ refusal, a refused handshake, a frame that declares more bytes than it sends — so
372
+ they need no server. The live tests start their own `tricore-server` on an ephemeral
373
+ port: point `TRICORE_SERVER_BIN` at the binary, and without one they skip.
374
+
375
+ ## License
376
+
377
+ [Apache License 2.0](LICENSE)