satori-db / satori-client
PHP client for Satori database
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/satori-db/satori-client
Requires
- php: >=7.4
- textalk/websocket: ^1.5
This package is auto-updated.
Last update: 2025-12-16 21:15:41 UTC
README
This library allows you to easily and efficiently interact with the Satori database via WebSockets, supporting CRUD operations, real-time notifications, advanced queries, and graph-like relations.
β¨ Main Features
- Ultra-fast CRUD operations β‘
- Advanced queries using
field_arrayπ - Real-time notifications π’
- Graph-like relations (vertices and references) πΈοΈ
- Data encryption and decryption π
π Installation
Install the required dependencies (for example, using Composer):
composer require textalk/websocket
Copy the Satori.php file to your project and make sure Composer's autoload is configured.
π Basic Usage
require_once 'vendor/autoload.php'; require_once 'Satori.php'; use Satori\Satori; $client = new Satori('ws://localhost:8000', 'username', 'password'); $client->connect();
ποΈ CRUD Operations
Create Data
$client->set([ 'key' => 'user:123', 'data' => ['name' => 'John', 'email' => 'john@example.com'], 'type' => 'user' ]);
Read Data
$user = $client->get(['key' => 'user:123']);
Modify a Field
$client->put([ 'key' => 'user:123', 'replace_field' => 'name', 'replace_value' => 'Peter' ]);
Delete Data
$client->delete(['key' => 'user:123']);
π§© Advanced Queries with field_array π
You can perform operations on multiple objects that meet certain conditions using the field_array field:
$results = $client->get([ 'field_array' => [ ['field' => 'email', 'value' => 'john@example.com'] ] ]);
field_arrayis an array of conditions['field' => ..., 'value' => ...].- You can combine it with
'one' => trueto get only the first matching result.
π Real-time Notifications
Receive automatic updates when an object changes:
$client->notify('user:123', function($data) { echo "User updated!\n"; print_r($data); });
πΈοΈ Relations and Graphs
You can create relationships between objects (vertices):
$client->setVertex([ 'key' => 'user:123', 'vertex' => 'friend:456', 'relation' => 'friend', 'encryption_key' => 'secret' ]);
And traverse the graph with DFS:
$client->dfs(['node' => 'user:123', 'encryption_key' => 'secret']);
Get all neighbors of an object:
$client->getVertex([ 'key' => 'user:123', 'encryption_key' => 'secret', 'relation' => 'friends' ]);
Remove a specific neighbor:
$client->deleteVertex([ 'key' => 'user:123', 'vertex' => 'user:512', 'encryption_key' => 'secret' ]);
π Encryption and Security
Easily encrypt and decrypt data:
$client->encrypt(['key' => 'user:123', 'encryption_key' => 'secret']); $client->decrypt(['key' => 'user:123', 'encryption_key' => 'secret']);
π¦ Array Manipulation Methods
Below are the available methods to manipulate arrays in the Satori database using the PHP client:
πΉ push
Adds a value to an existing array in an object.
$client->push(['key' => 'user:123', 'array' => 'friends', 'value' => 'user:456']);
- key: Object key.
- array: Name of the array.
- value: Value to add.
πΉ pop
Removes the last element from an array in an object.
$client->pop(['key' => 'user:123', 'array' => 'friends']);
- key: Object key.
- array: Name of the array.
πΉ splice
Modifies an array in an object (for example, to cut or replace elements).
$client->splice(['key' => 'user:123', 'array' => 'friends']);
- key: Object key.
- array: Name of the array.
πΉ remove
Removes a specific value from an array in an object.
$client->remove(['key' => 'user:123', 'array' => 'friends', 'value' => 'user:456']);
- key: Object key.
- array: Name of the array.
- value: Value to remove.
π€ AI Methods
Satori has AI features integrated that boost developers productivity. By example you can train an embedding model with your data and use it wherever you want to. You can train your embedding model manually whenever you want to but Satori will automatically fine-tune your model with any new updates and use this updated model for all emebedding operations.
πΉ train
Train an embedding model with your data. The model will be at the root of your db in the satori_semantic_model folder
$client->train();
πΉ ann
Perform an Aproximate Nearest Neighbors search
$client->ann(['key' => 'user:123', 'top_k' => '5']);
- key: Source object key.
- top_k: Number of nearest neighbors to return
πΉ query
Make querys in natural language
$client->query(['query' => 'Insert the value 5 into the grades array of user:123', 'backend' => 'openai:gpt-4o-mini']);
- query: Your query in natural language.
- ref: The LLM backend. Must be
openai:model-nameorollama:model-name, if not specifiedopenai:gpt-4o-miniwill be used as default. If you're using OpenAI as your backend you must specify theOPENAI_API_KEYenv variable.
πΉ ask
Ask question about your data in natural language
$client->query(['question' => 'How many user over 25 years old do we have. Just return the number.', 'backend' => 'openai:gpt-4o-mini']);
- question: Your question in natural language.
- ref: The LLM backend. Must be
openai:model-nameorollama:model-name, if not specifiedopenai:gpt-4o-miniwill be used as default. If you're using OpenAI as your backend you must specify theOPENAI_API_KEYenv variable.
π Schema Class (Data Model)
You can use the Schema class to model your data in an object-oriented way:
use Satori\Satori; use Satori\Schema; $satori = new Satori("username", "password", "ws://localhost:1234"); $satori->connect(); $user = new Schema($satori, "user", ["name" => "Anna"], "my_key"); $user->set();
It includes useful methods such as:
-
set,delete,encrypt,decrypt,set_vertex,get_vertex,delete_vertex,dfs -
Reference methods:
set_ref,get_refs,delete_refs -
Array methods:
push,pop,splice,remove
π Complete Example
use Satori\Satori; $client = new Satori('username', 'password', 'ws://localhost:8000'); $client->connect(); $client->set([ 'key' => 'user:1', 'data' => ['name' => 'Carlos', 'age' => 30], 'type' => 'user' ]); $client->notify('user:1', function($data) { echo "Real-time update: "; print_r($data); });
π§ Key Concepts
- key: Unique identifier of the object.
- type: Object type (e.g., 'user').
- field_array: Advanced filters for bulk operations.
- notifications: Subscription to real-time changes.
- vertices: Graph-like relationships between objects.
Responses
All responses obbey the following pattern:
{ data: any //the requested data if any message: string //status message type: string //SUCCESS || ERROR }
AI responses obbey a different patern:
ask
{ response: string //response to the question }
query
{ result: string //response from the operation made in the db status: string //status }
ann
{ results: array //response from the operation made in the db }
π¬ Questions or Suggestions?
Feel free to open an issue or contribute! With β€οΈ from the Satori team.