Sergiusz

Sergiusz

Would anyone else like to see a driver for TypeDB?

Hello everyone,

I don’t know if my post is appropriate. If it isn’t, you can delete it.

After a year of designing and defining the requirements of a web application (interactive dictionary of the languages ​​Hebrew, Aramaic, Latin, Greek, Sanskrit, English, German, Spanish and French, I have found that their interconnections and similarities in phonetic sounds and the numerical values ​​of the letters connects them with each other) Elixir/Phoenix is ​​chosen to accompany us on this journey. Finding the right database was much more difficult, but I still found something that met my criteria.

This database is called TypeDB, but unfortunately it currently does not have a driver for Erlang.

Therefore, on the one hand, I would like to draw attention to this database, and on the other hand, I would like to ask the members of this group, if you like this database, to convince the TypeDB team to create a driver for Erlang.

The easiest way to do this is on github, e.g. B. through comments and likes under the following link:

https://github.com/typedb/typedb-driver/issues/586

First of all, I hope for your understanding of my contribution and am grateful for your support.

Most Liked

Sergiusz

Sergiusz

Hello,

TypeDB offers significant advantages over PostgreSQL, especially in scenarios that require complex knowledge representation, semantic modeling, and automated reasoning. Here are the key benefits of TypeDB:

Rich Schema Capabilities

  • Complex Entities and Relationships: TypeDB supports a rich schema model that allows for the representation of complex entities, attributes, and relationships, ideal for applications with intricate data interrelations.
  • Type Hierarchies: Supports type hierarchies and inheritance, simplifying the modeling and querying of hierarchical structures.
  • Reasoning Engine: The built-in reasoning engine can infer new data based on existing data and rules, enabling automated data augmentation and consistency checks.

Advanced Querying with TypeQL

  • Declarative Query Language: TypeQL, TypeDB’s query language, is designed for expressing complex queries and patterns effortlessly. It excels at handling multi-hop queries and graph traversals.
  • Pattern Matching: Graql’s expressive pattern matching simplifies querying complex relationships and constraints.

Graph-Based Storage

  • Efficient Relationship Handling: TypeDB’s underlying graph-based storage is optimized for managing complex relationships and interconnected data efficiently.
  • Optimized for Relationships: Excels in scenarios where relationships and their traversals are central, such as knowledge graphs and network analyses.

Automated Inference and Consistency

  • Automated Inference: The reasoning engine can automatically infer new facts and relationships from defined rules, providing powerful knowledge discovery and data enrichment.
  • Consistency Checks: Enforces data consistency and integrity through logical constraints and rules.

Ideal Use Cases

  • Knowledge Graphs: Perfect for building and querying complex knowledge graphs where relationships are essential.
  • Biological Data: Suitable for bioinformatics and domains requiring detailed modeling of complex systems.
  • AI and Machine Learning: Beneficial for AI applications needing rich, interconnected data representations.

I hope that I have highlighted the main advantages of TypeDB.

A good article to consider TypeDB versus SQL databases can be found here:

Best regards
Sergiusz

alexjpwalker

alexjpwalker

Hi. TypeDB engineer here!

Is this still something you’d be interested in seeing @Sergiusz ? Unfortunately my experience in Elixir and Erlang is zero, but as @jkwchui noted, the fastest way to build a new DB driver is by piggybacking on the Rust driver.

I’d imagine that, if you wanted an Erlang driver for TypeDB, one engineer with AI assistance could whip up something functional within days :slight_smile:

As an experiment, I asked AI to sketch the project keeping it high-level; this is what it came up with - I have no idea how accurate it is.

typedb_ex/
├── mix.exs
├── native/
│   └── typedb_ex_nif/
│       ├── Cargo.toml
│       └── src/lib.rs
└── lib/
    └── typedb_ex.ex
defp deps do
  [
    {:rustler, "~> 0.30"}
  ]
end

def project do
  [
    compilers: [:rustler] ++ Mix.compilers(),
    rustler_crates: rustler_crates()
  ]
end

defp rustler_crates do
  [
    typedb_ex_nif: [
      path: "native/typedb_ex_nif",
      mode: :release
    ]
  ]
end
[package]
name = "typedb_ex_nif"
version = "0.1.0"
edition = "2021"

[lib]
name = "typedb_ex_nif"
crate-type = ["cdylib"]

[dependencies]
rustler = "0.30"
typedb-driver = "2.28"  # Official TypeDB Rust driver
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
use rustler::{Env, Term, NifResult, ResourceArc};
use typedb_driver::{DatabaseManager, Session, Transaction, TypeDBDriver, Driver, SessionType, TransactionType};
use std::sync::Mutex;

rustler::init!("Elixir.TypeDBEx.Nif", [connect, query]);

struct DriverResource {
    driver: Mutex<TypeDBDriver>,
}

#[rustler::nif]
fn connect<'a>(env: Env<'a>, address: String) -> NifResult<Term<'a>> {
    let driver = TypeDBDriver::new(address).map_err(|e| rustler::Error::Atom("connection_failed"))?;
    let resource = ResourceArc::new(DriverResource { driver: Mutex::new(driver) });
    Ok(resource.to_term(env))
}

#[rustler::nif(schedule = "DirtyCpu")]
fn query<'a>(
    env: Env<'a>,
    driver_res: ResourceArc<DriverResource>,
    database: String,
    query_str: String,
) -> NifResult<Term<'a>> {
    let driver = driver_res.driver.lock().unwrap();

    let databases = DatabaseManager::new(&driver);
    let session = Session::new(&databases, &database, SessionType::Data)
        .map_err(|_| rustler::Error::Atom("session_failed"))?;

    let mut tx = session
        .transaction(TransactionType::Read)
        .map_err(|_| rustler::Error::Atom("tx_failed"))?;

    let answers = tx
        .query(&query_str)
        .map_err(|_| rustler::Error::Atom("query_failed"))?;

    let mut results = vec![];
    for answer in answers {
        results.push(format!("{:?}", answer)); // Simplified
    }

    Ok(results.to_term(env))
}
defmodule TypeDBEx do
  use Rustler, otp_app: :typedb_ex, crate: "typedb_ex_nif"

  def connect(_address), do: :erlang.nif_error(:nif_not_loaded)
  def query(_driver, _db, _query), do: :erlang.nif_error(:nif_not_loaded)

  # High-level wrapper
  def with_connection(address, fun) do
    {:ok, driver} = connect(address)
    try do
      fun.(driver)
    after
      # Close driver (add close/1 NIF if needed)
    end
  end

  def run_query(driver, db, query) do
    query(driver, db, query)
  end
end
{:ok, driver} = TypeDBEx.connect("localhost:1729")

result = TypeDBEx.run_query(driver, "my_db", "match $x isa person, has name $n; get $n;")

IO.inspect(result)
# => ["name: \"Alice\"", "name: \"Bob\""]
dimitarvp

dimitarvp

I took a quick look at TypeDB but couldn’t get what are the very clear advantages compared to e.g. PostgreSQL?

jkwchui

jkwchui

TypeDB provides a Rust driver. Binding a Rust NIF via Rustler is probably a better approach. This will not require the TypeDB devs to maintain one more driver indefinitely (big ask), and there are probably people here that have that skill.

D4no0

D4no0

For me that would be an argument to not use it :joy: .

I’m also positive that you will not be able to integrate it with Ecto, the de-facto tool we use for database interactions in our apps, and building another “ORM” from scratch would be a huge time investment.

Where Next?

Popular in Discussions Top

artimath
I think I’ve tried 5 different graph database libraries in the last two days and not a single one has been able to connect to a remote/lo...
New
fklement
This is a thread to gather some information about the efforts of using elixir in combination with cars or vehicular systems in general. ...
New
AstonJ
A recent chat with @leifericf inspired this thread - he’s worked in the gaming industry, and so it got me wondering what kind of industri...
New
sym_num
I created a Forth processor in Elixir. This is my hobby project. https://github.com/sasagawa888/Forth
New
fireproofsocks
I’m not a Lambda fan-boy because I think it’s overprescribed as a cure-all for every possible problem when in reality, Lambdas are best s...
New
garrison
The Elixir ecosystem is one of our biggest strengths, and the BEAM really lends itself to native implementations (e.g. Cachex over Redis,...
New
BigTom
With Phoenix, Liveview, Ash, Oban Web, Nx, Livebook, Beacon, Liveview Native, Flame, Nerves etc all getting mature, are there any major g...
New
AstonJ
@Garrison’s comment in another thread reminded me of this post by Joe: With the big five exerting more control than ever, new (AI) play...
New
dogweather
I’ve been brainstorming about ways to solve the N-dimensional code organization problem, and am thinking about developing a Smalltalk-lik...
New
PragTob
:wave: I’m currently extracting the statistics calculation part from benchee and stumbled upon how to present error conditions. In the c...
New

Other popular topics Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

We're in Beta

About us Mission Statement