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

adamu
When starting a new project, do you have any go-to libraries you pull in out of habit/preference? For example, Ash, Credo, Mox, ExMachin...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
thiagomajesk
I came across this PKGX tool the other day, if anyone here is using it, could you share your experience? I’m wondering how useful it wou...
New
James_E
I see that the current ExUnit source code has support for rich failure messages on a small whitelist of “recognized” assertion patterns, ...
New
fredwu
Hey folks, Just wanted to share my journey and experiences so far. Preface: I’ve been using Elixir for about 10 years now, so relatively...
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
stevensonmt
Has anyone else ever wanted to merge two maps, but have the resulting map only include keys common to both maps? I think of it as analogo...
New
bartblast
Added by a user on X: https://x.com/aldicodes/status/1952095492139299036
New
New
chrisliaw
Hi, I’m wondering is it my thinking process or this is the norm among the Elixir developer for the use of Struct and accessor functions ...
New

Other popular topics Top

aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement