Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oakfang/thothd
https://github.com/oakfang/thothd
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/oakfang/thothd
- Owner: oakfang
- Created: 2016-04-24T10:15:40.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-24T10:26:18.000Z (almost 9 years ago)
- Last Synced: 2024-11-09T18:19:21.718Z (3 months ago)
- Language: Elixir
- Size: 2.93 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Thoth Server
Run the [Thoth](https://github.com/oakfang/thoth) DB as a TCP server.
## Installation
- Git clone
- `mix deps.get` from project dir## Usage
Run `mix run --no-halt` from the project directory. This starts an instance running on port `4040`.
### Connect to DB
Send `USE ` to the server.
### Load models
Send `REQUIRE ` where the absolute path is a path to an elixir file that defines models.
Models should `derive` both Thoth.Model (a must) and Poison.Encoder (increased performance).### Do stuff!
From here on, just send Elixir code over the wire, using `graph` as the global representing the instance.
Example:
```elixir
Thoth.Query.query(
graph,
:alex_russell,
[:friends, :friends]
) |> Enum.reduce(%{}, fn vid, acc -> Map.put(acc, vid, Thoth.Entities.get_vertex(graph, vid)) end)
```## Sample client
A simple python client can be written as such:
```python
from socket import socket
from json import loadsclass Thoth(object):
def __init__(self, host='localhost', port=4040):
self.conn = socket()
self.conn.connect((host, port))def use(self, db_path):
self.conn.send('USE {}'.format(db_path))
assert self.conn.recv(4096) == 'OK'def require(self, path):
self.conn.send('REQUIRE {}'.format(path))
assert self.conn.recv(4096) == 'OK'def execute(self, command):
self.conn.send(command)
return loads(self.conn.recv(4096))
```